oipage 0.1.0 → 0.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/CHANGELOG CHANGED
@@ -1,21 +1,9 @@
1
1
  v0.1.0:
2
- date:2023-09-21
2
+ date:2024-09-21
3
3
  changes:
4
4
  - 初始化版本
5
5
  1、命令
6
- * --help, -h 获得帮助
7
- * --server, -s 启动服务器
8
- * --version, -v 查看版本
9
- * --config, -c 启动配置文件
10
- * --delete 删除文件或文件夹
11
- * --copy 复制文件或文件夹
12
- * --pick 提取文件夹文件到指定位置
13
- * --move 移动文件或文件夹
14
- * --network 查看网络信息
15
- * --get 发送get请求
16
- * --post 发送post请求
17
- * --cat 查看文本内容
18
- * --run 多进程运行任务
6
+ (包括:help、server、version、config、delete、copy、pick、move、network、get、post、cat、run)
19
7
  2、corejs
20
8
  * animation 动画
21
9
  * throttle 节流函数
@@ -27,12 +15,29 @@ v0.1.0:
27
15
  * options 命令行参数解析
28
16
  * file 文件相关操作
29
17
  * console 控制台打印
18
+ (包括:log、warn、error、linelog、deeplog)
30
19
  * ajax 网络请求
31
20
  * network 网络信息等
32
21
  * data 资源数据
33
22
  * image 图片相关操作
34
23
  * loader 文件解析
24
+ (simpleScss、xhtml)
35
25
  5、stylecss
36
26
  * 统一浏览器样式 normalize.css
37
27
  * 十二栅格化 rasterize.css
38
- * 架屏动画 skeleton.css
28
+ * 架屏动画 skeleton.css
29
+ v0.2.0:
30
+ date:
31
+ changes:
32
+ - 优化改造
33
+ 1、nodejs
34
+ * linelog新增清除行记录重置功能
35
+ * deeplog新增清除行记录重置功能
36
+ - 新增功能
37
+ 1、nodejs
38
+ * plain 读取文本内容
39
+ * form 表单录入
40
+ (包括:input输入框、select列表选择)
41
+ * server hander方法补充api
42
+ (包括:getFileInfo()、filePath)
43
+
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # [OIPage](https://github.com/oi-contrib/OIPage)
2
- OI页面快速开发辅助库
2
+ OI页面快速开发辅助库,包括核心包、Nodejs、浏览器、样式文件等
3
3
 
4
4
  <p>
5
5
  <a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=oipage&interval=7">
@@ -70,7 +70,7 @@ oipage-cli -s 8080
70
70
  对于更复杂的业务,我们推荐使用配置文件的方式。比如我们准备了配置文件 oipage.config.js ,那么就可以:
71
71
 
72
72
  ```shell
73
- devby -c ./oipage.config.js
73
+ oipage-cli -c ./oipage.config.js
74
74
  ```
75
75
 
76
76
  配置文件的内容如下:
