oipage 1.0.0-beta.0 → 1.1.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
@@ -1,5 +1,5 @@
1
1
  v1.0.0:
2
- date:
2
+ date:2025-02-13
3
3
  changes:
4
4
  - 原v0.x的功能将独立一个分支继续维护:https://github.com/oi-contrib/OIPage/blob/v0.x/CHANGELOG
5
5
  (v0.x保持对零碎方法这种形式的支持和维护,此版本开始将作为一个框架或一个系统的工具箱以提供更高效的使用方式,这是一次彻底的非兼容改造)
@@ -17,3 +17,13 @@ v1.0.0:
17
17
  * throttle 节流函数
18
18
  3、命令(oipage-cli)
19
19
  * serve 开发服务器
20
+ v1.1.0:
21
+ date:
22
+ changes:
23
+ - 优化改造
24
+ 1、使用流读取以使开发服务器支持大文件下载
25
+ - 新增功能
26
+ 1、API功能(Node.js)
27
+ * disk 磁盘相关操作
28
+ (包括:deleteDisk、copyDisk、moveDisk)
29
+ * logform 表单输入
package/bin/serve.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { join } = require("path");
2
- const { existsSync, lstatSync, readFileSync } = require("fs");
2
+ const { existsSync, lstatSync, readFileSync, createReadStream } = require("fs");
3
3
  const { createServer } = require('http');
4
4
  const packageValue = require("../package.json");
5
5
  const network = require("./network");
@@ -11,7 +11,7 @@ module.exports = function (config) {
11
11
  let startTime = new Date().valueOf();
12
12
 
13
13
  const port = config.port; // 端口号
14
- const basePath = join(process.cwd(), config.baseUrl); // 服务器根路径
14
+ const basePath = (/^\./.test(config.baseUrl)) ? join(process.cwd(), config.baseUrl) : config.baseUrl; // 服务器根路径
15
15
 
16
16
  let Server = createServer(function (request, response) {
17
17
 
@@ -32,8 +32,13 @@ module.exports = function (config) {
32
32
  'Access-Control-Allow-Origin': '*',
33
33
  'Server': 'Powered by OIPage-dev-server@' + packageValue.version
34
34
  });
35
- response.write(readFileSync(filePath));
36
- response.end();
35
+
36
+ // 方式一
37
+ // response.write(readFileSync(filePath));
38
+ // response.end();
39
+
40
+ // 方式二
41
+ createReadStream(filePath).pipe(response);
37
42
 
38
43
  console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read File: " + url + '\x1b[0m ' + new Date().toLocaleString());
39
44
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.0.0-beta.0
2
+ * animation of OIPage v1.1.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -106,5 +106,5 @@ function animation(doback, duration, callback) {
106
106
  }
107
107
  };
108
108
 
109
- };
109
+ }
110
110
  exports.animation = animation;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * cmdlog of OIPage v1.0.0-beta.0
2
+ * cmdlog of OIPage v1.1.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -77,6 +77,6 @@ function deeplog (percentum, stream) {
77
77
  }
78
78
 
79
79
  linelog(percentum.toFixed(2) + "%[" + txt + "]" + stream);
80
- };
80
+ }
81
81
  exports.linelog = linelog;
82
82
  exports.deeplog = deeplog;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 删除文件或文件夹
