Skip to content

Commit

Permalink
Support Server in cli generator - fixes #12077
Browse files Browse the repository at this point in the history
  • Loading branch information
jonspalmer committed Feb 20, 2021
1 parent bbade61 commit 7cf5c72
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/cli/src/generators/SERVER/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fse from 'fs-extra';
import { baseGenerator, Generator } from '../baseGenerator';

const generator: Generator = async (packageManager, npmOptions, options) => {
const prefix = fse.existsSync('./src') ? '../src' : '../stories';
const stories = [`${prefix}/**/*.stories.json`];

baseGenerator(packageManager, npmOptions, options, 'server', {
addComponents: false,
configureOptions: { stories },
});
};

export default generator;
5 changes: 4 additions & 1 deletion lib/cli/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface FrameworkOptions {
addComponents?: boolean;
addBabel?: boolean;
addESLint?: boolean;
configureOptions?: any;
}

export type Generator = (
Expand All @@ -33,6 +34,7 @@ const defaultOptions: FrameworkOptions = {
addComponents: true,
addBabel: true,
addESLint: false,
configureOptions: {},
};

export async function baseGenerator(
Expand All @@ -50,6 +52,7 @@ export async function baseGenerator(
addComponents,
addBabel,
addESLint,
configureOptions,
} = {
...defaultOptions,
...options,
Expand Down Expand Up @@ -81,7 +84,7 @@ export async function baseGenerator(

const versionedPackages = await packageManager.getVersionedPackages(...packages);

configure(framework, [...addons, ...extraAddons]);
configure(framework, [...addons, ...extraAddons], configureOptions);
if (addComponents) {
copyComponents(framework, language);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import riotGenerator from './generators/RIOT';
import preactGenerator from './generators/PREACT';
import svelteGenerator from './generators/SVELTE';
import raxGenerator from './generators/RAX';
import serverGenerator from './generators/SERVER';
import { warn } from './warn';
import { JsPackageManagerFactory, readPackageJson } from './js-package-manager';
import { NpmOptions } from './NpmOptions';
Expand Down Expand Up @@ -228,6 +229,11 @@ const installStorybook = (projectType: ProjectType, options: CommandOptions): Pr
.then(commandLog('Adding Storybook support to your "Aurelia" app'))
.then(end);

case ProjectType.SERVER:
return serverGenerator(packageManager, npmOptions, generatorOptions)
.then(commandLog('Adding Storybook support to your "Server" app'))
.then(end);

case ProjectType.UNSUPPORTED:
paddedLog(`We detected a project type that we don't support yet.`);
paddedLog(
Expand Down
4 changes: 3 additions & 1 deletion lib/cli/src/project_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export type SupportedFrameworks =
| 'rax'
| 'aurelia'
| 'html'
| 'web-components';
| 'web-components'
| 'server';

export enum ProjectType {
UNDETECTED = 'UNDETECTED',
Expand Down Expand Up @@ -56,6 +57,7 @@ export enum ProjectType {
SVELTE = 'SVELTE',
RAX = 'RAX',
AURELIA = 'AURELIA',
SERVER = 'SERVER',
}

export const SUPPORTED_FRAMEWORKS: SupportedFrameworks[] = [
Expand Down

0 comments on commit 7cf5c72

Please sign in to comment.