@oipage/cli 0.2.1 → 0.3.0-alpha.2

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.
Files changed (73) hide show
  1. package/.github/FUNDING.yml +11 -11
  2. package/AUTHORS.txt +6 -6
  3. package/CHANGELOG +40 -21
  4. package/LICENSE +20 -20
  5. package/README.md +132 -132
  6. package/bin/WebSocket/decodeWsFrame.js +43 -43
  7. package/bin/WebSocket/encodeWsFrame.js +28 -28
  8. package/bin/WebSocket/headersToJSON.js +26 -26
  9. package/bin/WebSocket/index.js +106 -83
  10. package/bin/data/mineTypes.json +104 -104
  11. package/bin/disk.js +42 -42
  12. package/bin/help.js +53 -50
  13. package/bin/intercept.js +15 -15
  14. package/bin/network.js +21 -21
  15. package/bin/notebook/index.js +9 -0
  16. package/bin/proxy.js +82 -75
  17. package/bin/run +142 -134
  18. package/bin/serve.js +245 -195
  19. package/bin/template/404.html +184 -184
  20. package/bin/tools/deleteEmptyFolder.js +33 -33
  21. package/bin/tools/format.js +75 -75
  22. package/bin/tools/network.js +42 -42
  23. package/bin/tools/openBrowser.js +34 -25
  24. package/bin/tools/resolve404.js +98 -83
  25. package/bin/tools/resolveImport.js +89 -88
  26. package/bin/website-htmls/components/ui-select-file/index.html +8 -8
  27. package/bin/website-htmls/components/ui-select-file/index.js +42 -42
  28. package/bin/website-htmls/components/ui-select-file/index.scss +44 -44
  29. package/bin/website-htmls/dialogs/imageSize/index.html +54 -54
  30. package/bin/website-htmls/dialogs/imageSize/index.js +53 -53
  31. package/bin/website-htmls/dialogs/imageSize/index.scss +140 -140
  32. package/bin/website-htmls/dialogs/index.js +52 -52
  33. package/bin/website-htmls/images/addFile.svg +1 -1
  34. package/bin/website-htmls/images/img-to-pdf.svg +1 -1
  35. package/bin/website-htmls/index.html +17 -17
  36. package/bin/website-htmls/main.js +13 -13
  37. package/bin/website-htmls/pages/App/index.html +6 -6
  38. package/bin/website-htmls/pages/App/index.js +22 -22
  39. package/bin/website-htmls/pages/App/index.scss +43 -43
  40. package/bin/website-htmls/pages/appStore/index.html +7 -7
  41. package/bin/website-htmls/pages/appStore/index.js +19 -19
  42. package/bin/website-htmls/pages/appStore/index.scss +54 -54
  43. package/bin/website-htmls/pages/chart/index.html +8 -8
  44. package/bin/website-htmls/pages/chart/index.js +72 -72
  45. package/bin/website-htmls/pages/chart/index.scss +71 -71
  46. package/bin/website-htmls/pages/home/index.html +19 -19
  47. package/bin/website-htmls/pages/home/index.js +19 -19
  48. package/bin/website-htmls/pages/home/index.scss +87 -87
  49. package/bin/website-htmls/pages/image-editor/index.html +27 -27
  50. package/bin/website-htmls/pages/image-editor/index.js +106 -106
  51. package/bin/website-htmls/pages/image-editor/index.scss +69 -69
  52. package/bin/website-htmls/pages/img-to-pdf/index.html +3 -3
  53. package/bin/website-htmls/pages/img-to-pdf/index.js +44 -44
  54. package/bin/website-htmls/pages/img-to-pdf/index.scss +9 -9
  55. package/bin/website-htmls/pages/recorder-screen/index.html +15 -15
  56. package/bin/website-htmls/pages/recorder-screen/index.js +227 -227
  57. package/bin/website-htmls/pages/recorder-screen/index.scss +52 -52
  58. package/bin/website-htmls/router.config.js +29 -29
  59. package/bin/website-htmls/styles/common.css +44 -44
  60. package/bin/website-htmls/styles/normalize.css +94 -94
  61. package/bin/website-plugins/intercept/chart.js +33 -33
  62. package/bin/website-plugins/intercept/getPackage.js +17 -17
  63. package/bin/website-plugins/intercept/head.js +8 -8
  64. package/bin/website-plugins/intercept/index.js +8 -8
  65. package/bin/website-plugins/intercept/oipage-vislite-intercept.js +55 -55
  66. package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +36 -36
  67. package/bin/website-plugins/loader/index.js +11 -11
  68. package/bin/website-plugins/loader/oipage-html-loader.js +7 -7
  69. package/bin/website-plugins/loader/oipage-scss-loader.js +149 -149
  70. package/docs/config.md +84 -84
  71. package/package.json +42 -42
  72. package/src/index.js +28 -28
  73. package/types/serve.d.ts +76 -76
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
  };
@@ -0,0 +1,9 @@
1
+ module.exports = function (config) {
2
+
3
+ console.log(`\x1b[36m
4
+
5
+ 1、查看指定端口的进程PID: lsof -i :[端口号]
6
+
7
+ \x1b[0m`);
8
+
9
+ };
package/bin/proxy.js CHANGED
@@ -1,75 +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 = 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
- };
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,134 +1,142 @@
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
- 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
- }
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
+ 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 if (process.argv[2] === "notebook") {
133
+
134
+ let argvObj = formatArgv(process.argv, {}, true);
135
+
136
+ require("./notebook/index.js")(argvObj);
137
+ }
138
+
139
+ // 默认,帮助
140
+ else {
141
+ require("./help.js")();
142
+ }