3
+ */
4
+ export interface deleteDiskType {
5
+ (diskPath: string): void
6
+ }
7
+
8
+ export let deleteDisk: deleteDiskType
9
+
10
+ /**
11
+ * 复制文件或文件夹
12
+ */
13
+ export interface copyDiskType {
14
+ (sourcePath: string, targetPath: string): void
15
+ }
16
+
17
+ export let copyDisk: copyDiskType
18
+
19
+ /**
20
+ * 移动文件或文件夹
21
+ */
22
+ export interface moveDiskType {
23
+ (sourcePath: string, targetPath: string): void
24
+ }
25
+
26
+ export let moveDisk: moveDiskType
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * disk of OIPage v1.1.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+
6
+
7
+ exports.deleteDisk = deleteDisk;
8
+ exports.copyDisk = copyDisk;
9
+ exports.moveDisk = moveDisk;
@@ -0,0 +1,19 @@
1
+ export interface inputType {
2
+ type: string
3
+ label: string
4
+ }
5
+
6
+ export interface selectType extends inputType {
7
+ value: Array<string>
8
+ }
9
+
10
+ /**
11
+ * 表单输入
12
+ * @param form 表单内容
13
+ * @returns 返回一个结果数组
14
+ */
15
+ export interface logformType {
16
+ (config: Array<inputType | selectType>): Promise<Array<string | number>>
17
+ }
18
+
19
+ export let deeplog: logformType
@@ -0,0 +1,100 @@
1
+ /*!
2
+ * logform of OIPage v1.1.0-alpha.0
3
+ * git+https://github.com/oi-contrib/OIPage.git
4
+ */
5
+ const {linelog} = require("../cmdlog/index.js");
6
+ let getTitle = function (title) {
7
+ return "➤ " + title;
8
+ };
9
+
10
+ let closeForm = function () {
11
+ process.removeAllListeners("keypress");
12
+ rl.close();
13
+ };
14
+
15
+ let selectView = (title, list, index) => {
16
+ let txtArray = [];
17
+ for (let i = 0; i < list.length; i++) {
18
+ txtArray.push(" " + (i == index ? "●" : "○") + " " + list[i]);
19
+ }
20
+
21
+ linelog(`${title}\n${txtArray.join("\n")}\n`);
22
+ };
23
+
24
+ function logform(config) {
25
+ const rl = require("readline").createInterface({
26
+ input: process.stdin,
27
+ output: process.stdout
28
+ });
29
+
30
+ return new Promise(function (resolve, reject) {
31
+ let result = [], keyback = () => { };
32
+
33
+ console.log("");
34
+
35
+ process.stdin.on("keypress", (_str, key) => {
36
+ keyback(key.name);
37
+ });
38
+
39
+ let getResult = (index) => {
40
+ if (index >= config.length) {
41
+ closeForm();
42
+ resolve(result);
43
+ } else {
44
+ let item = config[index];
45
+
46
+ // 文本输入
47
+ if (item.type == "input") {
48
+
49
+ rl.question(getTitle(item.label), (answer) => {
50
+ result.push(answer);
51
+ setTimeout(() => {
52
+ console.log("");
53
+ getResult(index + 1);
54
+ }, 50);
55
+ });
56
+
57
+ }
58
+
59
+ // 列表选择
60
+ else if (item.type == "select") {
61
+ let title = getTitle(item.label);
62
+
63
+ let selectIndex = 0;
64
+ selectView(title, item.value, selectIndex);
65
+ keyback = (keyname) => {
66
+ if (keyname == "return") {
67
+ result.push(selectIndex);
68
+ keyback = () => { };
69
+ linelog();
70
+ setTimeout(() => {
71
+ getResult(index + 1);
72
+ }, 50);
73
+ } else {
74
+ if (keyname == "left" || keyname == "up") {
75
+ if (selectIndex > 0) selectIndex -= 1;
76
+ else selectIndex = item.value.length - 1;
77
+ } else if (keyname == "right" || keyname == "down") {
78
+ if (selectIndex < item.value.length - 1) selectIndex += 1;
79
+ else selectIndex = 0;
80
+ } else {
81
+ return;
82
+ }
83
+ selectView(title, item.value, selectIndex);
84
+ }
85
+ };
86
+
87
+ }
88
+
89
+ // 非法类型
90
+ else {
91
+ closeForm();
92
+ reject(new Error("Illegal type!"));
93
+ }
94
+ }
95
+
96
+ };
97
+ getResult(0);
98
+ });
99
+ }
100
+ exports.logform = logform;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.0.0-beta.0
2
+ * throttle of OIPage v1.1.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -52,5 +52,5 @@ function throttle(callback, _option) {
52
52
  }
53
53
 
54
54
  };
55
- };
55
+ }
56
56
  exports.throttle = throttle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.1.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.0.0-beta.0
2
+ * animation of OIPage v1.1.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -106,4 +106,4 @@ export function animation(doback, duration, callback) {
106
106
  }
107
107
  };
108
108
 
109
- };
109
+ }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * onReady of OIPage v1.0.0-beta.0
2
+ * onReady of OIPage v1.1.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -10,4 +10,4 @@ export function onReady(callback) {
10
10
  } else {
11
11
  window.addEventListener("DOMContentLoaded", callback);
12
12
  }
13
- };
13
+ }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * style of OIPage v1.0.0-beta.0
2
+ * style of OIPage v1.1.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -7,7 +7,7 @@ export function setStyle(el, styles) {
7
7
  for (var key in styles) {
8
8
  el.style[key] = styles[key];
9
9
  }
10
- };
10
+ }
11
11
 
12
12
  export function getStyle(el, name) {
13
13
 
@@ -21,4 +21,4 @@ export function getStyle(el, name) {
21
21
  allStyle.getPropertyValue(name) :
22
22
  allStyle;
23
23
 
24
- };
24
+ }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.0.0-beta.0
2
+ * throttle of OIPage v1.1.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -52,4 +52,4 @@ export function throttle(callback, _option) {
52
52
  }
53
53
 
54
54
  };
55
- };
55
+ }