-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
executable file
·93 lines (86 loc) · 3.07 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
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
#!/usr/bin/env node
'use strict';
const program = require('commander');
const chalk = require('chalk');
const createAllTemplates = require('./src/create-all-templates');
const applyConfig = require('./src/apply-config-file');
const DEFAULT_NAME = 'kebab-example-name';
const DEFAULT_COMPONENT_DIRECTORY = 'src/components';
const DEFAULT_REDUX_CORE_DIRECTORY = 'src/redux';
program
.option(
'-n, --name [name]',
`This is the lower kebab case name of the feature/component you would like to generate (e.g. ${DEFAULT_NAME}).`,
DEFAULT_NAME
)
.option(
'-d, --directory [directory]',
`This is the relative directory where the generated component will be placed (e.g ${DEFAULT_COMPONENT_DIRECTORY}).`,
DEFAULT_COMPONENT_DIRECTORY
)
.option(
'-N, --native [native]',
'If you wish to generate code for React-Native, add this parameter - else React web code will be generated.',
false
)
.option(
'-r, --redux [redux]',
'If you wish to generate Redux code in the duck pattern, add this parameter - else regular React code will be generated.',
false
)
.option(
'-o, --omit-comments [omitComments]',
'If you wish to hide the comments within the generated files, add this parameter - else descriptive comments will be left in the generated code.',
false
)
.option(
'-R, --redux-core [reduxCore]',
"If you would like to generate the Redux core files ('store', 'root-reducer', and 'action-utilities'), add this parameter. These files are used to connect your application with Redux.",
false
)
.option(
'-D, --redux-core-directory [reduxCoreDirectory]',
`This is the relative directory where the generated Redux core file will be placed (e.g ${DEFAULT_REDUX_CORE_DIRECTORY}). It is recommended to leave this as the default.`,
DEFAULT_REDUX_CORE_DIRECTORY
)
.parse(process.argv);
applyConfig(
program,
({
name,
directory,
native = false,
redux = false,
omitComments = false,
reduxCore = false,
reduxCoreDirectory
}) => {
console.log(
chalk.bold.underline.cyan('Parameters:'),
chalk.bold.magenta('\nname:\t\t\t'),
chalk.yellow(name),
chalk.bold.magenta('\ndirectory:\t\t'),
chalk.yellow(directory),
chalk.bold.magenta('\nnative:\t\t\t'),
chalk.yellow(native),
chalk.bold.magenta('\nredux:\t\t\t'),
chalk.yellow(redux),
chalk.bold.magenta('\nomitComments:\t\t'),
chalk.yellow(omitComments),
chalk.bold.magenta('\nreduxCore:\t\t'),
chalk.yellow(reduxCore),
chalk.bold.magenta('\nreduxCoreDirectory:\t'),
chalk.yellow(reduxCoreDirectory),
'\n'
);
createAllTemplates(
name,
directory,
native,
redux,
omitComments,
reduxCore,
reduxCoreDirectory
);
}
);