Skip to content

Commit

Permalink
refactor(cli): use a unified type across all CLI generators
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetanmaisse committed May 17, 2020
1 parent cb149f6 commit ffa1522
Show file tree
Hide file tree
Showing 22 changed files with 82 additions and 63 deletions.
5 changes: 0 additions & 5 deletions lib/cli/src/GeneratorOptions.ts

This file was deleted.

6 changes: 4 additions & 2 deletions lib/cli/src/generators/ANGULAR/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator, GeneratorOptions } from '../Generator';

async function addDependencies(npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) {
const packages = [
Expand Down Expand Up @@ -64,7 +64,7 @@ function editAngularAppTsConfig() {
writeFileAsJson(getAngularAppTsConfigPath(), tsConfigJson);
}

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
if (!isDefaultProjectSet()) {
throw new Error(
'Could not find a default project in your Angular workspace.\nSet a defaultProject in your angular.json and re-run the installation.'
Expand All @@ -77,3 +77,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
editAngularAppTsConfig();
editStorybookTsConfig(path.resolve('./.storybook/tsconfig.json'));
};

export default generator;
11 changes: 4 additions & 7 deletions lib/cli/src/generators/AURELIA/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
copyTemplate,
readFileAsJson,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';
import { StoryFormat } from '../../project_types';

function addStorybookExcludeGlobToTsConfig() {
Expand All @@ -27,11 +26,7 @@ function addStorybookExcludeGlobToTsConfig() {
tsConfigJson.exclude = [...exclude, glob];
writeFileAsJson('tsconfig.json', tsConfigJson);
}

export default async (
npmOptions: NpmOptions,
{ storyFormat = StoryFormat.CSF }: GeneratorOptions
) => {
const generator: Generator = async (npmOptions, { storyFormat = StoryFormat.CSF }) => {
copyTemplate(__dirname, storyFormat);
const packages = [
'@storybook/aurelia',
Expand Down Expand Up @@ -62,3 +57,5 @@ export default async (
const babelDependencies = await getBabelDependencies(npmOptions, packageJson);
installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/EMBER/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [
storybookVersion,
babelPluginEmberModulePolyfillVersion,
Expand Down Expand Up @@ -58,3 +57,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
...babelDependencies,
]);
};

export default generator;
8 changes: 8 additions & 0 deletions lib/cli/src/generators/Generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NpmOptions } from '../NpmOptions';
import { StoryFormat } from '../project_types';

export type GeneratorOptions = {
storyFormat: StoryFormat;
};

export type Generator = (npmOptions: NpmOptions, options: GeneratorOptions) => Promise<void>;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/HTML/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
copyTemplate,
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const packages = ['@storybook/html', '@storybook/addon-actions', '@storybook/addon-links'];

const versionedPackages = await getVersionedPackages(npmOptions, ...packages);
Expand All @@ -35,3 +34,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
6 changes: 4 additions & 2 deletions lib/cli/src/generators/MARIONETTE/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
installDependencies,
retrievePackageJson,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions) => {
const generator: Generator = async (npmOptions) => {
const storybookVersion = await getVersion(npmOptions, '@storybook/marionette');
fse.copySync(path.resolve(__dirname, 'template/'), '.', { overwrite: true });

Expand All @@ -31,3 +31,5 @@ export default async (npmOptions: NpmOptions) => {
...babelDependencies,
]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/MARKO/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [storybookVersion, addonActionVersion, addonKnobsVersion] = await getVersions(
npmOptions,
'@storybook/marko',
Expand Down Expand Up @@ -39,3 +38,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
...babelDependencies,
]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/METEOR/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [
storybookVersion,
actionsVersion,
Expand Down Expand Up @@ -96,3 +95,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...devDependencies, ...babelDependencies]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/MITHRIL/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [
storybookVersion,
actionsVersion,
Expand Down Expand Up @@ -49,3 +48,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
...babelDependencies,
]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/PREACT/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [storybookVersion, actionsVersion, linksVersion, addonsVersion] = await getVersions(
npmOptions,
'@storybook/preact',
Expand Down Expand Up @@ -41,3 +40,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
...babelDependencies,
]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/RAX/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [
storybookVersion,
actionsVersion,
Expand Down Expand Up @@ -59,3 +58,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
...babelDependencies,
]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/REACT/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
copyTemplate,
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const packages = [
'@storybook/react',
'@storybook/addon-actions',
Expand Down Expand Up @@ -40,3 +39,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
2 changes: 1 addition & 1 deletion lib/cli/src/generators/REACT_NATIVE/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { GeneratorOptions } from '../Generator';

export default async (
npmOptions: NpmOptions,
Expand Down
7 changes: 4 additions & 3 deletions lib/cli/src/generators/REACT_SCRIPTS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import {
copyTemplate,
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const packages = [
'@storybook/react',
'@storybook/preset-create-react-app',
Expand Down Expand Up @@ -50,3 +49,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/RIOT/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [
storybookVersion,
actionsVersion,
Expand Down Expand Up @@ -54,3 +53,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...dependencies, ...babelDependencies]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/SFC_VUE/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
copyTemplate,
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const packages = [
'@storybook/vue',
'@storybook/addon-actions',
Expand Down Expand Up @@ -39,3 +38,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/SVELTE/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
installDependencies,
copyTemplate,
} from '../../helpers';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const [
storybookVersion,
actionsVersion,
Expand Down Expand Up @@ -52,3 +51,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
...babelDependencies,
]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/VUE/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import {
copyTemplate,
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const packages = [
'@storybook/vue',
'@storybook/addon-actions',
Expand Down Expand Up @@ -59,3 +58,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)
// see: https://github.com/storybookjs/storybook/issues/4475#issuecomment-432141296
installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/WEB-COMPONENTS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
installDependencies,
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const packages = [
'@storybook/web-components',
'@storybook/addon-actions',
Expand Down Expand Up @@ -42,3 +41,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
7 changes: 4 additions & 3 deletions lib/cli/src/generators/WEBPACK_REACT/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
copyTemplate,
} from '../../helpers';
import { StoryFormat } from '../../project_types';
import { NpmOptions } from '../../NpmOptions';
import { GeneratorOptions } from '../../GeneratorOptions';
import { Generator } from '../Generator';

export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions) => {
const generator: Generator = async (npmOptions, { storyFormat }) => {
const packages = [
'@storybook/react',
'@storybook/addon-actions',
Expand Down Expand Up @@ -39,3 +38,5 @@ export default async (npmOptions: NpmOptions, { storyFormat }: GeneratorOptions)

installDependencies({ ...npmOptions, packageJson }, [...versionedPackages, ...babelDependencies]);
};

export default generator;
2 changes: 1 addition & 1 deletion lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const installStorybook = (projectType: ProjectType, options: CommandOptions): Pr
.then(end);

case ProjectType.MARIONETTE:
return marionetteGenerator(npmOptions)
return marionetteGenerator(npmOptions, generatorOptions)
.then(commandLog('Adding storybook support to your "Marionette.js" app'))
.then(end);

Expand Down

0 comments on commit ffa1522

Please sign in to comment.