@aiot-toolkit/shared-utils 2.0.5-widget-provider-beta.2 → 2.0.5
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/README.md +11 -11
- package/lib/ColorConsole.js +33 -33
- package/lib/data/PositionError.js +2 -2
- package/lib/enum/ProjectType.js +2 -2
- package/lib/interface/ILog.js +2 -2
- package/lib/utils/CommonUtil.js +29 -29
- package/lib/utils/FileUtil.js +59 -59
- package/lib/utils/NetworkUtil.js +22 -22
- package/lib/utils/QuickAppDocHelp.js +2 -2
- package/lib/utils/StringUtil.js +18 -18
- package/lib/utils/WrapCallback.js +6 -6
- package/lib/utils/ZipFileUtil.js +7 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# `shared-utils`
|
|
2
|
-
|
|
3
|
-
> TODO: description
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
const sharedUtils = require('shared-utils');
|
|
9
|
-
|
|
10
|
-
// TODO: DEMONSTRATE API
|
|
11
|
-
```
|
|
1
|
+
# `shared-utils`
|
|
2
|
+
|
|
3
|
+
> TODO: description
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
const sharedUtils = require('shared-utils');
|
|
9
|
+
|
|
10
|
+
// TODO: DEMONSTRATE API
|
|
11
|
+
```
|
package/lib/ColorConsole.js
CHANGED
|
@@ -8,8 +8,8 @@ var _chalk = _interopRequireDefault(require("chalk"));
|
|
|
8
8
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
9
|
var _ILog = require("./interface/ILog");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
/**
|
|
12
|
-
* Log
|
|
11
|
+
/**
|
|
12
|
+
* Log
|
|
13
13
|
*/
|
|
14
14
|
class ColorConsole {
|
|
15
15
|
static defaultStyle = {
|
|
@@ -79,15 +79,15 @@ class ColorConsole {
|
|
|
79
79
|
return ColorConsole._log(_ILog.Loglevel.WARN, ...message);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/**
|
|
83
|
-
* 创建复杂格式的消息,可单独设置词语样式
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```js
|
|
87
|
-
* createMessage("my name is", {message:'****', style:{ color:'red' }})
|
|
88
|
-
* ```
|
|
89
|
-
* @param words
|
|
90
|
-
* @returns
|
|
82
|
+
/**
|
|
83
|
+
* 创建复杂格式的消息,可单独设置词语样式
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```js
|
|
87
|
+
* createMessage("my name is", {message:'****', style:{ color:'red' }})
|
|
88
|
+
* ```
|
|
89
|
+
* @param words
|
|
90
|
+
* @returns
|
|
91
91
|
*/
|
|
92
92
|
static createMessage(words) {
|
|
93
93
|
const list = Array.isArray(words) ? words : [words];
|
|
@@ -147,26 +147,26 @@ class ColorConsole {
|
|
|
147
147
|
return result;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/**
|
|
151
|
-
* 按照日志类型打印不同颜色的日志
|
|
152
|
-
* @param log 默认日志类型为info
|
|
153
|
-
* @returns 返回打印的日志信息
|
|
150
|
+
/**
|
|
151
|
+
* 按照日志类型打印不同颜色的日志
|
|
152
|
+
* @param log 默认日志类型为info
|
|
153
|
+
* @returns 返回打印的日志信息
|
|
154
154
|
*/
|
|
155
155
|
static logger(log) {
|
|
156
156
|
const str = ColorConsole.logToString(log);
|
|
157
157
|
console.log(str);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
/**
|
|
161
|
-
* 日志转换为带颜色的字符串
|
|
162
|
-
*
|
|
163
|
-
* @param log 日志对象
|
|
164
|
-
* @param prefix 前缀列表
|
|
165
|
-
* false-不使用前缀
|
|
166
|
-
* string[]-自定义前缀
|
|
167
|
-
* 默认-[图标、时间、toolkit字样]
|
|
168
|
-
*
|
|
169
|
-
* @example logToString(log, ['myPrefix'])
|
|
160
|
+
/**
|
|
161
|
+
* 日志转换为带颜色的字符串
|
|
162
|
+
*
|
|
163
|
+
* @param log 日志对象
|
|
164
|
+
* @param prefix 前缀列表
|
|
165
|
+
* false-不使用前缀
|
|
166
|
+
* string[]-自定义前缀
|
|
167
|
+
* 默认-[图标、时间、toolkit字样]
|
|
168
|
+
*
|
|
169
|
+
* @example logToString(log, ['myPrefix'])
|
|
170
170
|
*/
|
|
171
171
|
static logToString(log, prefix) {
|
|
172
172
|
const {
|
|
@@ -212,14 +212,14 @@ class ColorConsole {
|
|
|
212
212
|
}));
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
/**
|
|
216
|
-
* 创建默认消息前缀列表
|
|
217
|
-
*
|
|
218
|
-
* 1. 图标
|
|
219
|
-
* 2. 时间
|
|
220
|
-
* 3. toolkit 字样
|
|
221
|
-
*
|
|
222
|
-
* @param log
|
|
215
|
+
/**
|
|
216
|
+
* 创建默认消息前缀列表
|
|
217
|
+
*
|
|
218
|
+
* 1. 图标
|
|
219
|
+
* 2. 时间
|
|
220
|
+
* 3. toolkit 字样
|
|
221
|
+
*
|
|
222
|
+
* @param log
|
|
223
223
|
*/
|
|
224
224
|
static createDefaultPrefix(log) {
|
|
225
225
|
const {
|
package/lib/enum/ProjectType.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
/**
|
|
11
|
-
* 项目类型
|
|
10
|
+
/**
|
|
11
|
+
* 项目类型
|
|
12
12
|
*/
|
|
13
13
|
var ProjectType = /*#__PURE__*/function (ProjectType) {
|
|
14
14
|
ProjectType["VELA_UX"] = "velaUx";
|
package/lib/interface/ILog.js
CHANGED
package/lib/utils/CommonUtil.js
CHANGED
|
@@ -12,16 +12,16 @@ var _qrcode = _interopRequireDefault(require("qrcode"));
|
|
|
12
12
|
var _ColorConsole = _interopRequireDefault(require("../ColorConsole"));
|
|
13
13
|
var _ILog = require("../interface/ILog");
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
/**
|
|
16
|
-
* 不好分类的工具函数
|
|
15
|
+
/**
|
|
16
|
+
* 不好分类的工具函数
|
|
17
17
|
*/
|
|
18
18
|
class CommonUtil {
|
|
19
|
-
/**
|
|
20
|
-
* 根据 buffer 生成 hash 值
|
|
21
|
-
*
|
|
22
|
-
* 用于唯一标识流内容,通常用于文件校验
|
|
23
|
-
* @param buffer
|
|
24
|
-
* @returns hash 值
|
|
19
|
+
/**
|
|
20
|
+
* 根据 buffer 生成 hash 值
|
|
21
|
+
*
|
|
22
|
+
* 用于唯一标识流内容,通常用于文件校验
|
|
23
|
+
* @param buffer
|
|
24
|
+
* @returns hash 值
|
|
25
25
|
*/
|
|
26
26
|
static calcDataDigest(buffer) {
|
|
27
27
|
const hash = _crypto.default.createHash('SHA256');
|
|
@@ -34,10 +34,10 @@ class CommonUtil {
|
|
|
34
34
|
return hash.digest('hex').substring(0, 8);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* 从开发者项目的 node_module 中加载指定依赖;
|
|
39
|
-
* 如果不存在,提示下载;存在则返回加载的依赖
|
|
40
|
-
* @param packageName
|
|
37
|
+
/**
|
|
38
|
+
* 从开发者项目的 node_module 中加载指定依赖;
|
|
39
|
+
* 如果不存在,提示下载;存在则返回加载的依赖
|
|
40
|
+
* @param packageName
|
|
41
41
|
*/
|
|
42
42
|
static requireNodeModule(projectPath, packageName) {
|
|
43
43
|
const modulePath = _path.default.resolve(projectPath, `./node_modules/${packageName}`);
|
|
@@ -70,23 +70,23 @@ class CommonUtil {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/**
|
|
74
|
-
* 验证 json 内容
|
|
75
|
-
* @param json json 内容
|
|
76
|
-
* @param schema 验证配置, 详见:https://github.com/ajv-validator/ajv
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```
|
|
81
|
-
* CommonUtil.validateJson({a:123},
|
|
82
|
-
* {
|
|
83
|
-
* a:{
|
|
84
|
-
* type:'number'
|
|
85
|
-
* }
|
|
86
|
-
* }
|
|
87
|
-
* )
|
|
88
|
-
* ```
|
|
89
|
-
* @returns
|
|
73
|
+
/**
|
|
74
|
+
* 验证 json 内容
|
|
75
|
+
* @param json json 内容
|
|
76
|
+
* @param schema 验证配置, 详见:https://github.com/ajv-validator/ajv
|
|
77
|
+
*
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```
|
|
81
|
+
* CommonUtil.validateJson({a:123},
|
|
82
|
+
* {
|
|
83
|
+
* a:{
|
|
84
|
+
* type:'number'
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* )
|
|
88
|
+
* ```
|
|
89
|
+
* @returns
|
|
90
90
|
*/
|
|
91
91
|
static validateJson(json, schema) {
|
|
92
92
|
if (!json || !schema) {
|
package/lib/utils/FileUtil.js
CHANGED
|
@@ -10,20 +10,20 @@ var _rimraf = require("rimraf");
|
|
|
10
10
|
var _fswin = _interopRequireDefault(require("fswin"));
|
|
11
11
|
var _minimatch = require("minimatch");
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
/**
|
|
14
|
-
* FileUtil
|
|
13
|
+
/**
|
|
14
|
+
* FileUtil
|
|
15
15
|
*/
|
|
16
16
|
class FileUtil {
|
|
17
|
-
/**
|
|
18
|
-
* 判断字符串是否符合包含、不包含的条件
|
|
19
|
-
*
|
|
20
|
-
* 规则为:
|
|
21
|
-
* 1. 如果设置了不包含且匹配,则不包含
|
|
22
|
-
* 2. 否则,如果设置了包含且不匹配,则不包含
|
|
23
|
-
* 3. 否则,包含
|
|
24
|
-
* @param value
|
|
25
|
-
* @param include
|
|
26
|
-
* @param exclude
|
|
17
|
+
/**
|
|
18
|
+
* 判断字符串是否符合包含、不包含的条件
|
|
19
|
+
*
|
|
20
|
+
* 规则为:
|
|
21
|
+
* 1. 如果设置了不包含且匹配,则不包含
|
|
22
|
+
* 2. 否则,如果设置了包含且不匹配,则不包含
|
|
23
|
+
* 3. 否则,包含
|
|
24
|
+
* @param value
|
|
25
|
+
* @param include
|
|
26
|
+
* @param exclude
|
|
27
27
|
*/
|
|
28
28
|
static include(path, include, exclude) {
|
|
29
29
|
if (exclude && this.match(path, exclude)) {
|
|
@@ -34,11 +34,11 @@ class FileUtil {
|
|
|
34
34
|
}
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* 判断字符串是否匹配指定规则
|
|
39
|
-
* @param value
|
|
40
|
-
* @param matchType
|
|
41
|
-
* @returns
|
|
37
|
+
/**
|
|
38
|
+
* 判断字符串是否匹配指定规则
|
|
39
|
+
* @param value
|
|
40
|
+
* @param matchType
|
|
41
|
+
* @returns
|
|
42
42
|
*/
|
|
43
43
|
static match(value, matchType) {
|
|
44
44
|
switch (typeof matchType) {
|
|
@@ -63,10 +63,10 @@ class FileUtil {
|
|
|
63
63
|
return false;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
67
|
-
* 获取指定目录所有层级的文件
|
|
68
|
-
* @param dir
|
|
69
|
-
* @returns
|
|
66
|
+
/**
|
|
67
|
+
* 获取指定目录所有层级的文件
|
|
68
|
+
* @param dir
|
|
69
|
+
* @returns
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
static readAlldirSync(dir, includes, excludes) {
|
|
@@ -91,12 +91,12 @@ class FileUtil {
|
|
|
91
91
|
return result;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/**
|
|
95
|
-
* 替换文件内容
|
|
96
|
-
*
|
|
97
|
-
* @see replaceKeywords
|
|
98
|
-
* @param filePath
|
|
99
|
-
* @param keywordDic
|
|
94
|
+
/**
|
|
95
|
+
* 替换文件内容
|
|
96
|
+
*
|
|
97
|
+
* @see replaceKeywords
|
|
98
|
+
* @param filePath
|
|
99
|
+
* @param keywordDic
|
|
100
100
|
*/
|
|
101
101
|
static replaceFileContent(filePath, keywordDic) {
|
|
102
102
|
let content = _fsExtra.default.readFileSync(filePath, 'utf-8');
|
|
@@ -104,16 +104,16 @@ class FileUtil {
|
|
|
104
104
|
_fsExtra.default.writeFileSync(filePath, content);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
/**
|
|
108
|
-
* 替换字符串内容
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* // 替换 abc{{value}} 为 abc123
|
|
112
|
-
* replaceKeywords(`abc{{value}}`, {value: '123'})
|
|
113
|
-
*
|
|
114
|
-
* @param content
|
|
115
|
-
* @param keywordDic
|
|
116
|
-
* @returns
|
|
107
|
+
/**
|
|
108
|
+
* 替换字符串内容
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // 替换 abc{{value}} 为 abc123
|
|
112
|
+
* replaceKeywords(`abc{{value}}`, {value: '123'})
|
|
113
|
+
*
|
|
114
|
+
* @param content
|
|
115
|
+
* @param keywordDic
|
|
116
|
+
* @returns
|
|
117
117
|
*/
|
|
118
118
|
static replaceKeywords(content, keywordDic) {
|
|
119
119
|
return content.replace(/{{(.*?)}}/gm, (origin, key) => {
|
|
@@ -121,23 +121,23 @@ class FileUtil {
|
|
|
121
121
|
return keywordDic[key] !== undefined ? keywordDic[key] : origin;
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
|
-
/**
|
|
125
|
-
* 更新文件路径
|
|
126
|
-
* @param filePath
|
|
127
|
-
* @param newFileName
|
|
128
|
-
* @returns
|
|
129
|
-
* @example updateFileName('./a/b/c.ux', 'd.js') 转换结果为'./a/b/d.js'
|
|
124
|
+
/**
|
|
125
|
+
* 更新文件路径
|
|
126
|
+
* @param filePath
|
|
127
|
+
* @param newFileName
|
|
128
|
+
* @returns
|
|
129
|
+
* @example updateFileName('./a/b/c.ux', 'd.js') 转换结果为'./a/b/d.js'
|
|
130
130
|
*/
|
|
131
131
|
static updateFileName(filePath, newFileName) {
|
|
132
132
|
return filePath && newFileName ? _path.default.join(_path.default.dirname(filePath), newFileName) : '';
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
/**
|
|
136
|
-
* 复制文件
|
|
137
|
-
* @param sourceDir 源目录
|
|
138
|
-
* @param targetDir 目标目录
|
|
139
|
-
* @param excludes 不包含的文件
|
|
140
|
-
* @param includes 包含的文件
|
|
135
|
+
/**
|
|
136
|
+
* 复制文件
|
|
137
|
+
* @param sourceDir 源目录
|
|
138
|
+
* @param targetDir 目标目录
|
|
139
|
+
* @param excludes 不包含的文件
|
|
140
|
+
* @param includes 包含的文件
|
|
141
141
|
*/
|
|
142
142
|
static copyFiles(sourceDir, targetDir, excludes, includes) {
|
|
143
143
|
const files = FileUtil.readAlldirSync(sourceDir, includes, excludes);
|
|
@@ -148,9 +148,9 @@ class FileUtil {
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
/**
|
|
152
|
-
* 检查指定的文件列表是否全部存在
|
|
153
|
-
* @param fileList 文件列表
|
|
151
|
+
/**
|
|
152
|
+
* 检查指定的文件列表是否全部存在
|
|
153
|
+
* @param fileList 文件列表
|
|
154
154
|
*/
|
|
155
155
|
static checkFilePath(fileList) {
|
|
156
156
|
return fileList?.every(filePath => _fsExtra.default.existsSync(filePath));
|
|
@@ -162,13 +162,13 @@ class FileUtil {
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
/**
|
|
166
|
-
* 创建目录
|
|
167
|
-
*
|
|
168
|
-
* *支持 windows 系统创建隐藏目录
|
|
169
|
-
* @param path
|
|
170
|
-
* @param options
|
|
171
|
-
* @returns
|
|
165
|
+
/**
|
|
166
|
+
* 创建目录
|
|
167
|
+
*
|
|
168
|
+
* *支持 windows 系统创建隐藏目录
|
|
169
|
+
* @param path
|
|
170
|
+
* @param options
|
|
171
|
+
* @returns
|
|
172
172
|
*/
|
|
173
173
|
static mkdirSync(path, options) {
|
|
174
174
|
const result = _fsExtra.default.mkdirSync(path, options);
|
package/lib/utils/NetworkUtil.js
CHANGED
|
@@ -13,16 +13,16 @@ var _os = _interopRequireDefault(require("os"));
|
|
|
13
13
|
var _portfinder = _interopRequireDefault(require("portfinder"));
|
|
14
14
|
var _simpleGit = _interopRequireDefault(require("simple-git"));
|
|
15
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
/**
|
|
17
|
-
* NetworkUtil
|
|
16
|
+
/**
|
|
17
|
+
* NetworkUtil
|
|
18
18
|
*/
|
|
19
19
|
class NetworkUtil {
|
|
20
|
-
/**
|
|
21
|
-
* clone git 项目
|
|
22
|
-
* @param url
|
|
23
|
-
* @param localPath
|
|
24
|
-
* @param showProgress 是否显示进度条,默认为 true,会在命令行工具中显示绿色进度条
|
|
25
|
-
* @returns
|
|
20
|
+
/**
|
|
21
|
+
* clone git 项目
|
|
22
|
+
* @param url
|
|
23
|
+
* @param localPath
|
|
24
|
+
* @param showProgress 是否显示进度条,默认为 true,会在命令行工具中显示绿色进度条
|
|
25
|
+
* @returns
|
|
26
26
|
*/
|
|
27
27
|
static gitClone(url, localPath) {
|
|
28
28
|
let showProgress = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
@@ -53,10 +53,10 @@ class NetworkUtil {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* 创建 http 服务器
|
|
58
|
-
* @param data
|
|
59
|
-
* @returns
|
|
56
|
+
/**
|
|
57
|
+
* 创建 http 服务器
|
|
58
|
+
* @param data
|
|
59
|
+
* @returns
|
|
60
60
|
*/
|
|
61
61
|
static async createHttpServer(data) {
|
|
62
62
|
const {
|
|
@@ -113,10 +113,10 @@ class NetworkUtil {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
/**
|
|
117
|
-
* 从请求中获取客户端 ip
|
|
118
|
-
* @param ctx koa的请求上下文
|
|
119
|
-
* @returns
|
|
116
|
+
/**
|
|
117
|
+
* 从请求中获取客户端 ip
|
|
118
|
+
* @param ctx koa的请求上下文
|
|
119
|
+
* @returns
|
|
120
120
|
*/
|
|
121
121
|
static getClientIp(ctx) {
|
|
122
122
|
const request = ctx.request;
|
|
@@ -126,12 +126,12 @@ class NetworkUtil {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
/**
|
|
130
|
-
* 从网络地址中获取真实 ip
|
|
131
|
-
*
|
|
132
|
-
* @example
|
|
133
|
-
* @param ip
|
|
134
|
-
* @returns
|
|
129
|
+
/**
|
|
130
|
+
* 从网络地址中获取真实 ip
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* @param ip
|
|
134
|
+
* @returns
|
|
135
135
|
*/
|
|
136
136
|
static stripPrefixForIPV4MappedIPV6Address(ip) {
|
|
137
137
|
if (/^::1$/.test(ip)) {
|
|
@@ -7,8 +7,8 @@ exports.VelaAppDocHelp = exports.QuickAppDocWidgetType = exports.QuickAppDocHelp
|
|
|
7
7
|
var _ColorConsole = _interopRequireDefault(require("../ColorConsole"));
|
|
8
8
|
var _ILog = require("../interface/ILog");
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
/**
|
|
11
|
-
* 文档帮助
|
|
10
|
+
/**
|
|
11
|
+
* 文档帮助
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
class QuickAppDocHelper {
|
package/lib/utils/StringUtil.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* StringUtil
|
|
7
|
+
/**
|
|
8
|
+
* StringUtil
|
|
9
9
|
*/
|
|
10
10
|
class StringUtil {
|
|
11
11
|
/** 使用正则表达式去除开头和结尾的 ' " ` */
|
|
@@ -13,12 +13,12 @@ class StringUtil {
|
|
|
13
13
|
return str.replace(/^['"`]+|['"`]+$/g, '');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* 中划线文本转为驼峰
|
|
18
|
-
*
|
|
19
|
-
* aaa-bbb 转换为 aaaBbb
|
|
20
|
-
* @param value
|
|
21
|
-
* @returns
|
|
16
|
+
/**
|
|
17
|
+
* 中划线文本转为驼峰
|
|
18
|
+
*
|
|
19
|
+
* aaa-bbb 转换为 aaaBbb
|
|
20
|
+
* @param value
|
|
21
|
+
* @returns
|
|
22
22
|
*/
|
|
23
23
|
static hyphenedToCamel(value) {
|
|
24
24
|
return value?.replace(/-([a-z])/g, (_, match) => match.toUpperCase());
|
|
@@ -35,11 +35,11 @@ class StringUtil {
|
|
|
35
35
|
if (!value) return [];
|
|
36
36
|
return value.replace(' ', '').split(',');
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* 数组转字符串
|
|
40
|
-
* @param arr
|
|
41
|
-
* @param styleTransform 是否为style解析树的数组转换
|
|
42
|
-
* @returns
|
|
38
|
+
/**
|
|
39
|
+
* 数组转字符串
|
|
40
|
+
* @param arr
|
|
41
|
+
* @param styleTransform 是否为style解析树的数组转换
|
|
42
|
+
* @returns
|
|
43
43
|
*/
|
|
44
44
|
static arrayToString(arr) {
|
|
45
45
|
if (Array.isArray(arr)) {
|
|
@@ -70,11 +70,11 @@ class StringUtil {
|
|
|
70
70
|
});
|
|
71
71
|
return `[${tempArr.join(',')}]`;
|
|
72
72
|
}
|
|
73
|
-
/**
|
|
74
|
-
* 对象转字符串
|
|
75
|
-
* @param obj
|
|
76
|
-
* @param styleTransform 是否为style解析树的数组转换
|
|
77
|
-
* @returns
|
|
73
|
+
/**
|
|
74
|
+
* 对象转字符串
|
|
75
|
+
* @param obj
|
|
76
|
+
* @param styleTransform 是否为style解析树的数组转换
|
|
77
|
+
* @returns
|
|
78
78
|
*/
|
|
79
79
|
static objectToString(obj) {
|
|
80
80
|
return `{${Object.keys(obj).map(key => {
|
|
@@ -8,14 +8,14 @@ var _ColorConsole = _interopRequireDefault(require("../ColorConsole"));
|
|
|
8
8
|
var _PositionError = _interopRequireDefault(require("../data/PositionError"));
|
|
9
9
|
var _ILog = require("../interface/ILog");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
/**
|
|
12
|
-
* 包装回调函数
|
|
11
|
+
/**
|
|
12
|
+
* 包装回调函数
|
|
13
13
|
*/
|
|
14
14
|
class WrapCallback {
|
|
15
|
-
/**
|
|
16
|
-
* 包装日志回调函数
|
|
17
|
-
* @param onLog
|
|
18
|
-
* @returns
|
|
15
|
+
/**
|
|
16
|
+
* 包装日志回调函数
|
|
17
|
+
* @param onLog
|
|
18
|
+
* @returns
|
|
19
19
|
*/
|
|
20
20
|
static wrapOnLog(onLog) {
|
|
21
21
|
return log => {
|
package/lib/utils/ZipFileUtil.js
CHANGED
|
@@ -7,15 +7,15 @@ exports.default = void 0;
|
|
|
7
7
|
var _archiver = _interopRequireDefault(require("archiver"));
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
/**
|
|
11
|
-
* ZipFileUtil
|
|
10
|
+
/**
|
|
11
|
+
* ZipFileUtil
|
|
12
12
|
*/
|
|
13
13
|
class ZipFileUtil {
|
|
14
|
-
/**
|
|
15
|
-
* 创建zip文件
|
|
16
|
-
* @param zipFilePath zip文件路径
|
|
17
|
-
* @param fileList 压缩进 zip 的文件列表
|
|
18
|
-
* @param options 压缩参数, 默认{ zlib: { level: 9 } }
|
|
14
|
+
/**
|
|
15
|
+
* 创建zip文件
|
|
16
|
+
* @param zipFilePath zip文件路径
|
|
17
|
+
* @param fileList 压缩进 zip 的文件列表
|
|
18
|
+
* @param options 压缩参数, 默认{ zlib: { level: 9 } }
|
|
19
19
|
*/
|
|
20
20
|
static createZipFile(zipFilePath, fileList, options) {
|
|
21
21
|
return new Promise((resolve, reject) => {
|
|
@@ -27,7 +27,6 @@ class ZipFileUtil {
|
|
|
27
27
|
...options
|
|
28
28
|
});
|
|
29
29
|
output.on('close', () => {
|
|
30
|
-
console.log('close');
|
|
31
30
|
resolve();
|
|
32
31
|
});
|
|
33
32
|
output.on('error', error => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/shared-utils",
|
|
3
|
-
"version": "2.0.5
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "The common method functions of the aiot-toolkit.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"koa": "^2.15.3",
|
|
28
28
|
"koa-router": "^13.0.1",
|
|
29
29
|
"koa-static": "^5.0.0",
|
|
30
|
-
"minimatch": "
|
|
30
|
+
"minimatch": "10.0.1",
|
|
31
31
|
"portfinder": "^1.0.32",
|
|
32
32
|
"qrcode": "^1.5.4",
|
|
33
33
|
"rimraf": "^5.0.9",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@types/minimatch": "^5.1.2",
|
|
43
43
|
"@types/qrcode": "^1.5.5"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "deb83e8b8fa65191a286690efe3d957d7df772f4"
|
|
46
46
|
}
|