2018-07-04 23:12:47 +03:00

62 lines
2.0 KiB
JavaScript

import mergeDirs from 'merge-dirs';
import path from 'path';
import { getVersions, getPackageJson, writePackageJson } from '../../lib/helpers';
export default async npmOptions => {
const [
storybookVersion,
actionsVersion,
linksVersion,
addonsVersion,
babelCoreVersion,
babelRuntimeVersion,
propTypesVersion,
] = await getVersions(
npmOptions,
'@storybook/react-native',
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addons',
'@babel/core',
'@babel/runtime',
'prop-types'
);
// copy all files from the template directory to project directory
mergeDirs(path.resolve(__dirname, 'template/'), '.', 'overwrite');
const packageJson = getPackageJson();
packageJson.dependencies = packageJson.dependencies || {};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies['@storybook/react-native'] = storybookVersion;
packageJson.devDependencies['@storybook/addon-actions'] = actionsVersion;
packageJson.devDependencies['@storybook/addon-links'] = linksVersion;
packageJson.devDependencies['@storybook/addons'] = addonsVersion;
if (!packageJson.dependencies['@babel/core'] && !packageJson.devDependencies['@babel/core']) {
packageJson.devDependencies['@babel/core'] = babelCoreVersion;
}
if (
!packageJson.dependencies['@babel/runtime'] &&
!packageJson.devDependencies['babel-runtime']
) {
packageJson.devDependencies['@babel/runtime'] = babelRuntimeVersion;
}
if (!packageJson.dependencies['react-dom'] && !packageJson.devDependencies['react-dom']) {
const reactVersion = packageJson.dependencies.react;
packageJson.devDependencies['react-dom'] = reactVersion;
}
if (!packageJson.dependencies['prop-types'] && !packageJson.devDependencies['prop-types']) {
packageJson.devDependencies['prop-types'] = propTypesVersion;
}
packageJson.scripts = packageJson.scripts || {};
packageJson.scripts.storybook = 'storybook start -p 7007';
writePackageJson(packageJson);
};