Skip to content

Commit 06e759b

Browse files
authored
Merge pull request #31 from devisle/multiple-package-install
Multiple package install
2 parents e659b12 + 61f2fee commit 06e759b

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

cliModel/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports.cliCommand = [
44
name: 'installation',
55
message: 'What would you like to install?',
66
choices: [
7+
'CustomPackageInstall',
78
'CreateReactApp',
89
'ReactComponent',
910
'ReactRouter',
@@ -15,6 +16,33 @@ module.exports.cliCommand = [
1516
}
1617
]
1718

19+
module.exports.multiplePackageInstall = [
20+
{
21+
type: 'checkbox',
22+
name: 'packages',
23+
message: 'Select packages for your new React Project: ',
24+
default: ['create-react-app'],
25+
pageSize: 9,
26+
choices: [
27+
'create-react-app',
28+
'react-router react-router-dom',
29+
'redux react-redux',
30+
'redux-thunk',
31+
'prop-types',
32+
'node-sass',
33+
'styled-components',
34+
'unstated',
35+
'unstated-next',
36+
'typescript',
37+
'@types/node',
38+
'@types/react-redux',
39+
'@types/react @types/react-dom',
40+
'@types/react-router @types/react-router-dom',
41+
'@types/jest'
42+
]
43+
}
44+
]
45+
1846
module.exports.installOption = [
1947
{
2048
type: 'list',
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const inquirer = require('inquirer')
2+
const customCMD = require('../../customNodeCMD')
3+
const errorLogging = require('../../customNodeCMD/customError')
4+
5+
// Cli Model
6+
const cliModel = require('../../cliModel')
7+
const multiplePackageInstall = cliModel.multiplePackageInstall
8+
const YarnOrNpm = cliModel.YarnOrNpm
9+
10+
const { createReactApp } = require('../../cliModel/install-commands')
11+
12+
const { createReactAppYarn } = require('../../cliModel/install-commands-yarn')
13+
14+
const prompt = inquirer.createPromptModule()
15+
16+
/*
17+
18+
Installs A React Application with Custom Packages
19+
20+
*/
21+
22+
module.exports = class CustomPackageInstall {
23+
prompt () {
24+
prompt(YarnOrNpm).then(({ packageManager }) => {
25+
prompt(multiplePackageInstall).then(({ packages }) => {
26+
if ([...packages].includes('create-react-app')) {
27+
packages.shift()
28+
packages.join(' ')
29+
switch (packageManager) {
30+
case 'Yarn':
31+
customCMD.get(
32+
`${createReactAppYarn} my-app && cd my-app && yarn add ${packages.join(
33+
' '
34+
)} `,
35+
(err, data, stderr) => {
36+
err ? console.log(err) : errorLogging(stderr, data)
37+
},
38+
'install'
39+
)
40+
break
41+
42+
case 'NPM':
43+
customCMD.get(
44+
`${createReactApp} my-app && cd my-app && npm install --save ${packages.join(
45+
' '
46+
)}`,
47+
(err, data, stderr) => {
48+
err ? console.log(err) : errorLogging(stderr, data)
49+
},
50+
'install'
51+
)
52+
}
53+
} else {
54+
switch (packageManager) {
55+
case 'Yarn':
56+
customCMD.get(
57+
`yarn add ${packages.join(' ')} `,
58+
(err, data, stderr) => {
59+
err ? console.log(err) : errorLogging(stderr, data)
60+
},
61+
'install'
62+
)
63+
break
64+
65+
case 'NPM':
66+
customCMD.get(
67+
`npm install --save ${packages.join(' ')}`,
68+
(err, data, stderr) => {
69+
err ? console.log(err) : errorLogging(stderr, data)
70+
},
71+
'install'
72+
)
73+
}
74+
}
75+
})
76+
})
77+
}
78+
}

options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ReactComponent = require('./cliRoutes/ReactComponent/mainReactComponent')
66
const PropTypes = require('./cliRoutes/propTypes')
77
const StateManagement = require('./cliRoutes/StateManagement/stateManagement')
88
const TypeScript = require('./cliRoutes/TypeScript/index')
9+
const CustomPackageInstall = require('./cliRoutes/CustomPackageInstall')
910

1011
module.exports = answers => {
1112
switch (answers.installation) {
@@ -36,6 +37,9 @@ module.exports = answers => {
3637
case 'TypeScript':
3738
new TypeScript().prompt()
3839
break
40+
case 'CustomPackageInstall':
41+
new CustomPackageInstall().prompt()
42+
break
3943

4044
default:
4145
console.log('You must select an option!')

0 commit comments

Comments
 (0)