This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·56 lines (52 loc) · 2.15 KB
/
index.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
#!/usr/bin/env node
const program = require('commander');
const { prompt } = require('inquirer');
const CONSTANTS = require('./modules/constants');
const hydrateTemplates = require('./modules/hydrateTemplates');
const exportTemplates = require('./modules/exportTemplates');
const readAnswers = require('./modules/readAnswers');
const readTemplates = require('./modules/readTemplates');
const saveAnswers = require('./modules/saveAnswers');
program.version('2.0.0').description('Customizable redux reducer and action boilerplate');
program
.option('-t, --typescript', 'generate as typescript')
.option('-s, --save', 'save your answers for being even faster')
.option('-e, --export', 'export the default templates')
.description('Generate reducer')
.action(() => {
const preSavedAnswers = readAnswers();
const overrideTemplates = readTemplates(CONSTANTS.overrideTemplatesPath);
const questions = preSavedAnswers ? [CONSTANTS.defaultQuestions[0]] : CONSTANTS.defaultQuestions;
if (!!program.export) {
exportTemplates(!!program.typescript);
} else {
prompt(questions)
.then(answers =>
hydrateTemplates(
preSavedAnswers ? { ...answers, ...preSavedAnswers } : answers,
!!program.typescript,
overrideTemplates
)
)
.then(answers => {
if (!!program.save) {
saveAnswers(answers);
}
})
.then(() => {
console.log('*******************************************');
console.log('Thanks for using rdxgen! For help -> https://github.com/onerzafer/rdxgen');
const chance = Math.random();
if (chance <= 0.5) {
console.log('Hint: -s or --save will save your answers. You will be faster next time. 😉');
} else {
console.log('Hint: -e or --export will export the default templates. You can create your own boilerplate with them. 😉');
}
console.log('\n');
console.log("Here's a potato!");
console.log('🥔');
console.log('*******************************************');
});
}
});
program.parse(process.argv);