oipage 1.3.1 → 1.4.0-alpha.1

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 (46) hide show
  1. package/.github/FUNDING.yml +11 -11
  2. package/AUTHORS.txt +6 -6
  3. package/CHANGELOG +83 -76
  4. package/LICENSE +20 -20
  5. package/README.md +80 -80
  6. package/bin/data/mineTypes.json +104 -104
  7. package/bin/disk.js +31 -31
  8. package/bin/help.js +24 -24
  9. package/bin/intercept.js +15 -15
  10. package/bin/run +96 -96
  11. package/bin/serve.d.ts +51 -0
  12. package/bin/serve.js +131 -128
  13. package/bin/template/404.html +171 -171
  14. package/bin/tools/format.js +75 -75
  15. package/bin/tools/network.js +42 -42
  16. package/bin/tools/resolve404.js +83 -83
  17. package/bin/tools/resolveImport.js +88 -88
  18. package/nodejs/animation/index.d.ts +19 -19
  19. package/nodejs/animation/index.js +104 -104
  20. package/nodejs/cmdlog/index.d.ts +20 -20
  21. package/nodejs/cmdlog/index.js +75 -75
  22. package/nodejs/disk/index.d.ts +16 -16
  23. package/nodejs/disk/index.js +78 -78
  24. package/nodejs/json/index.d.ts +9 -9
  25. package/nodejs/json/index.js +206 -206
  26. package/nodejs/logform/index.d.ts +18 -18
  27. package/nodejs/logform/index.js +94 -94
  28. package/nodejs/reader/index.d.ts +32 -32
  29. package/nodejs/reader/index.js +20 -20
  30. package/nodejs/throttle/index.d.ts +30 -30
  31. package/nodejs/throttle/index.js +50 -50
  32. package/package.json +40 -40
  33. package/web/animation/index.d.ts +19 -19
  34. package/web/animation/index.js +104 -104
  35. package/web/json/index.d.ts +9 -9
  36. package/web/json/index.js +206 -206
  37. package/web/onReady/index.d.ts +7 -7
  38. package/web/onReady/index.js +8 -8
  39. package/web/performChunk/index.d.ts +4 -4
  40. package/web/performChunk/index.js +19 -19
  41. package/web/reader/index.d.ts +32 -32
  42. package/web/reader/index.js +20 -20
  43. package/web/style/index.d.ts +21 -21
  44. package/web/style/index.js +19 -19
  45. package/web/throttle/index.d.ts +30 -30
  46. package/web/throttle/index.js +50 -50
@@ -1,76 +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;
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
76
  };
