oipage 1.3.0 → 1.3.1-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.
@@ -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,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,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.3.0
2
+ * animation of OIPage v1.3.1-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * cmdlog of OIPage v1.3.0
2
+ * cmdlog of OIPage v1.3.1-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * disk of OIPage v1.3.0
2
+ * disk of OIPage v1.3.1-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,10 +1,10 @@
1
- /**
2
- * 把一段字符串变成json返回
3
- * @param express 非严格json字符串
4
- * @returns 返回一个JSON对象
5
- */
6
- export interface strToJsonType {
7
- (express:string): object
8
- }
9
-
1
+ /**
2
+ * 把一段字符串变成json返回
3
+ * @param express 非严格json字符串
4
+ * @returns 返回一个JSON对象
5
+ */
6
+ export interface strToJsonType {
7
+ (express:string): object
8
+ }
9
+
10
10
  export let strToJson: strToJsonType