1
|
|
|
const Inquire = require('./Inquire'); |
2
|
|
|
const Generate = require('./Generate'); |
3
|
|
|
const Structure = require('./Structure'); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* ReactRaise class |
7
|
|
|
* @class ReactRaise |
8
|
|
|
*/ |
9
|
|
|
class ReactRaise { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Creates an instance of ReactRaise. |
13
|
|
|
* @memberOf ReactRaise |
14
|
|
|
*/ |
15
|
|
|
constructor() { |
16
|
|
|
this.privateProps = new WeakMap(); |
17
|
|
|
this.privateProps.set(this, { |
18
|
|
|
setupInfo: {}, |
19
|
|
|
}); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* set or alter the private properties; |
24
|
|
|
* @param {String} key - key of item to set |
25
|
|
|
* @param {any} value - value to store inside private property |
26
|
|
|
* @returns {object} set private properties |
27
|
|
|
* @memberOf ReactRaise |
28
|
|
|
*/ |
29
|
|
|
setProp(key, value) { |
30
|
|
|
return this.privateProps.set( |
31
|
|
|
this, |
32
|
|
|
Object.assign({}, this.privateProps.get(this), { [key]: value }) |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* get the private properties; |
38
|
|
|
* @param {String} key - key of item to get |
39
|
|
|
* @returns {object} set private properties |
40
|
|
|
* @memberOf ReactRaise |
41
|
|
|
*/ |
42
|
|
|
getProp(key) { |
43
|
|
|
return this.privateProps.get(this)[key]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* initialize command and ask setup questions |
48
|
|
|
* @param {Function} callback - function to execute after answers |
49
|
|
|
* has been given |
50
|
|
|
* @returns {Void} returns nothing |
51
|
|
|
* @memberOf ReactRaise |
52
|
|
|
*/ |
53
|
|
|
init(callback) { |
54
|
|
|
const configGenerate = new Generate(); |
55
|
|
|
const fileStructure = new Structure(); |
56
|
|
|
const startInquire = new Inquire(); |
57
|
|
|
startInquire.question( |
58
|
|
|
'description', |
59
|
|
|
'input', |
60
|
|
|
'Can you describe your app[optional]'); |
61
|
|
|
startInquire.question( |
62
|
|
|
'main', |
63
|
|
|
'input', |
64
|
|
|
'What is the main entry file of your app[Default: index.js]'); |
65
|
|
|
startInquire.question( |
66
|
|
|
'author', |
67
|
|
|
'input', |
68
|
|
|
'What is your name[optional]'); |
69
|
|
|
startInquire.question( |
70
|
|
|
'license', |
71
|
|
|
'input', |
72
|
|
|
'What is license is your app under[Default: MIT]' |
73
|
|
|
); |
74
|
|
|
startInquire.question( |
75
|
|
|
'express', |
76
|
|
|
'input', |
77
|
|
|
'Do you want to configure an express server with this app(y/n)', |
78
|
|
|
'yesNo' |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
startInquire.ask((answers) => { |
82
|
|
|
this.setProp('setupInfo', answers); |
83
|
|
|
if (callback) { |
84
|
|
|
callback(); |
85
|
|
|
} |
86
|
|
|
configGenerate.all(answers); |
87
|
|
|
fileStructure.build(); |
88
|
|
|
}); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
module.exports = ReactRaise; |
93
|
|
|
|