-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·125 lines (116 loc) · 3.54 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
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
const path = require('path');
const fs = require('fs-extra');
const nds = require('./node-dev-server');
const eject = require('./eject');
const { consoleHook, _log, } = require('./console-hook');
/**
* Create a project dir and init it
* @param {string} project
*/
function create(project) {
console.info(`Create project ${project}`);
fs.mkdirSync(project); // dir: pro
init(project);
}
/**
* Init a project, e.g: eject the TypeScript config file.
* @param {string} project
*/
function init(project) {
console.info(`Init project ${project}`);
const DIR_APP = path.resolve(project, '.');
const DIR_APP_TEMPLATE = path.resolve(__dirname, `./public/${globalThis.kind === 'electron' ? 'electron-app' : 'node-app'}`); // 项目模板
fs.copySync(DIR_APP_TEMPLATE, DIR_APP);
eject(project);
console.log(`A electron-main project init succeed! To continue, please:\n\ncd ${project}\nyarn setup`);
}
function main() {
switch (process.argv[2]) {
case '-ie': {
globalThis.kind = 'electron';
}
case '-i':
case 'init':
case '--init': { // Init cwd() or a project
consoleHook();
init(path.resolve(process.cwd(), process.argv[3] || '.'));
break;
}
case '-ce': {
globalThis.kind = 'electron';
}
case '-c':
case 'create':
case '--create': { // Create a project directory and init
if (!process.argv[3]) { // No a project name provided
help();
break;
}
consoleHook();
create(path.resolve(process.cwd(), process.argv[3]));
break;
}
case '-ej':
case 'eject':
case '--eject': {
consoleHook();
eject(path.resolve(process.cwd(), process.argv[3] || '.'));
break;
}
case '-h':
case 'help':
case '-help':
case '--help': {
help();
break;
}
case '-v':
case '-V':
case 'version':
case '--version': {
version();
break;
}
case '-j':
case '-just':
case '--just': {
consoleHook();
nds(true);
break;
}
case '-n':
case '-ng':
case '--no-gnome': {
consoleHook();
nds(false, true);
break;
}
default: {
consoleHook();
nds();
}
}
}
function help() {
const info = `
Usage: nds [options] [project]
node-dev-server [options] [project]
Serves a Node.js app. Restart the app on changes.
Options:
[project] The project directory
-c, --create Create a TypeScript project and init it
-ce electron
-i, --init Init a TypeScript project
-ie electron
-ej, --eject Eject the TypeScript supported configuration file
-j, --just Just auto compile, don't run
-v, --version Display version of node-dev-server
-h, --help Display help for command`;
_log(info);
process.exit(0);
}
function version() {
const PACKAGE_JSON = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json')));
console.log(PACKAGE_JSON.version);
}
main();