@@ -100,7 +100,9 @@ module.exports = {
100
100
  - [网络信息等](./docs/nodejs/network.md)
101
101
  - [资源数据](./docs/nodejs/data.md)
102
102
  - [图片相关操作](./docs/nodejs/image.md)
103
- - [文件解析Loader](./docs/nodejs/loader.md)
103
+ - [文件解析](./docs/nodejs/loader.md)
104
+ - [文件读取](./docs/nodejs/reader.md)
105
+ - [表单录入](./docs/nodejs/form.md)
104
106
 
105
107
  ### 浏览器
106
108
 
package/bin/run CHANGED
@@ -6,12 +6,12 @@ process.title = 'OIPage';
6
6
 
7
7
  const server = require('../nodejs/core/server');
8
8
  const { options, help } = require('./options');
9
- const path = require('path');
10
9
  const { log, error } = require('../nodejs/core/log');
11
10
  const { deleteSync, copySync, moveSync, listFileSync, fullPathSync } = require("../nodejs/core/file");
12
11
  const network = require("../nodejs/core/network");
13
12
  const { get, post } = require("../nodejs/core/remote");
14
13
  const fs = require("fs");
14
+ const path = require("path");
15
15
  const { exec } = require('child_process');
16
16
 
17
17
  const jsonfile = require("../package.json");
@@ -26,6 +26,7 @@ for (let key in options) {
26
26
  const parsed = require("../nodejs/core/options")(shortHands, process.argv);
27
27
 
28
28
  (() => {
29
+
29
30
  // 打印版本
30
31
  if (Array.isArray(parsed.version)) {
31
32
  log("\nOIPage@v" + jsonfile.version + "\n");
@@ -1,10 +1,13 @@
1
1
  import { getStyleType } from "./getStyle"
2
+ import { setStyleType } from "./setStyle"
2
3
  import { onReadyType } from "./onReady"
3
4
 
4
5
  export default class Corejs {
5
6
  static getStyle: getStyleType
7
+ static setStyle: setStyleType
6
8
  static onReady: onReadyType
7
9
  }
8
10
 
9
11
  export let getStyle: getStyleType
12
+ export let setStyle: setStyleType
10
13
  export let onReady: onReadyType
@@ -1,7 +1,9 @@
1
1
  import { getStyle } from "./getStyle/index.js";
2
+ import { setStyle } from "./setStyle/index.js";
2
3
  import { onReady } from "./onReady/index.js";
3
4
 
4
5
  export default {
5
6
  getStyle: getStyle,
7
+ setStyle: setStyle,
6
8
  onReady: onReady
7
9
  };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 设置节点样式
3
+ */
4
+ export interface setStyleType {
5
+ (el: HTMLElement, styles: {
6
+ [key: string]: string | number
7
+ }): void
8
+ }
9
+
10
+ export let setStyle: setStyleType
@@ -0,0 +1,5 @@
1
+ export function setStyle(el, styles) {
2
+ for (var key in styles) {
3
+ el.style[key] = styles[key];
4
+ }
5
+ };
@@ -32,6 +32,10 @@ const linelog = (function (stream) {
32
32
 
33
33
  // 返回实际同行打印的方法
34
34
  return function (nextStr) {
35
+ if (arguments.length == 0) {
36
+ prevLineCount = 0;
37
+ return;
38
+ }
35
39
  let txt = "";
36
40
 
37
41
  // 清除屏幕
@@ -62,6 +66,10 @@ exports.linelog = linelog;
62
66
  * @param {string} stream 说明文字,可选择
63
67
  */
64
68
  exports.deeplog = function (percentum, stream) {
69
+ if (arguments.length == 0) {
70
+ linelog();
71
+ return;
72
+ }
65
73
 
66
74
  if (arguments.length <= 1) stream = "";
67
75
 
@@ -44,12 +44,40 @@ module.exports = function (config = {}) {
44
44
  request.on('end', () => {
45
45
  let url = decodeURIComponent(request.url);
46
46
 
47
+ url = url.split("?")[0];
48
+
49
+ // 请求的文件路径
50
+ let filePath = path.join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
51
+
47
52
  log("[" + index++ + "]" + url);
48
53
 
54
+ let getFileInfo = function (filePath) {
55
+ let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
56
+ let type = mineTypes[dotName];
57
+ if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
58
+ return {
59
+ type,
60
+ path: filePath
61
+ };
62
+ } else {
63
+ for (let suffix of suffixs) {
64
+ if (fs.existsSync(filePath + suffix) && !fs.lstatSync(filePath + suffix).isDirectory()) {
65
+ type = mineTypes[suffix.replace(/^\./, "")];
66
+ return {
67
+ type,
68
+ path: filePath + suffix
69
+ };
70
+ }
71
+ }
72
+ }
73
+ };
74
+
49
75
  // 自定义拦截
50
76
  if (handler.call({
51
77
  data: requestData,
52
- base: basePath
78
+ base: basePath,
79
+ getFileInfo,
80
+ filePath
53
81
  }, request, response)) return;
54
82
 
55
83
  // proxy拦截
@@ -101,13 +129,6 @@ module.exports = function (config = {}) {
101
129
  }
102
130
  }
103
131
 
104
- url = url.split("?")[0];
105
-
106
- // 请求的文件路径
107
- let filePath = path.join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
108
-
109
- let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
110
-
111
132
  let is404 = true;
112
133
  let doResponse = function (type, filePath) {
113
134
  response.writeHead(200, {
@@ -119,17 +140,9 @@ module.exports = function (config = {}) {
119
140
  is404 = false;
120
141
  };
121
142
 
122
- // 文件类型
123
- type = mineTypes[dotName];
124
- if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
125
- doResponse(type, filePath);
126
- } else {
127
- for (let suffix of suffixs) {
128
- if (fs.existsSync(filePath + suffix) && !fs.lstatSync(filePath + suffix).isDirectory()) {
129
- type = mineTypes[suffix.replace(/^\./, "")];
130
- doResponse(type, filePath + suffix);
131
- }
132
- }
143
+ let fileInfo = getFileInfo(filePath);
144
+ if (fileInfo) { // 如果文件存在
145
+ doResponse(fileInfo.type, fileInfo.path);
133
146
  }
134
147
 
135
148
  if (is404) {
@@ -0,0 +1,3 @@
1
+ exports.getTitle = (title) => {
2
+ return "➤ " + title;
3
+ };
@@ -0,0 +1,80 @@
1
+ const { getTitle } = require("./common");
2
+ const { logView } = require("./select");
3
+ const { linelog } = require("../core/log");
4
+
5
+ module.exports = function (form) {
6
+ const rl = require("readline").createInterface({
7
+ input: process.stdin,
8
+ output: process.stdout
9
+ });
10
+
11
+ return new Promise(function (resolve, reject) {
12
+ let result = [], keyback = () => { };
13
+
14
+ console.log("");
15
+
16
+ process.stdin.on("keypress", (_str, key) => {
17
+ keyback(key.name);
18
+ });
19
+
20
+ let getResult = (index) => {
21
+ if (index >= form.length) {
22
+ process.removeAllListeners("keypress");
23
+ rl.close();
24
+ resolve(result);
25
+ } else {
26
+ let item = form[index];
27
+
28
+ // 文本输入
29
+ if (item.type == "input") {
30
+
31
+ rl.question(getTitle(item.label), (answer) => {
32
+ result.push(answer);
33
+ setTimeout(() => {
34
+ console.log("");
35
+ getResult(index + 1);
36
+ }, 50);
37
+ });
38
+
39
+ }
40
+
41
+ // 列表选择
42
+ else if (item.type == "select") {
43
+ let title = getTitle(item.label);
44
+
45
+ let selectIndex = 0;
46
+ logView(title, item.value, selectIndex);
47
+ keyback = (keyname) => {
48
+ if (keyname == "return") {
49
+ result.push(selectIndex);
50
+ keyback = () => { };
51
+ linelog();
52
+ setTimeout(() => {
53
+ getResult(index + 1);
54
+ }, 50);
55
+ } else {
56
+ if (keyname == "left" || keyname == "up") {
57
+ if (selectIndex > 0) selectIndex -= 1;
58
+ else selectIndex = item.value.length - 1;
59
+ } else if (keyname == "right" || keyname == "down") {
60
+ if (selectIndex < item.value.length - 1) selectIndex += 1;
61
+ else selectIndex = 0;
62
+ } else {
63
+ return;
64
+ }
65
+ logView(title, item.value, selectIndex);
66
+ }
67
+ };
68
+
69
+ }
70
+
71
+ // 非法类型
72
+ else {
73
+ throw new Error("Illegal type!");
74
+ }
75
+ }
76
+
77
+ };
78
+ getResult(0);
79
+ });
80
+ };
@@ -0,0 +1,10 @@
1
+ const { linelog } = require("../core/log");
2
+
3
+ exports.logView = (title, list, index) => {
4
+ let txtArray = [];
5
+ for (let i = 0; i < list.length; i++) {
6
+ txtArray.push(" " + (i == index ? "●" : "○") + " " + list[i]);
7
+ }
8
+
9
+ linelog(`${title}\n${txtArray.join("\n")}\n`);
10
+ };
package/nodejs/index.js CHANGED
@@ -10,6 +10,10 @@ const { toBase64 } = require('./core/image');
10
10
  const simpleScss = require('./loader/simpleScss');
11
11
  const xhtml = require('./loader/xhtml');
12
12
 
13
+ const plain = require('./reader/plain');
14
+
15
+ const form = require('./form/index');
16
+
13
17
  module.exports = {
14
18
 
15
19
  // 命令行相关
@@ -43,6 +47,12 @@ module.exports = {
43
47
  // 服务器
44
48
  server,
45
49
 
46
- // 文件解析Loader
47
- simpleScss, xhtml
50
+ // 文件解析
51
+ simpleScss, xhtml,
52
+
53
+ // 文件读取
54
+ plain,
55
+
56
+ // 表单录入
57
+ form
48
58
  };
@@ -0,0 +1,20 @@
1
+ module.exports = function (txt) {
2
+
3
+ let reader = {
4
+ index: -1,
5
+ currentChar: null
6
+ };
7
+
8
+ // 读取下一个字符
9
+ reader.readNext = function () {
10
+ reader.currentChar = reader.index++ < txt.length - 1 ? txt[reader.index] : null;
11
+ return reader.currentChar;
12
+ };
13
+
14
+ // 获取往后num个值
15
+ reader.getNextN = function (num) {
16
+ return txt.substring(reader.index, num + reader.index > txt.length ? txt.length : num + reader.index);
17
+ };
18
+
19
+ return reader;
20
+ };
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "0.1.0",
4
- "description": "OI页面快速开发辅助库",
3
+ "version": "0.2.0-alpha.1",
4
+ "description": "OI页面快速开发辅助库,包括核心包、Nodejs、浏览器、样式文件等",
5
5
  "main": "./nodejs/index.js",
6
6
  "typings": "./types/index.d.ts",
7
7
  "sideEffects": false,
8
- "scripts": {},
9
8
  "bin": {
10
9
  "oipage-cli": "bin/run"
11
10
  },
@@ -31,8 +30,5 @@
31
30
  "bugs": {
32
31
  "url": "https://github.com/oi-contrib/OIPage/issues"
33
32
  },
34
- "homepage": "https://github.com/oi-contrib/OIPage",
35
- "devDependencies": {
36
- "vislite": "^1.2.0"
37
- }
33
+ "homepage": "https://github.com/oi-contrib/OIPage"
38
34
  }