diff --git a/lib/cli/src/generators/METEOR/index.ts b/lib/cli/src/generators/METEOR/index.ts index 95ae01834906..852f4e29bc04 100644 --- a/lib/cli/src/generators/METEOR/index.ts +++ b/lib/cli/src/generators/METEOR/index.ts @@ -1,43 +1,12 @@ import fs from 'fs'; import JSON5 from 'json5'; -import { getBabelDependencies, copyTemplate } from '../../helpers'; -import { Generator } from '../Generator'; -import { writePackageJson } from '../../js-package-manager'; +import { baseGenerator, Generator } from '../generator'; -const generator: Generator = async (packageManager, npmOptions, { storyFormat }) => { - const [ - storybookVersion, - actionsVersion, - linksVersion, - knobsVersion, - addonsVersion, - reactVersion, - reactDomVersion, - presetEnvVersion, - presetReactVersion, - ] = await packageManager.getVersions( - '@storybook/react', - '@storybook/addon-actions', - '@storybook/addon-links', - '@storybook/addon-knobs', - '@storybook/addons', - 'react', - 'react-dom', - '@babel/preset-env', - '@babel/preset-react' - ); - - copyTemplate(__dirname, storyFormat); - - const packageJson = packageManager.retrievePackageJson(); - - const devDependencies = [ - `@storybook/react@${storybookVersion}`, - `@storybook/addon-actions@${actionsVersion}`, - `@storybook/addon-links@${linksVersion}`, - `@storybook/addon-knobs@${knobsVersion}`, - `@storybook/addons@${addonsVersion}`, - ]; +const generator: Generator = async (packageManager, npmOptions, options) => { + baseGenerator(packageManager, npmOptions, options, 'react', { + extraPackages: ['react', 'react-dom', '@babel/preset-env', '@babel/preset-react'], + staticDir: 'dist', + }); // create or update .babelrc let babelrc = null; @@ -52,39 +21,9 @@ const generator: Generator = async (packageManager, npmOptions, { storyFormat }) '@babel/preset-react', ], }; - - devDependencies.push(`@babel/preset-env@${presetEnvVersion}`); - devDependencies.push(`@babel/preset-react@${presetReactVersion}`); } fs.writeFileSync('.babelrc', JSON.stringify(babelrc, null, 2), 'utf8'); - - writePackageJson(packageJson); - - const babelDependencies = await getBabelDependencies(packageManager, packageJson); - - // add react packages. - const dependencies = []; - if (!packageJson.dependencies.react) { - dependencies.push(`react@${reactVersion}`); - } - if (!packageJson.dependencies['react-dom']) { - dependencies.push(`react-dom@${reactDomVersion}`); - } - - if (dependencies.length > 0) { - packageManager.addDependencies( - { ...npmOptions, packageJson, installAsDevDependencies: false }, - dependencies - ); - } - - packageManager.addDependencies({ ...npmOptions, packageJson }, [ - ...devDependencies, - ...babelDependencies, - ]); - - packageManager.addStorybookCommandInScripts(); }; export default generator; diff --git a/lib/cli/src/generators/METEOR/template-csf/.storybook/main.js b/lib/cli/src/generators/METEOR/template-csf/.storybook/main.js deleted file mode 100644 index c6a06f1fbc34..000000000000 --- a/lib/cli/src/generators/METEOR/template-csf/.storybook/main.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - stories: ['../stories/**/*.stories.js'], - addons: ['@storybook/addon-actions', '@storybook/addon-knobs'], -}; diff --git a/lib/cli/src/generators/METEOR/template-csf/stories/0-Welcome.stories.js b/lib/cli/src/generators/METEOR/template-csf/stories/0-Welcome.stories.js deleted file mode 100644 index 9920a416e1ff..000000000000 --- a/lib/cli/src/generators/METEOR/template-csf/stories/0-Welcome.stories.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import { linkTo } from '@storybook/addon-links'; -import { Welcome } from '@storybook/react/demo'; - -export default { - title: 'Welcome', - component: Welcome, -}; - -export const ToStorybook = () => ; - -ToStorybook.storyName = 'to Storybook'; diff --git a/lib/cli/src/generators/METEOR/template-csf/stories/1-Button.stories.js b/lib/cli/src/generators/METEOR/template-csf/stories/1-Button.stories.js deleted file mode 100644 index 6bcfa2146627..000000000000 --- a/lib/cli/src/generators/METEOR/template-csf/stories/1-Button.stories.js +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react'; -import { action } from '@storybook/addon-actions'; -import { Button } from '@storybook/react/demo'; - -export default { - title: 'Button', - component: Button, -}; - -export const Text = () => ; - -export const Emoji = () => ( - -);