oipage 1.4.0-alpha.0 → 1.4.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.
- package/.github/FUNDING.yml +11 -11
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +94 -83
- package/LICENSE +20 -20
- package/README.md +80 -80
- package/bin/data/mineTypes.json +104 -104
- package/bin/disk.js +31 -31
- package/bin/help.js +25 -24
- package/bin/intercept.js +15 -15
- package/bin/run +98 -96
- package/bin/serve.d.ts +56 -55
- package/bin/serve.js +147 -131
- package/bin/template/404.html +183 -171
- package/bin/tools/format.js +75 -75
- package/bin/tools/network.js +42 -42
- package/bin/tools/resolve404.js +83 -83
- package/bin/tools/resolveImport.js +88 -88
- package/bin/website-htmls/dialogs/index.js +43 -0
- package/bin/website-htmls/index.html +18 -0
- package/bin/website-htmls/logo.png +0 -0
- package/bin/website-htmls/main.js +10 -0
- package/bin/website-htmls/pages/App/index.html +4 -0
- package/bin/website-htmls/pages/App/index.js +23 -0
- package/bin/website-htmls/pages/App/index.scss +43 -0
- package/bin/website-htmls/pages/appStore/index.html +6 -0
- package/bin/website-htmls/pages/appStore/index.js +18 -0
- package/bin/website-htmls/pages/appStore/index.scss +27 -0
- package/bin/website-htmls/router.config.js +11 -0
- package/bin/website-htmls/styles/common.css +3 -0
- package/bin/website-htmls/styles/normalize.css +95 -0
- package/bin/website-plugins/intercept/head.js +9 -0
- package/bin/website-plugins/intercept/index.js +5 -0
- package/bin/website-plugins/intercept/oipage-zipaper-intercept.js +40 -0
- package/bin/website-plugins/loader/index.js +12 -0
- package/bin/website-plugins/loader/oipage-html-loader.js +8 -0
- package/bin/website-plugins/loader/oipage-scss-loader.js +150 -0
- package/nodejs/animation/index.d.ts +19 -19
- package/nodejs/animation/index.js +104 -104
- package/nodejs/cmdlog/index.d.ts +20 -20
- package/nodejs/cmdlog/index.js +75 -75
- package/nodejs/disk/index.d.ts +16 -16
- package/nodejs/disk/index.js +78 -78
- package/nodejs/format/index.d.ts +29 -0
- package/nodejs/format/index.js +114 -0
- package/nodejs/json/index.d.ts +9 -9
- package/nodejs/json/index.js +206 -206
- package/nodejs/logform/index.d.ts +18 -18
- package/nodejs/logform/index.js +94 -94
- package/nodejs/reader/index.d.ts +32 -32
- package/nodejs/reader/index.js +20 -20
- package/nodejs/throttle/index.d.ts +30 -30
- package/nodejs/throttle/index.js +50 -50
- package/package.json +42 -40
- package/web/XMLHttpRequest/index.d.ts +18 -0
- package/web/XMLHttpRequest/index.js +65 -0
- package/web/animation/index.d.ts +19 -19
- package/web/animation/index.js +104 -104
- package/web/format/index.d.ts +29 -0
- package/web/format/index.js +112 -0
- package/web/json/index.d.ts +9 -9
- package/web/json/index.js +206 -206
- package/web/onReady/index.d.ts +7 -7
- package/web/onReady/index.js +8 -8
- package/web/performChunk/index.d.ts +4 -4
- package/web/performChunk/index.js +19 -19
- package/web/reader/index.d.ts +32 -32
- package/web/reader/index.js +20 -20
- package/web/style/index.d.ts +21 -21
- package/web/style/index.js +19 -19
- package/web/throttle/index.d.ts +30 -30
- package/web/throttle/index.js +50 -50
package/bin/tools/format.js
CHANGED
|
@@ -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
|
};
|
package/bin/tools/network.js
CHANGED
|
@@ -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
|
};
|
package/bin/tools/resolve404.js
CHANGED
|
@@ -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, isWebsite) {
|
|
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 (isWebsite ? "/_oipage_website_/@modules/" : "/@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
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createApp } from "zipaper"
|
|
2
|
+
|
|
3
|
+
const dialogs = {
|
|
4
|
+
|
|
5
|
+
// xxx
|
|
6
|
+
xxx: () => import("./xxx/index.js")
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let dialogsResolve = []
|
|
10
|
+
export default {
|
|
11
|
+
install(Zipaper) {
|
|
12
|
+
|
|
13
|
+
// 打开弹框
|
|
14
|
+
Zipaper.prototype.$openDialog = function (dialogName, callback) {
|
|
15
|
+
let el = document.createElement("div")
|
|
16
|
+
|
|
17
|
+
dialogs[dialogName]().then(App => {
|
|
18
|
+
|
|
19
|
+
// 准备好挂载点
|
|
20
|
+
el.setAttribute("class", "content " + dialogName)
|
|
21
|
+
|
|
22
|
+
// 创建并挂载
|
|
23
|
+
document.getElementById("dialog-root").appendChild(el)
|
|
24
|
+
createApp(App.default).mount(el)
|
|
25
|
+
if (callback) callback()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
dialogsResolve.push({
|
|
30
|
+
resolve,
|
|
31
|
+
el
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 关闭弹框
|
|
37
|
+
Zipaper.prototype.$closeDialog = function (data) {
|
|
38
|
+
let dialog = dialogsResolve.pop()
|
|
39
|
+
dialog.el.parentNode.removeChild(dialog.el);
|
|
40
|
+
dialog.resolve(data)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-cn">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>OIPage 应用市场</title>
|
|
8
|
+
<link rel="shortcut icon" href="./logo.png">
|
|
9
|
+
<link rel="stylesheet" href="./styles/normalize.css">
|
|
10
|
+
<link rel="stylesheet" href="./styles/common.css">
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body>
|
|
14
|
+
<div id="root"></div>
|
|
15
|
+
<script type="module" src="./main.js"></script>
|
|
16
|
+
</body>
|
|
17
|
+
|
|
18
|
+
</html>
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createApp } from "zipaper"
|
|
2
|
+
|
|
3
|
+
import App from "./pages/App/index.js"
|
|
4
|
+
import router from "./router.config.js"
|
|
5
|
+
import dialogs from "./dialogs/index.js"
|
|
6
|
+
|
|
7
|
+
createApp(App)
|
|
8
|
+
.use(router) // 路由
|
|
9
|
+
.use(dialogs) // 弹框
|
|
10
|
+
.mount(document.getElementById("root")) // 挂载到页面
|