@oipage/cli 0.1.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 +12 -0
- package/.mailmap +1 -0
- package/AUTHORS.txt +6 -0
- package/CHANGELOG +5 -0
- package/LICENSE +21 -0
- package/README.md +184 -0
- package/bin/WebSocket/decodeWsFrame.js +43 -0
- package/bin/WebSocket/encodeWsFrame.js +28 -0
- package/bin/WebSocket/headersToJSON.js +26 -0
- package/bin/WebSocket/index.js +80 -0
- package/bin/data/mineTypes.json +105 -0
- package/bin/disk.js +43 -0
- package/bin/help.js +51 -0
- package/bin/images/file.png +0 -0
- package/bin/images/folder.png +0 -0
- package/bin/intercept.js +16 -0
- package/bin/network.js +22 -0
- package/bin/proxy.js +75 -0
- package/bin/run +134 -0
- package/bin/serve.js +189 -0
- package/bin/template/404.html +185 -0
- package/bin/tools/deleteEmptyFolder.js +34 -0
- package/bin/tools/format.js +76 -0
- package/bin/tools/network.js +43 -0
- package/bin/tools/openBrowser.js +26 -0
- package/bin/tools/resolve404.js +84 -0
- package/bin/tools/resolveImport.js +89 -0
- package/bin/website-htmls/components/ui-select-file/index.html +9 -0
- package/bin/website-htmls/components/ui-select-file/index.js +43 -0
- package/bin/website-htmls/components/ui-select-file/index.scss +45 -0
- package/bin/website-htmls/dialogs/imageSize/index.html +55 -0
- package/bin/website-htmls/dialogs/imageSize/index.js +53 -0
- package/bin/website-htmls/dialogs/imageSize/index.scss +141 -0
- package/bin/website-htmls/dialogs/index.js +53 -0
- package/bin/website-htmls/images/addFile.svg +1 -0
- package/bin/website-htmls/images/chart.png +0 -0
- package/bin/website-htmls/images/image-editor.png +0 -0
- package/bin/website-htmls/images/img-to-pdf.svg +1 -0
- package/bin/website-htmls/images/lock.png +0 -0
- package/bin/website-htmls/images/logo.png +0 -0
- package/bin/website-htmls/images/mosaic.png +0 -0
- package/bin/website-htmls/images/recorder-screen.png +0 -0
- package/bin/website-htmls/images/size.png +0 -0
- package/bin/website-htmls/images/video-player.jpeg +0 -0
- package/bin/website-htmls/index.html +18 -0
- package/bin/website-htmls/main.js +14 -0
- package/bin/website-htmls/pages/App/index.html +7 -0
- package/bin/website-htmls/pages/App/index.js +23 -0
- package/bin/website-htmls/pages/App/index.scss +44 -0
- package/bin/website-htmls/pages/appStore/index.html +6 -0
- package/bin/website-htmls/pages/appStore/index.js +20 -0
- package/bin/website-htmls/pages/appStore/index.scss +44 -0
- package/bin/website-htmls/pages/chart/index.html +9 -0
- package/bin/website-htmls/pages/chart/index.js +73 -0
- package/bin/website-htmls/pages/chart/index.scss +72 -0
- package/bin/website-htmls/pages/home/index.html +20 -0
- package/bin/website-htmls/pages/home/index.js +20 -0
- package/bin/website-htmls/pages/home/index.scss +88 -0
- package/bin/website-htmls/pages/image-editor/index.html +28 -0
- package/bin/website-htmls/pages/image-editor/index.js +107 -0
- package/bin/website-htmls/pages/image-editor/index.scss +70 -0
- package/bin/website-htmls/pages/img-to-pdf/index.html +4 -0
- package/bin/website-htmls/pages/img-to-pdf/index.js +45 -0
- package/bin/website-htmls/pages/img-to-pdf/index.scss +10 -0
- package/bin/website-htmls/pages/recorder-screen/index.html +16 -0
- package/bin/website-htmls/pages/recorder-screen/index.js +228 -0
- package/bin/website-htmls/pages/recorder-screen/index.scss +53 -0
- package/bin/website-htmls/router.config.js +30 -0
- package/bin/website-htmls/styles/common.css +44 -0
- package/bin/website-htmls/styles/normalize.css +95 -0
- package/bin/website-plugins/intercept/chart.js +34 -0
- package/bin/website-plugins/intercept/getPackage.js +18 -0
- package/bin/website-plugins/intercept/head.js +9 -0
- package/bin/website-plugins/intercept/index.js +9 -0
- package/bin/website-plugins/intercept/oipage-vislite-intercept.js +31 -0
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +37 -0
- package/bin/website-plugins/loader/index.js +12 -0
- package/bin/website-plugins/loader/oipage-html-loader.js +8 -0
- package/bin/website-plugins/loader/oipage-scss-loader.js +150 -0
- package/package.json +43 -0
- package/types/index.d.ts +77 -0
package/bin/proxy.js
ADDED
|
@@ -0,0 +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 + "@" + 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
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
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("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
|
+
open: false,
|
|
26
|
+
cache: true,
|
|
27
|
+
proxy: {},
|
|
28
|
+
intercept: [],
|
|
29
|
+
404: null,
|
|
30
|
+
website: true
|
|
31
|
+
},
|
|
32
|
+
module: {
|
|
33
|
+
rules: []
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (argvObj["--proxy"] && argvObj["--proxy"].length === 2) {
|
|
38
|
+
config.devServer.proxy[argvObj["--proxy"][0]] = {
|
|
39
|
+
target: argvObj["--proxy"][1],
|
|
40
|
+
pathRewrite: { ['^' + argvObj["--proxy"][0]]: '' }
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 如果设置了配置文件
|
|
45
|
+
if (argvObj["--config"]) {
|
|
46
|
+
let configPath = join(process.cwd(), argvObj["--config"][0] || "./oipage.config.js");
|
|
47
|
+
if (existsSync(configPath) && !lstatSync(configPath).isDirectory()) {
|
|
48
|
+
let configValue = require(configPath);
|
|
49
|
+
mergeOption(config, configValue);
|
|
50
|
+
} else {
|
|
51
|
+
console.log("\x1b[0m\x1b[31m" + configPath + "\x1b[0m");
|
|
52
|
+
throw new Error("OIPage: The configuration file does not exist or is not a file.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (argvObj["--port"]) config.devServer.port = argvObj["--port"][0];
|
|
57
|
+
if (argvObj["--baseUrl"]) config.devServer.baseUrl = argvObj["--baseUrl"][0];
|
|
58
|
+
if (argvObj["--cache"]) config.devServer.cache = argvObj["--cache"][0] === "true";
|
|
59
|
+
if (argvObj["--open"]) config.devServer.open = argvObj["--open"][0] || true;
|
|
60
|
+
if (argvObj["--website"]) config.devServer.website = argvObj["--website"][0] === "true";
|
|
61
|
+
|
|
62
|
+
require("./serve.js")(config);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 磁盘操作
|
|
66
|
+
else if (process.argv[2] === "disk") {
|
|
67
|
+
|
|
68
|
+
let argvObj = formatArgv(process.argv, {
|
|
69
|
+
"-f": "--force",
|
|
70
|
+
"-d": "--delete",
|
|
71
|
+
"-m": "--move",
|
|
72
|
+
"-c": "--copy",
|
|
73
|
+
"-l": "--link"
|
|
74
|
+
}, true);
|
|
75
|
+
|
|
76
|
+
require("./disk.js")(argvObj);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 运行多命令
|
|
80
|
+
else if (process.argv[2] === "run") {
|
|
81
|
+
|
|
82
|
+
let argvObj = formatArgv(process.argv, {});
|
|
83
|
+
|
|
84
|
+
let tasks = [], runArgs = [];
|
|
85
|
+
for (let index = 0; index < argvObj.args.length; index++) {
|
|
86
|
+
|
|
87
|
+
// 参数
|
|
88
|
+
if (/^:/.test(argvObj.args[index])) {
|
|
89
|
+
runArgs.push(argvObj.args[index].replace(/^:/, ""));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 任务
|
|
93
|
+
else {
|
|
94
|
+
tasks.push(argvObj.args[index]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (let index = 0; index < tasks.length; index++) {
|
|
99
|
+
|
|
100
|
+
// 补充动态参数的支持
|
|
101
|
+
// npm run bug:issue5 ":-p 9090"
|
|
102
|
+
// 2025年12月1日 于南京
|
|
103
|
+
let task = (tasks[index] + (runArgs[index] ? (" " + runArgs[index]) : "")).split(" ");
|
|
104
|
+
let command = task.shift();
|
|
105
|
+
|
|
106
|
+
// 修复exec无法正常使用logform问题
|
|
107
|
+
// npm run bug:issue4
|
|
108
|
+
// 2025年12月2日 于南京
|
|
109
|
+
spawn(command, task, {
|
|
110
|
+
|
|
111
|
+
// https://nodejs.org/api/child_process.html#child_process_options_stdio
|
|
112
|
+
stdio: 'inherit',
|
|
113
|
+
|
|
114
|
+
// 修复https://github.com/oi-contrib/OIPage/issues/8
|
|
115
|
+
// 在Unix系统中使用`/bin/sh`,在Windows系统中使用`process.env.ComSpec`
|
|
116
|
+
// 2025年12月28日 于南京
|
|
117
|
+
shell: true
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 网络相关
|
|
124
|
+
else if (process.argv[2] === "network") {
|
|
125
|
+
|
|
126
|
+
let argvObj = formatArgv(process.argv, {}, true);
|
|
127
|
+
|
|
128
|
+
require("./network.js")(argvObj);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 默认,帮助
|
|
132
|
+
else {
|
|
133
|
+
require("./help.js")();
|
|
134
|
+
}
|
package/bin/serve.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
const { join } = require("path");
|
|
2
|
+
const { existsSync, lstatSync, statSync, createReadStream } = require("fs");
|
|
3
|
+
const { createServer } = require('http');
|
|
4
|
+
const packageValue = require("../package.json");
|
|
5
|
+
const network = require("./tools/network.js");
|
|
6
|
+
const mineTypes = require("./data/mineTypes.json");
|
|
7
|
+
const resolveImportFactory = require("./tools/resolveImport.js");
|
|
8
|
+
const openBrowser = require("./tools/openBrowser.js");
|
|
9
|
+
const { doIntercept } = require("./intercept.js");
|
|
10
|
+
const proxy = require("./proxy.js");
|
|
11
|
+
const resolve404_default = require("./tools/resolve404.js");
|
|
12
|
+
const websiteIntercept = require("./website-plugins/intercept/index.js");
|
|
13
|
+
const websiteLoader = require("./website-plugins/loader/index.js");
|
|
14
|
+
|
|
15
|
+
const WebSocketClass = require("./WebSocket/index.js");
|
|
16
|
+
|
|
17
|
+
// 开发服务器
|
|
18
|
+
module.exports = function (config) {
|
|
19
|
+
let startTime = new Date().valueOf();
|
|
20
|
+
|
|
21
|
+
const resolve404 = config.devServer["404"] || resolve404_default;
|
|
22
|
+
const cache = "cache" in config.devServer ? config.devServer.cache : true;
|
|
23
|
+
const website = "website" in config.devServer ? config.devServer.website : true;
|
|
24
|
+
const port = +config.devServer.port; // 端口号
|
|
25
|
+
const basePath = (/^\./.test(config.devServer.baseUrl)) ? join(process.cwd(), config.devServer.baseUrl) : config.devServer.baseUrl; // 服务器根路径
|
|
26
|
+
|
|
27
|
+
const name = (config.name || "OIPage") + "-http-server";
|
|
28
|
+
const version = config.version || packageValue.version;
|
|
29
|
+
|
|
30
|
+
const wsHandler = WebSocketClass(port + 1, (config.name || "OIPage") + "-ws-server", version);
|
|
31
|
+
|
|
32
|
+
let Server = createServer(function (request, response) {
|
|
33
|
+
let headers = request.headers;
|
|
34
|
+
let url = decodeURIComponent(request.url);
|
|
35
|
+
|
|
36
|
+
let urlArray = url.split("?");
|
|
37
|
+
url = urlArray[0];
|
|
38
|
+
|
|
39
|
+
// 请求的文件路径
|
|
40
|
+
let filePath;
|
|
41
|
+
|
|
42
|
+
let isWebsite = website && /^\/_oipage_cli_website_\//.test(url);
|
|
43
|
+
if (isWebsite) {
|
|
44
|
+
filePath = join(__dirname, "./website-htmls/", url.replace(/^\/_oipage_cli_website_\//, ""));
|
|
45
|
+
} else {
|
|
46
|
+
filePath = join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let proxyIntercept = proxy({
|
|
50
|
+
name,
|
|
51
|
+
version
|
|
52
|
+
}, config.devServer.proxy || {});
|
|
53
|
+
delete config.devServer.proxy;
|
|
54
|
+
for (let i = 0; i < proxyIntercept.length; i++) {
|
|
55
|
+
config.devServer.intercept.push(proxyIntercept[i]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 请求拦截
|
|
59
|
+
if (doIntercept(url.replace(/^\/_oipage_cli_website_/, "").replace(/^\/@modules\//, ""), isWebsite ? websiteIntercept : config.devServer.intercept, request, response, wsHandler)) {
|
|
60
|
+
console.log("<i> \x1b[1m\x1b[32m[" + name + "] intercept: " + url + '\x1b[0m ' + new Date().toLocaleString());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 如果存在且是文件
|
|
64
|
+
else if (existsSync(filePath) && !lstatSync(filePath).isDirectory()) {
|
|
65
|
+
|
|
66
|
+
// 判断是否是请求而无需进一步解析
|
|
67
|
+
// 2025年12月5日 于南京
|
|
68
|
+
let isXHR = headers["sec-fetch-dest"] === "empty";
|
|
69
|
+
|
|
70
|
+
let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
|
|
71
|
+
let fileType = mineTypes[dotName]; // 文件类型
|
|
72
|
+
let fileInfo = statSync(filePath);
|
|
73
|
+
|
|
74
|
+
let fileModifiedTime = new Date(fileInfo.mtime).toGMTString();
|
|
75
|
+
|
|
76
|
+
let responseHeader = {
|
|
77
|
+
'Content-Type': (fileType || "text/plain") + ";charset=utf-8",
|
|
78
|
+
'Access-Control-Allow-Origin': '*',
|
|
79
|
+
'Server': 'Powered by ' + name + '@' + version,
|
|
80
|
+
'Cache-Control': 'no-cache',
|
|
81
|
+
// 'Content-Length': fileInfo.size, // 会导致拦截修改的文本内容不对
|
|
82
|
+
|
|
83
|
+
// 与if-modified-since配合使用,做缓存验证
|
|
84
|
+
'Last-Modified': fileModifiedTime,
|
|
85
|
+
|
|
86
|
+
// 与if-none-match配合使用,做缓存验证
|
|
87
|
+
// 'ETag': basePath + "-" + new Date(fileInfo.mtime).toString()
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (cache && headers["if-modified-since"]) {
|
|
91
|
+
let ifModifiedSince = new Date(headers["if-modified-since"]).valueOf()
|
|
92
|
+
let lastModified = new Date(fileModifiedTime).valueOf()
|
|
93
|
+
|
|
94
|
+
// 注意这里不能使用<=,否则
|
|
95
|
+
// 1、会出现时区问题
|
|
96
|
+
// 2、作为开发服务器,可能同一个url地址对应的文件不同,被误判为未修改
|
|
97
|
+
// 2025年12月29日 于南京
|
|
98
|
+
// if (lastModified <= ifModifiedSince) {}
|
|
99
|
+
if (lastModified === ifModifiedSince) {
|
|
100
|
+
response.writeHead('304', responseHeader);
|
|
101
|
+
response.end();
|
|
102
|
+
console.log("<i> \x1b[1m\x1b[32m[" + name + "] Cache File: " + url + "\x1b[0m " + new Date().toLocaleString() + "\x1b[33m\x1b[1m 304" + (isXHR ? " " + request.method : "") + "\x1b[0m");
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let sendType = "";
|
|
108
|
+
let entry = headers.accept !== "*/*";
|
|
109
|
+
|
|
110
|
+
// 如果文件小于10M,认为不大,直接读取
|
|
111
|
+
if (fileInfo.size < 10 * 1024 * 1024) {
|
|
112
|
+
let { source, resolveImport } = resolveImportFactory(basePath, filePath, entry, isWebsite ? websiteIntercept : config.devServer.intercept, urlArray[1] === "download", isWebsite)
|
|
113
|
+
|
|
114
|
+
// 只处理非下载文件
|
|
115
|
+
// 过大的也不进行处理
|
|
116
|
+
// (对website无效)
|
|
117
|
+
if (urlArray[1] !== "download") {
|
|
118
|
+
let loaders = isWebsite ? websiteLoader : config.module;
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < loaders.rules.length; i++) {
|
|
121
|
+
if (loaders.rules[i].test.test(filePath)) {
|
|
122
|
+
source = loaders.rules[i].use.call({
|
|
123
|
+
root: basePath, // 服务器根路径
|
|
124
|
+
path: filePath.replace(basePath, ""), // 文件相对路径
|
|
125
|
+
entry, // 是否是浏览器地址栏直接访问
|
|
126
|
+
setFileType(_fileType) { // 设置文件类型
|
|
127
|
+
fileType = _fileType;
|
|
128
|
+
responseHeader['Content-Type'] = _fileType + ";charset=utf-8";
|
|
129
|
+
}
|
|
130
|
+
}, source);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
sendType = "Read";
|
|
138
|
+
response.writeHead('200', responseHeader);
|
|
139
|
+
response.write(isXHR ? source : resolveImport(source, fileType !== "application/javascript"));
|
|
140
|
+
response.end();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 对于大文件,使用流读取
|
|
144
|
+
else {
|
|
145
|
+
sendType = "Stream";
|
|
146
|
+
|
|
147
|
+
responseHeader['Content-Length'] = fileInfo.size
|
|
148
|
+
|
|
149
|
+
response.writeHead('200', responseHeader);
|
|
150
|
+
createReadStream(filePath).pipe(response);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
console.log("<i> \x1b[1m\x1b[32m[" + name + "] " + sendType + " File: " + url + '\x1b[0m ' + new Date().toLocaleString() + "\x1b[33m\x1b[1m" + (isXHR ? " " + request.method : "") + "\x1b[0m");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 否则就是404
|
|
157
|
+
else {
|
|
158
|
+
response.writeHead(404, {
|
|
159
|
+
'Content-Type': "text/html;charset=utf-8",
|
|
160
|
+
'Access-Control-Allow-Origin': '*',
|
|
161
|
+
'Server': 'Powered by ' + name + '@' + version
|
|
162
|
+
});
|
|
163
|
+
response.write(resolve404(filePath, url, website));
|
|
164
|
+
response.end();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
Server.listen(port);
|
|
170
|
+
|
|
171
|
+
// 获取网络信息
|
|
172
|
+
let networkValue = network();
|
|
173
|
+
|
|
174
|
+
// 打印成功提示
|
|
175
|
+
console.log('<i> \x1b[1m\x1b[32m[' + name + '] Project is running at:\x1b[0m');
|
|
176
|
+
console.log('<i> \x1b[1m\x1b[32m[' + name + '] Loopback: \x1b[36mhttp://localhost:' + port + '/\x1b[0m');
|
|
177
|
+
for (let ipv4Item of networkValue.IPv4) console.log('<i> \x1b[1m\x1b[32m[' + name + '] On Your Network (IPv4):\x1b[36m http://' + ipv4Item.address + ':' + port + '/\x1b[0m');
|
|
178
|
+
for (let ipv6Item of networkValue.IPv6) console.log('<i> \x1b[1m\x1b[32m[' + name + '] On Your Network (IPv6): \x1b[36mhttp://[' + ipv6Item.address + ']:' + port + '/\x1b[0m');
|
|
179
|
+
console.log('<i> \x1b[1m\x1b[32m[' + name + '] Content not from ' + (config.name || "OIPage") + ' is served from \x1b[36m"' + basePath + '" \x1b[0mdirectory');
|
|
180
|
+
|
|
181
|
+
if (typeof config.devServer.open === "string" || config.devServer.open) {
|
|
182
|
+
let url = 'http://localhost:' + port + "/" + (typeof config.devServer.open === "string" ? config.devServer.open : "");
|
|
183
|
+
openBrowser(url);
|
|
184
|
+
console.log('<i> \x1b[1m\x1b[32m[' + name + '] Open: \x1b[36m' + url + '\x1b[0m');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!cache) console.log('<i> \x1b[1m\x1b[32m[' + name + '] Cancel 304 Cache!\x1b[0m');
|
|
188
|
+
console.log('\n' + (config.name || "OIPage") + ' ' + version + ' compiled \x1b[1m\x1b[32msuccessfully\x1b[0m in ' + (new Date().valueOf() - startTime) + ' ms\n');
|
|
189
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-cn">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
8
|
+
<title>404 Not Found</title>
|
|
9
|
+
<link rel="shortcut icon" href="/_oipage_cli_website_/logo.png">
|
|
10
|
+
<style>
|
|
11
|
+
body {
|
|
12
|
+
margin: 0px;
|
|
13
|
+
background-color: #ffffff;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-wrap: wrap;
|
|
16
|
+
padding: 100px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
a {
|
|
20
|
+
text-decoration: none;
|
|
21
|
+
color: #284259;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
a:hover {
|
|
25
|
+
text-decoration: underline;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.fork {
|
|
29
|
+
line-height: 30px;
|
|
30
|
+
position: fixed;
|
|
31
|
+
background-color: #607D8B;
|
|
32
|
+
text-align: center;
|
|
33
|
+
color: white;
|
|
34
|
+
outline: 2px dashed #607D8B;
|
|
35
|
+
width: 200px;
|
|
36
|
+
transform: rotate(45deg);
|
|
37
|
+
right: -45px;
|
|
38
|
+
top: 45px;
|
|
39
|
+
z-index: 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.current {
|
|
43
|
+
box-sizing: border-box;
|
|
44
|
+
position: fixed;
|
|
45
|
+
left: 0;
|
|
46
|
+
top: 0;
|
|
47
|
+
line-height: 50px;
|
|
48
|
+
padding-left: 20px;
|
|
49
|
+
font-size: 14px;
|
|
50
|
+
color: #000000;
|
|
51
|
+
font-style: italic;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.filelist {
|
|
55
|
+
box-sizing: border-box;
|
|
56
|
+
position: fixed;
|
|
57
|
+
left: 20px;
|
|
58
|
+
top: 50px;
|
|
59
|
+
outline: 1px solid #9E9E9E;
|
|
60
|
+
width: calc(100vw - 40px);
|
|
61
|
+
|
|
62
|
+
/* 2025年9月17日 于南京 */
|
|
63
|
+
/* 100vh改成100%是为了解决手机端显示问题 */
|
|
64
|
+
height: calc(100% - 100px);
|
|
65
|
+
|
|
66
|
+
overflow: auto;
|
|
67
|
+
padding: 20px;
|
|
68
|
+
border-radius: 5px;
|
|
69
|
+
background-color: #fcfcfc;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.filelist>table {
|
|
73
|
+
width: 100%;
|
|
74
|
+
text-align: left;
|
|
75
|
+
border-collapse: collapse;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.filelist>table tr>th {
|
|
79
|
+
white-space: nowrap;
|
|
80
|
+
padding: 0 10px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.filelist>table>thead>tr>th {
|
|
84
|
+
color: #284259;
|
|
85
|
+
font-size: 13px;
|
|
86
|
+
line-height: 40px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.filelist>table>tbody>tr>th {
|
|
90
|
+
text-decoration: none;
|
|
91
|
+
font-size: 12px;
|
|
92
|
+
color: #3c3c3c;
|
|
93
|
+
word-break: break-all;
|
|
94
|
+
font-weight: 400;
|
|
95
|
+
line-height: 30px;
|
|
96
|
+
border-top: 1px solid #e4e4e4;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.filelist>table>tbody>tr>th>.btn {
|
|
100
|
+
color: white;
|
|
101
|
+
background-color: #2196F3;
|
|
102
|
+
padding: 2px 5px;
|
|
103
|
+
border-radius: 5px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.filelist>table>tbody>tr>th.name {
|
|
107
|
+
background-repeat: no-repeat;
|
|
108
|
+
background-position: left center;
|
|
109
|
+
background-size: auto 90%;
|
|
110
|
+
padding-left: 30px;
|
|
111
|
+
color: #000000;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.filelist>table>tbody>tr>th.name>span {
|
|
115
|
+
white-space: nowrap;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.filelist>table>tbody>tr.file>th.name {
|
|
119
|
+
background-image: url('${img_file}');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.filelist>table>tbody>tr.folder>th.name {
|
|
123
|
+
background-image: url('${img_folder}');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.website-link {
|
|
127
|
+
position: fixed;
|
|
128
|
+
bottom: 10px;
|
|
129
|
+
line-height: 30px;
|
|
130
|
+
left: 16px;
|
|
131
|
+
font-size: 14px;
|
|
132
|
+
text-decoration: underline;
|
|
133
|
+
font-weight: 800;
|
|
134
|
+
}
|
|
135
|
+
</style>
|
|
136
|
+
</head>
|
|
137
|
+
|
|
138
|
+
<body>
|
|
139
|
+
<a href="https://github.com/oi-contrib/oipage-cli" target="_blank" class="fork">
|
|
140
|
+
Fork me on Github
|
|
141
|
+
</a>
|
|
142
|
+
<div class="current">
|
|
143
|
+
当前位置:${current}
|
|
144
|
+
</div>
|
|
145
|
+
<div class="filelist">
|
|
146
|
+
<table>
|
|
147
|
+
<thead>
|
|
148
|
+
<tr>
|
|
149
|
+
<th>
|
|
150
|
+
名称
|
|
151
|
+
</th>
|
|
152
|
+
<th>
|
|
153
|
+
修改日期
|
|
154
|
+
</th>
|
|
155
|
+
<th>
|
|
156
|
+
类型
|
|
157
|
+
</th>
|
|
158
|
+
<th>
|
|
159
|
+
大小
|
|
160
|
+
</th>
|
|
161
|
+
<th>
|
|
162
|
+
操作
|
|
163
|
+
</th>
|
|
164
|
+
</tr>
|
|
165
|
+
</thead>
|
|
166
|
+
<tbody>
|
|
167
|
+
<tr class="folder">
|
|
168
|
+
<th class="name"><a href='../'>..</a></th>
|
|
169
|
+
<th>-</th>
|
|
170
|
+
<th>
|
|
171
|
+
文件夹
|
|
172
|
+
</th>
|
|
173
|
+
<th>-</th>
|
|
174
|
+
<th>
|
|
175
|
+
<a href='../' class="btn">打开</a>
|
|
176
|
+
</th>
|
|
177
|
+
</tr>
|
|
178
|
+
${template}
|
|
179
|
+
</tbody>
|
|
180
|
+
</table>
|
|
181
|
+
</div>
|
|
182
|
+
${website}
|
|
183
|
+
</body>
|
|
184
|
+
|
|
185
|
+
</html>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { readdirSync, lstatSync, rmdirSync, existsSync } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
|
+
|
|
4
|
+
module.exports = function (rootPath) {
|
|
5
|
+
|
|
6
|
+
// 命令地方已经确保是全路径
|
|
7
|
+
// rootPath = path.resolve(rootPath);
|
|
8
|
+
|
|
9
|
+
// 路径不存在,什么也不用干
|
|
10
|
+
if (!existsSync(rootPath)) {
|
|
11
|
+
console.log("路径不存在:\x1b[31m" + rootPath + "\x1b[0m");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
; (function deleteEmptyFolder(folderPath) {
|
|
16
|
+
let subItems = readdirSync(folderPath);
|
|
17
|
+
if (subItems.length > 0) {
|
|
18
|
+
for (let i = 0; i < subItems.length; i++) {
|
|
19
|
+
let itemPath = join(folderPath, subItems[i]);
|
|
20
|
+
if (lstatSync(itemPath).isDirectory()) deleteEmptyFolder(itemPath);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
rmdirSync(folderPath);
|
|
24
|
+
|
|
25
|
+
folderPath = join(folderPath, "..");
|
|
26
|
+
while (folderPath.length >= rootPath.length) {
|
|
27
|
+
subItems = readdirSync(folderPath);
|
|
28
|
+
if (readdirSync(folderPath).length > 0) break;
|
|
29
|
+
rmdirSync(folderPath);
|
|
30
|
+
folderPath = join(folderPath, "..");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})(rootPath);
|
|
34
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把字节转换成更可读的内容
|
|
3
|
+
* @param {*} value
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
exports.formatByte = function (value) {
|
|
7
|
+
if (value < 1024) return value + "Byte";
|
|
8
|
+
|
|
9
|
+
let kb = value / 1024;
|
|
10
|
+
if (kb < 1024) return kb.toFixed(1) + "KB";
|
|
11
|
+
|
|
12
|
+
let mb = kb / 1024;
|
|
13
|
+
if (mb < 1024) return mb.toFixed(1) + "MB";
|
|
14
|
+
|
|
15
|
+
let gb = mb / 1024;
|
|
16
|
+
return gb.toFixed(1) + "GB";
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 把时间变成更可读的格式
|
|
21
|
+
* @param {*} value
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
exports.formatTime = function (value) {
|
|
25
|
+
let year = value.getFullYear();
|
|
26
|
+
let month = value.getMonth() + 1;
|
|
27
|
+
let day = value.getDate();
|
|
28
|
+
|
|
29
|
+
let hour = value.getHours();
|
|
30
|
+
let minutes = value.getMinutes();
|
|
31
|
+
|
|
32
|
+
let today = new Date();
|
|
33
|
+
if (year == today.getFullYear() && month == today.getMonth() + 1 && day == today.getDate()) {
|
|
34
|
+
return "今天 " + hour + ":" + minutes;
|
|
35
|
+
} else {
|
|
36
|
+
return year + "年" + month + "月" + day + "日 " + hour + ":" + minutes;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 命令行参数解析
|
|
42
|
+
* @param {*} argvs
|
|
43
|
+
* @param {*} shorts
|
|
44
|
+
* @param {*} isArray 是否按序号记录
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
exports.formatArgv = function (argvs, shorts, isArray) {
|
|
48
|
+
let result = {}, keyName = "args", value = [];
|
|
49
|
+
if (isArray) result["value"] = [];
|
|
50
|
+
|
|
51
|
+
let pushValue = function () {
|
|
52
|
+
if (isArray && keyName !== "args") {
|
|
53
|
+
result["value"].push({
|
|
54
|
+
name: keyName,
|
|
55
|
+
value
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
result[keyName] = value;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
for (let index = 3; index < argvs.length; index++) {
|
|
63
|
+
let argv = argvs[index];
|
|
64
|
+
|
|
65
|
+
if (/^\-/.test(argv)) {
|
|
66
|
+
pushValue();
|
|
67
|
+
keyName = shorts[argv] || argv;
|
|
68
|
+
value = [];
|
|
69
|
+
} else {
|
|
70
|
+
value.push(argv);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
pushValue();
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
|
+
};
|