@oipage/cli 0.3.0 → 1.0.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 (92) hide show
  1. package/.github/FUNDING.yml +11 -11
  2. package/AUTHORS.txt +6 -6
  3. package/CHANGELOG +76 -47
  4. package/LICENSE +20 -20
  5. package/README.md +204 -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 -106
  10. package/bin/data/mineTypes.json +108 -104
  11. package/bin/disk.js +42 -42
  12. package/bin/help.js +63 -55
  13. package/bin/intercept.js +15 -15
  14. package/bin/network.js +21 -21
  15. package/bin/notebook/data.js +185 -0
  16. package/bin/notebook/index.js +168 -9
  17. package/bin/proxy.js +82 -82
  18. package/bin/run +146 -146
  19. package/bin/serve.js +455 -318
  20. package/bin/template/404.html +184 -184
  21. package/bin/tools/deleteEmptyFolder.js +33 -33
  22. package/bin/tools/format.js +75 -75
  23. package/bin/tools/isBinary.js +83 -83
  24. package/bin/tools/moduleForm.js +548 -0
  25. package/bin/tools/network.js +42 -42
  26. package/bin/tools/openBrowser.js +34 -34
  27. package/bin/tools/resolve404.js +98 -98
  28. package/bin/tools/resolveImport.js +278 -97
  29. package/bin/tools/resolvePackage.js +412 -0
  30. package/bin/website-htmls/components/ui-select-file/index.html +8 -8
  31. package/bin/website-htmls/components/ui-select-file/index.js +42 -42
  32. package/bin/website-htmls/components/ui-select-file/index.scss +44 -44
  33. package/bin/website-htmls/dialogs/imageSize/index.html +54 -54
  34. package/bin/website-htmls/dialogs/imageSize/index.js +53 -53
  35. package/bin/website-htmls/dialogs/imageSize/index.scss +140 -140
  36. package/bin/website-htmls/dialogs/index.js +52 -52
  37. package/bin/website-htmls/images/addFile.svg +1 -1
  38. package/bin/website-htmls/images/img-to-pdf.svg +1 -1
  39. package/bin/website-htmls/index.html +17 -17
  40. package/bin/website-htmls/main.js +13 -13
  41. package/bin/website-htmls/pages/App/index.html +6 -6
  42. package/bin/website-htmls/pages/App/index.js +22 -22
  43. package/bin/website-htmls/pages/App/index.scss +43 -43
  44. package/bin/website-htmls/pages/appStore/index.html +7 -7
  45. package/bin/website-htmls/pages/appStore/index.js +19 -19
  46. package/bin/website-htmls/pages/appStore/index.scss +54 -54
  47. package/bin/website-htmls/pages/chart/index.html +8 -8
  48. package/bin/website-htmls/pages/chart/index.js +72 -72
  49. package/bin/website-htmls/pages/chart/index.scss +71 -71
  50. package/bin/website-htmls/pages/home/index.html +19 -19
  51. package/bin/website-htmls/pages/home/index.js +19 -19
  52. package/bin/website-htmls/pages/home/index.scss +87 -87
  53. package/bin/website-htmls/pages/image-editor/index.html +27 -27
  54. package/bin/website-htmls/pages/image-editor/index.js +106 -106
  55. package/bin/website-htmls/pages/image-editor/index.scss +69 -69
  56. package/bin/website-htmls/pages/img-to-pdf/index.html +3 -3
  57. package/bin/website-htmls/pages/img-to-pdf/index.js +44 -44
  58. package/bin/website-htmls/pages/img-to-pdf/index.scss +9 -9
  59. package/bin/website-htmls/pages/recorder-screen/index.html +15 -15
  60. package/bin/website-htmls/pages/recorder-screen/index.js +227 -227
  61. package/bin/website-htmls/pages/recorder-screen/index.scss +52 -52
  62. package/bin/website-htmls/router.config.js +29 -29
  63. package/bin/website-htmls/styles/common.css +44 -44
  64. package/bin/website-htmls/styles/normalize.css +94 -94
  65. package/bin/website-plugins/intercept/chart.js +33 -33
  66. package/bin/website-plugins/intercept/getPackage.js +17 -17
  67. package/bin/website-plugins/intercept/head.js +8 -8
  68. package/bin/website-plugins/intercept/index.js +4 -8
  69. package/bin/website-plugins/loader/index.js +11 -11
  70. package/bin/website-plugins/loader/oipage-html-loader.js +7 -7
  71. package/bin/website-plugins/loader/oipage-scss-loader.js +149 -149
  72. package/docs/css/base.css +122 -0
  73. package/docs/css/components.css +180 -0
  74. package/docs/css/layout.css +295 -0
  75. package/docs/css/responsive.css +49 -0
  76. package/docs/images/file-list.webp +0 -0
  77. package/docs/images/logo-topbar.svg +5 -0
  78. package/docs/images/logo.png +0 -0
  79. package/docs/images/logo.svg +6 -0
  80. package/docs/images/manual.webp +0 -0
  81. package/docs/images/terminal-serve.webp +0 -0
  82. package/docs/index.html +1392 -0
  83. package/docs/js/copy.js +37 -0
  84. package/docs/js/nav.js +111 -0
  85. package/docs/js/search.js +241 -0
  86. package/docs/js/theme.js +17 -0
  87. package/package.json +42 -42
  88. package/src/index.js +26 -29
  89. package/types/serve.d.ts +83 -83
  90. package/bin/website-plugins/intercept/oipage-vislite-intercept.js +0 -56
  91. package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +0 -37
  92. package/docs/config.md +0 -107
