11const inquirer = require ( 'inquirer' )
2- // const customCMD = require('../customNodeCMD');
3- // const errorLogging = require('../customNodeCMD/customError');
2+ const customCMD = require ( '../../ customNodeCMD' )
3+ const errorLogging = require ( '../../ customNodeCMD/customError' )
44
55// Cli Model
66const cliModel = require ( '../../cliModel' )
77const multiplePackageInstall = cliModel . multiplePackageInstall
8+ const installFolder = cliModel . installFolder
89const YarnOrNpm = cliModel . YarnOrNpm
910
10- const {
11- TypeScriptReactObj,
12- createReactApp,
13- nodeSassObj,
14- propTypesObj,
15- reactRouterObj,
16- reduxObj,
17- reduxThunkObj,
18- styledComponentsObj,
19- unstatedObj
20- } = require ( '../../cliModel/install-commands' )
21-
22- const {
23- TypeScriptReactObjYarn,
24- createReactAppYarn,
25- nodeSassObjYarn,
26- propTypesObjYarn,
27- reactRouterObjYarn,
28- reduxObjYarn,
29- reduxThunkObjYarn,
30- styledComponentsObjYarn,
31- unstatedObjYarn
32- } = require ( '../../cliModel/install-commands-yarn' )
11+ const { createReactApp } = require ( '../../cliModel/install-commands' )
12+
13+ const { createReactAppYarn } = require ( '../../cliModel/install-commands-yarn' )
3314
3415const prompt = inquirer . createPromptModule ( )
3516
@@ -41,8 +22,58 @@ const prompt = inquirer.createPromptModule()
4122
4223module . exports = class CustomPackageInstall {
4324 prompt ( ) {
44- prompt ( multiplePackageInstall ) . then ( ( { packages } ) => {
45- console . log ( packages )
25+ prompt ( YarnOrNpm ) . then ( ( { packageManager } ) => {
26+ prompt ( multiplePackageInstall ) . then ( ( { packages } ) => {
27+ if ( [ ...packages ] . includes ( 'create-react-app' ) ) {
28+ packages . shift ( )
29+ packages . join ( ' ' )
30+ switch ( packageManager ) {
31+ case 'Yarn' :
32+ customCMD . get (
33+ `${ createReactAppYarn } . && yarn add ${ packages . join ( ' ' ) } ` ,
34+ ( err , data , stderr ) => {
35+ err ? console . log ( err ) : errorLogging ( stderr , data )
36+ } ,
37+ 'install'
38+ )
39+ break
40+
41+ case 'NPM' :
42+ customCMD . get (
43+ `${ createReactApp } && npm install --save ${ packages . join ( ' ' ) } ` ,
44+ ( err , data , stderr ) => {
45+ err ? console . log ( err ) : errorLogging ( stderr , data )
46+ } ,
47+ 'install'
48+ )
49+ }
50+ } else {
51+ switch ( packageManager ) {
52+ case 'Yarn' :
53+ customCMD . get (
54+ `${ createReactAppYarn } . && yarn add ${ packages . join ( ' ' ) } ` ,
55+ ( err , data , stderr ) => {
56+ err ? console . log ( err ) : errorLogging ( stderr , data )
57+ } ,
58+ 'install'
59+ )
60+ break
61+
62+ case 'NPM' :
63+ customCMD . get (
64+ `${ createReactApp } && npm install --save ${ packages . join ( ' ' ) } ` ,
65+ ( err , data , stderr ) => {
66+ err ? console . log ( err ) : errorLogging ( stderr , data )
67+ } ,
68+ 'install'
69+ )
70+ }
71+ }
72+ console . log ( packages . shift ( ) )
73+ console . log ( packages . join ( ' ' ) )
74+ console . log ( packages . join ( ' ' ) )
75+ console . log ( `${ packages . join ( ' ' ) } ` )
76+ } )
4677 } )
4778 }
4879}
0 commit comments