mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-05 16:11:33 +08:00
Added few comments in template. Only notifies about not found app name if you use React Native Vanilla.
79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
import mergeDirs from 'merge-dirs';
|
|
import path from 'path';
|
|
import shell from 'shelljs';
|
|
import chalk from 'chalk';
|
|
import { getVersions, getPackageJson, writePackageJson, paddedLog } 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');
|
|
|
|
// set correct project name on entry files if possible
|
|
const dirname = shell.ls('-d', 'ios/*.xcodeproj').stdout;
|
|
|
|
// Only notify about app name if running in React Native vanilla (Expo projects do not have ios directory)
|
|
if (dirname) {
|
|
const projectName =
|
|
dirname && dirname.slice('ios/'.length, dirname.length - '.xcodeproj'.length - 1);
|
|
if (projectName) {
|
|
shell.sed('-i', '%APP_NAME%', projectName, 'storybook/storybook.js');
|
|
} else {
|
|
paddedLog(
|
|
chalk.red(
|
|
'ERR: Could not determine project name, to fix: https://github.com/storybooks/storybook/issues/1277'
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
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';
|
|
|
|
writePackageJson(packageJson);
|
|
};
|