@aiot-toolkit/shared-utils 2.0.3-beta.9 → 2.0.3
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 +1 -1
- package/lib/ColorConsole.js +24 -24
- 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
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,
|
|
@@ -125,7 +126,7 @@ class ColorConsole {
|
|
|
125
126
|
bgColor,
|
|
126
127
|
bold,
|
|
127
128
|
italic
|
|
128
|
-
} = style ||
|
|
129
|
+
} = style || ColorConsole.defaultStyle;
|
|
129
130
|
let result = word;
|
|
130
131
|
if (color) {
|
|
131
132
|
result = _chalk.default.hex(color)(result);
|
|
@@ -148,7 +149,7 @@ class ColorConsole {
|
|
|
148
149
|
* @returns 返回打印的日志信息
|
|
149
150
|
*/
|
|
150
151
|
static logger(log) {
|
|
151
|
-
const str =
|
|
152
|
+
const str = ColorConsole.logToString(log);
|
|
152
153
|
console.log(str);
|
|
153
154
|
}
|
|
154
155
|
|
|
@@ -172,11 +173,10 @@ class ColorConsole {
|
|
|
172
173
|
} = log;
|
|
173
174
|
|
|
174
175
|
// 位置消息
|
|
175
|
-
let positionMessage
|
|
176
|
-
|
|
177
|
-
style: this.getStyle(level),
|
|
176
|
+
let positionMessage = filePath ? {
|
|
177
|
+
style: ColorConsole.getStyle(level),
|
|
178
178
|
word: [filePath, position?.startLine, position?.startColumn].filter(item => Boolean(item)).join(':')
|
|
179
|
-
};
|
|
179
|
+
} : null;
|
|
180
180
|
const logs = Array.isArray(message) ? message : [message];
|
|
181
181
|
if (positionMessage) {
|
|
182
182
|
logs.unshift(positionMessage);
|
|
@@ -192,8 +192,8 @@ class ColorConsole {
|
|
|
192
192
|
} else {
|
|
193
193
|
effectPrefix = prefix;
|
|
194
194
|
}
|
|
195
|
-
const style =
|
|
196
|
-
return [...effectPrefix].join(' ') +
|
|
195
|
+
const style = ColorConsole.styleDic[level] || ColorConsole.defaultStyle;
|
|
196
|
+
return [...effectPrefix].join(' ') + ColorConsole.createMessage(logs.map(item => {
|
|
197
197
|
if (typeof item === 'object') {
|
|
198
198
|
return {
|
|
199
199
|
...item,
|
|
@@ -218,8 +218,8 @@ class ColorConsole {
|
|
|
218
218
|
const {
|
|
219
219
|
level = _ILog.Loglevel.INFO
|
|
220
220
|
} = log;
|
|
221
|
-
const style =
|
|
222
|
-
const time =
|
|
221
|
+
const style = ColorConsole.styleDic[level] || ColorConsole.defaultStyle;
|
|
222
|
+
const time = ColorConsole.formatWord(`[${(0, _dayjs.default)().format('MM-DD HH:mm:ss')}] [toolkit]: `, style);
|
|
223
223
|
const icon = style.icon ? style.icon : '';
|
|
224
224
|
return [icon, time];
|
|
225
225
|
}
|
|
@@ -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
|
|
3
|
+
"version": "2.0.3",
|
|
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": "e29e61eb89c2559eb9f3a18c51fd5ce4c4196cc2"
|
|
45
46
|
}
|