mm_expand 2.0.0 → 2.0.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/lib/base.js +27 -10
- package/lib/eventer.js +1 -1
- package/lib/file.js +22 -13
- package/lib/logger.js +12 -12
- package/package.json +1 -1
package/lib/base.js
CHANGED
|
@@ -8,6 +8,17 @@ require('./global');
|
|
|
8
8
|
* 基础类
|
|
9
9
|
*/
|
|
10
10
|
class Base extends Event {
|
|
11
|
+
static config = {
|
|
12
|
+
// 模块名称
|
|
13
|
+
name: '',
|
|
14
|
+
// 模块标题
|
|
15
|
+
title: '',
|
|
16
|
+
// 模块描述
|
|
17
|
+
description: '',
|
|
18
|
+
// 状态, 可选值: 1-启用, 0-禁用
|
|
19
|
+
state: 1
|
|
20
|
+
};
|
|
21
|
+
|
|
11
22
|
/**
|
|
12
23
|
* 构造函数
|
|
13
24
|
* @param {object} config 配置参数
|
|
@@ -18,16 +29,7 @@ class Base extends Event {
|
|
|
18
29
|
* 配置参数
|
|
19
30
|
* @type {object}
|
|
20
31
|
*/
|
|
21
|
-
this.config = {
|
|
22
|
-
// 模块名称
|
|
23
|
-
name: '',
|
|
24
|
-
// 模块标题
|
|
25
|
-
title: '',
|
|
26
|
-
// 模块描述
|
|
27
|
-
description: '',
|
|
28
|
-
// 状态, 可选值: 1-启用, 0-禁用
|
|
29
|
-
state: 1
|
|
30
|
-
};
|
|
32
|
+
this.config = {...this.constructor.config};
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* 状态
|
|
@@ -42,6 +44,16 @@ class Base extends Event {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 日志输出
|
|
49
|
+
* @param {string} level 日志级别
|
|
50
|
+
* @param {string} message 日志消息
|
|
51
|
+
* @param {...any} args 日志参数
|
|
52
|
+
*/
|
|
53
|
+
Base.prototype.log = function (level, message, ...args) {
|
|
54
|
+
this._logger[level](`[${this.constructor.name}] [${this.config.name}] ${message}`, ...args);
|
|
55
|
+
};
|
|
56
|
+
|
|
45
57
|
/**
|
|
46
58
|
* 初始化监听
|
|
47
59
|
*/
|
|
@@ -222,6 +234,11 @@ Base.prototype._doExecuteMethod = async function (method, ctx) {
|
|
|
222
234
|
}
|
|
223
235
|
};
|
|
224
236
|
|
|
237
|
+
/**
|
|
238
|
+
* 检查阶段
|
|
239
|
+
* @param {string} method 方法名称
|
|
240
|
+
* @param {object} ctx 上下文对象
|
|
241
|
+
*/
|
|
225
242
|
Base.prototype._doCheckPhase = async function (method, ctx) {
|
|
226
243
|
let check_result;
|
|
227
244
|
try {
|
package/lib/eventer.js
CHANGED
package/lib/file.js
CHANGED
|
@@ -26,7 +26,7 @@ require('./global.js');
|
|
|
26
26
|
/**
|
|
27
27
|
* @description 判断是否文件
|
|
28
28
|
* @param {string} fileOrDir 文件或目录
|
|
29
|
-
* @param file_or_dir
|
|
29
|
+
* @param file_or_dir
|
|
30
30
|
* @returns {boolean} 是文件返回true,否则返回false
|
|
31
31
|
*/
|
|
32
32
|
function isFile(file_or_dir) {
|
|
@@ -92,11 +92,11 @@ function validateFilePath(file) {
|
|
|
92
92
|
return null;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
97
|
-
* @param file
|
|
98
|
-
* @param dir
|
|
99
|
-
*/
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param file
|
|
98
|
+
* @param dir
|
|
99
|
+
*/
|
|
100
100
|
function fullname(file, dir) {
|
|
101
101
|
var validation_result = validateFilePath(file);
|
|
102
102
|
if (validation_result) {
|
|
@@ -278,7 +278,7 @@ File.prototype.copy = function (source, target) {
|
|
|
278
278
|
* @param {string} file 文件路径
|
|
279
279
|
* @returns {boolean} 删除成功返回true,否则返回false
|
|
280
280
|
*/
|
|
281
|
-
File.prototype.
|
|
281
|
+
File.prototype.del = function (file) {
|
|
282
282
|
if (!file || typeof file !== 'string') {
|
|
283
283
|
throw new Error('file参数必须是非空字符串');
|
|
284
284
|
}
|
|
@@ -404,9 +404,9 @@ function getFile(list, dir, keyword) {
|
|
|
404
404
|
* 目录类函数
|
|
405
405
|
*/
|
|
406
406
|
class Dir {
|
|
407
|
-
/**
|
|
408
|
-
*
|
|
409
|
-
*/
|
|
407
|
+
/**
|
|
408
|
+
*
|
|
409
|
+
*/
|
|
410
410
|
constructor() {
|
|
411
411
|
// 构造函数,仅用于初始化
|
|
412
412
|
}
|
|
@@ -416,7 +416,7 @@ class Dir {
|
|
|
416
416
|
* 补全目录路径
|
|
417
417
|
* @param {string} dir 目录路径
|
|
418
418
|
* @param {string} baseDir 基础目录
|
|
419
|
-
* @param base_dir
|
|
419
|
+
* @param base_dir
|
|
420
420
|
* @returns {string} 完整路径
|
|
421
421
|
*/
|
|
422
422
|
Dir.prototype.fullname = function (dir, base_dir) {
|
|
@@ -467,6 +467,15 @@ Dir.prototype.del = function (dir, func) {
|
|
|
467
467
|
rimrafSync(dir.fullname(), func);
|
|
468
468
|
};
|
|
469
469
|
|
|
470
|
+
/**
|
|
471
|
+
* @description 判断目录是否存在
|
|
472
|
+
* @param {string} dir 目录路径
|
|
473
|
+
* @returns {boolean} 存在返回true, 否则返回false
|
|
474
|
+
*/
|
|
475
|
+
Dir.prototype.exists = function (dir) {
|
|
476
|
+
return existsSync(dir.fullname());
|
|
477
|
+
};
|
|
478
|
+
|
|
470
479
|
/** === 文件类函数 === */
|
|
471
480
|
/**
|
|
472
481
|
* @description 补全路径
|
|
@@ -507,7 +516,7 @@ String.prototype.copyFile = function (file) {
|
|
|
507
516
|
/**
|
|
508
517
|
* @description 复制目录
|
|
509
518
|
* @param {string} file 保存路径
|
|
510
|
-
* @param func
|
|
519
|
+
* @param func
|
|
511
520
|
* @returns {boolean} 复制成功返回true, 失败返回false
|
|
512
521
|
*/
|
|
513
522
|
String.prototype.copyDir = function (file, func) {
|
|
@@ -697,7 +706,7 @@ String.prototype.delDir = function (dir, func) {
|
|
|
697
706
|
/**
|
|
698
707
|
* @创建路径
|
|
699
708
|
* @param {string} dir 文件路径
|
|
700
|
-
* @param dirbase
|
|
709
|
+
* @param dirbase
|
|
701
710
|
*/
|
|
702
711
|
String.prototype.addDir = function (dirbase) {
|
|
703
712
|
var d = (this + '').fullname(dirbase);
|
package/lib/logger.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const { Event } = require('./event.js');
|
|
2
2
|
require('colors');
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
if (!console.debug) {
|
|
5
|
+
console.debug = console.log;
|
|
6
|
+
}
|
|
7
|
+
if (!console.success) {
|
|
8
|
+
console.success = console.info;
|
|
9
|
+
}
|
|
10
|
+
if (!console.fatal) {
|
|
11
|
+
console.fatal = console.error;
|
|
12
|
+
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* 日志类
|
|
@@ -26,9 +26,9 @@ class Logger extends Event {
|
|
|
26
26
|
*/
|
|
27
27
|
this.is_plugin = false;
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
* 日志对象
|
|
30
|
+
* @type {object} - 日志对象, 默认值: console
|
|
31
|
+
*/
|
|
32
32
|
this._logger = console;
|
|
33
33
|
}
|
|
34
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Super Meimei Prototype Function Extension Module - Enhanced operations for string, array, object, date manipulation with error prevention and simplified business logic.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|