mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 05:21:06 +08:00
79 lines
2.0 KiB
JavaScript
79 lines
2.0 KiB
JavaScript
import mergeDirs from 'merge-dirs';
|
|
import path from 'path';
|
|
import {
|
|
editStorybookTsConfig,
|
|
getAngularAppTsConfigJson,
|
|
getAngularAppTsConfigPath,
|
|
} from './angular-helpers';
|
|
import {
|
|
getVersions,
|
|
getPackageJson,
|
|
writePackageJson,
|
|
getBabelDependencies,
|
|
installDependencies,
|
|
writeFileAsJson,
|
|
} from '../../lib/helpers';
|
|
|
|
async function addDependencies(npmOptions) {
|
|
const [
|
|
storybookVersion,
|
|
notesVersion,
|
|
actionsVersion,
|
|
linksVersion,
|
|
addonsVersion,
|
|
] = await getVersions(
|
|
npmOptions,
|
|
'@storybook/angular',
|
|
'@storybook/addon-notes',
|
|
'@storybook/addon-actions',
|
|
'@storybook/addon-links',
|
|
'@storybook/addons'
|
|
);
|
|
|
|
const packageJson = getPackageJson();
|
|
|
|
packageJson.dependencies = packageJson.dependencies || {};
|
|
packageJson.devDependencies = packageJson.devDependencies || {};
|
|
|
|
packageJson.scripts = packageJson.scripts || {};
|
|
packageJson.scripts.storybook = 'start-storybook -p 6006';
|
|
packageJson.scripts['build-storybook'] = 'build-storybook';
|
|
|
|
writePackageJson(packageJson);
|
|
|
|
const babelDependencies = await getBabelDependencies(npmOptions, packageJson);
|
|
|
|
installDependencies(npmOptions, [
|
|
`@storybook/angular@${storybookVersion}`,
|
|
`@storybook/addon-notes@${notesVersion}`,
|
|
`@storybook/addon-actions@${actionsVersion}`,
|
|
`@storybook/addon-links@${linksVersion}`,
|
|
`@storybook/addons@${addonsVersion}`,
|
|
...babelDependencies,
|
|
]);
|
|
}
|
|
|
|
function editAngularAppTsConfig() {
|
|
const tsConfigJson = getAngularAppTsConfigJson();
|
|
const glob = '**/*.stories.ts';
|
|
if (!tsConfigJson) {
|
|
return;
|
|
}
|
|
|
|
const { exclude = [] } = tsConfigJson;
|
|
if (exclude.includes(glob)) {
|
|
return;
|
|
}
|
|
|
|
tsConfigJson.exclude = [...exclude, glob];
|
|
writeFileAsJson(getAngularAppTsConfigPath(), tsConfigJson);
|
|
}
|
|
|
|
export default async npmOptions => {
|
|
mergeDirs(path.resolve(__dirname, 'template'), '.', 'overwrite');
|
|
|
|
await addDependencies(npmOptions);
|
|
editAngularAppTsConfig();
|
|
editStorybookTsConfig(path.resolve('./.storybook/tsconfig.json'));
|
|
};
|