-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-env.js
69 lines (61 loc) · 1.66 KB
/
gen-env.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
const inquirer = require('inquirer');
const fs = require('fs-extra');
const validateYN = (value) => {
const pass = value.match('y') || value.match('n');
if (pass) {
return true;
}
return 'Please enter y or n';
};
const generateShrc = () => {
const questions = [
{
type: 'input',
name: 'GENERATE_README',
message: 'Generate a readme with the new package created by apart? (y/n)',
validate: validateYN
},
{
type: 'input',
name: 'ADD_CHILD_DEPS',
message: 'Add dependencies to new package? (y/n)',
validate: validateYN
},
{
type: 'input',
name: 'ADD_NEW_DEP',
message: 'Automatically add the new package to the dependencies of current project? (y/n)',
validate: validateYN
},
{
type: 'input',
name: 'PUSH_TO_GITHUB',
message: "Push new repo to github? (y/n)",
validate: validateYN
},
{
type: 'input',
name: 'IS_PRIVATE',
message: 'Make new repo private (y/n)',
validate: validateYN
},
{
type: 'input',
name: 'DELETE_LOCAL_REPO',
message: 'Delete generated local folder for new package? (y/n)',
validate: validateYN
}
];
inquirer.prompt(questions).then(answers => {
let apartrc = Object.keys(answers).reduce((av, cv) => {
return {...av, [cv]: answers[cv] === 'y'}
}, {IS_APP: false});
fs.writeFile(`${__dirname}/.apartrc`, JSON.stringify(apartrc, null, '\t'), (err, success) => {
if (err) {
throw new Error(err);
}
console.log(apartrc)
});
});
};
fs.unlink(`${__dirname}/.apartrc`).then(ret => generateShrc()).catch(e => generateShrc());