@@ -1,83 +1,83 @@
1
- const { openSync, readSync, closeSync } = require("fs");
2
- const mineTypes = require("../data/mineTypes.json");
3
-
4
- // 读取文件头部用于判断的字节数
5
- const CHECK_BYTES = 4096;
6
-
7
- // 文本类型白名单(即使 Content-Type 是 application/* 也视为文本)
8
- // 仅在文件内容读取失败时作为回退判断依据
9
- const TEXT_TYPES = new Set([
10
- "application/javascript",
11
- "application/json",
12
- "application/xml",
13
- "application/xhtml+xml",
14
- "application/rss+xml",
15
- "application/atom+xml",
16
- "image/svg+xml",
17
- "application/xspf+xml",
18
- "application/vnd.google-earth.kml+xml"
19
- ]);
20
-
21
- /**
22
- * 通过后缀名回退判断(仅在文件内容读取失败时使用)
23
- * @param {string} filepath 文件路径
24
- * @returns {boolean} 是否为二进制文件
25
- */
26
- function isBinaryByExtension(filepath) {
27
- const dotName = (filepath.match(/\.([^.]+)$/) || [])[1] || "";
28
- const fileType = mineTypes[dotName];
29
-
30
- if (!fileType) {
31
- // 未知类型默认视为二进制
32
- return true;
33
- }
34
-
35
- if (fileType.startsWith("text/")) {
36
- return false;
37
- }
38
-
39
- if (TEXT_TYPES.has(fileType)) {
40
- return false;
41
- }
42
-
43
- return true;
44
- }
45
-
46
- /**
47
- * 判断文件是否是二进制文件
48
- * 通过读取文件前若干字节,检查是否包含 NULL 字节(\0)来判断
49
- * 文本文件(UTF-8/ASCII)通常不包含 NULL 字节,而二进制文件通常包含
50
- * 如果文件读取失败,回退到后缀名判断
51
- * @param {string} filepath 文件路径
52
- * @returns {boolean} 是否为二进制文件
53
- */
54
- module.exports = function isBinary(filepath) {
55
- let fd;
56
- try {
57
- fd = openSync(filepath, 'r');
58
- const buffer = Buffer.alloc(CHECK_BYTES);
59
- const bytesRead = readSync(fd, buffer, 0, CHECK_BYTES, 0);
60
-
61
- // 检查是否包含 NULL 字节
62
- // NULL 字节是二进制文件的可靠标志,文本文件(UTF-8/ASCII)不会包含
63
- for (let i = 0; i < bytesRead; i++) {
64
- if (buffer[i] === 0) {
65
- return true;
66
- }
67
- }
68
-
69
- return false;
70
- } catch (e) {
71
- // 文件读取失败时,回退到后缀名判断
72
- console.log(e);
73
- return isBinaryByExtension(filepath);
74
- } finally {
75
- if (fd !== undefined) {
76
- try {
77
- closeSync(fd);
78
- } catch (e) {
79
- // 关闭失败不影响判断结果
80
- }
81
- }
82
- }
83
- };
1
+ const { openSync, readSync, closeSync } = require("fs");
2
+ const mineTypes = require("../data/mineTypes.json");
3
+
4
+ // 读取文件头部用于判断的字节数
5
+ const CHECK_BYTES = 4096;
6
+
7
+ // 文本类型白名单(即使 Content-Type 是 application/* 也视为文本)
8
+ // 仅在文件内容读取失败时作为回退判断依据
9
+ const TEXT_TYPES = new Set([
10
+ "application/javascript",
11
+ "application/json",
12
+ "application/xml",
13
+ "application/xhtml+xml",
14
+ "application/rss+xml",
15
+ "application/atom+xml",
16
+ "image/svg+xml",
17
+ "application/xspf+xml",
18
+ "application/vnd.google-earth.kml+xml"
19
+ ]);
20
+
21
+ /**
22
+ * 通过后缀名回退判断(仅在文件内容读取失败时使用)
23
+ * @param {string} filepath 文件路径
24
+ * @returns {boolean} 是否为二进制文件
25
+ */
26
+ function isBinaryByExtension(filepath) {
27
+ const dotName = (filepath.match(/\.([^.]+)$/) || [])[1] || "";
28
+ const fileType = mineTypes[dotName];
29
+
30
+ if (!fileType) {
31
+ // 未知类型默认视为二进制
32
+ return true;
33
+ }
34
+
35
+ if (fileType.startsWith("text/")) {
36
+ return false;
37
+ }
38
+
39
+ if (TEXT_TYPES.has(fileType)) {
40
+ return false;
41
+ }
42
+
43
+ return true;
44
+ }
45
+
46
+ /**
47
+ * 判断文件是否是二进制文件
48
+ * 通过读取文件前若干字节,检查是否包含 NULL 字节(\0)来判断
49
+ * 文本文件(UTF-8/ASCII)通常不包含 NULL 字节,而二进制文件通常包含
50
+ * 如果文件读取失败,回退到后缀名判断
51
+ * @param {string} filepath 文件路径
52
+ * @returns {boolean} 是否为二进制文件
53
+ */
54
+ module.exports = function isBinary(filepath) {
55
+ let fd;
56
+ try {
57
+ fd = openSync(filepath, 'r');
58
+ const buffer = Buffer.alloc(CHECK_BYTES);
59
+ const bytesRead = readSync(fd, buffer, 0, CHECK_BYTES, 0);
60
+
61
+ // 检查是否包含 NULL 字节
62
+ // NULL 字节是二进制文件的可靠标志,文本文件(UTF-8/ASCII)不会包含
63
+ for (let i = 0; i < bytesRead; i++) {
64
+ if (buffer[i] === 0) {
65
+ return true;
66
+ }
67
+ }
68
+
69
+ return false;
70
+ } catch (e) {
71
+ // 文件读取失败时,回退到后缀名判断
72
+ console.log(e);
73
+ return isBinaryByExtension(filepath);
74
+ } finally {
75
+ if (fd !== undefined) {
76
+ try {
77
+ closeSync(fd);
78
+ } catch (e) {
79
+ // 关闭失败不影响判断结果
80
+ }
81
+ }
82
+ }
83
+ };