@@ -4,51 +4,76 @@ const path = require('path');
44const fs = require ( 'fs' ) ;
55const sh = require ( 'shelljs' ) ;
66const JSON5 = require ( 'json5' ) ;
7+ const latestVersion = require ( 'latest-version' ) ;
78
8- mergeDirs ( path . resolve ( __dirname , 'template/' ) , '.' , 'overwrite' ) ;
9-
10- const packageJson = helpers . getPackageJson ( ) ;
11- packageJson . devDependencies = packageJson . devDependencies || { } ;
12- packageJson . scripts = packageJson . scripts || { } ;
13- packageJson . dependencies = packageJson . dependencies || { } ;
14-
15- // create or update .babelrc
16- let babelrc = null ;
17- if ( fs . existsSync ( '.babelrc' ) ) {
18- const babelrcContent = fs . readFileSync ( '.babelrc' , 'utf8' ) ;
19- babelrc = JSON5 . parse ( babelrcContent ) ;
20- babelrc . plugins = babelrc . plugins || [ ] ;
21-
22- if ( babelrc . plugins . indexOf ( 'babel-root-slash-import' ) < 0 ) {
23- babelrc . plugins . push ( 'babel-root-slash-import' ) ;
24- packageJson . devDependencies [ 'babel-root-slash-import' ] = '^1.1.0' ;
25- }
26- } else {
27- babelrc = {
28- presets : [ 'es2015' , 'es2016' , 'react' , 'stage-1' ] ,
29- plugins : [ 'babel-root-slash-import' ] ,
30- } ;
31-
32- packageJson . devDependencies [ 'babel-preset-es2015' ] = '^6.9.0' ;
33- packageJson . devDependencies [ 'babel-preset-es2016' ] = '^6.11.3' ;
34- packageJson . devDependencies [ 'babel-preset-react' ] = '^6.11.1' ;
35- packageJson . devDependencies [ 'babel-preset-stage-1' ] = '^6.13.0' ;
36- packageJson . devDependencies [ 'babel-root-slash-import' ] = '^1.1.0' ;
37- }
38-
39- fs . writeFileSync ( '.babelrc' , JSON . stringify ( babelrc , null , 2 ) , 'utf8' ) ;
40-
41- // write the new package.json.
42- packageJson . devDependencies [ '@storybook/react' ] = '^2.21.0' ;
43- packageJson . scripts [ 'storybook' ] = 'start-storybook -p 6006' ;
44- packageJson . scripts [ 'build-storybook' ] = 'build-storybook' ;
45-
46- // add react packages.
47- if ( ! packageJson . dependencies . react ) {
48- packageJson . dependencies . react = '^15.3.0' ;
49- }
50- if ( ! packageJson . dependencies [ 'react-dom' ] ) {
51- packageJson . dependencies [ 'react-dom' ] = '^15.3.0' ;
52- }
53-
54- helpers . writePackageJson ( packageJson ) ;
9+ module . exports = Promise . all ( [
10+ latestVersion ( '@storybook/react' ) ,
11+ latestVersion ( 'react' ) ,
12+ latestVersion ( 'react-dom' ) ,
13+ latestVersion ( 'babel-preset-es2015' ) ,
14+ latestVersion ( 'babel-preset-es2016' ) ,
15+ latestVersion ( 'babel-preset-react' ) ,
16+ latestVersion ( 'babel-preset-stage-1' ) ,
17+ latestVersion ( 'babel-root-slash-import' ) ,
18+ ] ) . then (
19+ (
20+ [
21+ storybookVersion ,
22+ reactVersion ,
23+ reactDomVersion ,
24+ presetEs2015Version ,
25+ presetEs2016Version ,
26+ presetReactVersion ,
27+ presetStage1Version ,
28+ rootSlashImportVersion ,
29+ ] ,
30+ ) => {
31+ mergeDirs ( path . resolve ( __dirname , 'template/' ) , '.' , 'overwrite' ) ;
32+
33+ const packageJson = helpers . getPackageJson ( ) ;
34+ packageJson . devDependencies = packageJson . devDependencies || { } ;
35+ packageJson . scripts = packageJson . scripts || { } ;
36+ packageJson . dependencies = packageJson . dependencies || { } ;
37+
38+ // create or update .babelrc
39+ let babelrc = null ;
40+ if ( fs . existsSync ( '.babelrc' ) ) {
41+ const babelrcContent = fs . readFileSync ( '.babelrc' , 'utf8' ) ;
42+ babelrc = JSON5 . parse ( babelrcContent ) ;
43+ babelrc . plugins = babelrc . plugins || [ ] ;
44+
45+ if ( babelrc . plugins . indexOf ( 'babel-root-slash-import' ) < 0 ) {
46+ babelrc . plugins . push ( 'babel-root-slash-import' ) ;
47+ packageJson . devDependencies [ 'babel-root-slash-import' ] = `^${ rootSlashImportVersion } ` ;
48+ }
49+ } else {
50+ babelrc = {
51+ presets : [ 'es2015' , 'es2016' , 'react' , 'stage-1' ] ,
52+ plugins : [ 'babel-root-slash-import' ] ,
53+ } ;
54+
55+ packageJson . devDependencies [ 'babel-preset-es2015' ] = `^${ presetEs2015Version } ` ;
56+ packageJson . devDependencies [ 'babel-preset-es2016' ] = `^${ presetEs2016Version } ` ;
57+ packageJson . devDependencies [ 'babel-preset-react' ] = `^${ presetReactVersion } ` ;
58+ packageJson . devDependencies [ 'babel-preset-stage-1' ] = `^${ presetStage1Version } ` ;
59+ packageJson . devDependencies [ 'babel-root-slash-import' ] = `^${ rootSlashImportVersion } ` ;
60+ }
61+
62+ fs . writeFileSync ( '.babelrc' , JSON . stringify ( babelrc , null , 2 ) , 'utf8' ) ;
63+
64+ // write the new package.json.
65+ packageJson . devDependencies [ '@storybook/react' ] = `^${ storybookVersion } ` ;
66+ packageJson . scripts [ 'storybook' ] = 'start-storybook -p 6006' ;
67+ packageJson . scripts [ 'build-storybook' ] = 'build-storybook' ;
68+
69+ // add react packages.
70+ if ( ! packageJson . dependencies . react ) {
71+ packageJson . dependencies . react = `^${ reactVersion } ` ;
72+ }
73+ if ( ! packageJson . dependencies [ 'react-dom' ] ) {
74+ packageJson . dependencies [ 'react-dom' ] = `^${ reactDomVersion } ` ;
75+ }
76+
77+ helpers . writePackageJson ( packageJson ) ;
78+ } ,
79+ ) ;
0 commit comments