Skip to content

Commit 6590bbb

Browse files
committed
set init install requared package
1 parent 8ca4fd2 commit 6590bbb

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

lib/getOptions.js renamed to lib/actions.js

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ const chalk = require('chalk');
66
const { upperFirst } = require('lodash');
77

88
const root = path.resolve(process.cwd());
9+
const checkPkgManager = pathExistsSync(
10+
path.resolve(process.cwd(), 'yarn.lock'),
11+
);
12+
13+
const usePkgManager = checkPkgManager ? 'yarn' : 'npm';
14+
15+
// yarn.cmd/npm.cmd run in windows
16+
const isWin = process.platform === 'win32';
917

1018
function getOptions(opts) {
1119
const { create, all } = opts;
@@ -59,23 +67,50 @@ function setInit() {
5967
const storyPath = path.normalize(`${__dirname}/..//.storybook`);
6068
prompt(initial).then((res) => {
6169
if (!res.init) return;
62-
copy(storyPath, `${root}\\src\\.storybook`, (err) => {
63-
if (err) console.log(err);
64-
console.log('success create dir /.storybook');
65-
});
70+
71+
const isYarn = [
72+
'add',
73+
'--dev',
74+
'@storybook/react',
75+
'@babel/core',
76+
'@storybook/addon-actions',
77+
'@storybook/addon-essentials',
78+
'babel-loader',
79+
];
80+
81+
const isNpm = [
82+
'install',
83+
'@storybook/react',
84+
'@babel/core',
85+
'@storybook/addon-actions',
86+
'@storybook/addon-essentials',
87+
'babel-loader',
88+
'--save-dev',
89+
];
90+
91+
copy(storyPath, `${root}\\src\\.storybook`)
92+
.then(() => {
93+
console.log('success build directory ./.storybook');
94+
console.log('waiting install dependencies...');
95+
96+
const getPkg = spawn(
97+
isWin ? `${usePkgManager}.cmd` : `${usePkgManager}`,
98+
checkPkgManager ? isYarn : isNpm,
99+
{ stdio: 'inherit' },
100+
);
101+
102+
getPkg.on('error', (err) => {
103+
console.error(err);
104+
process.exit(1);
105+
});
106+
})
107+
.catch((err) => {
108+
console.log(err);
109+
});
66110
});
67111
}
68112

69113
function runStorybook() {
70-
const checkPkgManager = pathExistsSync(
71-
path.resolve(process.cwd(), 'yarn.lock'),
72-
);
73-
74-
const usePkgManager = checkPkgManager ? 'yarn' : 'npm';
75-
76-
// yarn.cmd/npm.cmd run in windows
77-
const isWin = process.platform === 'win32';
78-
79114
const sb = spawn(
80115
isWin ? `${usePkgManager}.cmd` : `${usePkgManager}`,
81116
checkPkgManager ? ['start-storybook', '-p', '9001'] : ['run', 'storybook'],

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const program = require('commander');
22
const { version } = require('../package.json');
3-
const { getOptions, setInit, runStorybook } = require('./getOptions');
3+
const { getOptions, setInit, runStorybook } = require('./actions');
44

55
module.exports = (args) => {
66
program

src/.storybook/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
stories: ['../template/**/*.stories.@(js|mdx)'],
3+
addons: ['@storybook/addon-essentials']
4+
}

0 commit comments

Comments
 (0)