@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.
Files changed (81) hide show
  1. package/.github/FUNDING.yml +12 -0
  2. package/.mailmap +1 -0
  3. package/AUTHORS.txt +6 -0
  4. package/CHANGELOG +5 -0
  5. package/LICENSE +21 -0
  6. package/README.md +184 -0
  7. package/bin/WebSocket/decodeWsFrame.js +43 -0
  8. package/bin/WebSocket/encodeWsFrame.js +28 -0
  9. package/bin/WebSocket/headersToJSON.js +26 -0
  10. package/bin/WebSocket/index.js +80 -0
  11. package/bin/data/mineTypes.json +105 -0
  12. package/bin/disk.js +43 -0
  13. package/bin/help.js +51 -0
  14. package/bin/images/file.png +0 -0
  15. package/bin/images/folder.png +0 -0
  16. package/bin/intercept.js +16 -0
  17. package/bin/network.js +22 -0
  18. package/bin/proxy.js +75 -0
  19. package/bin/run +134 -0
  20. package/bin/serve.js +189 -0
  21. package/bin/template/404.html +185 -0
  22. package/bin/tools/deleteEmptyFolder.js +34 -0
  23. package/bin/tools/format.js +76 -0
  24. package/bin/tools/network.js +43 -0
  25. package/bin/tools/openBrowser.js +26 -0
  26. package/bin/tools/resolve404.js +84 -0
  27. package/bin/tools/resolveImport.js +89 -0
  28. package/bin/website-htmls/components/ui-select-file/index.html +9 -0
  29. package/bin/website-htmls/components/ui-select-file/index.js +43 -0
  30. package/bin/website-htmls/components/ui-select-file/index.scss +45 -0
  31. package/bin/website-htmls/dialogs/imageSize/index.html +55 -0
  32. package/bin/website-htmls/dialogs/imageSize/index.js +53 -0
  33. package/bin/website-htmls/dialogs/imageSize/index.scss +141 -0
  34. package/bin/website-htmls/dialogs/index.js +53 -0
  35. package/bin/website-htmls/images/addFile.svg +1 -0
  36. package/bin/website-htmls/images/chart.png +0 -0
  37. package/bin/website-htmls/images/image-editor.png +0 -0
  38. package/bin/website-htmls/images/img-to-pdf.svg +1 -0
  39. package/bin/website-htmls/images/lock.png +0 -0
  40. package/bin/website-htmls/images/logo.png +0 -0
  41. package/bin/website-htmls/images/mosaic.png +0 -0
  42. package/bin/website-htmls/images/recorder-screen.png +0 -0
  43. package/bin/website-htmls/images/size.png +0 -0
  44. package/bin/website-htmls/images/video-player.jpeg +0 -0
  45. package/bin/website-htmls/index.html +18 -0
  46. package/bin/website-htmls/main.js +14 -0
  47. package/bin/website-htmls/pages/App/index.html +7 -0
  48. package/bin/website-htmls/pages/App/index.js +23 -0
  49. package/bin/website-htmls/pages/App/index.scss +44 -0
  50. package/bin/website-htmls/pages/appStore/index.html +6 -0
  51. package/bin/website-htmls/pages/appStore/index.js +20 -0
  52. package/bin/website-htmls/pages/appStore/index.scss +44 -0
  53. package/bin/website-htmls/pages/chart/index.html +9 -0
  54. package/bin/website-htmls/pages/chart/index.js +73 -0
  55. package/bin/website-htmls/pages/chart/index.scss +72 -0
  56. package/bin/website-htmls/pages/home/index.html +20 -0
  57. package/bin/website-htmls/pages/home/index.js +20 -0
  58. package/bin/website-htmls/pages/home/index.scss +88 -0
  59. package/bin/website-htmls/pages/image-editor/index.html +28 -0
  60. package/bin/website-htmls/pages/image-editor/index.js +107 -0
  61. package/bin/website-htmls/pages/image-editor/index.scss +70 -0
  62. package/bin/website-htmls/pages/img-to-pdf/index.html +4 -0
  63. package/bin/website-htmls/pages/img-to-pdf/index.js +45 -0
  64. package/bin/website-htmls/pages/img-to-pdf/index.scss +10 -0
  65. package/bin/website-htmls/pages/recorder-screen/index.html +16 -0
  66. package/bin/website-htmls/pages/recorder-screen/index.js +228 -0
  67. package/bin/website-htmls/pages/recorder-screen/index.scss +53 -0
  68. package/bin/website-htmls/router.config.js +30 -0
  69. package/bin/website-htmls/styles/common.css +44 -0
  70. package/bin/website-htmls/styles/normalize.css +95 -0
  71. package/bin/website-plugins/intercept/chart.js +34 -0
  72. package/bin/website-plugins/intercept/getPackage.js +18 -0
  73. package/bin/website-plugins/intercept/head.js +9 -0
  74. package/bin/website-plugins/intercept/index.js +9 -0
  75. package/bin/website-plugins/intercept/oipage-vislite-intercept.js +31 -0
  76. package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +37 -0
  77. package/bin/website-plugins/loader/index.js +12 -0
  78. package/bin/website-plugins/loader/oipage-html-loader.js +8 -0
  79. package/bin/website-plugins/loader/oipage-scss-loader.js +150 -0
  80. package/package.json +43 -0
  81. package/types/index.d.ts +77 -0
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: ['https://zxl20070701.github.io/notebook/home.html']
package/.mailmap ADDED
@@ -0,0 +1 @@
1
+ zxl20070701 <1904314465@qq.com>
package/AUTHORS.txt ADDED
@@ -0,0 +1,6 @@
1
+ Authors ordered by first contribution.
2
+
3
+ zxl20070701 <1904314465@qq.com> <https://github.com/zxl20070701>
4
+
5
+ -----------------------------------------------------
6
+ We thank all of them for their contributions!
package/CHANGELOG ADDED
@@ -0,0 +1,5 @@
1
+ v0.1.0:
2
+ date:
3
+ changes:
4
+ - 初始化版本
5
+ (承接原OIPagev1.x的命令行相关功能: https://github.com/oi-contrib/OIPage/tree/v1.x)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) zxl20070701 走一步,再走一步
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # [@oipage/cli](https://github.com/oi-contrib/oipage-cli)
2
+ 开发快速助手,一个包含常用功能的命令行工具,旨在提升开发效率
3
+
4
+ <p>
5
+ <a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@oipage/cli&interval=7">
6
+ <img src="https://img.shields.io/npm/dm/@oipage/cli.svg" alt="downloads">
7
+ </a>
8
+ <a href="https://www.npmjs.com/package/@oipage/cli">
9
+ <img src="https://img.shields.io/npm/v/@oipage/cli.svg" alt="npm">
10
+ </a>
11
+ <a href="https://github.com/oi-contrib/oipage-cli/issues">
12
+ <img src="https://img.shields.io/github/issues/oi-contrib/oipage-cli" alt="issue">
13
+ </a>
14
+ <a href="https://github.com/oi-contrib/oipage-cli" target='_blank'>
15
+ <img alt="GitHub repo stars" src="https://img.shields.io/github/stars/oi-contrib/oipage-cli?style=social">
16
+ </a>
17
+ <a href="https://github.com/oi-contrib/oipage-cli">
18
+ <img src="https://img.shields.io/github/forks/oi-contrib/oipage-cli" alt="forks">
19
+ </a>
20
+ <a href="https://gitee.com/oi-contrib/oipage-cli" target='_blank'>
21
+ <img alt="Gitee repo stars" src="https://gitee.com/oi-contrib/oipage-cli/badge/star.svg">
22
+ </a>
23
+ <a href="https://gitee.com/oi-contrib/oipage-cli">
24
+ <img src="https://gitee.com/oi-contrib/oipage-cli/badge/fork.svg" alt="forks">
25
+ </a>
26
+ </p>
27
+
28
+ <img src="https://nodei.co/npm/@oipage/cli.png?downloads=true&amp;downloadRank=true&amp;stars=true" alt="NPM">
29
+
30
+ ## 如何使用?
31
+
32
+ 作为一个命令行,你可以全局安装:
33
+
34
+ ```shell
35
+ npm install -g @oipage/cli
36
+ ```
37
+
38
+ 也可以作为项目开发中的一个功能加强,在 package.json 中配置命令使用,那么就在项目中执行安装命令:
39
+
40
+ ```shell
41
+ npm install @oipage/cli --save
42
+ ```
43
+
44
+ 安装后,就可以直使用了。你可以打印帮助查看:
45
+
46
+ ```shell
47
+ oipage-cli
48
+ ```
49
+
50
+ 比如会出现类似下列内容:
51
+
52
+ ```
53
+ @oipage/cli@v1.2.0
54
+
55
+ 可以使用的命令如下:
56
+
57
+ 【1】oipage-cli serve 开发服务器
58
+ --port|-p 端口号
59
+ --baseUrl 服务器根目录
60
+ ......
61
+ ```
62
+
63
+ 根据提示我们知道,比如第一个命令,其提供了一个快速访问本地资源服务器的功能,比如执行:
64
+
65
+ ```shell
66
+ oipage-cli serve -p 8080
67
+ ```
68
+
69
+ 启动成功后,直接访问: http://localhost:8080/ 即可。
70
+
71
+ ### oipage.config.js
72
+
73
+ 通过配置文件 `oipage.config.js` 可以对服务器进行更精细化的配置:
74
+
75
+ ```shell
76
+ oipage-cli serve --config ./oipage.config.js
77
+ ```
78
+
79
+ 其中 `oipage.config.js` 格式如下:
80
+
81
+ ```js
82
+ module.exports = {
83
+ devServer: {
84
+ port: 20000,
85
+ baseUrl: "./"
86
+ },
87
+ module: {
88
+ rules: [{ // 配置对文件的自定义处理
89
+ test: /\.html$/, // 匹配文件,如果多个匹配到,只会选用第一个
90
+ use(source) { return source }
91
+ }]
92
+ }
93
+ }
94
+ ```
95
+
96
+ - 温馨提示:上述一级配置项(devServer、module等)皆可选,按需配置即可。
97
+
98
+ ## devServer
99
+
100
+ ### open
101
+
102
+ 是否自动打开浏览器,默认false,true表示打开;也可以是一段地址,比如设置open=“docs/index.html”。
103
+
104
+ ### cache
105
+
106
+ 是否开启304缓存,默认true,表示开启。
107
+
108
+ ### port
109
+
110
+ 端口,默认8080。此外,可以在执行的时候,通过命令参数覆盖(下同):
111
+
112
+ ```shell
113
+ oipage-cli serve --config ./oipage.config.js -p 20000
114
+ ```
115
+
116
+ ### baseUrl
117
+
118
+ 服务器根目录,默认当前命令行目录。可以是绝对路径,如果为相对路径,则是相对当前命令行目录。
119
+
120
+ ### 404
121
+
122
+ 自定义 404 页面,函数接收两个参数 filePath(文件磁盘路径) 和 url(请求地址)。
123
+
124
+ ```js
125
+ 404: function (filePath, url) {
126
+ return "<h1>自定义的 404 页面</h1><p>你访问的页面不存在!</p>";
127
+ }
128
+ ```
129
+
130
+ ### proxy
131
+
132
+ 转发功能
133
+
134
+ ```js
135
+ proxy: {
136
+ "/apidemo": {
137
+ target: "https://oi-contrib.github.io/OIPage",
138
+ pathRewrite: { '^/apidemo': '' }, // 地址重写,可选
139
+ }
140
+ }
141
+ ```
142
+
143
+ ### intercept
144
+
145
+ 请求拦截,可以实现针对特殊请求的自定义处理。
146
+
147
+ ```js
148
+ intercept: Array<{
149
+ test: /\.do$/,
150
+ handler(request, response) {
151
+ // todo
152
+ }
153
+ }>
154
+ ```
155
+
156
+ ## module
157
+
158
+ ### rules
159
+
160
+ 用于处理特殊文件,其中use的参数source为原始内容,此函数返回处理后的内容。此外,此函数的this包含若干有用属性或方法,具体如下:
161
+
162
+ - root: 字符串,服务器根路径。
163
+
164
+ - setFileType: 函数,用于设置文件类型。比如如果希望设置为js文件:
165
+
166
+ ```js
167
+ this.setFileType("application/javascript")
168
+ ```
169
+
170
+ - path: 字符串,文件相对路径。
171
+
172
+ - entry: 布尔值,是否是浏览器地址栏直接访问。
173
+
174
+ ## 应用市场
175
+
176
+ 为了方便日常使用,内置了一个应用市场网站,比如有如下功能:群聊天、图片编辑器等。
177
+
178
+ 已有功能或更多功能我们将根据实际情况逐步完善和维护,当然,你可以通过 [issue](https://github.com/oi-contrib/oipage-cli/issues) 给我们留言,告诉我们你的改进意见。
179
+
180
+ ## 版权
181
+
182
+ MIT License
183
+
184
+ Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
@@ -0,0 +1,43 @@
1
+
2
+ // 处理收到的数据
3
+ module.exports = function decodeWsFrame(data) {
4
+ let start = 0;
5
+ let frame = {
6
+ isFinal: (data[start] & 0x80) === 0x80,
7
+ opcode: data[start++] & 0xF,
8
+ masked: (data[start] & 0x80) === 0x80,
9
+ payloadLen: data[start++] & 0x7F,
10
+ maskingKey: '',
11
+ payloadData: null
12
+ };
13
+
14
+ if (frame.payloadLen === 126) {
15
+ frame.payloadLen = (data[start++] << 8) + data[start++];
16
+ } else if (frame.payloadLen === 127) {
17
+ frame.payloadLen = 0;
18
+ for (let i = 7; i >= 0; --i) {
19
+ frame.payloadLen += (data[start++] << (i * 8));
20
+ }
21
+ }
22
+
23
+ if (frame.payloadLen) {
24
+ if (frame.masked) {
25
+ const maskingKey = [
26
+ data[start++],
27
+ data[start++],
28
+ data[start++],
29
+ data[start++]
30
+ ];
31
+
32
+ frame.maskingKey = maskingKey;
33
+
34
+ frame.payloadData = data
35
+ .slice(start, start + frame.payloadLen)
36
+ .map((byte, idx) => byte ^ maskingKey[idx % 4]);
37
+ } else {
38
+ frame.payloadData = data.slice(start, start + frame.payloadLen);
39
+ }
40
+ }
41
+
42
+ return frame;
43
+ };
@@ -0,0 +1,28 @@
1
+
2
+ // 处理发出的数据
3
+ module.exports = function encodeWsFrame(data) {
4
+ const isFinal = data.isFinal !== undefined ? data.isFinal : true,
5
+ opcode = data.opcode !== undefined ? data.opcode : 1,
6
+ payloadData = data.payloadData ? Buffer.from(data.payloadData) : null,
7
+ payloadLen = payloadData ? payloadData.length : 0;
8
+
9
+ let frame = [];
10
+
11
+ if (isFinal) frame.push((1 << 7) + opcode);
12
+ else frame.push(opcode);
13
+
14
+ if (payloadLen < 126) {
15
+ frame.push(payloadLen);
16
+ } else if (payloadLen < 65536) {
17
+ frame.push(126, payloadLen >> 8, payloadLen & 0xFF);
18
+ } else {
19
+ frame.push(127);
20
+ for (let i = 7; i >= 0; --i) {
21
+ frame.push((payloadLen & (0xFF << (i * 8))) >> (i * 8));
22
+ }
23
+ }
24
+
25
+ frame = payloadData ? Buffer.concat([Buffer.from(frame), payloadData]) : Buffer.from(frame);
26
+
27
+ return frame;
28
+ };
@@ -0,0 +1,26 @@
1
+ module.exports = function (headersStr) {
2
+
3
+ let headersArray = headersStr.split(/\r{0,1}\n/);
4
+ let headersJSON = {};
5
+
6
+ // 第一行的内容:GET / HTTP/1.1
7
+ let firstLine = headersArray.shift().split(' ');
8
+ headersJSON.method = firstLine[0];
9
+ headersJSON.url = firstLine[1];
10
+ headersJSON.protocol = firstLine[2];
11
+
12
+ for (let item of headersArray) {
13
+ let temp = item.split(':');
14
+
15
+ if (temp.length > 1) {
16
+
17
+ let key = temp.shift();
18
+ let value = temp.join(':');
19
+
20
+ headersJSON[key] = value.trim();
21
+
22
+ }
23
+ }
24
+
25
+ return headersJSON;
26
+ };
@@ -0,0 +1,80 @@
1
+ const net = require('net');
2
+ const crypto = require('crypto');
3
+
4
+ const headersToJSON = require('./headersToJSON');
5
+ const decodeWsFrame = require('./decodeWsFrame');
6
+ const encodeWsFrame = require('./encodeWsFrame');
7
+
8
+ module.exports = function (port, name, version) {
9
+ let sockets = [];
10
+
11
+ let handler = {
12
+ notifyBrowser: (msg) => {
13
+ for (let socket of sockets) {
14
+ socket.write(encodeWsFrame(msg));
15
+ }
16
+ }
17
+ };
18
+
19
+ const server = net.createServer(socket => {
20
+
21
+ // 错误
22
+ socket.on('error', (error) => {
23
+ console.log('Connection error:', error.message);
24
+ });
25
+
26
+ // 数据
27
+ socket.on('data', buffer => {
28
+ console.log('Connection data:' + (decodeWsFrame(buffer).payloadData?.toString() || "断开连接......"));
29
+ });
30
+
31
+ // 连接
32
+ socket.once('data', buffer => {
33
+
34
+ // 把请求头变成容易操作的json
35
+ const headers = headersToJSON(buffer.toString());
36
+
37
+ // 如果是ws请求
38
+ // 就需要建立连接
39
+ if (headers.Upgrade == 'websocket') {
40
+
41
+ if (headers['Sec-WebSocket-Version'] !== '13') {
42
+ console.log('\r\n警告:当前WebSocket版本为' + headers['Sec-WebSocket-Version'] + ",可能存在兼容问题~\r\n");
43
+ }
44
+
45
+ // 开始连接
46
+ /*
47
+ 协议中规定的校验用GUID,可参考如下链接:
48
+ https://tools.ietf.org/html/rfc6455#section-5.5.2
49
+ https://stackoverflow.com/questions/13456017/what-does-258eafa5-e914-47da-95ca-c5ab0dc85b11-means-in-websocket-protocol
50
+ */
51
+ const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
52
+ const key = headers['Sec-WebSocket-Key'];
53
+ const hash = crypto.createHash('sha1'); // 创建一个签名算法为sha1的哈希对象
54
+
55
+ hash.update(`${key}${GUID}`); // 将key和GUID连接后,更新到hash
56
+ const result = hash.digest('base64'); // 生成base64字符串
57
+ const header = `HTTP/1.1 101 Switching Protocols\r\nServer: Powered by ${name}@${version}\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-Websocket-Accept: ${result}\r\n\r\n`; // 生成供前端校验用的请求头
58
+
59
+ socket.write(header); // 返回HTTP头,告知客户端校验结果,HTTP状态码101表示切换协议:https://httpstatuses.com/101。
60
+ // 若客户端校验结果正确,在控制台的Network模块可以看到HTTP请求的状态码变为101 Switching Protocols,同时客户端的ws.onopen事件被触发。
61
+
62
+ sockets.push(socket);
63
+ }
64
+
65
+ // 否则就普通的,
66
+ // 普通的由http服务器提供支持
67
+ else {
68
+ socket.end();
69
+
70
+ }
71
+ });
72
+ });
73
+
74
+ // 启动
75
+ server.listen(port);
76
+
77
+ console.log('<i> \x1b[1m\x1b[32m[' + name + '] Loopback: \x1b[36mws://localhost:' + port + '/\x1b[0m\n');
78
+
79
+ return handler;
80
+ };
@@ -0,0 +1,105 @@
1
+ {
2
+ "html": "text/html",
3
+ "htm": "text/html",
4
+ "shtml": "text/html",
5
+ "css": "text/css",
6
+ "xml": "text/xml",
7
+ "gif": "image/gif",
8
+ "jpeg": "image/jpeg",
9
+ "jpg": "image/jpeg",
10
+ "js": "application/javascript",
11
+ "atom": "application/atom+xml",
12
+ "rss": "application/rss+xml",
13
+ "mml": "text/mathml",
14
+ "txt": "text/plain",
15
+ "jad": "text/vnd.sun.j2me.app-descriptor",
16
+ "wml": "text/vnd.wap.wml",
17
+ "htc": "text/x-component",
18
+ "png": "image/png",
19
+ "tif": "image/tiff",
20
+ "tiff": "image/tiff",
21
+ "wbmp": "image/vnd.wap.wbmp",
22
+ "ico": "image/x-icon",
23
+ "jng": "image/x-jng",
24
+ "bmp": "image/x-ms-bmp",
25
+ "svg": "image/svg+xml",
26
+ "svgz": "image/svg+xml",
27
+ "webp": "image/webp",
28
+ "woff": "application/font-woff",
29
+ "jar": "application/java-archive",
30
+ "war": "application/java-archive",
31
+ "ear": "application/java-archive",
32
+ "json": "application/json",
33
+ "hqx": "application/mac-binhex40",
34
+ "doc": "application/msword",
35
+ "pdf": "application/pdf",
36
+ "ps": "application/postscript",
37
+ "eps": "application/postscript",
38
+ "ai": "application/postscript",
39
+ "rtf": "application/rtf",
40
+ "m3u8": "application/vnd.apple.mpegurl",
41
+ "xls": "application/vnd.ms-excel",
42
+ "eot": "application/vnd.ms-fontobject",
43
+ "ppt": "application/vnd.ms-powerpoint",
44
+ "wmlc": "application/vnd.wap.wmlc",
45
+ "kml": "application/vnd.google-earth.kml+xml",
46
+ "kmz": "application/vnd.google-earth.kmz",
47
+ "7z": "application/x-7z-compressed",
48
+ "cco": "application/x-cocoa",
49
+ "jardiff": "application/x-java-archive-diff",
50
+ "jnlp": "application/x-java-jnlp-file",
51
+ "run": "application/x-makeself",
52
+ "pl": "application/x-perl",
53
+ "pm": "application/x-perl",
54
+ "prc": "application/x-pilot",
55
+ "pdb": "application/x-pilot",
56
+ "rar": "application/x-rar-compressed",
57
+ "rpm": "application/x-redhat-package-manager",
58
+ "sea": "application/x-sea",
59
+ "swf": "application/x-shockwave-flash",
60
+ "sit": "application/x-stuffit",
61
+ "tcl": "application/x-tcl",
62
+ "tk": "application/x-tcl",
63
+ "der": "application/x-x509-ca-cert",
64
+ "pem": "application/x-x509-ca-cert",
65
+ "crt": "application/x-x509-ca-cert",
66
+ "xpi": "application/x-xpinstall",
67
+ "xhtml": "application/xhtml+xml",
68
+ "xspf": "application/xspf+xml",
69
+ "zip": "application/zip",
70
+ "bin": "application/octet-stream",
71
+ "exe": "application/octet-stream",
72
+ "dll": "application/octet-stream",
73
+ "deb": "application/octet-stream",
74
+ "dmg": "application/octet-stream",
75
+ "iso": "application/octet-stream",
76
+ "img": "application/octet-stream",
77
+ "msi": "application/octet-stream",
78
+ "msp": "application/octet-stream",
79
+ "msm": "application/octet-stream",
80
+ "docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
81
+ "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
82
+ "pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
83
+ "mid": "audio/midi",
84
+ "midi": "audio/midi",
85
+ "kar": "audio/midi",
86
+ "mp3": "audio/mpeg",
87
+ "ogg": "audio/ogg",
88
+ "m4a": "audio/x-m4a",
89
+ "ra": "audio/x-realaudio",
90
+ "3gpp": "video/3gpp",
91
+ "3gp": "video/3gpp",
92
+ "ts": "video/mp2t",
93
+ "mp4": "video/mp4",
94
+ "mpeg": "video/mpeg",
95
+ "mpg": "video/mpeg",
96
+ "mov": "video/quicktime",
97
+ "webm": "video/webm",
98
+ "flv": "video/x-flv",
99
+ "m4v": "video/x-m4v",
100
+ "mng": "video/x-mng",
101
+ "asx": "video/x-ms-asf",
102
+ "asf": "video/x-ms-asf",
103
+ "wmv": "video/x-ms-wmv",
104
+ "avi": "video/x-msvideo"
105
+ }
package/bin/disk.js ADDED
@@ -0,0 +1,43 @@
1
+ const { join } = require("path");
2
+ const { deleteDisk, copyDisk, moveDisk, linkDisk } = require("oipage/nodejs/disk");
3
+ const deleteEmptyFolder = require("./tools/deleteEmptyFolder");
4
+
5
+ module.exports = function (config) {
6
+ let isForce = false;
7
+
8
+ // 判断是否开启强制执行
9
+ for (let i = 0; i < config.value.length; i++) {
10
+ if (config.value[i].name === "--force") isForce = true;
11
+ }
12
+
13
+ // 执行一个个任务
14
+ for (let i = 0; i < config.value.length; i++) {
15
+
16
+ // 删除文件或文件夹
17
+ if (config.value[i].name === "--delete") {
18
+ for (let j = 0; j < config.value[i].value.length; j++) {
19
+ deleteDisk(config.value[i].value[j]);
20
+ }
21
+ }
22
+
23
+ // 移动文件或文件夹
24
+ else if (config.value[i].name === "--move") {
25
+ moveDisk(config.value[i].value[0], config.value[i].value[1], isForce);
26
+ }
27
+
28
+ // 复制文件或文件夹
29
+ else if (config.value[i].name === "--copy") {
30
+ copyDisk(config.value[i].value[0], config.value[i].value[1], isForce);
31
+ }
32
+
33
+ // 创建磁盘链接
34
+ else if (config.value[i].name === "--link") {
35
+ linkDisk(config.value[i].value[0], config.value[i].value[1], isForce);
36
+ }
37
+
38
+ // 删除空文件夹
39
+ else if (config.value[i].name === "--delempty") {
40
+ deleteEmptyFolder(join(process.cwd(), config.value[i].value[0]));
41
+ }
42
+ }
43
+ };
package/bin/help.js ADDED
@@ -0,0 +1,51 @@
1
+ const packageValue = require("../package.json");
2
+
3
+ module.exports = function () {
4
+ console.log(`\x1b[36m
5
+ @oipage/cli@v${packageValue.version}
6
+
7
+ 可以使用的命令如下:
8
+
9
+ 【1】oipage-cli serve 开发服务器
10
+ --port|-p [端口号]
11
+ 默认8080
12
+ --baseUrl [文件夹地址]
13
+ 服务器根目录
14
+ --open
15
+ 自动打开浏览器
16
+ (也可以设置打开地址,比如 oipage-cli serve --open docs/index.html)
17
+ --website [true|false]
18
+ 是否开启应用市场(默认true表示开启)
19
+ --config|-c [配置文件地址]
20
+ 设置配置文件,相对地址是相对当前命令行
21
+ --cache [true|false]
22
+ 是否启用304(默认true表示开启)
23
+ (eg: oipage-cli serve -p 20000 )
24
+ --proxy [转发前缀] [转发地址]
25
+ (注意:转发前缀会被替换为空,相当于设置了 pathRewrite: { '^/demo': '' })
26
+
27
+ 【2】oipage-cli disk 磁盘操作
28
+ --force|-f
29
+ 强制执行,如果目标地址已有内容,会直接强制删除已有内容
30
+ --delete|-d [文件或文件夹地址]
31
+ 删除文件或文件夹
32
+ --delempty [文件夹地址]
33
+ 删除空文件夹
34
+ --move|-m [源地址] [软链接地址]
35
+ 移动文件或文件夹
36
+ --copy|-c [源地址] [目标地址]
37
+ 复制文件或文件夹
38
+ --link|-l [源地址] [软链接地址]
39
+ 创建磁盘链接
40
+ (eg: oipage-cli disk -m ./test.js ~/test.js -f )
41
+
42
+ 【3】oipage-cli run "任务一" "任务二" ... 运行多命令
43
+ ( 如果希望动态给任务传递参数,可以查看: https://github.com/oi-contrib/OIPage/issues/5 )
44
+
45
+ 【4】oipage-cli network 网络相关
46
+ --log
47
+ 打印网络信息
48
+ (eg: oipage-cli network --log )
49
+ \x1b[0m`);
50
+
51
+ };
Binary file
Binary file
@@ -0,0 +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
+ }
16
+ }
package/bin/network.js ADDED
@@ -0,0 +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
+ }
22
+ };