@aiot-toolkit/shared-utils 1.0.20-importfile-dev.2 → 2.0.1-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.
- package/README.md +10 -2
- package/lib/ColorConsole.d.ts +13 -0
- package/lib/ColorConsole.js +45 -0
- package/lib/ColorConsole.js.map +1 -0
- package/lib/ColorConsole2.d.ts +41 -0
- package/lib/ColorConsole2.js +107 -0
- package/lib/ColorConsole2.js.map +1 -0
- package/lib/data/MapData.d.ts +8 -0
- package/lib/data/MapData.js +12 -0
- package/lib/data/MapData.js.map +1 -0
- package/lib/data/PositionError.d.ts +9 -0
- package/lib/data/PositionError.js +14 -0
- package/lib/data/PositionError.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +24 -1
- package/lib/index.js.map +1 -0
- package/lib/interface/ILog.d.ts +19 -0
- package/lib/interface/ILog.js +15 -0
- package/lib/interface/ILog.js.map +1 -0
- package/lib/interface/IPosition.d.ts +30 -0
- package/lib/interface/IPosition.js +4 -0
- package/lib/interface/IPosition.js.map +1 -0
- package/lib/type/Type.d.ts +4 -0
- package/lib/type/Type.js +4 -0
- package/lib/type/Type.js.map +1 -0
- package/lib/utils/CommonUtil.d.ts +21 -0
- package/lib/utils/CommonUtil.js +54 -0
- package/lib/utils/CommonUtil.js.map +1 -0
- package/lib/utils/FileUtil.d.ts +73 -0
- package/lib/utils/FileUtil.js +157 -0
- package/lib/utils/FileUtil.js.map +1 -0
- package/lib/utils/NetworkUtil.d.ts +14 -0
- package/lib/utils/NetworkUtil.js +54 -0
- package/lib/utils/NetworkUtil.js.map +1 -0
- package/lib/utils/StringUtil.d.ts +16 -0
- package/lib/utils/StringUtil.js +26 -0
- package/lib/utils/StringUtil.js.map +1 -0
- package/lib/utils/WrapCallback.d.ts +13 -0
- package/lib/utils/WrapCallback.js +34 -0
- package/lib/utils/WrapCallback.js.map +1 -0
- package/package.json +17 -20
- package/compilation-config.js +0 -141
- package/config.js +0 -14
- package/event-bus.js +0 -13
- package/lib/buildMode/BuildModeManager.js +0 -2
- package/lib/buildMode/util.js +0 -2
- package/lib/protobuf/protobuf.js +0 -2
- package/lib/protobuf/protobufControl.js +0 -2
- package/lib/protobuf/vdom_pb.js +0 -2
- package/lib/record-client.js +0 -2
package/README.md
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const ILog_1 = require("./interface/ILog");
|
|
9
|
+
/**
|
|
10
|
+
* Log
|
|
11
|
+
*/
|
|
12
|
+
class ColorConsole {
|
|
13
|
+
/**
|
|
14
|
+
* 按照日志类型打印不同颜色的日志
|
|
15
|
+
* @param log 默认日志类型为info
|
|
16
|
+
* @returns 返回打印的日志信息
|
|
17
|
+
*/
|
|
18
|
+
static log(log) {
|
|
19
|
+
const time = (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss');
|
|
20
|
+
const { message, position, level = ILog_1.LOG_LEVEL.Info, isOnlyPrintError = false } = log;
|
|
21
|
+
let result = position ? `${message}\n${JSON.stringify(position)}` : `${message}`;
|
|
22
|
+
switch (level) {
|
|
23
|
+
case ILog_1.LOG_LEVEL.Success:
|
|
24
|
+
case ILog_1.LOG_LEVEL.Info:
|
|
25
|
+
console.log(`${chalk_1.default.green.bold(`[${time} ${ILog_1.LOG_LEVEL[level]}]`)}: ${result}`);
|
|
26
|
+
break;
|
|
27
|
+
case ILog_1.LOG_LEVEL.Warn:
|
|
28
|
+
console.log(`${chalk_1.default.yellow.bold(`[${time} ${ILog_1.LOG_LEVEL[level]}]`)}: ${result}`);
|
|
29
|
+
break;
|
|
30
|
+
case ILog_1.LOG_LEVEL.Error:
|
|
31
|
+
case ILog_1.LOG_LEVEL.Throw:
|
|
32
|
+
result = message;
|
|
33
|
+
if (isOnlyPrintError) {
|
|
34
|
+
console.log(`${chalk_1.default.red.bold(`[${time} ${ILog_1.LOG_LEVEL[level]}]`)}: ${result}`);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error(result);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.default = ColorConsole;
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=ColorConsole.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ColorConsole.ts"],"names":[],"mappings":";;;;;AAAA,kDAAyB;AACzB,kDAAyB;AACzB,2CAAkD;AAClD;;GAEG;AACH,MAAM,YAAY;IAChB;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,GAAS;QAClB,MAAM,IAAI,GAAG,IAAA,eAAK,GAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAA;QAClD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,GAAG,gBAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,KAAK,EAAE,GAAG,GAAG,CAAA;QACnF,IAAI,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,CAAA;QAChF,QAAQ,KAAK,EAAE;YACb,KAAK,gBAAS,CAAC,OAAO,CAAC;YACvB,KAAK,gBAAS,CAAC,IAAI;gBACjB,OAAO,CAAC,GAAG,CAAC,GAAG,eAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,gBAAS,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA;gBAC9E,MAAK;YACP,KAAK,gBAAS,CAAC,IAAI;gBACjB,OAAO,CAAC,GAAG,CAAC,GAAG,eAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,gBAAS,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA;gBAC/E,MAAK;YACP,KAAK,gBAAS,CAAC,KAAK,CAAC;YACrB,KAAK,gBAAS,CAAC,KAAK;gBAClB,MAAM,GAAG,OAAO,CAAA;gBAChB,IAAI,gBAAgB,EAAE;oBACpB,OAAO,CAAC,GAAG,CAAC,GAAG,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,gBAAS,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE,CAAC,CAAA;iBAC7E;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAA;iBACxB;SACJ;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AACD,kBAAe,YAAY,CAAA","file":"ColorConsole.js","sourcesContent":["import chalk from 'chalk'\nimport dayjs from 'dayjs'\nimport { ILog, LOG_LEVEL } from './interface/ILog'\n/**\n * Log\n */\nclass ColorConsole {\n /**\n * 按照日志类型打印不同颜色的日志\n * @param log 默认日志类型为info\n * @returns 返回打印的日志信息\n */\n static log(log: ILog): string {\n const time = dayjs().format('YYYY-MM-DD HH:mm:ss')\n const { message, position, level = LOG_LEVEL.Info, isOnlyPrintError = false } = log\n let result = position ? `${message}\\n${JSON.stringify(position)}` : `${message}`\n switch (level) {\n case LOG_LEVEL.Success:\n case LOG_LEVEL.Info:\n console.log(`${chalk.green.bold(`[${time} ${LOG_LEVEL[level]}]`)}: ${result}`)\n break\n case LOG_LEVEL.Warn:\n console.log(`${chalk.yellow.bold(`[${time} ${LOG_LEVEL[level]}]`)}: ${result}`)\n break\n case LOG_LEVEL.Error:\n case LOG_LEVEL.Throw:\n result = message\n if (isOnlyPrintError) {\n console.log(`${chalk.red.bold(`[${time} ${LOG_LEVEL[level]}]`)}: ${result}`)\n } else {\n throw new Error(result)\n }\n }\n return result\n }\n}\nexport default ColorConsole\n"],"sourceRoot":"../src"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { LOG_LEVEL } from './interface/ILog';
|
|
2
|
+
interface IStyle {
|
|
3
|
+
color?: string;
|
|
4
|
+
bgColor?: string;
|
|
5
|
+
bold?: boolean;
|
|
6
|
+
italic?: boolean;
|
|
7
|
+
}
|
|
8
|
+
type Message = string | number | boolean | undefined | {
|
|
9
|
+
word: string;
|
|
10
|
+
style?: IStyle;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 带颜色的输出
|
|
14
|
+
*/
|
|
15
|
+
declare class ColorConsole2 {
|
|
16
|
+
static defaultStyle: IStyle;
|
|
17
|
+
static styleDic: {
|
|
18
|
+
[key in LOG_LEVEL]: IStyle;
|
|
19
|
+
};
|
|
20
|
+
static getStyle(logLevel: LOG_LEVEL): IStyle;
|
|
21
|
+
static log(...message: Message[]): void;
|
|
22
|
+
static error(...message: Message[]): void;
|
|
23
|
+
static info(...message: Message[]): void;
|
|
24
|
+
static success(...message: Message[]): void;
|
|
25
|
+
static throw(...message: Message[]): void;
|
|
26
|
+
static warn(...message: Message[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* 创建复杂格式的消息,可单独设置词语样式
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```js
|
|
32
|
+
* createMessage("my name is", {message:'****', style:{ color:'red' }})
|
|
33
|
+
* ```
|
|
34
|
+
* @param words
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
static createMessage(...words: Message[]): string;
|
|
38
|
+
private static _log;
|
|
39
|
+
private static formatWord;
|
|
40
|
+
}
|
|
41
|
+
export default ColorConsole2;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
|
+
const ILog_1 = require("./interface/ILog");
|
|
10
|
+
/**
|
|
11
|
+
* 带颜色的输出
|
|
12
|
+
*/
|
|
13
|
+
class ColorConsole2 {
|
|
14
|
+
static getStyle(logLevel) {
|
|
15
|
+
return this.styleDic[logLevel] || this.defaultStyle;
|
|
16
|
+
}
|
|
17
|
+
static log(...message) {
|
|
18
|
+
return this._log(ILog_1.LOG_LEVEL.Log, ...message);
|
|
19
|
+
}
|
|
20
|
+
static error(...message) {
|
|
21
|
+
return this._log(ILog_1.LOG_LEVEL.Error, ...message);
|
|
22
|
+
}
|
|
23
|
+
static info(...message) {
|
|
24
|
+
return this._log(ILog_1.LOG_LEVEL.Info, ...message);
|
|
25
|
+
}
|
|
26
|
+
static success(...message) {
|
|
27
|
+
return this._log(ILog_1.LOG_LEVEL.Success, ...message);
|
|
28
|
+
}
|
|
29
|
+
static throw(...message) {
|
|
30
|
+
this._log(ILog_1.LOG_LEVEL.Throw, ...message);
|
|
31
|
+
process.exit();
|
|
32
|
+
}
|
|
33
|
+
static warn(...message) {
|
|
34
|
+
return this._log(ILog_1.LOG_LEVEL.Warn, ...message);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 创建复杂格式的消息,可单独设置词语样式
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```js
|
|
41
|
+
* createMessage("my name is", {message:'****', style:{ color:'red' }})
|
|
42
|
+
* ```
|
|
43
|
+
* @param words
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
static createMessage(...words) {
|
|
47
|
+
return words
|
|
48
|
+
.map((item) => {
|
|
49
|
+
if (typeof item === 'object') {
|
|
50
|
+
return this.formatWord(item.word, item.style);
|
|
51
|
+
}
|
|
52
|
+
return this.formatWord(item, this.defaultStyle);
|
|
53
|
+
})
|
|
54
|
+
.join(' ');
|
|
55
|
+
}
|
|
56
|
+
static _log(logLevel, ...message) {
|
|
57
|
+
const style = this.styleDic[logLevel] || this.defaultStyle;
|
|
58
|
+
const time = this.formatWord((0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss'), style);
|
|
59
|
+
console.log(`[${time}]: `, this.createMessage(...message));
|
|
60
|
+
}
|
|
61
|
+
static formatWord(word, style) {
|
|
62
|
+
if (word === undefined || word === null) {
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
const { color, bgColor, bold, italic } = style || this.defaultStyle;
|
|
66
|
+
let result = word;
|
|
67
|
+
if (color) {
|
|
68
|
+
result = chalk_1.default.hex(color)(result);
|
|
69
|
+
}
|
|
70
|
+
if (bgColor) {
|
|
71
|
+
result = chalk_1.default.bgHex(bgColor)(result);
|
|
72
|
+
}
|
|
73
|
+
if (bold) {
|
|
74
|
+
result = chalk_1.default.bold(result);
|
|
75
|
+
}
|
|
76
|
+
if (italic) {
|
|
77
|
+
result = chalk_1.default.italic(result);
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
_a = ColorConsole2;
|
|
83
|
+
ColorConsole2.defaultStyle = {
|
|
84
|
+
color: 'black'
|
|
85
|
+
};
|
|
86
|
+
ColorConsole2.styleDic = {
|
|
87
|
+
[ILog_1.LOG_LEVEL.Success]: {
|
|
88
|
+
color: '#008000'
|
|
89
|
+
},
|
|
90
|
+
[ILog_1.LOG_LEVEL.Info]: {
|
|
91
|
+
color: '#03A9F4'
|
|
92
|
+
},
|
|
93
|
+
[ILog_1.LOG_LEVEL.Warn]: {
|
|
94
|
+
color: '#FF9800'
|
|
95
|
+
},
|
|
96
|
+
[ILog_1.LOG_LEVEL.Error]: {
|
|
97
|
+
color: '#ff0000'
|
|
98
|
+
},
|
|
99
|
+
[ILog_1.LOG_LEVEL.Throw]: {
|
|
100
|
+
color: '#ff0000',
|
|
101
|
+
bold: true
|
|
102
|
+
},
|
|
103
|
+
[ILog_1.LOG_LEVEL.Log]: _a.defaultStyle
|
|
104
|
+
};
|
|
105
|
+
exports.default = ColorConsole2;
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=ColorConsole2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ColorConsole2.ts"],"names":[],"mappings":"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","file":"ColorConsole2.js","sourcesContent":["import chalk from 'chalk'\nimport dayjs from 'dayjs'\nimport { LOG_LEVEL } from './interface/ILog'\n\ninterface IStyle {\n color?: string\n bgColor?: string\n bold?: boolean\n italic?: boolean\n}\n\ntype Message = string | number | boolean | undefined | { word: string; style?: IStyle }\n/**\n * 带颜色的输出\n */\nclass ColorConsole2 {\n static defaultStyle: IStyle = {\n color: 'black'\n }\n static styleDic: {\n [key in LOG_LEVEL]: IStyle\n } = {\n [LOG_LEVEL.Success]: {\n color: '#008000'\n },\n [LOG_LEVEL.Info]: {\n color: '#03A9F4'\n },\n [LOG_LEVEL.Warn]: {\n color: '#FF9800'\n },\n [LOG_LEVEL.Error]: {\n color: '#ff0000'\n },\n [LOG_LEVEL.Throw]: {\n color: '#ff0000',\n bold: true\n },\n [LOG_LEVEL.Log]: this.defaultStyle\n }\n\n static getStyle(logLevel: LOG_LEVEL): IStyle {\n return this.styleDic[logLevel] || this.defaultStyle\n }\n\n static log(...message: Message[]) {\n return this._log(LOG_LEVEL.Log, ...message)\n }\n static error(...message: Message[]) {\n return this._log(LOG_LEVEL.Error, ...message)\n }\n static info(...message: Message[]) {\n return this._log(LOG_LEVEL.Info, ...message)\n }\n static success(...message: Message[]) {\n return this._log(LOG_LEVEL.Success, ...message)\n }\n static throw(...message: Message[]) {\n this._log(LOG_LEVEL.Throw, ...message)\n process.exit()\n }\n static warn(...message: Message[]) {\n return this._log(LOG_LEVEL.Warn, ...message)\n }\n\n /**\n * 创建复杂格式的消息,可单独设置词语样式\n *\n * @example\n * ```js\n * createMessage(\"my name is\", {message:'****', style:{ color:'red' }})\n * ```\n * @param words\n * @returns\n */\n public static createMessage(...words: Message[]) {\n return words\n .map((item) => {\n if (typeof item === 'object') {\n return this.formatWord(item.word, item.style)\n }\n return this.formatWord(item, this.defaultStyle)\n })\n .join(' ')\n }\n\n private static _log(logLevel: LOG_LEVEL, ...message: Message[]) {\n const style = this.styleDic[logLevel] || this.defaultStyle\n const time = this.formatWord(dayjs().format('YYYY-MM-DD HH:mm:ss'), style)\n console.log(`[${time}]: `, this.createMessage(...message))\n }\n\n private static formatWord(word?: string | number | boolean, style?: IStyle) {\n if (word === undefined || word === null) {\n return ''\n }\n const { color, bgColor, bold, italic } = style || this.defaultStyle\n\n let result = word\n if (color) {\n result = chalk.hex(color)(result)\n }\n if (bgColor) {\n result = chalk.bgHex(bgColor)(result)\n }\n\n if (bold) {\n result = chalk.bold(result)\n }\n\n if (italic) {\n result = chalk.italic(result)\n }\n return result\n }\n}\nexport default ColorConsole2\n"],"sourceRoot":"../src"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class MapData {
|
|
4
|
+
constructor(name, source, target) {
|
|
5
|
+
this.name = name;
|
|
6
|
+
this.source = source;
|
|
7
|
+
this.target = target;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.default = MapData;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=MapData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["data/MapData.ts"],"names":[],"mappings":";;AAEA,MAAM,OAAO;IAKX,YAAY,IAAY,EAAE,MAAiB,EAAE,MAAiB;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAED,kBAAe,OAAO,CAAA","file":"MapData.js","sourcesContent":["import IPosition from '../interface/IPosition'\n\nclass MapData {\n public readonly source: IPosition\n public readonly target: IPosition\n public readonly name: string\n\n constructor(name: string, source: IPosition, target: IPosition) {\n this.name = name\n this.source = source\n this.target = target\n }\n}\n\nexport default MapData\n"],"sourceRoot":"../../src"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* PositionError
|
|
5
|
+
*/
|
|
6
|
+
class PositionError extends Error {
|
|
7
|
+
constructor(position, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.position = position;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = PositionError;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=PositionError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["data/PositionError.ts"],"names":[],"mappings":";;AAEA;;GAEG;AACH,MAAM,aAAc,SAAQ,KAAK;IAC/B,YACS,QAAoB,EAC3B,OAAgB;QAEhB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHP,aAAQ,GAAR,QAAQ,CAAY;IAI7B,CAAC;CACF;AACD,kBAAe,aAAa,CAAA","file":"PositionError.js","sourcesContent":["import IPosition from '../interface/IPosition'\n\n/**\n * PositionError\n */\nclass PositionError extends Error {\n constructor(\n public position?: IPosition,\n message?: string\n ) {\n super(message)\n }\n}\nexport default PositionError\n"],"sourceRoot":"../../src"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import MapData from './data/MapData';
|
|
2
|
+
import PositionError from './data/PositionError';
|
|
3
|
+
import { ILog, LOG_LEVEL, Logger } from './interface/ILog';
|
|
4
|
+
import IPosition from './interface/IPosition';
|
|
5
|
+
import WrapCallback from './utils/WrapCallback';
|
|
6
|
+
export { ILog, IPosition, LOG_LEVEL, Logger, MapData, PositionError, WrapCallback, outputQRCodeOnTerminal };
|
|
7
|
+
declare function outputQRCodeOnTerminal(text: string): void;
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.outputQRCodeOnTerminal = exports.WrapCallback = exports.PositionError = exports.MapData = exports.LOG_LEVEL = void 0;
|
|
7
|
+
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
8
|
+
const ColorConsole_1 = __importDefault(require("./ColorConsole"));
|
|
9
|
+
const MapData_1 = __importDefault(require("./data/MapData"));
|
|
10
|
+
exports.MapData = MapData_1.default;
|
|
11
|
+
const PositionError_1 = __importDefault(require("./data/PositionError"));
|
|
12
|
+
exports.PositionError = PositionError_1.default;
|
|
13
|
+
const ILog_1 = require("./interface/ILog");
|
|
14
|
+
Object.defineProperty(exports, "LOG_LEVEL", { enumerable: true, get: function () { return ILog_1.LOG_LEVEL; } });
|
|
15
|
+
const WrapCallback_1 = __importDefault(require("./utils/WrapCallback"));
|
|
16
|
+
exports.WrapCallback = WrapCallback_1.default;
|
|
17
|
+
function outputQRCodeOnTerminal(text) {
|
|
18
|
+
ColorConsole_1.default.log({
|
|
19
|
+
message: `\nGenerate QR code for HTTP server: ${text}`
|
|
20
|
+
});
|
|
21
|
+
qrcode_terminal_1.default.generate(text, { small: true });
|
|
22
|
+
}
|
|
23
|
+
exports.outputQRCodeOnTerminal = outputQRCodeOnTerminal;
|
|
24
|
+
|
|
2
25
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAwC;AACxC,kEAAyC;AACzC,6DAAoC;AAWlC,kBAXK,iBAAO,CAWL;AAVT,yEAAgD;AAW9C,wBAXK,uBAAa,CAWL;AAVf,2CAA0D;AAOxD,0FAPa,gBAAS,OAOb;AALX,wEAA+C;AAS7C,uBATK,sBAAY,CASL;AAId,SAAS,sBAAsB,CAAC,IAAY;IAC1C,sBAAY,CAAC,GAAG,CAAC;QACf,OAAO,EAAE,uCAAuC,IAAI,EAAE;KACvD,CAAC,CAAA;IACF,yBAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AAC5C,CAAC;AARC,wDAAsB","file":"index.js","sourcesContent":["import qrTerminal from 'qrcode-terminal'\nimport ColorConsole from './ColorConsole'\nimport MapData from './data/MapData'\nimport PositionError from './data/PositionError'\nimport { ILog, LOG_LEVEL, Logger } from './interface/ILog'\nimport IPosition from './interface/IPosition'\nimport WrapCallback from './utils/WrapCallback'\n\nexport {\n ILog,\n IPosition,\n LOG_LEVEL,\n Logger,\n MapData,\n PositionError,\n WrapCallback,\n outputQRCodeOnTerminal\n}\n\nfunction outputQRCodeOnTerminal(text: string) {\n ColorConsole.log({\n message: `\\nGenerate QR code for HTTP server: ${text}`\n })\n qrTerminal.generate(text, { small: true })\n}\n"],"sourceRoot":"../src"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import IPosition from './IPosition';
|
|
2
|
+
export declare enum LOG_LEVEL {
|
|
3
|
+
Log = 0,
|
|
4
|
+
Success = 1,
|
|
5
|
+
Info = 2,
|
|
6
|
+
Warn = 3,
|
|
7
|
+
Error = 4,
|
|
8
|
+
Throw = 5
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* ILog
|
|
12
|
+
*/
|
|
13
|
+
export interface ILog {
|
|
14
|
+
level?: LOG_LEVEL;
|
|
15
|
+
message: string;
|
|
16
|
+
position?: IPosition;
|
|
17
|
+
isOnlyPrintError?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export type Logger = (log: ILog) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOG_LEVEL = void 0;
|
|
4
|
+
// 日志类别
|
|
5
|
+
var LOG_LEVEL;
|
|
6
|
+
(function (LOG_LEVEL) {
|
|
7
|
+
LOG_LEVEL[LOG_LEVEL["Log"] = 0] = "Log";
|
|
8
|
+
LOG_LEVEL[LOG_LEVEL["Success"] = 1] = "Success";
|
|
9
|
+
LOG_LEVEL[LOG_LEVEL["Info"] = 2] = "Info";
|
|
10
|
+
LOG_LEVEL[LOG_LEVEL["Warn"] = 3] = "Warn";
|
|
11
|
+
LOG_LEVEL[LOG_LEVEL["Error"] = 4] = "Error";
|
|
12
|
+
LOG_LEVEL[LOG_LEVEL["Throw"] = 5] = "Throw";
|
|
13
|
+
})(LOG_LEVEL || (exports.LOG_LEVEL = LOG_LEVEL = {}));
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=ILog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["interface/ILog.ts"],"names":[],"mappings":";;;AAEA,OAAO;AACP,IAAY,SAOX;AAPD,WAAY,SAAS;IACnB,uCAAG,CAAA;IACH,+CAAO,CAAA;IACP,yCAAI,CAAA;IACJ,yCAAI,CAAA;IACJ,2CAAK,CAAA;IACL,2CAAK,CAAA;AACP,CAAC,EAPW,SAAS,yBAAT,SAAS,QAOpB","file":"ILog.js","sourcesContent":["import IPosition from './IPosition'\n\n// 日志类别\nexport enum LOG_LEVEL {\n Log,\n Success,\n Info,\n Warn,\n Error,\n Throw\n}\n/**\n * ILog\n */\nexport interface ILog {\n level?: LOG_LEVEL\n message: string\n position?: IPosition\n isOnlyPrintError?: boolean\n}\nexport type Logger = (log: ILog) => void\n"],"sourceRoot":"../../src"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 节点位置数据结构
|
|
3
|
+
*/
|
|
4
|
+
interface IPosition {
|
|
5
|
+
/**
|
|
6
|
+
* 起始位置
|
|
7
|
+
*/
|
|
8
|
+
pos: number;
|
|
9
|
+
/**
|
|
10
|
+
* 结束位置
|
|
11
|
+
*/
|
|
12
|
+
end: number;
|
|
13
|
+
/**
|
|
14
|
+
* 起始行
|
|
15
|
+
*/
|
|
16
|
+
startLine: number;
|
|
17
|
+
/**
|
|
18
|
+
* 起始列
|
|
19
|
+
*/
|
|
20
|
+
startColumn: number;
|
|
21
|
+
/**
|
|
22
|
+
* 结束行
|
|
23
|
+
*/
|
|
24
|
+
endLine: number;
|
|
25
|
+
/**
|
|
26
|
+
* 结束列
|
|
27
|
+
*/
|
|
28
|
+
endColumn: number;
|
|
29
|
+
}
|
|
30
|
+
export default IPosition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["interface/IPosition.ts"],"names":[],"mappings":"","file":"IPosition.js","sourcesContent":["/**\n * 节点位置数据结构\n */\ninterface IPosition {\n /**\n * 起始位置\n */\n pos: number\n /**\n * 结束位置\n */\n end: number\n\n /**\n * 起始行\n */\n startLine: number\n\n /**\n * 起始列\n */\n startColumn: number\n\n /**\n * 结束行\n */\n endLine: number\n\n /**\n * 结束列\n */\n endColumn: number\n}\n\nexport default IPosition\n"],"sourceRoot":"../../src"}
|
package/lib/type/Type.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["type/Type.ts"],"names":[],"mappings":"","file":"Type.js","sourcesContent":["type Dictionary<T = any> = { [key: string | number]: T }\n\nexport { Dictionary }\n"],"sourceRoot":"../../src"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* 不好分类的工具函数
|
|
4
|
+
*/
|
|
5
|
+
declare class CommonUtil {
|
|
6
|
+
/**
|
|
7
|
+
* 根据 buffer 生成 hash 值
|
|
8
|
+
*
|
|
9
|
+
* 用于唯一标识流内容,通常用于文件校验
|
|
10
|
+
* @param buffer
|
|
11
|
+
* @returns hash 值
|
|
12
|
+
*/
|
|
13
|
+
static calcDataDigest(buffer: Buffer): Buffer;
|
|
14
|
+
/**
|
|
15
|
+
* 从开发者项目的 node_module 中加载指定依赖;
|
|
16
|
+
* 如果不存在,提示下载;存在则返回加载的依赖
|
|
17
|
+
* @param packageName
|
|
18
|
+
*/
|
|
19
|
+
static requireModule(projectPath: string, packageName: string): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
export default CommonUtil;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ColorConsole2_1 = __importDefault(require("../ColorConsole2"));
|
|
10
|
+
const ILog_1 = require("../interface/ILog");
|
|
11
|
+
/**
|
|
12
|
+
* 不好分类的工具函数
|
|
13
|
+
*/
|
|
14
|
+
class CommonUtil {
|
|
15
|
+
/**
|
|
16
|
+
* 根据 buffer 生成 hash 值
|
|
17
|
+
*
|
|
18
|
+
* 用于唯一标识流内容,通常用于文件校验
|
|
19
|
+
* @param buffer
|
|
20
|
+
* @returns hash 值
|
|
21
|
+
*/
|
|
22
|
+
static calcDataDigest(buffer) {
|
|
23
|
+
const hash = crypto_1.default.createHash('SHA256');
|
|
24
|
+
hash.update(buffer);
|
|
25
|
+
return hash.digest();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 从开发者项目的 node_module 中加载指定依赖;
|
|
29
|
+
* 如果不存在,提示下载;存在则返回加载的依赖
|
|
30
|
+
* @param packageName
|
|
31
|
+
*/
|
|
32
|
+
static requireModule(projectPath, packageName) {
|
|
33
|
+
const modulePath = path_1.default.resolve(projectPath, `./node_modules/${packageName}`);
|
|
34
|
+
if (!fs_1.default.existsSync(modulePath)) {
|
|
35
|
+
return Promise.reject(new Error(ColorConsole2_1.default.createMessage({
|
|
36
|
+
word: packageName,
|
|
37
|
+
style: ColorConsole2_1.default.getStyle(ILog_1.LOG_LEVEL.Error)
|
|
38
|
+
}, 'is missing, run', {
|
|
39
|
+
word: `npm i ${packageName}`,
|
|
40
|
+
style: ColorConsole2_1.default.getStyle(ILog_1.LOG_LEVEL.Error)
|
|
41
|
+
}, 'to install it')));
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const module = require(modulePath);
|
|
45
|
+
return Promise.resolve(module);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return Promise.reject(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = CommonUtil;
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=CommonUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["utils/CommonUtil.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAE3B,4CAAmB;AACnB,gDAAuB;AACvB,qEAA4C;AAC5C,4CAA6C;AAC7C;;GAEG;AACH,MAAM,UAAU;IACd;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,MAAc;QAClC,MAAM,IAAI,GAAG,gBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACnB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,WAAmB,EAAE,WAAmB;QAC3D,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,kBAAkB,WAAW,EAAE,CAAC,CAAA;QAC7E,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;YAC9B,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,uBAAa,CAAC,aAAa,CACzB;gBACE,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,uBAAa,CAAC,QAAQ,CAAC,gBAAS,CAAC,KAAK,CAAC;aAC/C,EACD,iBAAiB,EACjB;gBACE,IAAI,EAAE,SAAS,WAAW,EAAE;gBAC5B,KAAK,EAAE,uBAAa,CAAC,QAAQ,CAAC,gBAAS,CAAC,KAAK,CAAC;aAC/C,EACD,eAAe,CAChB,CACF,CACF,CAAA;SACF;QACD,IAAI;YACF,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;YAClC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;SAC/B;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;SAC7B;IACH,CAAC;CACF;AACD,kBAAe,UAAU,CAAA","file":"CommonUtil.js","sourcesContent":["import crypto from 'crypto'\n\nimport Fs from 'fs'\nimport Path from 'path'\nimport ColorConsole2 from '../ColorConsole2'\nimport { LOG_LEVEL } from '../interface/ILog'\n/**\n * 不好分类的工具函数\n */\nclass CommonUtil {\n /**\n * 根据 buffer 生成 hash 值\n *\n * 用于唯一标识流内容,通常用于文件校验\n * @param buffer\n * @returns hash 值\n */\n static calcDataDigest(buffer: Buffer) {\n const hash = crypto.createHash('SHA256')\n hash.update(buffer)\n return hash.digest()\n }\n\n /**\n * 从开发者项目的 node_module 中加载指定依赖;\n * 如果不存在,提示下载;存在则返回加载的依赖\n * @param packageName\n */\n static requireModule(projectPath: string, packageName: string): Promise<any> {\n const modulePath = Path.resolve(projectPath, `./node_modules/${packageName}`)\n if (!Fs.existsSync(modulePath)) {\n return Promise.reject(\n new Error(\n ColorConsole2.createMessage(\n {\n word: packageName,\n style: ColorConsole2.getStyle(LOG_LEVEL.Error)\n },\n 'is missing, run',\n {\n word: `npm i ${packageName}`,\n style: ColorConsole2.getStyle(LOG_LEVEL.Error)\n },\n 'to install it'\n )\n )\n )\n }\n try {\n const module = require(modulePath)\n return Promise.resolve(module)\n } catch (error) {\n return Promise.reject(error)\n }\n }\n}\nexport default CommonUtil\n"],"sourceRoot":"../../src"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
type OneMatchType = string | RegExp | ((path: string) => boolean);
|
|
2
|
+
export type MatchType = OneMatchType | OneMatchType[];
|
|
3
|
+
/**
|
|
4
|
+
* FileUtil
|
|
5
|
+
*/
|
|
6
|
+
declare class FileUtil {
|
|
7
|
+
/**
|
|
8
|
+
* 判断字符串是否符合包含、不包含的条件
|
|
9
|
+
*
|
|
10
|
+
* 规则为:
|
|
11
|
+
* 1. 如果设置了不包含且匹配,则不包含
|
|
12
|
+
* 2. 否则,如果设置了包含且不匹配,则不包含
|
|
13
|
+
* 3. 否则,包含
|
|
14
|
+
* @param value
|
|
15
|
+
* @param include
|
|
16
|
+
* @param exclude
|
|
17
|
+
*/
|
|
18
|
+
static include(path: string, include?: MatchType, exclude?: MatchType): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 判断字符串是否匹配指定规则
|
|
21
|
+
* @param value
|
|
22
|
+
* @param matchType
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
static match(value: string, matchType: MatchType): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 获取指定目录所有层级的文件
|
|
28
|
+
* @param dir
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
static readAlldirSync(dir: string, includes?: MatchType, excludes?: MatchType): string[];
|
|
32
|
+
/**
|
|
33
|
+
* 替换文件内容
|
|
34
|
+
*
|
|
35
|
+
* @see replaceKeywords
|
|
36
|
+
* @param filePath
|
|
37
|
+
* @param keywordDic
|
|
38
|
+
*/
|
|
39
|
+
static replaceFileContent(filePath: string, keywordDic: Record<string, string>): void;
|
|
40
|
+
/**
|
|
41
|
+
* 替换字符串内容
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // 替换 abc{{value}} 为 abc123
|
|
45
|
+
* replaceKeywords(`abc{{value}}`, {value: '123'})
|
|
46
|
+
*
|
|
47
|
+
* @param content
|
|
48
|
+
* @param keywordDic
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
static replaceKeywords(content: string, keywordDic: Record<string, string>): string;
|
|
52
|
+
/**
|
|
53
|
+
* 更新文件路径
|
|
54
|
+
* @param path
|
|
55
|
+
* @param fullName
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
static updatePath(path: string, fullName: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* 复制文件
|
|
61
|
+
* @param sourceDir 源目录
|
|
62
|
+
* @param targetDir 目标目录
|
|
63
|
+
* @param excludes 不包含的文件
|
|
64
|
+
* @param includes 包含的文件
|
|
65
|
+
*/
|
|
66
|
+
static copyFiles(sourceDir: string, targetDir: string, excludes?: MatchType, includes?: MatchType): void;
|
|
67
|
+
/**
|
|
68
|
+
* 校验文件
|
|
69
|
+
* @param fileList
|
|
70
|
+
*/
|
|
71
|
+
static checkFilePath(fileList: string[]): boolean;
|
|
72
|
+
}
|
|
73
|
+
export default FileUtil;
|