This repository was archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (72 loc) · 2.06 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
#!/usr/bin/env node
const fs = require('fs-extra');
if (!fs.existsSync('package.json')) {
process.exit();
}
const chalk = require('chalk');
const commander = require('commander');
const spawn = require('child_process').spawn;
const writePkg = require('write-pkg');
const { shouldUseYarn, tree, isNative } = require('./utils');
const { createIndex, createIndexNative, createStore, createStoreNative, createUtils, createAction, createReducer } = require('./generate');
const packageJson = require('./package.json');
const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.on('--help', () => {
console.log(` Commands:`);
console.log();
console.log(` init [dest]`);
console.log(` generate [name]`);
console.log();
})
.parse(process.argv);
if (program.args.length && program.args[0] === 'init')
{
const useYarn = shouldUseYarn();
const dependencies = ['redux', 'redux-thunk', 'redux-persist', 'react-redux', 'redux-mock-store'];
let command, args;
if (useYarn) {
command = 'yarnpkg';
args = ['add', '--exact'].concat(dependencies);
} else {
command = 'npm';
args = [
'install',
'--save',
'--save-exact',
'--loglevel',
'error',
].concat(dependencies);
}
const initReactReduxApp = spawn(command, args);
initReactReduxApp.stdout.on('data', function (data) {
console.log(data.toString());
});
initReactReduxApp.stderr.on('data', function (data) {
console.log(data.toString());
});
initReactReduxApp.on('exit', function (code) {
const pkg = JSON.parse(fs.readFileSync('./package.json'));
if (program.args.length > 1) {
pkg.appDir = program.args[1];
}
else {
pkg.appDir = '.';
}
writePkg.sync(pkg);
tree();
if (isNative()) {
createIndexNative();
createStoreNative();
}
else {
createIndex();
createStore();
}
createUtils();
});
}
else if (program.args.length == 2 && program.args[0] === 'generate' ) {
createAction(program.args[1]);
createReducer(program.args[1]);
}