Skip to content

Commit

Permalink
CLI: meteor
Browse files Browse the repository at this point in the history
  • Loading branch information
tooppaaa committed Jun 11, 2020
1 parent 082667e commit 4a6e31c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 101 deletions.
73 changes: 6 additions & 67 deletions lib/cli/src/generators/METEOR/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
4 changes: 0 additions & 4 deletions lib/cli/src/generators/METEOR/template-csf/.storybook/main.js

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 4a6e31c

Please sign in to comment.