oipage 1.3.1-alpha.0 → 1.4.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.
package/CHANGELOG CHANGED
@@ -68,8 +68,16 @@ v1.3.0:(废弃,请用1.3.1代替)
68
68
  * 新增 devServer.intercept 请求拦截
69
69
  * 新增对 if-modified-since和last-modified 之304协商缓存的支持
70
70
  v1.3.1:
71
- date:
71
+ date:2025-05-23
72
72
  changes:
73
73
  - 修复bug
74
74
  1、开发服务器
75
75
  * 由于是否入口判断导致import语句未正确解析
76
+ * 修复 Last-Modified 格式不规范导致的运行报错
77
+ v1.4.0:
78
+ date:
79
+ changes:
80
+ - 新增功能
81
+ 1、开发服务器
82
+ * 新增 serve.d.ts 以支持作为API在TypeScript中环境
83
+ (仅对内使用,未正式对外暴露API相关文档)
package/bin/serve.d.ts ADDED
@@ -0,0 +1,55 @@
1
+
2
+ interface DevServerType {
3
+
4
+ /**
5
+ * 服务器端口号
6
+ */
7
+ port?: number
8
+
9
+ /**
10
+ * 服务器根路径
11
+ */
12
+ baseUrl?: string
13
+ }
14
+
15
+ interface InterceptType {
16
+ test: RegExp
17
+ handler(request: any, response: any): void
18
+ }
19
+
20
+ interface LoaderType {
21
+ (source: string): string
22
+ }
23
+
24
+ interface ConfigType {
25
+
26
+ /**
27
+ * 服务器名称
28
+ */
29
+ name?: string
30
+
31
+ /**
32
+ * 服务器版本
33
+ */
34
+ version?: string
35
+
36
+ /**
37
+ * 服务器运行配置
38
+ */
39
+ devServer?: DevServerType
40
+
41
+ intercept?: Array<InterceptType>
42
+
43
+ module?: {
44
+ rules: Array<{
45
+ test: RegExp
46
+ use: LoaderType
47
+ }>
48
+ }
49
+ }
50
+
51
+ interface ServeType {
52
+ (config: ConfigType): void
53
+ }
54
+
55
+ export default ServeType
package/bin/serve.js CHANGED
@@ -15,6 +15,9 @@ module.exports = function (config) {
15
15
  const port = config.devServer.port; // 端口号
16
16
  const basePath = (/^\./.test(config.devServer.baseUrl)) ? join(process.cwd(), config.devServer.baseUrl) : config.devServer.baseUrl; // 服务器根路径
17
17
 
18
+ const name = (config.name || "OIPage") + "-http-server";
19
+ const version = config.version || packageValue.version;
20
+
18
21
  let Server = createServer(function (request, response) {
19
22
  let headers = request.headers;
20
23
  let url = decodeURIComponent(request.url);
@@ -27,7 +30,7 @@ module.exports = function (config) {
27
30
 
28
31
  // 请求拦截
29
32
  if (doIntercept(url.replace(/^\/@modules\//, ""), config.devServer.intercept, request, response)) {
30
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] intercept: " + url + '\x1b[0m ' + new Date().toLocaleString());
33
+ console.log("<i> \x1b[1m\x1b[32m[" + name + "] intercept: " + url + '\x1b[0m ' + new Date().toLocaleString());
31
34
  }
32
35
 
33
36
  // 如果存在且是文件
@@ -37,12 +40,12 @@ module.exports = function (config) {
37
40
  let fileType = mineTypes[dotName]; // 文件类型
38
41
  let fileInfo = statSync(filePath);
39
42
 
40
- let fileModifiedTime = new Date(fileInfo.mtime).toString();
43
+ let fileModifiedTime = new Date(fileInfo.mtime).toGMTString();
41
44
 
42
45
  let responseHeader = {
43
46
  'Content-type': (fileType || "text/plain") + ";charset=utf-8",
44
47
  'Access-Control-Allow-Origin': '*',
45
- 'Server': 'Powered by OIPage-dev-server@' + packageValue.version,
48
+ 'Server': 'Powered by ' + name + '@' + version,
46
49
  'Cache-Control': 'no-cache',
47
50
  'Last-Modified': fileModifiedTime
48
51
  };
@@ -53,7 +56,7 @@ module.exports = function (config) {
53
56
  if (lastModified <= ifModifiedSince) {
54
57
  response.writeHead('304', responseHeader);
55
58
  response.end();
56
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Cache File: " + url + "\x1b[0m " + new Date().toLocaleString() + "\x1b[33m\x1b[1m 304\x1b[0m");
59
+ console.log("<i> \x1b[1m\x1b[32m[" + name + "] Cache File: " + url + "\x1b[0m " + new Date().toLocaleString() + "\x1b[33m\x1b[1m 304\x1b[0m");
57
60
  return;
58
61
  }
59
62
  }
@@ -98,7 +101,7 @@ module.exports = function (config) {
98
101
  createReadStream(filePath).pipe(response);
99
102
  }
100
103
 
101
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] " + sendType + " File: " + url + '\x1b[0m ' + new Date().toLocaleString());
104
+ console.log("<i> \x1b[1m\x1b[32m[" + name + "] " + sendType + " File: " + url + '\x1b[0m ' + new Date().toLocaleString());
102
105
  }
103
106
 
104
107
  // 否则就是404
@@ -106,7 +109,7 @@ module.exports = function (config) {
106
109
  response.writeHead(404, {
107
110
  'Content-type': "text/html;charset=utf-8",
108
111
  'Access-Control-Allow-Origin': '*',
109
- 'Server': 'Powered by OIPage-dev-server@' + packageValue.version
112
+ 'Server': 'Powered by ' + name + '@' + version
110
113
  });
111
114
  response.write(resolve404(filePath, url));
112
115
  response.end();
@@ -120,10 +123,10 @@ module.exports = function (config) {
120
123
  let networkValue = network();
121
124
 
122
125
  // 打印成功提示
123
- console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] Project is running at:\x1b[0m');
124
- console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] Loopback: \x1b[36mhttp://localhost:' + port + '/\x1b[0m');
125
- for (let ipv4Item of networkValue.IPv4) console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] On Your Network (IPv4):\x1b[36m http://' + ipv4Item.address + ':' + port + '/\x1b[0m');
126
- for (let ipv6Item of networkValue.IPv6) console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] On Your Network (IPv6): \x1b[36mhttp://[' + ipv6Item.address + ']:' + port + '/\x1b[0m');
127
- console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] Content not from OIPage is served from \x1b[36m"' + basePath + '" \x1b[0mdirectory');
128
- console.log('\nOIPage ' + packageValue.version + ' compiled \x1b[1m\x1b[32msuccessfully\x1b[0m in ' + (new Date().valueOf() - startTime) + ' ms\n')
126
+ console.log('<i> \x1b[1m\x1b[32m[' + name + '] Project is running at:\x1b[0m');
127
+ console.log('<i> \x1b[1m\x1b[32m[' + name + '] Loopback: \x1b[36mhttp://localhost:' + port + '/\x1b[0m');
128
+ for (let ipv4Item of networkValue.IPv4) console.log('<i> \x1b[1m\x1b[32m[' + name + '] On Your Network (IPv4):\x1b[36m http://' + ipv4Item.address + ':' + port + '/\x1b[0m');
129
+ for (let ipv6Item of networkValue.IPv6) console.log('<i> \x1b[1m\x1b[32m[' + name + '] On Your Network (IPv6): \x1b[36mhttp://[' + ipv6Item.address + ']:' + port + '/\x1b[0m');
130
+ console.log('<i> \x1b[1m\x1b[32m[' + name + '] Content not from ' + (config.name || "OIPage") + ' is served from \x1b[36m"' + basePath + '" \x1b[0mdirectory');
131
+ console.log('\n' + (config.name || "OIPage") + ' ' + version + ' compiled \x1b[1m\x1b[32msuccessfully\x1b[0m in ' + (new Date().valueOf() - startTime) + ' ms\n')
129
132
  };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.3.1-alpha.0
2
+ * animation of OIPage v1.4.0-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.1-alpha.0
2
+ * cmdlog of OIPage v1.4.0-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.1-alpha.0
2
+ * disk of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * json of OIPage v1.3.1-alpha.0
2
+ * json of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {reader} = require("../reader/index.js");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * logform of OIPage v1.3.1-alpha.0
2
+ * logform of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {linelog} = require("../cmdlog/index.js");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * reader of OIPage v1.3.1-alpha.0
2
+ * reader of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.3.1-alpha.0
2
+ * throttle of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "1.3.1-alpha.0",
3
+ "version": "1.4.0-alpha.0",
4
4
  "description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.3.1-alpha.0
2
+ * animation of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
package/web/json/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * json of OIPage v1.3.1-alpha.0
2
+ * json of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  import {reader} from "../reader/index.js";
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * onReady of OIPage v1.3.1-alpha.0
2
+ * onReady of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * performChunk of OIPage v1.3.1-alpha.0
2
+ * performChunk of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * reader of OIPage v1.3.1-alpha.0
2
+ * reader of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * style of OIPage v1.3.1-alpha.0
2
+ * style of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.3.1-alpha.0
2
+ * throttle of OIPage v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5