oipage 1.1.0-alpha.0 → 1.1.0-alpha.2

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
@@ -2,15 +2,15 @@ v1.0.0:
2
2
  date:2025-02-13
3
3
  changes:
4
4
  - 原v0.x的功能将独立一个分支继续维护:https://github.com/oi-contrib/OIPage/blob/v0.x/CHANGELOG
5
- (v0.x保持对零碎方法这种形式的支持和维护,此版本开始将作为一个框架或一个系统的工具箱以提供更高效的使用方式,这是一次彻底的非兼容改造)
5
+ v0.x保持对零碎方法这种形式的支持和维护,此版本开始将作为一个框架或一个系统的工具箱以提供更高效的使用方式,这是一次彻底的非兼容改造)
6
6
  - 初始化版本(v1.x)
7
- 1、API功能(浏览器)
7
+ 1、API功能(浏览器)
8
8
  * animation 动画
9
9
  * getStyle 获取节点样式
10
10
  * setStyle 设置节点样式
11
11
  * onReady 加载完毕执行
12
12
  * throttle 节流函数
13
- 2、API功能(Node.js)
13
+ 2、API功能(Node.js
14
14
  * animation 动画
15
15
  * deeplog 进度打印
16
16
  * linglog 单行打印
@@ -20,10 +20,16 @@ v1.0.0:
20
20
  v1.1.0:
21
21
  date:
22
22
  changes:
23
+ - 修复bug
24
+ 1、通过路径类型判断以修复开发服务器无法设置绝对路径问题
23
25
  - 优化改造
24
26
  1、使用流读取以使开发服务器支持大文件下载
27
+ (同时添加下载进度可查)
25
28
  - 新增功能
26
- 1、API功能(Node.js)
29
+ 1、API功能(Node.js
27
30
  * disk 磁盘相关操作
28
- (包括:deleteDisk、copyDisk、moveDisk
31
+ (包括:deleteDisk、copyDisk)
29
32
  * logform 表单输入
33
+ 2、命令(oipage-cli)
34
+ * dist 磁盘操作
35
+ * run 运行多命令
package/README.md CHANGED
@@ -9,11 +9,14 @@
9
9
  <a href="https://www.npmjs.com/package/oipage">
10
10
  <img src="https://img.shields.io/npm/v/oipage.svg" alt="npm">
11
11
  </a>
12
- <a href="https://github.com/oi-contrib/OIPage/issues">
12
+ <a href="https://github.com/oi-contrib/OIPage/issues">
13
13
  <img src="https://img.shields.io/github/issues/oi-contrib/OIPage" alt="issue">
14
14
  </a>
15
15
  <a href="https://github.com/oi-contrib/OIPage" target='_blank'>
16
16
  <img alt="GitHub repo stars" src="https://img.shields.io/github/stars/oi-contrib/OIPage?style=social">
17
+ </a>
18
+ <a href="https://github.com/oi-contrib/OIPage">
19
+ <img src="https://img.shields.io/github/forks/oi-contrib/OIPage" alt="forks">
17
20
  </a>
18
21
  <a href="https://gitee.com/oi-contrib/OIPage" target='_blank'>
19
22
  <img alt="Gitee repo stars" src="https://gitee.com/oi-contrib/OIPage/badge/star.svg">
@@ -51,13 +54,13 @@ oipage-cli
51
54
  比如会出现下列内容:
52
55
 
53
56
  ```
54
- OIPage@v1.0.0
57
+ OIPage@v1.1.0
55
58
 
56
59
  可以使用的命令如下:
57
60
 
58
61
  【1】oipage-cli serve 开发服务器
59
62
  --port|-p 端口号
60
- --baseUrl 服务器根目录(相对命令行)
63
+ --baseUrl 服务器根目录
61
64
  ......
62
65
  ```
63
66
 
package/bin/disk.js ADDED
@@ -0,0 +1,32 @@
1
+ const { deleteDisk, copyDisk } = require("../nodejs/disk");
2
+
3
+ module.exports = function (config) {
4
+ let isForce = false;
5
+
6
+ // 判断是否开启强制执行
7
+ for (let i = 0; i < config.value.length; i++) {
8
+ if (config.value[i].name === "--force") isForce = true;
9
+ }
10
+
11
+ // 执行一个个任务
12
+ for (let i = 0; i < config.value.length; i++) {
13
+
14
+ // 删除文件或文件夹
15
+ if (config.value[i].name === "--delete") {
16
+ for (let j = 0; j < config.value[i].value.length; j++) {
17
+ deleteDisk(config.value[i].value[j]);
18
+ }
19
+ }
20
+
21
+ // 移动文件或文件夹
22
+ else if (config.value[i].name === "--move") {
23
+ copyDisk(config.value[i].value[0], config.value[i].value[1], isForce);
24
+ deleteDisk(config.value[i].value[0]);
25
+ }
26
+
27
+ // 复制文件或文件夹
28
+ else if (config.value[i].name === "--copy") {
29
+ copyDisk(config.value[i].value[0], config.value[i].value[1], isForce);
30
+ }
31
+ }
32
+ };
package/bin/format.js CHANGED
@@ -1,5 +1,8 @@
1
-
2
- // 把字节转换成更可读的内容
1
+ /**
2
+ * 把字节转换成更可读的内容
3
+ * @param {*} value
4
+ * @returns
5
+ */
3
6
  exports.formatByte = function (value) {
4
7
  if (value < 1024) return value + "Byte";
5
8
 
@@ -13,7 +16,11 @@ exports.formatByte = function (value) {
13
16
  return gb.toFixed(1) + "GB";
14
17
  };
15
18
 
16
- // 把时间变成更可读的格式
19
+ /**
20
+ * 把时间变成更可读的格式
21
+ * @param {*} value
22
+ * @returns
23
+ */
17
24
  exports.formatTime = function (value) {
18
25
  let year = value.getFullYear();
19
26
  let month = value.getMonth() + 1;
@@ -30,22 +37,40 @@ exports.formatTime = function (value) {
30
37
  }
31
38
  };
32
39
 
33
- exports.formatArgv = function (argvs, shorts) {
34
- let result = {};
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
+ };
35
61
 
36
- let keyName = "args", value = [];
37
62
  for (let index = 3; index < argvs.length; index++) {
38
63
  let argv = argvs[index];
39
64
 
40
65
  if (/^\-/.test(argv)) {
41
- result[keyName] = value;
66
+ pushValue();
42
67
  keyName = shorts[argv] || argv;
43
68
  value = [];
44
69
  } else {
45
70
  value.push(argv);
46
71
  }
47
72
  }
48
- result[keyName] = value;
73
+ pushValue();
49
74
 
50
75
  return result;
51
76
  };
package/bin/help.js CHANGED
@@ -8,7 +8,15 @@ OIPage@v${packageValue.version}
8
8
 
9
9
  【1】oipage-cli serve 开发服务器
10
10
  --port|-p 端口号
11
- --baseUrl 服务器根目录(相对命令行)
11
+ --baseUrl 服务器根目录
12
+
13
+ 【2】oipage-cli disk 磁盘操作
14
+ --force|-f 强制执行
15
+ --delete|-d 删除文件或文件夹
16
+ --move|m 移动文件或文件夹
17
+ --copy|-c 复制文件或文件夹
18
+
19
+ 【3】oipage-cli run "任务一" "任务二" ... 运行多命令
12
20
 
13
21
  Powered by https://github.com/zxl20070701
14
22
  \x1b[0m`);
package/bin/run CHANGED
@@ -4,24 +4,67 @@
4
4
 
5
5
  process.title = 'OIPage';
6
6
 
7
+ const { exec } = require('child_process');
7
8
  const { formatArgv } = require("./format");
8
- const doServe = require("./serve");
9
- const doHelp = require("./help");
10
9
 
11
10
  // 开发服务器
12
- if (process.argv[2] == "serve") {
11
+ if (process.argv[2] === "serve") {
13
12
 
14
13
  let argvObj = formatArgv(process.argv, {
15
14
  "-p": "--port"
16
15
  });
17
16
 
18
- doServe({
17
+ require("./serve")({
19
18
  port: (argvObj["--port"] || [])[0] || 8080,
20
19
  baseUrl: (argvObj["--baseUrl"] || [])[0] || "./",
21
20
  });
22
21
  }
23
22
 
23
+ // 磁盘操作
24
+ else if (process.argv[2] === "disk") {
25
+
26
+ let argvObj = formatArgv(process.argv, {
27
+ "-f": "--force",
28
+ "-d": "--delete",
29
+ "-m": "--move",
30
+ "-c": "--copy"
31
+ }, true);
32
+
33
+ require("./disk")(argvObj);
34
+ }
35
+
36
+ // 运行多命令
37
+ else if (process.argv[2] === "run") {
38
+
39
+ let argvObj = formatArgv(process.argv, {});
40
+
41
+ for (let index = 0; index < argvObj.args.length; index++) {
42
+ const child = exec(argvObj.args[index]);
43
+
44
+ // 监听子线程的stdout
45
+ child.stdout.on('data', (data) => {
46
+ console.log(`[${index + 1}] log:${data}`);
47
+ });
48
+
49
+ // 监听子线程的stderr
50
+ child.stderr.on('data', (data) => {
51
+ console.error(`[${index + 1}] error:${data}`);
52
+ });
53
+
54
+ // 子线程结束处理
55
+ child.on('close', (code) => {
56
+ console.log(`[${index + 1}] 子线程结束,退出码 ${code}`);
57
+ });
58
+
59
+ // 子线程出错处理
60
+ child.on('error', (error) => {
61
+ console.error(`[${index + 1}] 子线程错误: ${error.message}`);
62
+ });
63
+ }
64
+
65
+ }
66
+
24
67
  // 默认,帮助
25
68
  else {
26
- doHelp();
69
+ require("./help")();
27
70
  }
package/bin/serve.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { join } = require("path");
2
- const { existsSync, lstatSync, readFileSync, createReadStream } = require("fs");
2
+ const { existsSync, lstatSync, readFileSync, statSync, createReadStream } = require("fs");
3
3
  const { createServer } = require('http');
4
4
  const packageValue = require("../package.json");
5
5
  const network = require("./network");
@@ -26,21 +26,31 @@ module.exports = function (config) {
26
26
 
27
27
  let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
28
28
  let fileType = mineTypes[dotName]; // 文件类型
29
+ let fileInfo = statSync(filePath);
29
30
 
30
31
  response.writeHead('200', {
31
32
  'Content-type': (fileType || "text/plain") + ";charset=utf-8",
32
33
  'Access-Control-Allow-Origin': '*',
34
+ 'Content-Length': fileInfo.size,
33
35
  'Server': 'Powered by OIPage-dev-server@' + packageValue.version
34
36
  });
35
37
 
36
- // 方式一
37
- // response.write(readFileSync(filePath));
38
- // response.end();
38
+ let sendType = "";
39
39
 
40
- // 方式二
41
- createReadStream(filePath).pipe(response);
40
+ // 如果文件小于10M,认为不大,直接读取
41
+ if (fileInfo.size < 10 * 1024 * 1024) {
42
+ sendType = "Read";
43
+ response.write(readFileSync(filePath));
44
+ response.end();
45
+ }
42
46
 
43
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read File: " + url + '\x1b[0m ' + new Date().toLocaleString());
47
+ // 对于大文件,使用流读取
48
+ else {
49
+ sendType = "Stream";
50
+ createReadStream(filePath).pipe(response);
51
+ }
52
+
53
+ console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] " + sendType + " File: " + url + '\x1b[0m ' + new Date().toLocaleString());
44
54
  }
45
55
 
46
56
  // 否则就是404
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.1.0-alpha.0
2
+ * animation of OIPage v1.1.0-alpha.2
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.1.0-alpha.0
2
+ * cmdlog of OIPage v1.1.0-alpha.2
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -11,16 +11,7 @@ export let deleteDisk: deleteDiskType
11
11
  * 复制文件或文件夹
12
12
  */
13
13
  export interface copyDiskType {
14
- (sourcePath: string, targetPath: string): void
14
+ (sourcePath: string, targetPath: string, isForce?: boolean): void
15
15
  }
16
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
17
+ export let copyDisk: copyDiskType
@@ -1,9 +1,85 @@
1
1
  /*!
2
- * disk of OIPage v1.1.0-alpha.0
2
+ * disk of OIPage v1.1.0-alpha.2
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
6
-
6
+ const { join } = require("path");
7
+ const { existsSync, readdirSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, copyFileSync } = require("fs");
8
+
9
+ /**
10
+ * 删除文件或文件夹
11
+ * @param {string} diskPath
12
+ */
13
+ function deleteDisk(diskPath) {
14
+ // 如果文件夹不存在,直接返回即可
15
+ if (!existsSync(diskPath)) return;
16
+
17
+ // 如果是文件,直接删除即可
18
+ if (!lstatSync(diskPath).isDirectory()) {
19
+ unlinkSync(diskPath);
20
+ } else {
21
+
22
+ // 读取子文件
23
+ const subFiles = readdirSync(diskPath);
24
+
25
+ subFiles.forEach(function (item) {
26
+
27
+ // 调用这个方法,删除子文件或文件夹
28
+ const curPath = join(diskPath, "./" + item);
29
+ deleteDisk(curPath);
30
+
31
+ });
32
+
33
+ // 等子文件或文件夹删除完毕以后,删除本文件夹
34
+ rmdirSync(diskPath);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * 复制文件或文件夹
40
+ * @param {string} sourcePath
41
+ * @param {string} targetPath
42
+ * @param {boolean} isForce 可选,是否强制执行
43
+ */
44
+ function copyDisk(sourcePath, targetPath, isForce) {
45
+
46
+ // 如果源文件不存在
47
+ if (!existsSync(sourcePath)) {
48
+ console.log("\x1b[0m\x1b[31m" + sourcePath + "\x1b[0m");
49
+ throw new Error("OIPage: The source path does not exist");
50
+ }
51
+
52
+ // 如果模板文件已经存在
53
+ if (existsSync(targetPath)) {
54
+ if (isForce) {
55
+ deleteDisk(targetPath);
56
+ } else {
57
+ console.log("\x1b[0m\x1b[31m" + targetPath + "\x1b[0m");
58
+ throw new Error("OIPage: The target path already exists.");
59
+ }
60
+ }
61
+
62
+ (function copyDiskFun(sourcePath, targetPath) {
63
+ // 如果是文件,直接复制即可
64
+ if (!lstatSync(sourcePath).isDirectory()) {
65
+ copyFileSync(sourcePath, targetPath);
66
+ } else {
67
+
68
+ // 读取子文件
69
+ const subFiles = readdirSync(sourcePath);
70
+
71
+ // 如果文件夹不存在,创建
72
+ if (!existsSync(targetPath)) {
73
+ mkdirSync(targetPath, { recursive: true });
74
+ }
75
+
76
+ // 复制子文件或文件夹
77
+ subFiles.forEach(function (item) {
78
+ copyDiskFun(join(sourcePath, "./" + item), join(targetPath, "./" + item));
79
+ });
80
+
81
+ }
82
+ })(sourcePath, targetPath);
83
+ }
7
84
  exports.deleteDisk = deleteDisk;
8
85
  exports.copyDisk = copyDisk;
9
- exports.moveDisk = moveDisk;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * logform of OIPage v1.1.0-alpha.0
2
+ * logform of OIPage v1.1.0-alpha.2
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
- * throttle of OIPage v1.1.0-alpha.0
2
+ * throttle of OIPage v1.1.0-alpha.2
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.1.0-alpha.0",
3
+ "version": "1.1.0-alpha.2",
4
4
  "description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "author": {
29
29
  "name": "zxl20070701",
30
- "url": "https://github.com/zxl20070701"
30
+ "url": "https://zxl20070701.github.io/notebook/home.html"
31
31
  },
32
32
  "license": "MIT",
33
33
  "bugs": {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.1.0-alpha.0
2
+ * animation of OIPage v1.1.0-alpha.2
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * onReady of OIPage v1.1.0-alpha.0
2
+ * onReady of OIPage v1.1.0-alpha.2
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.1.0-alpha.0
2
+ * style of OIPage v1.1.0-alpha.2
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.1.0-alpha.0
2
+ * throttle of OIPage v1.1.0-alpha.2
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5