@oipage/cli 0.3.0 → 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +76 -47
- package/LICENSE +20 -20
- package/README.md +204 -132
- package/bin/WebSocket/decodeWsFrame.js +43 -43
- package/bin/WebSocket/encodeWsFrame.js +28 -28
- package/bin/WebSocket/headersToJSON.js +26 -26
- package/bin/WebSocket/index.js +106 -106
- package/bin/data/mineTypes.json +108 -104
- package/bin/disk.js +42 -42
- package/bin/help.js +63 -55
- package/bin/intercept.js +15 -15
- package/bin/network.js +21 -21
- package/bin/notebook/data.js +185 -0
- package/bin/notebook/index.js +168 -9
- package/bin/proxy.js +82 -82
- package/bin/run +146 -146
- package/bin/serve.js +455 -318
- package/bin/template/404.html +184 -184
- package/bin/tools/deleteEmptyFolder.js +33 -33
- package/bin/tools/format.js +75 -75
- package/bin/tools/isBinary.js +83 -83
- package/bin/tools/moduleForm.js +548 -0
- package/bin/tools/network.js +42 -42
- package/bin/tools/openBrowser.js +34 -34
- package/bin/tools/resolve404.js +98 -98
- package/bin/tools/resolveImport.js +278 -97
- package/bin/tools/resolvePackage.js +412 -0
- package/bin/website-htmls/components/ui-select-file/index.html +8 -8
- package/bin/website-htmls/components/ui-select-file/index.js +42 -42
- package/bin/website-htmls/components/ui-select-file/index.scss +44 -44
- package/bin/website-htmls/dialogs/imageSize/index.html +54 -54
- package/bin/website-htmls/dialogs/imageSize/index.js +53 -53
- package/bin/website-htmls/dialogs/imageSize/index.scss +140 -140
- package/bin/website-htmls/dialogs/index.js +52 -52
- package/bin/website-htmls/images/addFile.svg +1 -1
- package/bin/website-htmls/images/img-to-pdf.svg +1 -1
- package/bin/website-htmls/index.html +17 -17
- package/bin/website-htmls/main.js +13 -13
- package/bin/website-htmls/pages/App/index.html +6 -6
- package/bin/website-htmls/pages/App/index.js +22 -22
- package/bin/website-htmls/pages/App/index.scss +43 -43
- package/bin/website-htmls/pages/appStore/index.html +7 -7
- package/bin/website-htmls/pages/appStore/index.js +19 -19
- package/bin/website-htmls/pages/appStore/index.scss +54 -54
- package/bin/website-htmls/pages/chart/index.html +8 -8
- package/bin/website-htmls/pages/chart/index.js +72 -72
- package/bin/website-htmls/pages/chart/index.scss +71 -71
- package/bin/website-htmls/pages/home/index.html +19 -19
- package/bin/website-htmls/pages/home/index.js +19 -19
- package/bin/website-htmls/pages/home/index.scss +87 -87
- package/bin/website-htmls/pages/image-editor/index.html +27 -27
- package/bin/website-htmls/pages/image-editor/index.js +106 -106
- package/bin/website-htmls/pages/image-editor/index.scss +69 -69
- package/bin/website-htmls/pages/img-to-pdf/index.html +3 -3
- package/bin/website-htmls/pages/img-to-pdf/index.js +44 -44
- package/bin/website-htmls/pages/img-to-pdf/index.scss +9 -9
- package/bin/website-htmls/pages/recorder-screen/index.html +15 -15
- package/bin/website-htmls/pages/recorder-screen/index.js +227 -227
- package/bin/website-htmls/pages/recorder-screen/index.scss +52 -52
- package/bin/website-htmls/router.config.js +29 -29
- package/bin/website-htmls/styles/common.css +44 -44
- package/bin/website-htmls/styles/normalize.css +94 -94
- package/bin/website-plugins/intercept/chart.js +33 -33
- package/bin/website-plugins/intercept/getPackage.js +17 -17
- package/bin/website-plugins/intercept/head.js +8 -8
- package/bin/website-plugins/intercept/index.js +4 -8
- package/bin/website-plugins/loader/index.js +11 -11
- package/bin/website-plugins/loader/oipage-html-loader.js +7 -7
- package/bin/website-plugins/loader/oipage-scss-loader.js +149 -149
- package/docs/css/base.css +122 -0
- package/docs/css/components.css +180 -0
- package/docs/css/layout.css +295 -0
- package/docs/css/responsive.css +49 -0
- package/docs/images/file-list.webp +0 -0
- package/docs/images/logo-topbar.svg +5 -0
- package/docs/images/logo.png +0 -0
- package/docs/images/logo.svg +6 -0
- package/docs/images/manual.webp +0 -0
- package/docs/images/terminal-serve.webp +0 -0
- package/docs/index.html +1392 -0
- package/docs/js/copy.js +37 -0
- package/docs/js/nav.js +111 -0
- package/docs/js/search.js +241 -0
- package/docs/js/theme.js +17 -0
- package/package.json +42 -42
- package/src/index.js +26 -29
- package/types/serve.d.ts +83 -83
- package/bin/website-plugins/intercept/oipage-vislite-intercept.js +0 -56
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +0 -37
- package/docs/config.md +0 -107
package/bin/proxy.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
const https = require('https');
|
|
2
|
-
const http = require('http');
|
|
3
|
-
|
|
4
|
-
module.exports = function (args, proxy) {
|
|
5
|
-
|
|
6
|
-
let intercept = [];
|
|
7
|
-
for (let key in proxy) {
|
|
8
|
-
intercept.push({
|
|
9
|
-
test: new RegExp("^" + key),
|
|
10
|
-
handler(request, response) {
|
|
11
|
-
let proxyItem = proxy[key];
|
|
12
|
-
|
|
13
|
-
let throwError = function (err) {
|
|
14
|
-
response.writeHead(500, {
|
|
15
|
-
'Content-Type': "text/plain;charset=utf-8",
|
|
16
|
-
'Access-Control-Allow-Origin': '*',
|
|
17
|
-
'Server': 'Powered by ' + args.name + "@" + args.version + ' proxy'
|
|
18
|
-
});
|
|
19
|
-
response.write(err);
|
|
20
|
-
response.end();
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
let headers = request.headers;
|
|
24
|
-
let url
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
url = decodeURIComponent(request.url);
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.log("decodeURIComponent error: ", e);
|
|
30
|
-
throw e;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (proxyItem.pathRewrite) {
|
|
34
|
-
for (let pathRewrite_key in proxyItem.pathRewrite) {
|
|
35
|
-
url = url.replace(new RegExp(pathRewrite_key), proxyItem.pathRewrite[pathRewrite_key]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let fullUrl = proxy[key].target + url;
|
|
40
|
-
|
|
41
|
-
let handler = /^https/.test(url) ? https : http;
|
|
42
|
-
|
|
43
|
-
let execArray = /https*:\/\/([^\/]+)(.+)?/.exec(fullUrl);
|
|
44
|
-
let hostport = execArray[1].split(":");
|
|
45
|
-
|
|
46
|
-
// 创建与目标服务器的连接
|
|
47
|
-
const req = handler.request({
|
|
48
|
-
hostname: hostport[0],
|
|
49
|
-
port: hostport[1] || 80,
|
|
50
|
-
path: execArray[2] || "/",
|
|
51
|
-
method: request.method,
|
|
52
|
-
headers
|
|
53
|
-
}, (res) => {
|
|
54
|
-
|
|
55
|
-
let resHeaders = {
|
|
56
|
-
...res.headers
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 标记响应服务器
|
|
60
|
-
delete resHeaders["server"];
|
|
61
|
-
resHeaders["Server"] = 'Powered by ' + args.name + "@" + args.version + ' proxy';
|
|
62
|
-
|
|
63
|
-
// 设置响应头
|
|
64
|
-
response.writeHead(res.statusCode, resHeaders);
|
|
65
|
-
// 流式传输响应体
|
|
66
|
-
res.pipe(response);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// 错误处理
|
|
70
|
-
req.on('error', (e) => {
|
|
71
|
-
throwError(e.message);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// 将原始请求体传递给目标服务器
|
|
75
|
-
request.pipe(req);
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return intercept;
|
|
82
|
-
};
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const http = require('http');
|
|
3
|
+
|
|
4
|
+
module.exports = function (args, proxy) {
|
|
5
|
+
|
|
6
|
+
let intercept = [];
|
|
7
|
+
for (let key in proxy) {
|
|
8
|
+
intercept.push({
|
|
9
|
+
test: new RegExp("^" + key),
|
|
10
|
+
handler(request, response) {
|
|
11
|
+
let proxyItem = proxy[key];
|
|
12
|
+
|
|
13
|
+
let throwError = function (err) {
|
|
14
|
+
response.writeHead(500, {
|
|
15
|
+
'Content-Type': "text/plain;charset=utf-8",
|
|
16
|
+
'Access-Control-Allow-Origin': '*',
|
|
17
|
+
'Server': 'Powered by ' + args.name + "@" + args.version + ' proxy'
|
|
18
|
+
});
|
|
19
|
+
response.write(err);
|
|
20
|
+
response.end();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
let headers = request.headers;
|
|
24
|
+
let url
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
url = decodeURIComponent(request.url);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.log("decodeURIComponent error: ", e);
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (proxyItem.pathRewrite) {
|
|
34
|
+
for (let pathRewrite_key in proxyItem.pathRewrite) {
|
|
35
|
+
url = url.replace(new RegExp(pathRewrite_key), proxyItem.pathRewrite[pathRewrite_key]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let fullUrl = proxy[key].target + url;
|
|
40
|
+
|
|
41
|
+
let handler = /^https/.test(url) ? https : http;
|
|
42
|
+
|
|
43
|
+
let execArray = /https*:\/\/([^\/]+)(.+)?/.exec(fullUrl);
|
|
44
|
+
let hostport = execArray[1].split(":");
|
|
45
|
+
|
|
46
|
+
// 创建与目标服务器的连接
|
|
47
|
+
const req = handler.request({
|
|
48
|
+
hostname: hostport[0],
|
|
49
|
+
port: hostport[1] || 80,
|
|
50
|
+
path: execArray[2] || "/",
|
|
51
|
+
method: request.method,
|
|
52
|
+
headers
|
|
53
|
+
}, (res) => {
|
|
54
|
+
|
|
55
|
+
let resHeaders = {
|
|
56
|
+
...res.headers
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 标记响应服务器
|
|
60
|
+
delete resHeaders["server"];
|
|
61
|
+
resHeaders["Server"] = 'Powered by ' + args.name + "@" + args.version + ' proxy';
|
|
62
|
+
|
|
63
|
+
// 设置响应头
|
|
64
|
+
response.writeHead(res.statusCode, resHeaders);
|
|
65
|
+
// 流式传输响应体
|
|
66
|
+
res.pipe(response);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// 错误处理
|
|
70
|
+
req.on('error', (e) => {
|
|
71
|
+
throwError(e.message);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// 将原始请求体传递给目标服务器
|
|
75
|
+
request.pipe(req);
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return intercept;
|
|
82
|
+
};
|
package/bin/run
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
process.title = '@oipage/cli';
|
|
6
|
-
|
|
7
|
-
const { spawn } = require('child_process');
|
|
8
|
-
const { join } = require("path");
|
|
9
|
-
const { existsSync, lstatSync } = require("fs");
|
|
10
|
-
const { mergeOption } = require("oipage/nodejs/option/index");
|
|
11
|
-
const { formatArgv } = require("./tools/format.js");
|
|
12
|
-
|
|
13
|
-
// 开发服务器
|
|
14
|
-
if (process.argv[2] === "serve") {
|
|
15
|
-
|
|
16
|
-
let argvObj = formatArgv(process.argv, {
|
|
17
|
-
"-p": "--port",
|
|
18
|
-
"-c": "--config"
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
let config = {
|
|
22
|
-
devServer: {
|
|
23
|
-
port: 8080,
|
|
24
|
-
baseUrl: "./",
|
|
25
|
-
open: false,
|
|
26
|
-
cache: true,
|
|
27
|
-
gzip: true,
|
|
28
|
-
proxy: {},
|
|
29
|
-
intercept: [],
|
|
30
|
-
404: null,
|
|
31
|
-
website: true
|
|
32
|
-
},
|
|
33
|
-
module: {
|
|
34
|
-
rules: []
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
if (argvObj["--proxy"] && argvObj["--proxy"].length === 2) {
|
|
39
|
-
config.devServer.proxy[argvObj["--proxy"][0]] = {
|
|
40
|
-
target: argvObj["--proxy"][1],
|
|
41
|
-
pathRewrite: { ['^' + argvObj["--proxy"][0]]: '' }
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 如果设置了配置文件
|
|
46
|
-
if (argvObj["--config"]) {
|
|
47
|
-
let configPath = join(process.cwd(), argvObj["--config"][0] || "./oipage.config.js");
|
|
48
|
-
if (existsSync(configPath) && !lstatSync(configPath).isDirectory()) {
|
|
49
|
-
let configValue = require(configPath);
|
|
50
|
-
mergeOption(config, configValue);
|
|
51
|
-
} else {
|
|
52
|
-
console.log("\x1b[0m\x1b[31m" + configPath + "\x1b[0m");
|
|
53
|
-
throw new Error("OIPage: The configuration file does not exist or is not a file.");
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let resolveBoolean = input => input[0] !== "false";
|
|
58
|
-
|
|
59
|
-
if (argvObj["--port"]) config.devServer.port =
|
|
60
|
-
if (argvObj["--baseUrl"]) config.devServer.baseUrl =
|
|
61
|
-
if (argvObj["--cache"]) config.devServer.cache = resolveBoolean(argvObj["--cache"]);
|
|
62
|
-
if (argvObj["--gzip"]) config.devServer.gzip = resolveBoolean(argvObj["--gzip"]);
|
|
63
|
-
if (argvObj["--open"]) config.devServer.open = resolveBoolean(argvObj["--open"]);
|
|
64
|
-
if (argvObj["--website"]) config.devServer.website = resolveBoolean(argvObj["--website"]);
|
|
65
|
-
|
|
66
|
-
require("./serve.js")(config);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 磁盘操作
|
|
70
|
-
else if (process.argv[2] === "disk") {
|
|
71
|
-
|
|
72
|
-
let argvObj = formatArgv(process.argv, {
|
|
73
|
-
"-f": "--force",
|
|
74
|
-
"-d": "--delete",
|
|
75
|
-
"-m": "--move",
|
|
76
|
-
"-c": "--copy",
|
|
77
|
-
"-l": "--link"
|
|
78
|
-
}, true);
|
|
79
|
-
|
|
80
|
-
require("./disk.js")(argvObj);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 运行多命令
|
|
84
|
-
else if (process.argv[2] === "run") {
|
|
85
|
-
|
|
86
|
-
let argvObj = formatArgv(process.argv, {});
|
|
87
|
-
|
|
88
|
-
let tasks = [], runArgs = [];
|
|
89
|
-
for (let index = 0; index < argvObj.args.length; index++) {
|
|
90
|
-
|
|
91
|
-
// 参数
|
|
92
|
-
if (/^:/.test(argvObj.args[index])) {
|
|
93
|
-
runArgs.push(argvObj.args[index].replace(/^:/, ""));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 任务
|
|
97
|
-
else {
|
|
98
|
-
tasks.push(argvObj.args[index]);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
for (let index = 0; index < tasks.length; index++) {
|
|
103
|
-
|
|
104
|
-
// 补充动态参数的支持
|
|
105
|
-
// npm run bug:issue5 ":-p 9090"
|
|
106
|
-
// 2025年12月1日 于南京
|
|
107
|
-
let task = (tasks[index] + (runArgs[index] ? (" " + runArgs[index]) : "")).split(" ");
|
|
108
|
-
let command = task.shift();
|
|
109
|
-
|
|
110
|
-
// 修复exec无法正常使用logform问题
|
|
111
|
-
// npm run bug:issue4
|
|
112
|
-
// 2025年12月2日 于南京
|
|
113
|
-
spawn(command, task, {
|
|
114
|
-
|
|
115
|
-
// https://nodejs.org/api/child_process.html#child_process_options_stdio
|
|
116
|
-
stdio: 'inherit',
|
|
117
|
-
|
|
118
|
-
// 修复https://github.com/oi-contrib/OIPage/issues/8
|
|
119
|
-
// 在Unix系统中使用`/bin/sh`,在Windows系统中使用`process.env.ComSpec`
|
|
120
|
-
// 2025年12月28日 于南京
|
|
121
|
-
shell: true
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// 网络相关
|
|
128
|
-
else if (process.argv[2] === "network") {
|
|
129
|
-
|
|
130
|
-
let argvObj = formatArgv(process.argv, {}, true);
|
|
131
|
-
|
|
132
|
-
require("./network.js")(argvObj);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// 快速笔记
|
|
136
|
-
else if (process.argv[2] === "notebook") {
|
|
137
|
-
|
|
138
|
-
let argvObj = formatArgv(process.argv, {}, true);
|
|
139
|
-
|
|
140
|
-
require("./notebook/index.js")(argvObj);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 默认,帮助
|
|
144
|
-
else {
|
|
145
|
-
require("./help.js")();
|
|
146
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
process.title = '@oipage/cli';
|
|
6
|
+
|
|
7
|
+
const { spawn } = require('child_process');
|
|
8
|
+
const { join } = require("path");
|
|
9
|
+
const { existsSync, lstatSync } = require("fs");
|
|
10
|
+
const { mergeOption } = require("oipage/nodejs/option/index");
|
|
11
|
+
const { formatArgv } = require("./tools/format.js");
|
|
12
|
+
|
|
13
|
+
// 开发服务器
|
|
14
|
+
if (process.argv[2] === "serve") {
|
|
15
|
+
|
|
16
|
+
let argvObj = formatArgv(process.argv, {
|
|
17
|
+
"-p": "--port",
|
|
18
|
+
"-c": "--config"
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
let config = {
|
|
22
|
+
devServer: {
|
|
23
|
+
port: 8080,
|
|
24
|
+
baseUrl: "./",
|
|
25
|
+
open: false,
|
|
26
|
+
cache: true,
|
|
27
|
+
gzip: true,
|
|
28
|
+
proxy: {},
|
|
29
|
+
intercept: [],
|
|
30
|
+
404: null,
|
|
31
|
+
website: true
|
|
32
|
+
},
|
|
33
|
+
module: {
|
|
34
|
+
rules: []
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (argvObj["--proxy"] && argvObj["--proxy"].length === 2) {
|
|
39
|
+
config.devServer.proxy[argvObj["--proxy"][0]] = {
|
|
40
|
+
target: argvObj["--proxy"][1],
|
|
41
|
+
pathRewrite: { ['^' + argvObj["--proxy"][0]]: '' }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 如果设置了配置文件
|
|
46
|
+
if (argvObj["--config"]) {
|
|
47
|
+
let configPath = join(process.cwd(), argvObj["--config"][0] || "./oipage.config.js");
|
|
48
|
+
if (existsSync(configPath) && !lstatSync(configPath).isDirectory()) {
|
|
49
|
+
let configValue = require(configPath);
|
|
50
|
+
mergeOption(config, configValue);
|
|
51
|
+
} else {
|
|
52
|
+
console.log("\x1b[0m\x1b[31m" + configPath + "\x1b[0m");
|
|
53
|
+
throw new Error("OIPage: The configuration file does not exist or is not a file.");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let resolveBoolean = input => input[0] !== "false";
|
|
58
|
+
|
|
59
|
+
if (argvObj["--port"]) config.devServer.port = Number(argvObj["--port"][0]) || config.devServer.port;
|
|
60
|
+
if (argvObj["--baseUrl"]) config.devServer.baseUrl = argvObj["--baseUrl"][0];
|
|
61
|
+
if (argvObj["--cache"]) config.devServer.cache = resolveBoolean(argvObj["--cache"]);
|
|
62
|
+
if (argvObj["--gzip"]) config.devServer.gzip = resolveBoolean(argvObj["--gzip"]);
|
|
63
|
+
if (argvObj["--open"]) config.devServer.open = resolveBoolean(argvObj["--open"]);
|
|
64
|
+
if (argvObj["--website"]) config.devServer.website = resolveBoolean(argvObj["--website"]);
|
|
65
|
+
|
|
66
|
+
require("./serve.js")(config);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 磁盘操作
|
|
70
|
+
else if (process.argv[2] === "disk") {
|
|
71
|
+
|
|
72
|
+
let argvObj = formatArgv(process.argv, {
|
|
73
|
+
"-f": "--force",
|
|
74
|
+
"-d": "--delete",
|
|
75
|
+
"-m": "--move",
|
|
76
|
+
"-c": "--copy",
|
|
77
|
+
"-l": "--link"
|
|
78
|
+
}, true);
|
|
79
|
+
|
|
80
|
+
require("./disk.js")(argvObj);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 运行多命令
|
|
84
|
+
else if (process.argv[2] === "run") {
|
|
85
|
+
|
|
86
|
+
let argvObj = formatArgv(process.argv, {});
|
|
87
|
+
|
|
88
|
+
let tasks = [], runArgs = [];
|
|
89
|
+
for (let index = 0; index < argvObj.args.length; index++) {
|
|
90
|
+
|
|
91
|
+
// 参数
|
|
92
|
+
if (/^:/.test(argvObj.args[index])) {
|
|
93
|
+
runArgs.push(argvObj.args[index].replace(/^:/, ""));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 任务
|
|
97
|
+
else {
|
|
98
|
+
tasks.push(argvObj.args[index]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (let index = 0; index < tasks.length; index++) {
|
|
103
|
+
|
|
104
|
+
// 补充动态参数的支持
|
|
105
|
+
// npm run bug:issue5 ":-p 9090"
|
|
106
|
+
// 2025年12月1日 于南京
|
|
107
|
+
let task = (tasks[index] + (runArgs[index] ? (" " + runArgs[index]) : "")).split(" ");
|
|
108
|
+
let command = task.shift();
|
|
109
|
+
|
|
110
|
+
// 修复exec无法正常使用logform问题
|
|
111
|
+
// npm run bug:issue4
|
|
112
|
+
// 2025年12月2日 于南京
|
|
113
|
+
spawn(command, task, {
|
|
114
|
+
|
|
115
|
+
// https://nodejs.org/api/child_process.html#child_process_options_stdio
|
|
116
|
+
stdio: 'inherit',
|
|
117
|
+
|
|
118
|
+
// 修复https://github.com/oi-contrib/OIPage/issues/8
|
|
119
|
+
// 在Unix系统中使用`/bin/sh`,在Windows系统中使用`process.env.ComSpec`
|
|
120
|
+
// 2025年12月28日 于南京
|
|
121
|
+
shell: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 网络相关
|
|
128
|
+
else if (process.argv[2] === "network") {
|
|
129
|
+
|
|
130
|
+
let argvObj = formatArgv(process.argv, {}, true);
|
|
131
|
+
|
|
132
|
+
require("./network.js")(argvObj);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 快速笔记
|
|
136
|
+
else if (process.argv[2] === "notebook") {
|
|
137
|
+
|
|
138
|
+
let argvObj = formatArgv(process.argv, {}, true);
|
|
139
|
+
|
|
140
|
+
require("./notebook/index.js")(argvObj);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 默认,帮助
|
|
144
|
+
else {
|
|
145
|
+
require("./help.js")();
|
|
146
|
+
}
|