oipage 1.7.0-alpha.7 → 1.7.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 +156 -159
- package/LICENSE +20 -20
- package/README.md +95 -95
- 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 +80 -80
- package/bin/data/mineTypes.json +104 -104
- package/bin/disk.js +42 -42
- package/bin/help.js +45 -45
- package/bin/intercept.js +15 -15
- package/bin/network.js +21 -21
- package/bin/proxy.js +75 -75
- package/bin/run +129 -129
- package/bin/serve.d.ts +64 -64
- package/bin/serve.js +179 -179
- package/bin/template/404.html +186 -186
- package/bin/tools/deleteEmptyFolder.js +23 -23
- package/bin/tools/format.js +75 -75
- package/bin/tools/network.js +42 -42
- package/bin/tools/resolve404.js +83 -83
- package/bin/tools/resolveImport.js +88 -88
- package/bin/website-htmls/components/ui-select-file/index.html +7 -7
- package/bin/website-htmls/components/ui-select-file/index.js +37 -37
- 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 +138 -138
- 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 +24 -24
- package/bin/website-htmls/pages/appStore/index.js +19 -19
- package/bin/website-htmls/pages/appStore/index.scss +41 -41
- 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 +72 -72
- 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 +45 -45
- 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 +4 -4
- package/bin/website-htmls/router.config.js +19 -19
- 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 +8 -8
- package/bin/website-plugins/intercept/oipage-vislite-intercept.js +30 -30
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +36 -36
- 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/nodejs/animation/index.d.ts +19 -19
- package/nodejs/animation/index.js +112 -112
- package/nodejs/cmdlog/index.d.ts +20 -20
- package/nodejs/cmdlog/index.js +75 -75
- package/nodejs/disk/index.d.ts +47 -47
- package/nodejs/disk/index.js +165 -165
- package/nodejs/format/index.d.ts +29 -29
- package/nodejs/format/index.js +107 -107
- package/nodejs/json/index.d.ts +9 -9
- package/nodejs/json/index.js +206 -206
- package/nodejs/logform/index.d.ts +18 -18
- package/nodejs/logform/index.js +94 -94
- package/nodejs/reader/index.d.ts +32 -32
- package/nodejs/reader/index.js +20 -20
- package/nodejs/throttle/index.d.ts +30 -30
- package/nodejs/throttle/index.js +50 -50
- package/package.json +45 -45
- package/types/index.d.ts +2 -4
- package/web/XMLHttpRequest/index.d.ts +17 -17
- package/web/XMLHttpRequest/index.js +60 -60
- package/web/animation/index.d.ts +19 -19
- package/web/animation/index.js +112 -112
- package/web/format/index.d.ts +29 -29
- package/web/format/index.js +107 -107
- package/web/json/index.d.ts +9 -9
- package/web/json/index.js +206 -206
- package/web/onReady/index.d.ts +7 -7
- package/web/onReady/index.js +8 -8
- package/web/performChunk/index.d.ts +4 -4
- package/web/performChunk/index.js +19 -19
- package/web/reader/index.d.ts +32 -32
- package/web/reader/index.js +20 -20
- package/web/style/index.d.ts +21 -21
- package/web/style/index.js +19 -19
- package/web/throttle/index.d.ts +30 -30
- package/web/throttle/index.js +50 -50
- package/nodejs/remote/index.d.ts +0 -39
- package/nodejs/remote/index.js +0 -91
package/bin/help.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
const packageValue = require("../package.json");
|
|
2
|
-
|
|
3
|
-
module.exports = function () {
|
|
4
|
-
console.log(`\x1b[36m
|
|
5
|
-
OIPage@v${packageValue.version}
|
|
6
|
-
|
|
7
|
-
可以使用的命令如下:
|
|
8
|
-
|
|
9
|
-
【1】oipage-cli serve 开发服务器
|
|
10
|
-
--port|-p [端口号]
|
|
11
|
-
默认8080
|
|
12
|
-
--baseUrl [文件夹地址]
|
|
13
|
-
服务器根目录
|
|
14
|
-
--config|-c [配置文件地址]
|
|
15
|
-
设置配置文件,相对地址是相对当前命令行
|
|
16
|
-
--cache [true|false]
|
|
17
|
-
是否启用304(默认true表示开启)
|
|
18
|
-
(eg: oipage-cli serve -p 20000 )
|
|
19
|
-
--proxy [转发前缀] [转发地址]
|
|
20
|
-
(注意:转发前缀会被替换为空,相当于设置了 pathRewrite: { '^/demo': '' })
|
|
21
|
-
|
|
22
|
-
【2】oipage-cli disk 磁盘操作
|
|
23
|
-
--force|-f
|
|
24
|
-
强制执行,如果目标地址已有内容,会直接强制删除已有内容
|
|
25
|
-
--delete|-d [文件或文件夹地址]
|
|
26
|
-
删除文件或文件夹
|
|
27
|
-
--delempty [文件夹地址]
|
|
28
|
-
删除空文件夹
|
|
29
|
-
--move|-m [源地址] [软链接地址]
|
|
30
|
-
移动文件或文件夹
|
|
31
|
-
--copy|-c [源地址] [目标地址]
|
|
32
|
-
复制文件或文件夹
|
|
33
|
-
--link|-l [源地址] [软链接地址]
|
|
34
|
-
创建磁盘链接
|
|
35
|
-
(eg: oipage-cli disk -m ./test.js ~/test.js -f )
|
|
36
|
-
|
|
37
|
-
【3】oipage-cli run "任务一" "任务二" ... 运行多命令
|
|
38
|
-
( 如果希望动态给任务传递参数,可以查看: https://github.com/oi-contrib/OIPage/issues/5 )
|
|
39
|
-
|
|
40
|
-
【4】oipage-cli network 网络相关
|
|
41
|
-
--log
|
|
42
|
-
打印网络信息
|
|
43
|
-
(eg: oipage-cli network --log )
|
|
44
|
-
\x1b[0m`);
|
|
45
|
-
|
|
1
|
+
const packageValue = require("../package.json");
|
|
2
|
+
|
|
3
|
+
module.exports = function () {
|
|
4
|
+
console.log(`\x1b[36m
|
|
5
|
+
OIPage@v${packageValue.version}
|
|
6
|
+
|
|
7
|
+
可以使用的命令如下:
|
|
8
|
+
|
|
9
|
+
【1】oipage-cli serve 开发服务器
|
|
10
|
+
--port|-p [端口号]
|
|
11
|
+
默认8080
|
|
12
|
+
--baseUrl [文件夹地址]
|
|
13
|
+
服务器根目录
|
|
14
|
+
--config|-c [配置文件地址]
|
|
15
|
+
设置配置文件,相对地址是相对当前命令行
|
|
16
|
+
--cache [true|false]
|
|
17
|
+
是否启用304(默认true表示开启)
|
|
18
|
+
(eg: oipage-cli serve -p 20000 )
|
|
19
|
+
--proxy [转发前缀] [转发地址]
|
|
20
|
+
(注意:转发前缀会被替换为空,相当于设置了 pathRewrite: { '^/demo': '' })
|
|
21
|
+
|
|
22
|
+
【2】oipage-cli disk 磁盘操作
|
|
23
|
+
--force|-f
|
|
24
|
+
强制执行,如果目标地址已有内容,会直接强制删除已有内容
|
|
25
|
+
--delete|-d [文件或文件夹地址]
|
|
26
|
+
删除文件或文件夹
|
|
27
|
+
--delempty [文件夹地址]
|
|
28
|
+
删除空文件夹
|
|
29
|
+
--move|-m [源地址] [软链接地址]
|
|
30
|
+
移动文件或文件夹
|
|
31
|
+
--copy|-c [源地址] [目标地址]
|
|
32
|
+
复制文件或文件夹
|
|
33
|
+
--link|-l [源地址] [软链接地址]
|
|
34
|
+
创建磁盘链接
|
|
35
|
+
(eg: oipage-cli disk -m ./test.js ~/test.js -f )
|
|
36
|
+
|
|
37
|
+
【3】oipage-cli run "任务一" "任务二" ... 运行多命令
|
|
38
|
+
( 如果希望动态给任务传递参数,可以查看: https://github.com/oi-contrib/OIPage/issues/5 )
|
|
39
|
+
|
|
40
|
+
【4】oipage-cli network 网络相关
|
|
41
|
+
--log
|
|
42
|
+
打印网络信息
|
|
43
|
+
(eg: oipage-cli network --log )
|
|
44
|
+
\x1b[0m`);
|
|
45
|
+
|
|
46
46
|
};
|
package/bin/intercept.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
exports.doIntercept = function (url, intercept, request, response, wsHandler) {
|
|
2
|
-
for (let item of intercept) {
|
|
3
|
-
if (item.test.test(url)) {
|
|
4
|
-
item.handler(request, response, wsHandler);
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
exports.testIntercept = function (url, intercept) {
|
|
11
|
-
for (let item of intercept) {
|
|
12
|
-
if (item.test.test(url)) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
exports.doIntercept = function (url, intercept, request, response, wsHandler) {
|
|
2
|
+
for (let item of intercept) {
|
|
3
|
+
if (item.test.test(url)) {
|
|
4
|
+
item.handler(request, response, wsHandler);
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.testIntercept = function (url, intercept) {
|
|
11
|
+
for (let item of intercept) {
|
|
12
|
+
if (item.test.test(url)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
16
|
}
|
package/bin/network.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const networkInfo = require("./tools/network");
|
|
2
|
-
|
|
3
|
-
module.exports = function (config) {
|
|
4
|
-
let info = networkInfo(true);
|
|
5
|
-
|
|
6
|
-
// 执行一个个任务
|
|
7
|
-
for (let i = 0; i < config.value.length; i++) {
|
|
8
|
-
|
|
9
|
-
// 打印信息
|
|
10
|
-
if (config.value[i].name === "--log") {
|
|
11
|
-
|
|
12
|
-
for (let iptype of ["IPv4", "IPv6"]) {
|
|
13
|
-
console.log("\n" + iptype);
|
|
14
|
-
for (let i = 0; i < info[iptype].length; i++) {
|
|
15
|
-
console.log(" \x1b[1m\x1b[32m" + info[iptype][i].address + "\x1b[0m " + info[iptype][i].mac);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
console.log("");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
const networkInfo = require("./tools/network");
|
|
2
|
+
|
|
3
|
+
module.exports = function (config) {
|
|
4
|
+
let info = networkInfo(true);
|
|
5
|
+
|
|
6
|
+
// 执行一个个任务
|
|
7
|
+
for (let i = 0; i < config.value.length; i++) {
|
|
8
|
+
|
|
9
|
+
// 打印信息
|
|
10
|
+
if (config.value[i].name === "--log") {
|
|
11
|
+
|
|
12
|
+
for (let iptype of ["IPv4", "IPv6"]) {
|
|
13
|
+
console.log("\n" + iptype);
|
|
14
|
+
for (let i = 0; i < info[iptype].length; i++) {
|
|
15
|
+
console.log(" \x1b[1m\x1b[32m" + info[iptype][i].address + "\x1b[0m " + info[iptype][i].mac);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log("");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
22
|
};
|
package/bin/proxy.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
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 + '
|
|
18
|
-
});
|
|
19
|
-
response.write(err);
|
|
20
|
-
response.end();
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
let headers = request.headers;
|
|
24
|
-
let url = decodeURIComponent(request.url);
|
|
25
|
-
|
|
26
|
-
if (proxyItem.pathRewrite) {
|
|
27
|
-
for (pathRewrite_key in proxyItem.pathRewrite) {
|
|
28
|
-
url = url.replace(new RegExp(pathRewrite_key), proxyItem.pathRewrite[pathRewrite_key]);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let fullUrl = proxy[key].target + url;
|
|
33
|
-
|
|
34
|
-
let handler = /^https/.test(url) ? https : http;
|
|
35
|
-
|
|
36
|
-
let execArray = /https*:\/\/([^\/]+)(.+)?/.exec(fullUrl);
|
|
37
|
-
let hostport = execArray[1].split(":");
|
|
38
|
-
|
|
39
|
-
// 创建与目标服务器的连接
|
|
40
|
-
const req = handler.request({
|
|
41
|
-
hostname: hostport[0],
|
|
42
|
-
port: hostport[1] || 80,
|
|
43
|
-
path: execArray[2] || "/",
|
|
44
|
-
method: request.method,
|
|
45
|
-
headers
|
|
46
|
-
}, (res) => {
|
|
47
|
-
|
|
48
|
-
let resHeaders = {
|
|
49
|
-
...res.headers
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 标记响应服务器
|
|
53
|
-
delete resHeaders["server"];
|
|
54
|
-
resHeaders["Server"] = 'Powered by ' + args.name + '
|
|
55
|
-
|
|
56
|
-
// 设置响应头
|
|
57
|
-
response.writeHead(res.statusCode, resHeaders);
|
|
58
|
-
// 流式传输响应体
|
|
59
|
-
res.pipe(response);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// 错误处理
|
|
63
|
-
req.on('error', (e) => {
|
|
64
|
-
throwError(e.message);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// 将原始请求体传递给目标服务器
|
|
68
|
-
request.pipe(req);
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return intercept;
|
|
75
|
-
};
|
|
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 = decodeURIComponent(request.url);
|
|
25
|
+
|
|
26
|
+
if (proxyItem.pathRewrite) {
|
|
27
|
+
for (pathRewrite_key in proxyItem.pathRewrite) {
|
|
28
|
+
url = url.replace(new RegExp(pathRewrite_key), proxyItem.pathRewrite[pathRewrite_key]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let fullUrl = proxy[key].target + url;
|
|
33
|
+
|
|
34
|
+
let handler = /^https/.test(url) ? https : http;
|
|
35
|
+
|
|
36
|
+
let execArray = /https*:\/\/([^\/]+)(.+)?/.exec(fullUrl);
|
|
37
|
+
let hostport = execArray[1].split(":");
|
|
38
|
+
|
|
39
|
+
// 创建与目标服务器的连接
|
|
40
|
+
const req = handler.request({
|
|
41
|
+
hostname: hostport[0],
|
|
42
|
+
port: hostport[1] || 80,
|
|
43
|
+
path: execArray[2] || "/",
|
|
44
|
+
method: request.method,
|
|
45
|
+
headers
|
|
46
|
+
}, (res) => {
|
|
47
|
+
|
|
48
|
+
let resHeaders = {
|
|
49
|
+
...res.headers
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 标记响应服务器
|
|
53
|
+
delete resHeaders["server"];
|
|
54
|
+
resHeaders["Server"] = 'Powered by ' + args.name + "@" + args.version + ' proxy';
|
|
55
|
+
|
|
56
|
+
// 设置响应头
|
|
57
|
+
response.writeHead(res.statusCode, resHeaders);
|
|
58
|
+
// 流式传输响应体
|
|
59
|
+
res.pipe(response);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// 错误处理
|
|
63
|
+
req.on('error', (e) => {
|
|
64
|
+
throwError(e.message);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// 将原始请求体传递给目标服务器
|
|
68
|
+
request.pipe(req);
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return intercept;
|
|
75
|
+
};
|
package/bin/run
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
process.title = 'OIPage';
|
|
6
|
-
|
|
7
|
-
const { spawn } = require('child_process');
|
|
8
|
-
const { join } = require("path");
|
|
9
|
-
const { existsSync, lstatSync } = require("fs");
|
|
10
|
-
const { mergeOption } = require("vislite");
|
|
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
|
-
cache: true,
|
|
26
|
-
proxy: {},
|
|
27
|
-
intercept: []
|
|
28
|
-
},
|
|
29
|
-
module: {
|
|
30
|
-
rules: []
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (argvObj["--proxy"] && argvObj["--proxy"].length === 2) {
|
|
35
|
-
config.devServer.proxy[argvObj["--proxy"][0]] = {
|
|
36
|
-
target: argvObj["--proxy"][1],
|
|
37
|
-
pathRewrite: { ['^' + argvObj["--proxy"][0]]: '' }
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 如果设置了配置文件
|
|
42
|
-
if (argvObj["--config"]) {
|
|
43
|
-
let configPath = join(process.cwd(), argvObj["--config"][0] || "./oipage.config.js");
|
|
44
|
-
if (existsSync(configPath) && !lstatSync(configPath).isDirectory()) {
|
|
45
|
-
let configValue = require(configPath);
|
|
46
|
-
mergeOption(config, configValue);
|
|
47
|
-
} else {
|
|
48
|
-
console.log("\x1b[0m\x1b[31m" + configPath + "\x1b[0m");
|
|
49
|
-
throw new Error("OIPage: The configuration file does not exist or is not a file.");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if ((argvObj["--port"] || [])[0]) config.devServer.port = (argvObj["--port"] || [])[0];
|
|
54
|
-
if ((argvObj["--baseUrl"] || [])[0]) config.devServer.baseUrl = (argvObj["--baseUrl"] || [])[0];
|
|
55
|
-
if ((argvObj["--cache"] || [])[0]) config.devServer.cache = (argvObj["--cache"] || [])[0] === "true";
|
|
56
|
-
|
|
57
|
-
require("./serve.js")(config);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 磁盘操作
|
|
61
|
-
else if (process.argv[2] === "disk") {
|
|
62
|
-
|
|
63
|
-
let argvObj = formatArgv(process.argv, {
|
|
64
|
-
"-f": "--force",
|
|
65
|
-
"-d": "--delete",
|
|
66
|
-
"-m": "--move",
|
|
67
|
-
"-c": "--copy",
|
|
68
|
-
"-l": "--link"
|
|
69
|
-
}, true);
|
|
70
|
-
|
|
71
|
-
require("./disk.js")(argvObj);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 运行多命令
|
|
75
|
-
else if (process.argv[2] === "run") {
|
|
76
|
-
|
|
77
|
-
let argvObj = formatArgv(process.argv, {});
|
|
78
|
-
|
|
79
|
-
let tasks = [], runArgs = [];
|
|
80
|
-
for (let index = 0; index < argvObj.args.length; index++) {
|
|
81
|
-
|
|
82
|
-
// 参数
|
|
83
|
-
if (/^:/.test(argvObj.args[index])) {
|
|
84
|
-
runArgs.push(argvObj.args[index].replace(/^:/, ""));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 任务
|
|
88
|
-
else {
|
|
89
|
-
tasks.push(argvObj.args[index]);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (let index = 0; index < tasks.length; index++) {
|
|
94
|
-
|
|
95
|
-
// 补充动态参数的支持
|
|
96
|
-
// npm run bug:issue5 ":-p 9090"
|
|
97
|
-
// 2025年12月1日 于南京
|
|
98
|
-
let task = (tasks[index] + (runArgs[index] ? (" " + runArgs[index]) : "")).split(" ");
|
|
99
|
-
let command = task.shift();
|
|
100
|
-
|
|
101
|
-
// 修复exec无法正常使用logform问题
|
|
102
|
-
// npm run bug:issue4
|
|
103
|
-
// 2025年12月2日 于南京
|
|
104
|
-
spawn(command, task, {
|
|
105
|
-
|
|
106
|
-
// https://nodejs.org/api/child_process.html#child_process_options_stdio
|
|
107
|
-
stdio: 'inherit',
|
|
108
|
-
|
|
109
|
-
// 修复https://github.com/oi-contrib/OIPage/issues/8
|
|
110
|
-
// 在Unix系统中使用`/bin/sh`,在Windows系统中使用`process.env.ComSpec`
|
|
111
|
-
// 2025年12月28日 于南京
|
|
112
|
-
shell: true
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 网络相关
|
|
119
|
-
else if (process.argv[2] === "network") {
|
|
120
|
-
|
|
121
|
-
let argvObj = formatArgv(process.argv, {}, true);
|
|
122
|
-
|
|
123
|
-
require("./network.js")(argvObj);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 默认,帮助
|
|
127
|
-
else {
|
|
128
|
-
require("./help.js")();
|
|
129
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
process.title = 'OIPage';
|
|
6
|
+
|
|
7
|
+
const { spawn } = require('child_process');
|
|
8
|
+
const { join } = require("path");
|
|
9
|
+
const { existsSync, lstatSync } = require("fs");
|
|
10
|
+
const { mergeOption } = require("vislite");
|
|
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
|
+
cache: true,
|
|
26
|
+
proxy: {},
|
|
27
|
+
intercept: []
|
|
28
|
+
},
|
|
29
|
+
module: {
|
|
30
|
+
rules: []
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (argvObj["--proxy"] && argvObj["--proxy"].length === 2) {
|
|
35
|
+
config.devServer.proxy[argvObj["--proxy"][0]] = {
|
|
36
|
+
target: argvObj["--proxy"][1],
|
|
37
|
+
pathRewrite: { ['^' + argvObj["--proxy"][0]]: '' }
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 如果设置了配置文件
|
|
42
|
+
if (argvObj["--config"]) {
|
|
43
|
+
let configPath = join(process.cwd(), argvObj["--config"][0] || "./oipage.config.js");
|
|
44
|
+
if (existsSync(configPath) && !lstatSync(configPath).isDirectory()) {
|
|
45
|
+
let configValue = require(configPath);
|
|
46
|
+
mergeOption(config, configValue);
|
|
47
|
+
} else {
|
|
48
|
+
console.log("\x1b[0m\x1b[31m" + configPath + "\x1b[0m");
|
|
49
|
+
throw new Error("OIPage: The configuration file does not exist or is not a file.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ((argvObj["--port"] || [])[0]) config.devServer.port = (argvObj["--port"] || [])[0];
|
|
54
|
+
if ((argvObj["--baseUrl"] || [])[0]) config.devServer.baseUrl = (argvObj["--baseUrl"] || [])[0];
|
|
55
|
+
if ((argvObj["--cache"] || [])[0]) config.devServer.cache = (argvObj["--cache"] || [])[0] === "true";
|
|
56
|
+
|
|
57
|
+
require("./serve.js")(config);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 磁盘操作
|
|
61
|
+
else if (process.argv[2] === "disk") {
|
|
62
|
+
|
|
63
|
+
let argvObj = formatArgv(process.argv, {
|
|
64
|
+
"-f": "--force",
|
|
65
|
+
"-d": "--delete",
|
|
66
|
+
"-m": "--move",
|
|
67
|
+
"-c": "--copy",
|
|
68
|
+
"-l": "--link"
|
|
69
|
+
}, true);
|
|
70
|
+
|
|
71
|
+
require("./disk.js")(argvObj);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 运行多命令
|
|
75
|
+
else if (process.argv[2] === "run") {
|
|
76
|
+
|
|
77
|
+
let argvObj = formatArgv(process.argv, {});
|
|
78
|
+
|
|
79
|
+
let tasks = [], runArgs = [];
|
|
80
|
+
for (let index = 0; index < argvObj.args.length; index++) {
|
|
81
|
+
|
|
82
|
+
// 参数
|
|
83
|
+
if (/^:/.test(argvObj.args[index])) {
|
|
84
|
+
runArgs.push(argvObj.args[index].replace(/^:/, ""));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 任务
|
|
88
|
+
else {
|
|
89
|
+
tasks.push(argvObj.args[index]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (let index = 0; index < tasks.length; index++) {
|
|
94
|
+
|
|
95
|
+
// 补充动态参数的支持
|
|
96
|
+
// npm run bug:issue5 ":-p 9090"
|
|
97
|
+
// 2025年12月1日 于南京
|
|
98
|
+
let task = (tasks[index] + (runArgs[index] ? (" " + runArgs[index]) : "")).split(" ");
|
|
99
|
+
let command = task.shift();
|
|
100
|
+
|
|
101
|
+
// 修复exec无法正常使用logform问题
|
|
102
|
+
// npm run bug:issue4
|
|
103
|
+
// 2025年12月2日 于南京
|
|
104
|
+
spawn(command, task, {
|
|
105
|
+
|
|
106
|
+
// https://nodejs.org/api/child_process.html#child_process_options_stdio
|
|
107
|
+
stdio: 'inherit',
|
|
108
|
+
|
|
109
|
+
// 修复https://github.com/oi-contrib/OIPage/issues/8
|
|
110
|
+
// 在Unix系统中使用`/bin/sh`,在Windows系统中使用`process.env.ComSpec`
|
|
111
|
+
// 2025年12月28日 于南京
|
|
112
|
+
shell: true
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 网络相关
|
|
119
|
+
else if (process.argv[2] === "network") {
|
|
120
|
+
|
|
121
|
+
let argvObj = formatArgv(process.argv, {}, true);
|
|
122
|
+
|
|
123
|
+
require("./network.js")(argvObj);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 默认,帮助
|
|
127
|
+
else {
|
|
128
|
+
require("./help.js")();
|
|
129
|
+
}
|