oipage 1.2.0-alpha.0 → 1.2.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.
- package/bin/run +8 -5
- package/bin/serve.js +22 -4
- package/bin/tools/resolve404.js +1 -1
- package/bin/tools/resolveImport.js +7 -2
- package/nodejs/animation/index.js +1 -1
- package/nodejs/cmdlog/index.js +1 -1
- package/nodejs/disk/index.js +1 -1
- package/nodejs/logform/index.js +1 -1
- package/nodejs/throttle/index.js +1 -1
- package/package.json +1 -1
- package/web/animation/index.js +1 -1
- package/web/onReady/index.js +1 -1
- package/web/style/index.js +1 -1
- package/web/throttle/index.js +1 -1
package/bin/run
CHANGED
|
@@ -19,8 +19,11 @@ if (process.argv[2] === "serve") {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
let config = {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
devServer: {
|
|
23
|
+
port: 8080,
|
|
24
|
+
baseUrl: "./",
|
|
25
|
+
},
|
|
26
|
+
bundle: []
|
|
24
27
|
};
|
|
25
28
|
|
|
26
29
|
// 如果设置了配置文件
|
|
@@ -28,15 +31,15 @@ if (process.argv[2] === "serve") {
|
|
|
28
31
|
let configPath = join(process.cwd(), argvObj["--config"][0] || "./oipage.config.js");
|
|
29
32
|
if (existsSync(configPath) && !lstatSync(configPath).isDirectory()) {
|
|
30
33
|
let configValue = require(configPath);
|
|
31
|
-
mergeOption(config, configValue
|
|
34
|
+
mergeOption(config, configValue);
|
|
32
35
|
} else {
|
|
33
36
|
console.log("\x1b[0m\x1b[31m" + configPath + "\x1b[0m");
|
|
34
37
|
throw new Error("OIPage: The configuration file does not exist or is not a file.");
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
if ((argvObj["--port"] || [])[0]) config.port = (argvObj["--port"] || [])[0];
|
|
39
|
-
if ((argvObj["--baseUrl"] || [])[0]) config.baseUrl = (argvObj["--baseUrl"] || [])[0];
|
|
41
|
+
if ((argvObj["--port"] || [])[0]) config.devServer.port = (argvObj["--port"] || [])[0];
|
|
42
|
+
if ((argvObj["--baseUrl"] || [])[0]) config.devServer.baseUrl = (argvObj["--baseUrl"] || [])[0];
|
|
40
43
|
|
|
41
44
|
require("./serve.js")(config);
|
|
42
45
|
}
|
package/bin/serve.js
CHANGED
|
@@ -12,14 +12,15 @@ const { formatRawHeaders } = require("./tools/format.js");
|
|
|
12
12
|
module.exports = function (config) {
|
|
13
13
|
let startTime = new Date().valueOf();
|
|
14
14
|
|
|
15
|
-
const port = config.port; // 端口号
|
|
16
|
-
const basePath = (/^\./.test(config.baseUrl)) ? join(process.cwd(), config.baseUrl) : config.baseUrl; // 服务器根路径
|
|
15
|
+
const port = config.devServer.port; // 端口号
|
|
16
|
+
const basePath = (/^\./.test(config.devServer.baseUrl)) ? join(process.cwd(), config.devServer.baseUrl) : config.devServer.baseUrl; // 服务器根路径
|
|
17
17
|
|
|
18
18
|
let Server = createServer(function (request, response) {
|
|
19
19
|
let headers = formatRawHeaders(request.rawHeaders);
|
|
20
20
|
let url = decodeURIComponent(request.url);
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
let urlArray = url.split("?");
|
|
23
|
+
url = urlArray[0];
|
|
23
24
|
|
|
24
25
|
// 请求的文件路径
|
|
25
26
|
let filePath = join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
|
|
@@ -41,9 +42,26 @@ module.exports = function (config) {
|
|
|
41
42
|
|
|
42
43
|
// 如果文件小于10M,认为不大,直接读取
|
|
43
44
|
if (fileInfo.size < 10 * 1024 * 1024) {
|
|
45
|
+
let source = resolveImport(basePath, filePath, headers.Accept === "*/*", urlArray[1] === "download")
|
|
46
|
+
|
|
47
|
+
// 只处理非下载文件
|
|
48
|
+
// 过大的也不进行处理
|
|
49
|
+
if (urlArray[1] !== "download") {
|
|
50
|
+
for (let i = 0; i < config.bundle.length; i++) {
|
|
51
|
+
if (config.bundle[i].test.test(filePath)) {
|
|
52
|
+
source = config.bundle[i].handler.call({
|
|
53
|
+
root: basePath, // 服务器根路径
|
|
54
|
+
path: filePath.replace(basePath, ""), // 文件相对路径
|
|
55
|
+
entry: headers.Accept !== "*/*", // 是否是浏览器地址栏直接访问
|
|
56
|
+
}, source);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
44
62
|
sendType = "Read";
|
|
45
63
|
response.writeHead('200', responseHeader);
|
|
46
|
-
response.write(
|
|
64
|
+
response.write(source);
|
|
47
65
|
response.end();
|
|
48
66
|
}
|
|
49
67
|
|
package/bin/tools/resolve404.js
CHANGED
|
@@ -72,7 +72,7 @@ module.exports = function (filePath, url) {
|
|
|
72
72
|
</th>
|
|
73
73
|
<th>
|
|
74
74
|
<a href='./${subItems[i]}' class="btn">访问</a>
|
|
75
|
-
<a href='./${subItems[i]}' class="btn" download='${subItems[i]}'>下载</a>
|
|
75
|
+
<a href='./${subItems[i]}?download' class="btn" download='${subItems[i]}'>下载</a>
|
|
76
76
|
</th>
|
|
77
77
|
</tr>`;
|
|
78
78
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { readFileSync, existsSync, lstatSync } = require("fs");
|
|
2
2
|
const { join } = require("path");
|
|
3
3
|
|
|
4
|
-
module.exports = function (basePath, filePath, needResolve) {
|
|
4
|
+
module.exports = function (basePath, filePath, needResolve, isDownload) {
|
|
5
5
|
let code = readFileSync(filePath);
|
|
6
6
|
|
|
7
7
|
let resolveImport = function (content) {
|
|
@@ -42,8 +42,13 @@ module.exports = function (basePath, filePath, needResolve) {
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
// 如果是下载
|
|
46
|
+
if (isDownload) {
|
|
47
|
+
return code;
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
// 如果需要解析
|
|
46
|
-
if (needResolve) {
|
|
51
|
+
else if (needResolve) {
|
|
47
52
|
return resolveImport(code + "");
|
|
48
53
|
}
|
|
49
54
|
|
package/nodejs/cmdlog/index.js
CHANGED
package/nodejs/disk/index.js
CHANGED
package/nodejs/logform/index.js
CHANGED
package/nodejs/throttle/index.js
CHANGED
package/package.json
CHANGED
package/web/animation/index.js
CHANGED
package/web/onReady/index.js
CHANGED
package/web/style/index.js
CHANGED
package/web/throttle/index.js
CHANGED