This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
112 lines (103 loc) · 2.54 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const inquirer = require('inquirer');
const { addHuskyHooksToPackageJSON } = require('./setup/add-husky-hooks-to-package-json');
const { addReactSnapToPackageJSON } = require('./setup/add-react-snap-to-package-json');
const { deleteSetupFiles } = require('./setup/delete-setup-files');
const { addSass } = require('./setup/add-sass');
const { replaceName } = require('./setup/replace-name');
const { runCliCommand } = require('./setup/helpers');
const {
checkForMinNodeVersion,
} = require('./setup/helpers')
checkForMinNodeVersion(12);
inquirer.prompt([
{
type: 'input',
name: 'projectName',
message: 'Please enter your project name:',
validate: function (value) {
if (value.trim().length === 0) {
return 'Project name is required';
}
return true;
},
},
{
type: 'list',
name: 'addSASS',
message: 'Do you want to add SASS support?',
choices: ['Yes', 'No'],
filter: function (val) {
return val === 'Yes';
},
},
{
type: 'list',
name: 'reactSnap',
message: 'Do you want to add react-snap?',
choices: ['Yes', 'No'],
filter: function (val) {
return val === 'Yes';
},
},
{
type: 'list',
name: 'addGitHooks',
message: 'Do you want to add git hooks?',
choices: ['Yes', 'No'],
filter: function (val) {
return val === 'Yes';
},
},
{
type: 'list',
name: 'deleteSetupFiles',
message: 'Do you want to delete setup files?',
choices: ['Yes', 'No'],
filter: function (val) {
return val === 'Yes';
},
},
])
.then(answers => {
console.log('\n');
console.log(answers);
inquirer.prompt([
{
type: 'list',
name: 'everythingOk',
message: `Looks OK?`,
choices: ['Yes', 'No'],
filter: function (val) {
return val === 'Yes';
},
},
])
.then(async confirmAnswer => {
if (confirmAnswer.everythingOk) {
try {
replaceName(answers.projectName);
// SASS
if (answers.addSASS) {
await addSass();
}
// React snap
if (answers.reactSnap) {
await addReactSnapToPackageJSON();
}
// Hooks
if (answers.addGitHooks) {
await addHuskyHooksToPackageJSON();
}
// Delete files
if (answers.deleteSetupFiles) {
deleteSetupFiles();
}
} catch(e) {
console.log(e);
runCliCommand('git', ['checkout', '.']);
}
} else {
console.log(`\n★★ Nothing changed, run script to try that again\n`);
}
});
});