@aiot-toolkit/shared-utils 2.0.3-beta.9 → 2.0.4-beta.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/ColorConsole.d.ts +2 -1
- package/lib/ColorConsole.js +32 -25
- package/lib/utils/QuickAppDocHelp.d.ts +64 -0
- package/lib/utils/QuickAppDocHelp.js +75 -0
- package/lib/utils/ZipFileUtil.d.ts +17 -0
- package/lib/utils/ZipFileUtil.js +46 -0
- package/package.json +3 -2
package/lib/ColorConsole.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface IStyle {
|
|
|
5
5
|
bold?: boolean;
|
|
6
6
|
italic?: boolean;
|
|
7
7
|
icon?: string;
|
|
8
|
+
underline?: boolean;
|
|
8
9
|
}
|
|
9
10
|
export type StyleMessage = string | number | boolean | undefined | {
|
|
10
11
|
word: string | number;
|
|
@@ -65,6 +66,6 @@ declare class ColorConsole {
|
|
|
65
66
|
*
|
|
66
67
|
* @param log
|
|
67
68
|
*/
|
|
68
|
-
|
|
69
|
+
static createDefaultPrefix(log: ILog): string[];
|
|
69
70
|
}
|
|
70
71
|
export default ColorConsole;
|
package/lib/ColorConsole.js
CHANGED
|
@@ -37,46 +37,46 @@ class ColorConsole {
|
|
|
37
37
|
bold: true,
|
|
38
38
|
icon: '❌'
|
|
39
39
|
},
|
|
40
|
-
[_ILog.Loglevel.LOG]:
|
|
40
|
+
[_ILog.Loglevel.LOG]: ColorConsole.defaultStyle
|
|
41
41
|
}))();
|
|
42
42
|
static getStyle(logLevel) {
|
|
43
|
-
return
|
|
43
|
+
return ColorConsole.styleDic[logLevel] || ColorConsole.defaultStyle;
|
|
44
44
|
}
|
|
45
45
|
static log() {
|
|
46
46
|
for (var _len = arguments.length, message = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
47
47
|
message[_key] = arguments[_key];
|
|
48
48
|
}
|
|
49
|
-
return
|
|
49
|
+
return ColorConsole._log(_ILog.Loglevel.LOG, ...message);
|
|
50
50
|
}
|
|
51
51
|
static error() {
|
|
52
52
|
for (var _len2 = arguments.length, message = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
53
53
|
message[_key2] = arguments[_key2];
|
|
54
54
|
}
|
|
55
|
-
return
|
|
55
|
+
return ColorConsole._log(_ILog.Loglevel.ERROR, ...message);
|
|
56
56
|
}
|
|
57
57
|
static info() {
|
|
58
58
|
for (var _len3 = arguments.length, message = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
59
59
|
message[_key3] = arguments[_key3];
|
|
60
60
|
}
|
|
61
|
-
return
|
|
61
|
+
return ColorConsole._log(_ILog.Loglevel.INFO, ...message);
|
|
62
62
|
}
|
|
63
63
|
static success() {
|
|
64
64
|
for (var _len4 = arguments.length, message = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
65
65
|
message[_key4] = arguments[_key4];
|
|
66
66
|
}
|
|
67
|
-
return
|
|
67
|
+
return ColorConsole._log(_ILog.Loglevel.SUCCESS, ...message);
|
|
68
68
|
}
|
|
69
69
|
static throw() {
|
|
70
70
|
for (var _len5 = arguments.length, message = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
71
71
|
message[_key5] = arguments[_key5];
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
ColorConsole._log(_ILog.Loglevel.THROW, ...message);
|
|
74
74
|
}
|
|
75
75
|
static warn() {
|
|
76
76
|
for (var _len6 = arguments.length, message = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
77
77
|
message[_key6] = arguments[_key6];
|
|
78
78
|
}
|
|
79
|
-
return
|
|
79
|
+
return ColorConsole._log(_ILog.Loglevel.WARN, ...message);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
@@ -91,22 +91,23 @@ class ColorConsole {
|
|
|
91
91
|
*/
|
|
92
92
|
static createMessage(words) {
|
|
93
93
|
const list = Array.isArray(words) ? words : [words];
|
|
94
|
-
|
|
94
|
+
const result = list.map(item => {
|
|
95
95
|
if (typeof item === 'object') {
|
|
96
|
-
return
|
|
96
|
+
return ColorConsole.formatWord(item.word, item.style);
|
|
97
97
|
}
|
|
98
|
-
return
|
|
98
|
+
return ColorConsole.formatWord(item, ColorConsole.defaultStyle);
|
|
99
99
|
}).join(' ');
|
|
100
|
+
return result;
|
|
100
101
|
}
|
|
101
102
|
static _log(logLevel) {
|
|
102
|
-
const style =
|
|
103
|
+
const style = ColorConsole.styleDic[logLevel] || ColorConsole.defaultStyle;
|
|
103
104
|
for (var _len7 = arguments.length, message = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
|
|
104
105
|
message[_key7 - 1] = arguments[_key7];
|
|
105
106
|
}
|
|
106
|
-
console.log(
|
|
107
|
+
console.log(ColorConsole.createDefaultPrefix({
|
|
107
108
|
level: logLevel,
|
|
108
109
|
message
|
|
109
|
-
})
|
|
110
|
+
}).join(' ') + ColorConsole.createMessage(message.map(item => {
|
|
110
111
|
if (typeof item === 'object') {
|
|
111
112
|
return {
|
|
112
113
|
...item,
|
|
@@ -124,8 +125,9 @@ class ColorConsole {
|
|
|
124
125
|
color,
|
|
125
126
|
bgColor,
|
|
126
127
|
bold,
|
|
127
|
-
italic
|
|
128
|
-
|
|
128
|
+
italic,
|
|
129
|
+
underline
|
|
130
|
+
} = style || ColorConsole.defaultStyle;
|
|
129
131
|
let result = word;
|
|
130
132
|
if (color) {
|
|
131
133
|
result = _chalk.default.hex(color)(result);
|
|
@@ -139,6 +141,9 @@ class ColorConsole {
|
|
|
139
141
|
if (italic) {
|
|
140
142
|
result = _chalk.default.italic(result);
|
|
141
143
|
}
|
|
144
|
+
if (underline) {
|
|
145
|
+
result = _chalk.default.underline(result);
|
|
146
|
+
}
|
|
142
147
|
return result;
|
|
143
148
|
}
|
|
144
149
|
|
|
@@ -148,7 +153,7 @@ class ColorConsole {
|
|
|
148
153
|
* @returns 返回打印的日志信息
|
|
149
154
|
*/
|
|
150
155
|
static logger(log) {
|
|
151
|
-
const str =
|
|
156
|
+
const str = ColorConsole.logToString(log);
|
|
152
157
|
console.log(str);
|
|
153
158
|
}
|
|
154
159
|
|
|
@@ -172,11 +177,13 @@ class ColorConsole {
|
|
|
172
177
|
} = log;
|
|
173
178
|
|
|
174
179
|
// 位置消息
|
|
175
|
-
let positionMessage
|
|
176
|
-
|
|
177
|
-
|
|
180
|
+
let positionMessage = filePath ? {
|
|
181
|
+
style: {
|
|
182
|
+
...ColorConsole.getStyle(_ILog.Loglevel.LOG),
|
|
183
|
+
underline: true
|
|
184
|
+
},
|
|
178
185
|
word: [filePath, position?.startLine, position?.startColumn].filter(item => Boolean(item)).join(':')
|
|
179
|
-
};
|
|
186
|
+
} : null;
|
|
180
187
|
const logs = Array.isArray(message) ? message : [message];
|
|
181
188
|
if (positionMessage) {
|
|
182
189
|
logs.unshift(positionMessage);
|
|
@@ -192,8 +199,8 @@ class ColorConsole {
|
|
|
192
199
|
} else {
|
|
193
200
|
effectPrefix = prefix;
|
|
194
201
|
}
|
|
195
|
-
const style =
|
|
196
|
-
return [...effectPrefix].join(' ') +
|
|
202
|
+
const style = ColorConsole.styleDic[level] || ColorConsole.defaultStyle;
|
|
203
|
+
return [...effectPrefix].join(' ') + ColorConsole.createMessage(logs.map(item => {
|
|
197
204
|
if (typeof item === 'object') {
|
|
198
205
|
return {
|
|
199
206
|
...item,
|
|
@@ -218,8 +225,8 @@ class ColorConsole {
|
|
|
218
225
|
const {
|
|
219
226
|
level = _ILog.Loglevel.INFO
|
|
220
227
|
} = log;
|
|
221
|
-
const style =
|
|
222
|
-
const time =
|
|
228
|
+
const style = ColorConsole.styleDic[level] || ColorConsole.defaultStyle;
|
|
229
|
+
const time = ColorConsole.formatWord(`[${(0, _dayjs.default)().format('MM-DD HH:mm:ss')}] [toolkit]: `, style);
|
|
223
230
|
const icon = style.icon ? style.icon : '';
|
|
224
231
|
return [icon, time];
|
|
225
232
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { StyleMessage } from '../ColorConsole';
|
|
2
|
+
/**
|
|
3
|
+
* 文档帮助
|
|
4
|
+
*/
|
|
5
|
+
export default interface IDocHelp {
|
|
6
|
+
/**
|
|
7
|
+
* 获取组件的文档地址
|
|
8
|
+
* @param option
|
|
9
|
+
*/
|
|
10
|
+
getWidgetsUrl(option: {
|
|
11
|
+
/**
|
|
12
|
+
* 组件名称
|
|
13
|
+
*/
|
|
14
|
+
componentName: string;
|
|
15
|
+
/**
|
|
16
|
+
* 组件章节
|
|
17
|
+
*/
|
|
18
|
+
chapter?: QuickAppDocWidgetType;
|
|
19
|
+
}): string;
|
|
20
|
+
/**
|
|
21
|
+
* 创建组件文档地址的提示信息
|
|
22
|
+
* @param tag 组件名称
|
|
23
|
+
* @param type 章节类型
|
|
24
|
+
*/
|
|
25
|
+
createWidgetReferenceMessage(option: {
|
|
26
|
+
/**
|
|
27
|
+
* 组件名称
|
|
28
|
+
*/
|
|
29
|
+
componentName: string;
|
|
30
|
+
/**
|
|
31
|
+
* 组件章节
|
|
32
|
+
*/
|
|
33
|
+
chapter?: QuickAppDocWidgetType;
|
|
34
|
+
}): StyleMessage;
|
|
35
|
+
}
|
|
36
|
+
export declare class QuickAppDocHelper implements IDocHelp {
|
|
37
|
+
private HOST;
|
|
38
|
+
getWidgetsUrl(option: {
|
|
39
|
+
componentName: string;
|
|
40
|
+
chapter?: QuickAppDocWidgetType;
|
|
41
|
+
}): string;
|
|
42
|
+
createWidgetReferenceMessage(option: {
|
|
43
|
+
componentName: string;
|
|
44
|
+
chapter?: QuickAppDocWidgetType;
|
|
45
|
+
}): StyleMessage;
|
|
46
|
+
}
|
|
47
|
+
export declare class VelaAppDocHelp implements IDocHelp {
|
|
48
|
+
private HOST;
|
|
49
|
+
private categoryDic;
|
|
50
|
+
private findCategoryName;
|
|
51
|
+
getWidgetsUrl(option: {
|
|
52
|
+
componentName: string;
|
|
53
|
+
chapter?: QuickAppDocWidgetType;
|
|
54
|
+
}): string;
|
|
55
|
+
createWidgetReferenceMessage(option: {
|
|
56
|
+
componentName: string;
|
|
57
|
+
chapter?: QuickAppDocWidgetType;
|
|
58
|
+
}): StyleMessage;
|
|
59
|
+
}
|
|
60
|
+
export declare enum QuickAppDocWidgetType {
|
|
61
|
+
ATTRIBUTE = "\u5C5E\u6027",
|
|
62
|
+
STYLE = "\u6837\u5F0F",
|
|
63
|
+
EVENT = "\u4E8B\u4EF6"
|
|
64
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.VelaAppDocHelp = exports.QuickAppDocWidgetType = exports.QuickAppDocHelper = void 0;
|
|
7
|
+
var _ColorConsole = _interopRequireDefault(require("../ColorConsole"));
|
|
8
|
+
var _ILog = require("../interface/ILog");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
/**
|
|
11
|
+
* 文档帮助
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
class QuickAppDocHelper {
|
|
15
|
+
HOST = 'https://doc.quickapp.cn';
|
|
16
|
+
getWidgetsUrl(option) {
|
|
17
|
+
const {
|
|
18
|
+
componentName,
|
|
19
|
+
chapter
|
|
20
|
+
} = option;
|
|
21
|
+
return `${this.HOST}/widgets/${componentName}.html${chapter ? `#${chapter}` : ''}`;
|
|
22
|
+
}
|
|
23
|
+
createWidgetReferenceMessage(option) {
|
|
24
|
+
return {
|
|
25
|
+
word: `(Reference: ${this.getWidgetsUrl(option)})`,
|
|
26
|
+
style: {
|
|
27
|
+
..._ColorConsole.default.getStyle(_ILog.Loglevel.INFO),
|
|
28
|
+
italic: true,
|
|
29
|
+
bold: true
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.QuickAppDocHelper = QuickAppDocHelper;
|
|
35
|
+
class VelaAppDocHelp {
|
|
36
|
+
HOST = 'https://iot.mi.com/vela/quickapp';
|
|
37
|
+
categoryDic = {
|
|
38
|
+
container: ['div', 'list', 'list-item', 'scroll', 'stack', 'swiper'],
|
|
39
|
+
basic: ['text', 'span', 'a', 'image', 'image-animator', 'progress', 'marquee', 'chart', 'qrcode', 'barcode'],
|
|
40
|
+
form: ['input', 'picker', 'switch', 'slider']
|
|
41
|
+
};
|
|
42
|
+
findCategoryName(componentName) {
|
|
43
|
+
for (let key in this.categoryDic) {
|
|
44
|
+
if (this.categoryDic[key].includes(componentName)) {
|
|
45
|
+
return key;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
getWidgetsUrl(option) {
|
|
51
|
+
const {
|
|
52
|
+
componentName,
|
|
53
|
+
chapter
|
|
54
|
+
} = option;
|
|
55
|
+
const componentCategory = this.findCategoryName(componentName);
|
|
56
|
+
return `${this.HOST}/zh/components/${componentCategory}/${componentName}.html${chapter ? `#${chapter}` : ''}`;
|
|
57
|
+
}
|
|
58
|
+
createWidgetReferenceMessage(option) {
|
|
59
|
+
return {
|
|
60
|
+
word: `(Reference: ${this.getWidgetsUrl(option)})`,
|
|
61
|
+
style: {
|
|
62
|
+
..._ColorConsole.default.getStyle(_ILog.Loglevel.INFO),
|
|
63
|
+
italic: true,
|
|
64
|
+
bold: true
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.VelaAppDocHelp = VelaAppDocHelp;
|
|
70
|
+
let QuickAppDocWidgetType = exports.QuickAppDocWidgetType = /*#__PURE__*/function (QuickAppDocWidgetType) {
|
|
71
|
+
QuickAppDocWidgetType["ATTRIBUTE"] = "\u5C5E\u6027";
|
|
72
|
+
QuickAppDocWidgetType["STYLE"] = "\u6837\u5F0F";
|
|
73
|
+
QuickAppDocWidgetType["EVENT"] = "\u4E8B\u4EF6";
|
|
74
|
+
return QuickAppDocWidgetType;
|
|
75
|
+
}({});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Archiver from 'archiver';
|
|
2
|
+
/**
|
|
3
|
+
* ZipFileUtil
|
|
4
|
+
*/
|
|
5
|
+
declare class ZipFileUtil {
|
|
6
|
+
/**
|
|
7
|
+
* 创建zip文件
|
|
8
|
+
* @param zipFilePath zip文件路径
|
|
9
|
+
* @param fileList 压缩进 zip 的文件列表
|
|
10
|
+
* @param options 压缩参数, 默认{ zlib: { level: 9 } }
|
|
11
|
+
*/
|
|
12
|
+
static createZipFile(zipFilePath: string, fileList: {
|
|
13
|
+
filePath: string;
|
|
14
|
+
zipFilePath: string;
|
|
15
|
+
}[], options?: Archiver.ArchiverOptions): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export default ZipFileUtil;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _archiver = _interopRequireDefault(require("archiver"));
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
/**
|
|
11
|
+
* ZipFileUtil
|
|
12
|
+
*/
|
|
13
|
+
class ZipFileUtil {
|
|
14
|
+
/**
|
|
15
|
+
* 创建zip文件
|
|
16
|
+
* @param zipFilePath zip文件路径
|
|
17
|
+
* @param fileList 压缩进 zip 的文件列表
|
|
18
|
+
* @param options 压缩参数, 默认{ zlib: { level: 9 } }
|
|
19
|
+
*/
|
|
20
|
+
static createZipFile(zipFilePath, fileList, options) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const output = _fs.default.createWriteStream(zipFilePath);
|
|
23
|
+
const archiver = (0, _archiver.default)('zip', {
|
|
24
|
+
zlib: {
|
|
25
|
+
level: 9
|
|
26
|
+
},
|
|
27
|
+
...options
|
|
28
|
+
});
|
|
29
|
+
output.on('close', () => {
|
|
30
|
+
console.log('close');
|
|
31
|
+
resolve();
|
|
32
|
+
});
|
|
33
|
+
output.on('error', error => {
|
|
34
|
+
reject(error);
|
|
35
|
+
});
|
|
36
|
+
fileList.forEach(item => {
|
|
37
|
+
archiver.append(_fs.default.createReadStream(item.filePath), {
|
|
38
|
+
name: item.zipFilePath
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
archiver.pipe(output);
|
|
42
|
+
archiver.finalize();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
var _default = exports.default = ZipFileUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/shared-utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4-beta.1",
|
|
4
4
|
"description": "The common method functions of the aiot-toolkit.",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"ajv": "^8.12.0",
|
|
20
20
|
"ansi-colors": "^4.1.3",
|
|
21
|
+
"archiver": "^7.0.1",
|
|
21
22
|
"chalk": "^4.0.0",
|
|
22
23
|
"cli-progress": "^3.12.0",
|
|
23
24
|
"dayjs": "^1.11.9",
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"@types/minimatch": "^5.1.2",
|
|
42
43
|
"@types/qrcode": "^1.5.5"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "85c4287c7b9468c83d468cfc39b147f4975f8285"
|
|
45
46
|
}
|