oipage 1.3.0-alpha.1 → 1.3.0-alpha.3
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.
- package/CHANGELOG +68 -64
- package/bin/intercept.js +15 -7
- package/bin/run +96 -96
- package/bin/serve.js +129 -114
- package/bin/tools/resolveImport.js +88 -81
- package/nodejs/animation/index.js +1 -1
- package/nodejs/cmdlog/index.js +1 -1
- package/nodejs/disk/index.js +1 -1
- package/nodejs/json/index.d.ts +10 -0
- package/nodejs/json/index.js +212 -0
- package/nodejs/logform/index.js +1 -1
- package/nodejs/reader/index.js +2 -2
- package/nodejs/throttle/index.js +1 -1
- package/package.json +1 -1
- package/web/animation/index.js +1 -1
- package/web/json/index.d.ts +10 -0
- package/web/json/index.js +211 -0
- package/web/onReady/index.js +1 -1
- package/web/performChunk/index.d.ts +5 -0
- package/web/performChunk/index.js +24 -0
- package/web/reader/index.js +2 -2
- package/web/style/index.js +1 -1
- package/web/throttle/index.js +1 -1
|
@@ -1,82 +1,89 @@
|
|
|
1
|
-
const { readFileSync, existsSync, lstatSync } = require("fs");
|
|
2
|
-
const { join } = require("path");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
if (
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
};
|
|
82
89
|
};
|
package/nodejs/cmdlog/index.js
CHANGED
package/nodejs/disk/index.js
CHANGED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* json of OIPage v1.3.0-alpha.3
|
|
3
|
+
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
|
+
*/
|
|
5
|
+
const {reader} = require("../reader/index.js");
|
|
6
|
+
let calcValue = function (word) {
|
|
7
|
+
if (word.type != 'string' && word.type != 'object') {
|
|
8
|
+
|
|
9
|
+
// 数字
|
|
10
|
+
if (/[+-]{0,1}\d{1,}\.{0,1}\d{0,}/.test(word.value)) {
|
|
11
|
+
return +word.value;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// undefined
|
|
15
|
+
else if (word.value == 'undefined') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// null
|
|
20
|
+
else if (word.value == 'null') {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// false
|
|
25
|
+
else if (word.value == 'false') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// true
|
|
30
|
+
else if (word.value == 'true') {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return word.value;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let toValue = function (wordArray) {
|
|
40
|
+
let value;
|
|
41
|
+
|
|
42
|
+
// 是json
|
|
43
|
+
if (wordArray[0].value == '{') {
|
|
44
|
+
value = {};
|
|
45
|
+
for (let i = 3; i < wordArray.length; i += 4) {
|
|
46
|
+
value[wordArray[i - 2].value] = calcValue(wordArray[i]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 数组
|
|
51
|
+
else {
|
|
52
|
+
value = [];
|
|
53
|
+
for (let i = 2; i < wordArray.length; i += 2) {
|
|
54
|
+
value.push(calcValue(wordArray[i - 1]));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
type: "object",
|
|
60
|
+
value: value
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let analyseWord = function (express) {
|
|
65
|
+
// 剔除开头和结尾的空白
|
|
66
|
+
express = express.trim();
|
|
67
|
+
|
|
68
|
+
// 获取字符串分析对象
|
|
69
|
+
let readerHandler = reader(express);
|
|
70
|
+
|
|
71
|
+
let wordArray = [];
|
|
72
|
+
let tempWord = "";
|
|
73
|
+
readerHandler.readNext();
|
|
74
|
+
|
|
75
|
+
// 定义一个追加普通串的方法
|
|
76
|
+
let pushNormal = function () {
|
|
77
|
+
tempWord = tempWord.trim();
|
|
78
|
+
if (tempWord != '') {
|
|
79
|
+
wordArray.push({
|
|
80
|
+
type: /\d%/.test(tempWord) ? "string" : "normal",
|
|
81
|
+
value: tempWord
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
tempWord = "";
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
while (true) {
|
|
88
|
+
|
|
89
|
+
if (readerHandler.index >= express.length) break;
|
|
90
|
+
|
|
91
|
+
// 单行注释
|
|
92
|
+
if (readerHandler.getNextN(2) == '//') {
|
|
93
|
+
while (!/\n/.test(readerHandler.readNext()) && readerHandler.index < express.length);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 多行注释
|
|
97
|
+
else if (readerHandler.getNextN(2) == '/*') {
|
|
98
|
+
while (readerHandler.getNextN(2) != '*/') {
|
|
99
|
+
if (readerHandler.index >= express.length) {
|
|
100
|
+
throw new Error("Multiline comment not closed correctly : " + express + "\nstep='analyseWord-searchEndComment'");
|
|
101
|
+
}
|
|
102
|
+
readerHandler.readNext();
|
|
103
|
+
}
|
|
104
|
+
readerHandler.readNext();
|
|
105
|
+
readerHandler.readNext();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 如果是边界符号
|
|
109
|
+
else if (['{', '}', ',', '[', ']', ':'].indexOf(readerHandler.value) > -1) {
|
|
110
|
+
pushNormal();
|
|
111
|
+
|
|
112
|
+
wordArray.push({
|
|
113
|
+
type: "insign",
|
|
114
|
+
value: readerHandler.value
|
|
115
|
+
});
|
|
116
|
+
readerHandler.readNext();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 如果遇到字符串,应该是一个独立的单词
|
|
120
|
+
else if (['"', "'"].indexOf(readerHandler.value) > -1) {
|
|
121
|
+
|
|
122
|
+
let tempStrWord = "";
|
|
123
|
+
while (['"', "'"].indexOf(readerHandler.readNext()) < 0) {
|
|
124
|
+
if (readerHandler.index >= express.length) {
|
|
125
|
+
throw new Error("The string is not closed correctly : " + express + "\nstep='analyseWord-searchString',currentStrWord=" + tempStrWord);
|
|
126
|
+
}
|
|
127
|
+
tempStrWord += readerHandler.value;
|
|
128
|
+
}
|
|
129
|
+
readerHandler.readNext();
|
|
130
|
+
wordArray.push({
|
|
131
|
+
type: "string",
|
|
132
|
+
value: tempStrWord
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
} else {
|
|
136
|
+
tempWord += readerHandler.value;
|
|
137
|
+
readerHandler.readNext();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return wordArray;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
function strToJson(express) {
|
|
146
|
+
if (typeof express === "string") {
|
|
147
|
+
|
|
148
|
+
// 先分析出来单词
|
|
149
|
+
let wordArray = analyseWord(express);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 思路:
|
|
153
|
+
* 从后往前找,找到第一个需要归结的,直接归结,
|
|
154
|
+
* 归结完毕以后,继续,直到找到开头,说明归结完毕,
|
|
155
|
+
* 这样设计的好处是:
|
|
156
|
+
* 从后往前找,一定是叶子,这就消除了递归。
|
|
157
|
+
*/
|
|
158
|
+
let i = wordArray.length - 1, j;
|
|
159
|
+
|
|
160
|
+
// 只要单词数组归结完毕
|
|
161
|
+
while (wordArray.length > 1) {
|
|
162
|
+
|
|
163
|
+
// 从后往前找第一个需要归结的子对象
|
|
164
|
+
while (i >= 0 && (wordArray[i].type != 'insign' || ['{', '['].indexOf(wordArray[i].value) < 0)) {
|
|
165
|
+
i = i - 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (i < 0) {
|
|
169
|
+
// 如果到开头都没有遇到,缺少开始符号
|
|
170
|
+
throw new Error("Illegal express : " + express + "\nstep='toOne-searchBeginIndex',wordArray=" + wordArray);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 然后合并
|
|
174
|
+
j = i + 1;
|
|
175
|
+
let subWordArray = [wordArray[i]];
|
|
176
|
+
while (j < wordArray.length && (wordArray[j].type != 'insign' || wordArray[j].value != {
|
|
177
|
+
"{": "}",
|
|
178
|
+
"[": "]"
|
|
179
|
+
}[wordArray[i].value])) {
|
|
180
|
+
subWordArray.push(wordArray[j]);
|
|
181
|
+
j = j + 1;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (j >= wordArray.length) {
|
|
185
|
+
// 如果到结尾都没有需要应该闭合的符号,缺少闭合符号
|
|
186
|
+
throw new Error("Illegal express : " + express + "\nstep='toOne-searchEndIndex',wordArray=" + wordArray);
|
|
187
|
+
} else {
|
|
188
|
+
|
|
189
|
+
// 结尾追加进去
|
|
190
|
+
subWordArray.push(wordArray[j]);
|
|
191
|
+
|
|
192
|
+
// 归结
|
|
193
|
+
wordArray[i] = toValue(subWordArray);
|
|
194
|
+
|
|
195
|
+
// 调整
|
|
196
|
+
wordArray.splice(i + 1, j - i);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 返回计算结果
|
|
203
|
+
return wordArray[0].value;
|
|
204
|
+
|
|
205
|
+
} else {
|
|
206
|
+
|
|
207
|
+
throw new Error('The data passed is not a string.');
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
exports.strToJson = strToJson;
|
package/nodejs/logform/index.js
CHANGED
package/nodejs/reader/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* reader of OIPage v1.3.0-alpha.
|
|
2
|
+
* reader of OIPage v1.3.0-alpha.3
|
|
3
3
|
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ function reader(plain) {
|
|
|
18
18
|
|
|
19
19
|
// 获取往后num个值
|
|
20
20
|
handler.getNextN = function (num) {
|
|
21
|
-
return
|
|
21
|
+
return plain.substring(handler.index, num + handler.index > plain.length ? plain.length : num + handler.index);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
return handler;
|
package/nodejs/throttle/index.js
CHANGED
package/package.json
CHANGED
package/web/animation/index.js
CHANGED