@@ -1,43 +1,43 @@
1
- const { networkInterfaces } = require("os");
2
-
3
- // 网络信息
4
- module.exports = function () {
5
-
6
- let infomation = {
7
- IPv4: [],
8
- IPv6: []
9
- };
10
-
11
- let networks = networkInterfaces();
12
-
13
- let IPv4Had = {}, IPv6Had = {};
14
-
15
- for (let typeName in networks) {
16
- let network = networks[typeName]
17
- for (let index = 0; index < network.length; index++) {
18
- if (network[index].mac != "00:00:00:00:00:00") {
19
- if (network[index].family == 'IPv4' && network[index].address != '127.0.0.1') {
20
- if (!IPv4Had[network[index].mac]) {
21
- infomation.IPv4.push({
22
- address: network[index].address,
23
- mac: network[index].mac
24
- });
25
-
26
- IPv4Had[network[index].mac] = true;
27
- }
28
- } else if (network[index].family == 'IPv6' && network[index].address != '::1') {
29
- if (!IPv6Had[network[index].mac]) {
30
- infomation.IPv6.push({
31
- address: network[index].address,
32
- mac: network[index].mac
33
- });
34
-
35
- IPv6Had[network[index].mac] = true;
36
- }
37
- }
38
- }
39
- }
40
- }
41
-
42
- return infomation;
1
+ const { networkInterfaces } = require("os");
2
+
3
+ // 网络信息
4
+ module.exports = function () {
5
+
6
+ let infomation = {
7
+ IPv4: [],
8
+ IPv6: []
9
+ };
10
+
11
+ let networks = networkInterfaces();
12
+
13
+ let IPv4Had = {}, IPv6Had = {};
14
+
15
+ for (let typeName in networks) {
16
+ let network = networks[typeName]
17
+ for (let index = 0; index < network.length; index++) {
18
+ if (network[index].mac != "00:00:00:00:00:00") {
19
+ if (network[index].family == 'IPv4' && network[index].address != '127.0.0.1') {
20
+ if (!IPv4Had[network[index].mac]) {
21
+ infomation.IPv4.push({
22
+ address: network[index].address,
23
+ mac: network[index].mac
24
+ });
25
+
26
+ IPv4Had[network[index].mac] = true;
27
+ }
28
+ } else if (network[index].family == 'IPv6' && network[index].address != '::1') {
29
+ if (!IPv6Had[network[index].mac]) {
30
+ infomation.IPv6.push({
31
+ address: network[index].address,
32
+ mac: network[index].mac
33
+ });
34
+
35
+ IPv6Had[network[index].mac] = true;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ return infomation;
43
43
  };
@@ -1,84 +1,84 @@
1
- const { readdirSync, lstatSync, readFileSync, statSync } = require("fs");
2
- const { join } = require("path");
3
- const { formatByte, formatTime } = require("./format");
4
- const mineTypes = require("../data/mineTypes.json");
5
-
6
- const img_folder = "data:image/png;base64," + readFileSync(join(__dirname, "../images/folder.png")).toString('base64');
7
- const img_file = "data:image/png;base64," + readFileSync(join(__dirname, "../images/file.png")).toString('base64');
8
-
9
- const template_404 = readFileSync(join(__dirname, "../template/404.html"), {
10
- encoding: "utf8"
11
- })
12
- .replace("${img_folder}", img_folder)
13
- .replace("${img_file}", img_file);
14
-
15
- module.exports = function (filePath, url) {
16
-
17
- let subItems = [];
18
-
19
- try {
20
- subItems = readdirSync(filePath);
21
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read Folder: " + url + '\x1b[0m ' + new Date().toLocaleString());
22
- } catch (e) {
23
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read " + (/\/$/.test(url) ? "Folder" : "File") + ": \x1b[35m" + url + ' 404 Not Found\x1b[0m ' + new Date().toLocaleString());
24
- try {
25
- if (!/\/$/.test(url) || url === "/") {
26
- filePath = join(filePath, "../");
27
- subItems = readdirSync(filePath);
28
- }
29
- } catch (e) { }
30
- }
31
-
32
- let template = "";
33
- for (let i in subItems) {
34
- let isDirectory = lstatSync(join(filePath, subItems[i])).isDirectory();
35
- let statObj = statSync(join(filePath, subItems[i]));
36
-
37
- // 文件夹
38
- if (isDirectory) {
39
- template += `<tr class="folder">
40
- <th class="name">
41
- <a href='./${subItems[i]}/'>${subItems[i]}</a>
42
- </th>
43
- <th>
44
- ${formatTime(statObj.mtime)}
45
- </th>
46
- <th>
47
- 文件夹
48
- </th>
49
- <th>
50
- -
51
- </th>
52
- <th>
53
- <a href='./${subItems[i]}/' class="btn">打开</a>
54
- </th>
55
- </tr>`;
56
- }
57
-
58
- // 文件
59
- else {
60
- let dotName = /\./.test(subItems[i]) ? subItems[i].match(/\.([^.]+)$/)[1] : "";
61
-
62
- template += `<tr class="file">
63
- <th class="name">
64
- <a href='./${subItems[i]}'>${subItems[i]}</a>
65
- </th>
66
- <th>
67
- ${formatTime(statObj.mtime)}
68
- </th>
69
- <th>
70
- ${mineTypes[dotName] || "text/plain"}
71
- </th>
72
- <th>
73
- ${formatByte(statObj.size)}
74
- </th>
75
- <th>
76
- <a href='./${subItems[i]}' class="btn">访问</a>
77
- <a href='./${subItems[i]}?download' class="btn" download='${subItems[i]}'>下载</a>
78
- </th>
79
- </tr>`;
80
- }
81
- }
82
-
83
- return template_404.replace("${current}", filePath).replace("${template}", template);
1
+ const { readdirSync, lstatSync, readFileSync, statSync } = require("fs");
2
+ const { join } = require("path");
3
+ const { formatByte, formatTime } = require("./format");
4
+ const mineTypes = require("../data/mineTypes.json");
5
+
6
+ const img_folder = "data:image/png;base64," + readFileSync(join(__dirname, "../images/folder.png")).toString('base64');
7
+ const img_file = "data:image/png;base64," + readFileSync(join(__dirname, "../images/file.png")).toString('base64');
8
+
9
+ const template_404 = readFileSync(join(__dirname, "../template/404.html"), {
10
+ encoding: "utf8"
11
+ })
12
+ .replace("${img_folder}", img_folder)
13
+ .replace("${img_file}", img_file);
14
+
15
+ module.exports = function (filePath, url) {
16
+
17
+ let subItems = [];
18
+
19
+ try {
20
+ subItems = readdirSync(filePath);
21
+ console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read Folder: " + url + '\x1b[0m ' + new Date().toLocaleString());
22
+ } catch (e) {
23
+ console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read " + (/\/$/.test(url) ? "Folder" : "File") + ": \x1b[35m" + url + ' 404 Not Found\x1b[0m ' + new Date().toLocaleString());
24
+ try {
25
+ if (!/\/$/.test(url) || url === "/") {
26
+ filePath = join(filePath, "../");
27
+ subItems = readdirSync(filePath);
28
+ }
29
+ } catch (e) { }
30
+ }
31
+
32
+ let template = "";
33
+ for (let i in subItems) {
34
+ let isDirectory = lstatSync(join(filePath, subItems[i])).isDirectory();
35
+ let statObj = statSync(join(filePath, subItems[i]));
36
+
37
+ // 文件夹
38
+ if (isDirectory) {
39
+ template += `<tr class="folder">
40
+ <th class="name">
41
+ <a href='./${subItems[i]}/'>${subItems[i]}</a>
42
+ </th>
43
+ <th>
44
+ ${formatTime(statObj.mtime)}
45
+ </th>
46
+ <th>
47
+ 文件夹
48
+ </th>
49
+ <th>
50
+ -
51
+ </th>
52
+ <th>
53
+ <a href='./${subItems[i]}/' class="btn">打开</a>
54
+ </th>
55
+ </tr>`;
56
+ }
57
+
58
+ // 文件
59
+ else {
60
+ let dotName = /\./.test(subItems[i]) ? subItems[i].match(/\.([^.]+)$/)[1] : "";
61
+
62
+ template += `<tr class="file">
63
+ <th class="name">
64
+ <a href='./${subItems[i]}'>${subItems[i]}</a>
65
+ </th>
66
+ <th>
67
+ ${formatTime(statObj.mtime)}
68
+ </th>
69
+ <th>
70
+ ${mineTypes[dotName] || "text/plain"}
71
+ </th>
72
+ <th>
73
+ ${formatByte(statObj.size)}
74
+ </th>
75
+ <th>
76
+ <a href='./${subItems[i]}' class="btn">访问</a>
77
+ <a href='./${subItems[i]}?download' class="btn" download='${subItems[i]}'>下载</a>
78
+ </th>
79
+ </tr>`;
80
+ }
81
+ }
82
+
83
+ return template_404.replace("${current}", filePath).replace("${template}", template);
84
84
  };
@@ -1,89 +1,89 @@
1
- const { readFileSync, existsSync, lstatSync } = require("fs");
2
- const { join } = require("path");
3
- const { testIntercept } = require("../intercept.js");
4
-
5
- module.exports = function (basePath, filePath, entry, intercept, isDownload) {
6
- basePath = join(basePath, "./");
7
-
8
- let source = readFileSync(filePath);
9
- let resolveImport = content => content;
10
-
11
- let __resolveImport = function (content) {
12
- return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
13
- if (/^[./]/.test(_importUrl)) {
14
- return _importCode;
15
- } else {
16
- return _importCode.replace(_importUrl, _importUrl.replace(/([^/])+/s, function (npmName) {
17
-
18
- if (testIntercept(npmName, intercept)) {
19
- return "/@modules/" + npmName;
20
- } else {
21
-
22
- let node_modulesRootPath = join(filePath, "../");
23
- let prePath = "";
24
- while (true) {
25
- let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
26
-
27
- // 如果存在
28
- if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
29
- let npmNameValue = npmName;
30
-
31
- // 对于类似 import VISLite from "vislite"
32
- // 需要把包名解析成具体的文件
33
- if (!/\//.test(_importUrl)) {
34
- let bundlePackage = require(join(npmBundlePath, "./package.json"));
35
- npmNameValue = npmName + "/" + bundlePackage.main;
36
- }
37
-
38
- return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
39
- }
40
-
41
- if (node_modulesRootPath === basePath) {
42
-
43
- // 如果命令行根目录是一个项目
44
- let packagePath = join(basePath, "./package.json");
45
- if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
46
- let bundlePackage = require(packagePath);
47
- if (!/\//.test(_importUrl)) {
48
- return "/" + bundlePackage.main;
49
- } else {
50
- return "/"
51
- }
52
- }
53
-
54
- return npmName;
55
- } else {
56
- node_modulesRootPath = join(node_modulesRootPath, "../");
57
- prePath = "../" + prePath;
58
- }
59
- }
60
-
61
- }
62
- }));
63
- }
64
- });
65
- };
66
-
67
- // 如果是下载
68
- if (isDownload) {
69
- // todo
70
- }
71
-
72
- // 如果不是直接访问的
73
- else if (!entry) {
74
- source += "";
75
- resolveImport = (content, notResolve) => notResolve ? content : __resolveImport(content);
76
- }
77
-
78
- // 如果是.html或.htm结尾
79
- else if (/\.html{0,1}$/.test(filePath)) {
80
- source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
81
- return `<script type="module">${__resolveImport(_matchCode)}</script>`;
82
- });
83
- }
84
-
85
- return {
86
- source,
87
- resolveImport
88
- };
1
+ const { readFileSync, existsSync, lstatSync } = require("fs");
2
+ const { join } = require("path");
3
+ const { testIntercept } = require("../intercept.js");
4
+
5
+ module.exports = function (basePath, filePath, entry, intercept, isDownload) {
6
+ basePath = join(basePath, "./");
7
+
8
+ let source = readFileSync(filePath);
9
+ let resolveImport = content => content;
10
+
11
+ let __resolveImport = function (content) {
12
+ return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
13
+ if (/^[./]/.test(_importUrl)) {
14
+ return _importCode;
15
+ } else {
16
+ return _importCode.replace(_importUrl, _importUrl.replace(/([^/])+/s, function (npmName) {
17
+
18
+ if (testIntercept(npmName, intercept)) {
19
+ return "/@modules/" + npmName;
20
+ } else {
21
+
22
+ let node_modulesRootPath = join(filePath, "../");
23
+ let prePath = "";
24
+ while (true) {
25
+ let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
26
+
27
+ // 如果存在
28
+ if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
29
+ let npmNameValue = npmName;
30
+
31
+ // 对于类似 import VISLite from "vislite"
32
+ // 需要把包名解析成具体的文件
33
+ if (!/\//.test(_importUrl)) {
34
+ let bundlePackage = require(join(npmBundlePath, "./package.json"));
35
+ npmNameValue = npmName + "/" + bundlePackage.main;
36
+ }
37
+
38
+ return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
39
+ }
40
+
41
+ if (node_modulesRootPath === basePath) {
42
+
43
+ // 如果命令行根目录是一个项目
44
+ let packagePath = join(basePath, "./package.json");
45
+ if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
46
+ let bundlePackage = require(packagePath);
47
+ if (!/\//.test(_importUrl)) {
48
+ return "/" + bundlePackage.main;
49
+ } else {
50
+ return "/"
51
+ }
52
+ }
53
+
54
+ return npmName;
55
+ } else {
56
+ node_modulesRootPath = join(node_modulesRootPath, "../");
57
+ prePath = "../" + prePath;
58
+ }
59
+ }
60
+
61
+ }
62
+ }));
63
+ }
64
+ });
65
+ };
66
+
67
+ // 如果是下载
68
+ if (isDownload) {
69
+ // todo
70
+ }
71
+
72
+ // 如果不是直接访问的
73
+ else if (!entry) {
74
+ source += "";
75
+ resolveImport = (content, notResolve) => notResolve ? content : __resolveImport(content);
76
+ }
77
+
78
+ // 如果是.html或.htm结尾
79
+ else if (/\.html{0,1}$/.test(filePath)) {
80
+ source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
81
+ return `<script type="module">${__resolveImport(_matchCode)}</script>`;
82
+ });
83
+ }
84
+
85
+ return {
86
+ source,
87
+ resolveImport
88
+ };
89
89
  };
@@ -1,20 +1,20 @@
1
- interface animationResult {
2
-
3
- /**
4
- * 一个函数,调用该函数,可以提前结束动画
5
- */
6
- stop(): void
7
- }
8
-
9
- interface animationFun {
10
- (deep: number): void
11
- }
12
-
13
- /**
14
- * 轮询动画
15
- */
16
- export interface animationType {
17
- (doback: animationFun, duration?: number, callback?: animationFun): animationResult
18
- }
19
-
1
+ interface animationResult {
2
+
3
+ /**
4
+ * 一个函数,调用该函数,可以提前结束动画
5
+ */
6
+ stop(): void
7
+ }
8
+
9
+ interface animationFun {
10
+ (deep: number): void
11
+ }
12
+
13
+ /**
14
+ * 轮询动画
15
+ */
16
+ export interface animationType {
17
+ (doback: animationFun, duration?: number, callback?: animationFun): animationResult
18
+ }
19
+
20
20
  export let animation: animationType