oipage 1.2.1 → 1.3.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.
@@ -1,84 +1,84 @@
1
- const { readdirSync, lstatSync, readFileSync, statSync } = require("fs");
2
- const { join } = require("path");
3
- const { formatByte, formatTime } = require("./format");
4
- const mineTypes = require("../data/mineTypes.json");
5
-
6
- const img_folder = "data:image/png;base64," + readFileSync(join(__dirname, "../images/folder.png")).toString('base64');
7
- const img_file = "data:image/png;base64," + readFileSync(join(__dirname, "../images/file.png")).toString('base64');
8
-
9
- const template_404 = readFileSync(join(__dirname, "../template/404.html"), {
10
- encoding: "utf8"
11
- })
12
- .replace("${img_folder}", img_folder)
13
- .replace("${img_file}", img_file);
14
-
15
- module.exports = function (filePath, url) {
16
-
17
- let subItems = [];
18
-
19
- try {
20
- subItems = readdirSync(filePath);
21
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read Folder: " + url + '\x1b[0m ' + new Date().toLocaleString());
22
- } catch (e) {
23
- console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read " + (/\/$/.test(url) ? "Folder" : "File") + ": \x1b[35m" + url + ' 404 Not Found\x1b[0m ' + new Date().toLocaleString());
24
- try {
25
- if (!/\/$/.test(url) || url === "/") {
26
- filePath = join(filePath, "../");
27
- subItems = readdirSync(filePath);
28
- }
29
- } catch (e) { }
30
- }
31
-
32
- let template = "";
33
- for (let i in subItems) {
34
- let isDirectory = lstatSync(join(filePath, subItems[i])).isDirectory();
35
- let statObj = statSync(join(filePath, subItems[i]));
36
-
37
- // 文件夹
38
- if (isDirectory) {
39
- template += `<tr class="folder">
40
- <th class="name">
41
- <a href='./${subItems[i]}/'>${subItems[i]}</a>
42
- </th>
43
- <th>
44
- ${formatTime(statObj.mtime)}
45
- </th>
46
- <th>
47
- 文件夹
48
- </th>
49
- <th>
50
- -
51
- </th>
52
- <th>
53
- <a href='./${subItems[i]}/' class="btn">打开</a>
54
- </th>
55
- </tr>`;
56
- }
57
-
58
- // 文件
59
- else {
60
- let dotName = /\./.test(subItems[i]) ? subItems[i].match(/\.([^.]+)$/)[1] : "";
61
-
62
- template += `<tr class="file">
63
- <th class="name">
64
- <a href='./${subItems[i]}'>${subItems[i]}</a>
65
- </th>
66
- <th>
67
- ${formatTime(statObj.mtime)}
68
- </th>
69
- <th>
70
- ${mineTypes[dotName] || "text/plain"}
71
- </th>
72
- <th>
73
- ${formatByte(statObj.size)}
74
- </th>
75
- <th>
76
- <a href='./${subItems[i]}' class="btn">访问</a>
77
- <a href='./${subItems[i]}?download' class="btn" download='${subItems[i]}'>下载</a>
78
- </th>
79
- </tr>`;
80
- }
81
- }
82
-
83
- return template_404.replace("${current}", filePath).replace("${template}", template);
1
+ const { readdirSync, lstatSync, readFileSync, statSync } = require("fs");
2
+ const { join } = require("path");
3
+ const { formatByte, formatTime } = require("./format");
4
+ const mineTypes = require("../data/mineTypes.json");
5
+
6
+ const img_folder = "data:image/png;base64," + readFileSync(join(__dirname, "../images/folder.png")).toString('base64');
7
+ const img_file = "data:image/png;base64," + readFileSync(join(__dirname, "../images/file.png")).toString('base64');
8
+
9
+ const template_404 = readFileSync(join(__dirname, "../template/404.html"), {
10
+ encoding: "utf8"
11
+ })
12
+ .replace("${img_folder}", img_folder)
13
+ .replace("${img_file}", img_file);
14
+
15
+ module.exports = function (filePath, url) {
16
+
17
+ let subItems = [];
18
+
19
+ try {
20
+ subItems = readdirSync(filePath);
21
+ console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read Folder: " + url + '\x1b[0m ' + new Date().toLocaleString());
22
+ } catch (e) {
23
+ console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] Read " + (/\/$/.test(url) ? "Folder" : "File") + ": \x1b[35m" + url + ' 404 Not Found\x1b[0m ' + new Date().toLocaleString());
24
+ try {
25
+ if (!/\/$/.test(url) || url === "/") {
26
+ filePath = join(filePath, "../");
27
+ subItems = readdirSync(filePath);
28
+ }
29
+ } catch (e) { }
30
+ }
31
+
32
+ let template = "";
33
+ for (let i in subItems) {
34
+ let isDirectory = lstatSync(join(filePath, subItems[i])).isDirectory();
35
+ let statObj = statSync(join(filePath, subItems[i]));
36
+
37
+ // 文件夹
38
+ if (isDirectory) {
39
+ template += `<tr class="folder">
40
+ <th class="name">
41
+ <a href='./${subItems[i]}/'>${subItems[i]}</a>
42
+ </th>
43
+ <th>
44
+ ${formatTime(statObj.mtime)}
45
+ </th>
46
+ <th>
47
+ 文件夹
48
+ </th>
49
+ <th>
50
+ -
51
+ </th>
52
+ <th>
53
+ <a href='./${subItems[i]}/' class="btn">打开</a>
54
+ </th>
55
+ </tr>`;
56
+ }
57
+
58
+ // 文件
59
+ else {
60
+ let dotName = /\./.test(subItems[i]) ? subItems[i].match(/\.([^.]+)$/)[1] : "";
61
+
62
+ template += `<tr class="file">
63
+ <th class="name">
64
+ <a href='./${subItems[i]}'>${subItems[i]}</a>
65
+ </th>
66
+ <th>
67
+ ${formatTime(statObj.mtime)}
68
+ </th>
69
+ <th>
70
+ ${mineTypes[dotName] || "text/plain"}
71
+ </th>
72
+ <th>
73
+ ${formatByte(statObj.size)}
74
+ </th>
75
+ <th>
76
+ <a href='./${subItems[i]}' class="btn">访问</a>
77
+ <a href='./${subItems[i]}?download' class="btn" download='${subItems[i]}'>下载</a>
78
+ </th>
79
+ </tr>`;
80
+ }
81
+ }
82
+
83
+ return template_404.replace("${current}", filePath).replace("${template}", template);
84
84
  };
@@ -2,6 +2,8 @@ const { readFileSync, existsSync, lstatSync } = require("fs");
2
2
  const { join } = require("path");
3
3
 
4
4
  module.exports = function (basePath, filePath, entry, isDownload) {
5
+ basePath = join(basePath, "./");
6
+
5
7
  let source = readFileSync(filePath);
6
8
  let resolveImport = content => content;
7
9
 
@@ -44,7 +46,7 @@ module.exports = function (basePath, filePath, entry, isDownload) {
44
46
  }
45
47
  }
46
48
 
47
- return npmName;
49
+ return "/@modules/" + npmName;
48
50
  } else {
49
51
  node_modulesRootPath = join(node_modulesRootPath, "../");
50
52
  prePath = "../" + prePath;
@@ -1,12 +1,12 @@
1
- interface animationFun {
2
- (deep: number): void
3
- }
4
-
5
- /**
6
- * 轮询动画,返回一个函数,调用该函数,可以提前结束动画
7
- */
8
- export interface animationType {
9
- (doback: animationFun, duration?: number, callback?: animationFun): Function
10
- }
11
-
1
+ interface animationFun {
2
+ (deep: number): void
3
+ }
4
+
5
+ /**
6
+ * 轮询动画,返回一个函数,调用该函数,可以提前结束动画
7
+ */
8
+ export interface animationType {
9
+ (doback: animationFun, duration?: number, callback?: animationFun): Function
10
+ }
11
+
12
12
  export let animation: animationType
@@ -1,110 +1,110 @@
1
1
  /*!
2
- * animation of OIPage v1.2.1
2
+ * animation of OIPage v1.3.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
6
- //当前正在运动的动画的tick函数堆栈
7
- var $timers = [];
8
- //唯一定时器的定时间隔
9
- var $interval = 13;
10
- //定时器ID
11
- var $timerId;
12
-
13
- /**
14
- * 动画轮播
15
- * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
16
- * @param {number} duration 动画时长,可选
17
- * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
18
- *
19
- * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
20
- */
21
- function animation(doback, duration, callback) {
22
- if (arguments.length < 2) duration = 400;
23
- if (arguments.length < 3) callback = function () { };
24
-
25
- var clock = {
26
- //把tick函数推入堆栈
27
- "timer": function (tick, duration, callback) {
28
- if (!tick) {
29
- throw new Error('Tick is required!');
30
- }
31
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
32
- $timers.push({
33
- "id": id,
34
- "createTime": new Date(),
35
- "tick": tick,
36
- "duration": duration,
37
- "callback": callback
38
- });
39
- clock.start();
40
- return id;
41
- },
42
-
43
- //开启唯一的定时器timerId
44
- "start": function () {
45
- if (!$timerId) {
46
- $timerId = setInterval(clock.tick, $interval);
47
- }
48
- },
49
-
50
- //被定时器调用,遍历timers堆栈
51
- "tick": function () {
52
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
53
-
54
- $timers = [];
55
- $timers.length = 0;
56
-
57
- for (flag = 0; flag < timers.length; flag++) {
58
- //初始化数据
59
- timer = timers[flag];
60
- createTime = timer.createTime;
61
- tick = timer.tick;
62
- duration = timer.duration;
63
- callback = timer.callback;
64
-
65
- //执行
66
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
67
- passTime = passTime > 1 ? 1 : passTime;
68
- tick(passTime);
69
- if (passTime < 1 && timer.id) {
70
- //动画没有结束再添加
71
- $timers.push(timer);
72
- } else {
73
- callback(passTime);
74
- }
75
- }
76
- if ($timers.length <= 0) {
77
- clock.stop();
78
- }
79
- },
80
-
81
- //停止定时器,重置timerId=null
82
- "stop": function () {
83
- if ($timerId) {
84
- clearInterval($timerId);
85
- $timerId = null;
86
- }
87
- }
88
- };
89
-
90
- var id = clock.timer(function (deep) {
91
- //其中deep为0-1,表示改变的程度
92
- doback(deep);
93
- }, duration, callback);
94
-
95
- return {
96
- // 一个函数
97
- // 用于在动画结束前结束动画
98
- stop: function () {
99
- var i;
100
- for (i in $timers) {
101
- if ($timers[i].id == id) {
102
- $timers[i].id = void 0;
103
- return;
104
- }
105
- }
106
- }
107
- };
108
-
6
+ //当前正在运动的动画的tick函数堆栈
7
+ var $timers = [];
8
+ //唯一定时器的定时间隔
9
+ var $interval = 13;
10
+ //定时器ID
11
+ var $timerId;
12
+
13
+ /**
14
+ * 动画轮播
15
+ * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
16
+ * @param {number} duration 动画时长,可选
17
+ * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
18
+ *
19
+ * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
20
+ */
21
+ function animation(doback, duration, callback) {
22
+ if (arguments.length < 2) duration = 400;
23
+ if (arguments.length < 3) callback = function () { };
24
+
25
+ var clock = {
26
+ //把tick函数推入堆栈
27
+ "timer": function (tick, duration, callback) {
28
+ if (!tick) {
29
+ throw new Error('Tick is required!');
30
+ }
31
+ var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
32
+ $timers.push({
33
+ "id": id,
34
+ "createTime": new Date(),
35
+ "tick": tick,
36
+ "duration": duration,
37
+ "callback": callback
38
+ });
39
+ clock.start();
40
+ return id;
41
+ },
42
+
43
+ //开启唯一的定时器timerId
44
+ "start": function () {
45
+ if (!$timerId) {
46
+ $timerId = setInterval(clock.tick, $interval);
47
+ }
48
+ },
49
+
50
+ //被定时器调用,遍历timers堆栈
51
+ "tick": function () {
52
+ var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
53
+
54
+ $timers = [];
55
+ $timers.length = 0;
56
+
57
+ for (flag = 0; flag < timers.length; flag++) {
58
+ //初始化数据
59
+ timer = timers[flag];
60
+ createTime = timer.createTime;
61
+ tick = timer.tick;
62
+ duration = timer.duration;
63
+ callback = timer.callback;
64
+
65
+ //执行
66
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
67
+ passTime = passTime > 1 ? 1 : passTime;
68
+ tick(passTime);
69
+ if (passTime < 1 && timer.id) {
70
+ //动画没有结束再添加
71
+ $timers.push(timer);
72
+ } else {
73
+ callback(passTime);
74
+ }
75
+ }
76
+ if ($timers.length <= 0) {
77
+ clock.stop();
78
+ }
79
+ },
80
+
81
+ //停止定时器,重置timerId=null
82
+ "stop": function () {
83
+ if ($timerId) {
84
+ clearInterval($timerId);
85
+ $timerId = null;
86
+ }
87
+ }
88
+ };
89
+
90
+ var id = clock.timer(function (deep) {
91
+ //其中deep为0-1,表示改变的程度
92
+ doback(deep);
93
+ }, duration, callback);
94
+
95
+ return {
96
+ // 一个函数
97
+ // 用于在动画结束前结束动画
98
+ stop: function () {
99
+ var i;
100
+ for (i in $timers) {
101
+ if ($timers[i].id == id) {
102
+ $timers[i].id = void 0;
103
+ return;
104
+ }
105
+ }
106
+ }
107
+ };
108
+
109
109
  }
110
110
  exports.animation = animation;
@@ -1,20 +1,20 @@
1
- /**
2
- * 单行打印
3
- * @param stream 打印的内容
4
- */
5
- export interface linelogType {
6
- (stream: string): void
7
- }
8
-
9
- export let linelog: linelogType
10
-
11
- /**
12
- * 进度打印
13
- * @param percentum 进度0-100
14
- * @param stream 说明文字,可选
15
- */
16
- export interface deeplogType {
17
- (percentum: number, stream?: string): void
18
- }
19
-
20
- export let deeplog: deeplogType
1
+ /**
2
+ * 单行打印
3
+ * @param stream 打印的内容
4
+ */
5
+ export interface linelogType {
6
+ (stream: string): void
7
+ }
8
+
9
+ export let linelog: linelogType
10
+
11
+ /**
12
+ * 进度打印
13
+ * @param percentum 进度0-100
14
+ * @param stream 说明文字,可选
15
+ */
16
+ export interface deeplogType {
17
+ (percentum: number, stream?: string): void
18
+ }
19
+
20
+ export let deeplog: deeplogType
@@ -1,82 +1,82 @@
1
1
  /*!
2
- * cmdlog of OIPage v1.2.1
2
+ * cmdlog of OIPage v1.3.0-alpha.1
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
6
- // 预定义的常量
7
- const MOVE_LEFT = Buffer.from('1b5b3130303044', 'hex').toString();
8
- const MOVE_UP = Buffer.from('1b5b3141', 'hex').toString();
9
- const CLEAR_LINE = Buffer.from('1b5b304b', 'hex').toString();
10
-
11
- // 计算字符串长度的方法
12
- const stringwidth = function (str) {
13
- return str.length;
14
- };
15
-
16
- /**
17
- * 不换行打印
18
- * @param {string} stream 打印的内容
19
- */
20
- let linelog = (function (stream) {
21
-
22
- // 用来记录前置有多少行需要回退
23
- let prevLineCount = 0;
24
-
25
- // 返回实际同行打印的方法
26
- return function (nextStr) {
27
- if (arguments.length == 0) {
28
- prevLineCount = 0;
29
- return;
30
- }
31
- let txt = "";
32
-
33
- // 清除屏幕
34
- for (let i = 0; i < prevLineCount; i++) {
35
- txt += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount - 1 ? MOVE_UP : '');
36
- }
37
-
38
- // 写入屏幕
39
- stream.write(txt + nextStr);
40
-
41
- // 重新计算需要回滚多少行
42
- let prevLines = nextStr.split('\n');
43
- prevLineCount = 0;
44
- for (let i = 0; i < prevLines.length; i++) {
45
- // 因为有时候文字过多,因此拿总长度除以一行长度得出真实的行数
46
- prevLineCount += (Math.ceil(stringwidth(prevLines[i]) / stream.columns) || 1);
47
- }
48
-
49
- };
50
- })(process.stdout);
51
-
52
- /**
53
- * 进度打印
54
- *
55
- * @param {number} percentum 进度0-100
56
- * @param {string} stream 说明文字,可选
57
- */
58
- function deeplog (percentum, stream) {
59
- if (arguments.length == 0) {
60
- linelog();
61
- return;
62
- }
63
-
64
- if (arguments.length <= 1) stream = "";
65
-
66
- let txt = "",
67
- i = 0;
68
-
69
- // 补充已经有的进度
70
- for (; i <= percentum && i <= 100; i += 5) {
71
- txt += "█";
72
- }
73
-
74
- // 补充余下的空白
75
- for (; i <= 100; i += 5) {
76
- txt += "░";
77
- }
78
-
79
- linelog(percentum.toFixed(2) + "%[" + txt + "]" + stream);
6
+ // 预定义的常量
7
+ const MOVE_LEFT = Buffer.from('1b5b3130303044', 'hex').toString();
8
+ const MOVE_UP = Buffer.from('1b5b3141', 'hex').toString();
9
+ const CLEAR_LINE = Buffer.from('1b5b304b', 'hex').toString();
10
+
11
+ // 计算字符串长度的方法
12
+ const stringwidth = function (str) {
13
+ return str.length;
14
+ };
15
+
16
+ /**
17
+ * 不换行打印
18
+ * @param {string} stream 打印的内容
19
+ */
20
+ let linelog = (function (stream) {
21
+
22
+ // 用来记录前置有多少行需要回退
23
+ let prevLineCount = 0;
24
+
25
+ // 返回实际同行打印的方法
26
+ return function (nextStr) {
27
+ if (arguments.length == 0) {
28
+ prevLineCount = 0;
29
+ return;
30
+ }
31
+ let txt = "";
32
+
33
+ // 清除屏幕
34
+ for (let i = 0; i < prevLineCount; i++) {
35
+ txt += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount - 1 ? MOVE_UP : '');
36
+ }
37
+
38
+ // 写入屏幕
39
+ stream.write(txt + nextStr);
40
+
41
+ // 重新计算需要回滚多少行
42
+ let prevLines = nextStr.split('\n');
43
+ prevLineCount = 0;
44
+ for (let i = 0; i < prevLines.length; i++) {
45
+ // 因为有时候文字过多,因此拿总长度除以一行长度得出真实的行数
46
+ prevLineCount += (Math.ceil(stringwidth(prevLines[i]) / stream.columns) || 1);
47
+ }
48
+
49
+ };
50
+ })(process.stdout);
51
+
52
+ /**
53
+ * 进度打印
54
+ *
55
+ * @param {number} percentum 进度0-100
56
+ * @param {string} stream 说明文字,可选
57
+ */
58
+ function deeplog (percentum, stream) {
59
+ if (arguments.length == 0) {
60
+ linelog();
61
+ return;
62
+ }
63
+
64
+ if (arguments.length <= 1) stream = "";
65
+
66
+ let txt = "",
67
+ i = 0;
68
+
69
+ // 补充已经有的进度
70
+ for (; i <= percentum && i <= 100; i += 5) {
71
+ txt += "█";
72
+ }
73
+
74
+ // 补充余下的空白
75
+ for (; i <= 100; i += 5) {
76
+ txt += "░";
77
+ }
78
+
79
+ linelog(percentum.toFixed(2) + "%[" + txt + "]" + stream);
80
80
  }
81
81
  exports.linelog = linelog;
82
82
  exports.deeplog = deeplog;
@@ -1,17 +1,17 @@
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, isForce?: boolean): void
15
- }
16
-
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, isForce?: boolean): void
15
+ }
16
+
17
17
  export let copyDisk: copyDiskType