-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
126 lines (108 loc) · 3.01 KB
/
Copy pathindex.js
File metadata and controls
126 lines (108 loc) · 3.01 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env node
/*
* Create React Component
*/
const program = require('commander');
const settings = require('./lib/settings');
const fs = require('fs-extra');
const path = require('path');
const utils = require('./lib/utils');
const CWD = process.cwd();
try {
/**
* User local setting
*
* Look at settings module './lib/settings'
*/
var localSettings = fs.readJsonSync(path.join(CWD, '.ccr', 'settings.json'));
settings.import(localSettings);
} catch (e) {
settings.get('verbose') &&
console.log(
'Local settings were not located. Using default settings for configuration...'
);
}
const createReactComponents = require('./lib');
program.version('2.1.0');
program
.command('init')
.option(
'-t, --templates',
'Configure this repo to use template functionality'
)
.alias('i')
.description('create local configuration settings for a repo to use')
.action(function(options) {
var initProgress = createReactComponents.initializeLocalSettings(CWD);
if (options.templates) {
settings.set('templates', true);
initProgress.then(createReactComponents.initializeTemplates(CWD));
}
});
program
.command('template')
.alias('t')
.description('initalize templating')
.action(function(options) {
createReactComponents.initializeTemplates(CWD);
});
program
.command('create <components...>')
.option('-v, --verbose', 'logs', false)
.option('-c, --css-type <ext>', 'change extention for css file')
.option(
'-f, --functional',
'Use functional component instead of a state component'
)
.option(
'-i, --no-index',
"Don't include default index file for the components you create"
)
.option('-s, --no-css', "Don't include a css for the component(s) you create")
.option(
'-d, --no-default',
"Don't include any of the default packages for react.(index, style, component or functional)"
)
.option(
'-t, --test',
'Include a testing file for the component(s) you create'
)
.option(
'-r, --extend-cwd <path>',
'A path to add on to your current working directory'
)
.option(
'-p, --packages <packages>',
'A path to add on to your current working directory'
)
.alias('c')
.description('create a new component')
.action(function(files, options) {
deleteDefaultBoolFlags(options);
optionsToSettings(options);
createReactComponents(CWD, files);
});
program.parse(process.argv);
/*
* Helper Functions
*/
/*
* Deletes the property from commander with flags
* that have: ( --no-* ) so that it doesnt override
* settings from users style sheet
*/
function deleteDefaultBoolFlags(options) {
options.options.forEach(function(option) {
const prop = option.attributeName();
const isBoolFlag = /^--no/.test(option.long);
if (isBoolFlag && options[prop]) {
options[prop] = undefined;
}
});
}
function optionsToSettings(_program) {
_program.options.forEach(function(option) {
var prop = option.attributeName();
settings.set(prop, _program[prop], true);
});
}