@zwa73/utils 1.0.99 → 1.0.101
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/dist/QuickFunction.d.ts +1 -1
- package/dist/QuickFunction.js +2 -2
- package/dist/UtilClass.d.ts +0 -18
- package/dist/UtilClass.js +1 -27
- package/dist/UtilCom.js +1 -1
- package/dist/UtilDecorators.js +2 -4
- package/dist/UtilFileTools.js +1 -1
- package/dist/UtilFunctions.d.ts +11 -2
- package/dist/UtilFunctions.js +28 -7
- package/dist/UtilLogger.js +2 -2
- package/package.json +3 -3
- package/scripts/compile.ps1 +5 -0
- package/scripts/watch.ps1 +10 -0
- package/src/QuickFunction.ts +1 -0
- package/src/UtilClass.ts +0 -33
- package/src/UtilCom.ts +1 -1
- package/src/UtilDecorators.ts +2 -4
- package/src/UtilFileTools.ts +1 -1
- package/src/UtilFunctions.ts +27 -10
- package/src/UtilInterfaces.ts +0 -1
- package/src/UtilLogger.ts +2 -2
package/dist/QuickFunction.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UtilFunc } from "./UtilFunctions";
|
|
2
|
-
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, composeMixinable: typeof UtilFunc.composeMixinable, dedent: typeof UtilFunc.dedent;
|
|
2
|
+
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, composeMixinable: typeof UtilFunc.composeMixinable, dedent: typeof UtilFunc.dedent, throwError: typeof UtilFunc.throwError;
|
package/dist/QuickFunction.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dedent = exports.composeMixinable = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
|
|
3
|
+
exports.throwError = exports.dedent = exports.composeMixinable = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
|
|
4
4
|
const UtilFunctions_1 = require("./UtilFunctions");
|
|
5
5
|
const UtilSymbol_1 = require("./UtilSymbol");
|
|
6
|
-
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.composeMixinable = UtilFunctions_1.UtilFunc.composeMixinable, exports.dedent = UtilFunctions_1.UtilFunc.dedent;
|
|
6
|
+
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.composeMixinable = UtilFunctions_1.UtilFunc.composeMixinable, exports.dedent = UtilFunctions_1.UtilFunc.dedent, exports.throwError = UtilFunctions_1.UtilFunc.throwError;
|
|
7
7
|
if (false) {
|
|
8
8
|
let aaser = (0, exports.assertLiteral)({ a: 1 });
|
|
9
9
|
let a = null;
|
package/dist/UtilClass.d.ts
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
/**函数组合器 */
|
|
2
|
-
export declare class Composer<Result, PreArg = Result> {
|
|
3
|
-
/**组合函数列表 */
|
|
4
|
-
private funcs;
|
|
5
|
-
private constructor();
|
|
6
|
-
/**添加单个参数与返回值不同的函数 */
|
|
7
|
-
static push<Result, Arg>(func: (arg: Arg) => Result): Composer<Result, Arg>;
|
|
8
|
-
/**添加多个参数与返回值相同的函数 */
|
|
9
|
-
static push<Result>(func: ((arg: Result) => Result), ...funcs: ((arg: Result) => Result)[]): Composer<Result>;
|
|
10
|
-
/**添加单个参数与返回值不同的函数 */
|
|
11
|
-
push<T>(func: (arg: T) => PreArg): Composer<Result, T>;
|
|
12
|
-
/**添加多个参数与返回值相同的函数 */
|
|
13
|
-
push(func: ((arg: Result) => Result), ...funcs: ((arg: PreArg) => PreArg)[]): Composer<Result, PreArg>;
|
|
14
|
-
/**组合函数 */
|
|
15
|
-
compose(): (arg: PreArg) => Result;
|
|
16
|
-
/**直接调用 */
|
|
17
|
-
invoke(arg: PreArg): Result;
|
|
18
|
-
}
|
|
19
1
|
/**函数管道器 */
|
|
20
2
|
export declare class Piper<Arg, Result = Arg> {
|
|
21
3
|
/**管道函数列表 */
|
package/dist/UtilClass.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Stream = exports.Piper =
|
|
4
|
-
/**函数组合器 */
|
|
5
|
-
class Composer {
|
|
6
|
-
/**组合函数列表 */
|
|
7
|
-
funcs = [];
|
|
8
|
-
constructor() { }
|
|
9
|
-
;
|
|
10
|
-
static push(...funcs) {
|
|
11
|
-
const newComposer = new Composer();
|
|
12
|
-
newComposer.funcs = [...funcs];
|
|
13
|
-
return newComposer;
|
|
14
|
-
}
|
|
15
|
-
push(...funcs) {
|
|
16
|
-
const newComposer = new Composer();
|
|
17
|
-
newComposer.funcs = [...this.funcs, ...funcs];
|
|
18
|
-
return newComposer;
|
|
19
|
-
}
|
|
20
|
-
/**组合函数 */
|
|
21
|
-
compose() {
|
|
22
|
-
return (arg) => this.funcs.reduceRight((value, func) => func(value), arg);
|
|
23
|
-
}
|
|
24
|
-
/**直接调用 */
|
|
25
|
-
invoke(arg) {
|
|
26
|
-
return this.funcs.reduceRight((value, func) => func(value), arg);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.Composer = Composer;
|
|
3
|
+
exports.Stream = exports.Piper = void 0;
|
|
30
4
|
/**函数管道器 */
|
|
31
5
|
class Piper {
|
|
32
6
|
/**管道函数列表 */
|
package/dist/UtilCom.js
CHANGED
package/dist/UtilDecorators.js
CHANGED
|
@@ -84,8 +84,7 @@ function LogErr() {
|
|
|
84
84
|
return result;
|
|
85
85
|
}
|
|
86
86
|
catch (err) {
|
|
87
|
-
|
|
88
|
-
throw err;
|
|
87
|
+
UtilFunctions_1.UtilFunc.throwError(`函数出现错误: ${propertyKey}(${args}): ${err}`, 'warn');
|
|
89
88
|
}
|
|
90
89
|
};
|
|
91
90
|
return descriptor;
|
|
@@ -102,8 +101,7 @@ function LogErrAsync() {
|
|
|
102
101
|
return result;
|
|
103
102
|
}
|
|
104
103
|
catch (err) {
|
|
105
|
-
|
|
106
|
-
throw err;
|
|
104
|
+
UtilFunctions_1.UtilFunc.throwError(`函数出现错误: ${propertyKey}(${args}): ${err}`, 'warn');
|
|
107
105
|
}
|
|
108
106
|
};
|
|
109
107
|
return descriptor;
|
package/dist/UtilFileTools.js
CHANGED
|
@@ -227,7 +227,7 @@ var UtilFT;
|
|
|
227
227
|
* @deprecated 请使用 fileSearchRegex 或 fileSearchGlob
|
|
228
228
|
*/
|
|
229
229
|
function fileSearch(...patams) {
|
|
230
|
-
|
|
230
|
+
UtilFunctions_1.UtilFunc.throwError("请使用 fileSearchRegex 或 fileSearchGlob", 'fatal');
|
|
231
231
|
}
|
|
232
232
|
UtilFT.fileSearch = fileSearch;
|
|
233
233
|
/**是一个有效的文件路径
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AnyFunc, ComposedClass, ComposedMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, LiteralCheck, Matchable, MatchableFlag, Mixinable, Outcome, PromiseVerifyFn, UnionToIntersection } from "./UtilInterfaces";
|
|
2
|
+
import { LogLevel } from "./UtilLogger";
|
|
2
3
|
import { FailedLike, None, StatusSymbol, Success, SuccessLike, Timeout } from "./UtilSymbol";
|
|
3
4
|
type SuccessOut<T> = Outcome<Success, T>;
|
|
4
5
|
type TimeoutOut<T> = Outcome<Timeout, Promise<T>>;
|
|
@@ -47,9 +48,11 @@ export declare class UtilFunc {
|
|
|
47
48
|
*/
|
|
48
49
|
static sleep<T>(timeMs: number, result: T): Promise<T>;
|
|
49
50
|
/**封装的 cp.exec 执行一段指令 指令完成后返回 Promise
|
|
50
|
-
* @param command 指令文本
|
|
51
|
+
* @param command - 指令文本
|
|
52
|
+
* @param outlvl - 普通输出的日志等级
|
|
53
|
+
* @param errlvl - 错误的日志等级
|
|
51
54
|
*/
|
|
52
|
-
static exec(command: string): Promise<{
|
|
55
|
+
static exec(command: string, outlvl?: LogLevel, errlvl?: LogLevel): Promise<{
|
|
53
56
|
stdout: string;
|
|
54
57
|
stderr: string;
|
|
55
58
|
}>;
|
|
@@ -190,5 +193,11 @@ export declare class UtilFunc {
|
|
|
190
193
|
* // World!
|
|
191
194
|
*/
|
|
192
195
|
static dedent(strings: TemplateStringsArray, ...values: any[]): string;
|
|
196
|
+
/**抛出错误
|
|
197
|
+
* @param message - 错误信息
|
|
198
|
+
* @param lvl - 日志等级
|
|
199
|
+
* @param opt - 额外参数
|
|
200
|
+
*/
|
|
201
|
+
static throwError(message: string, lvl?: LogLevel, opt?: {}): never;
|
|
193
202
|
}
|
|
194
203
|
export {};
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -102,15 +102,22 @@ class UtilFunc {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
/**封装的 cp.exec 执行一段指令 指令完成后返回 Promise
|
|
105
|
-
* @param command 指令文本
|
|
105
|
+
* @param command - 指令文本
|
|
106
|
+
* @param outlvl - 普通输出的日志等级
|
|
107
|
+
* @param errlvl - 错误的日志等级
|
|
106
108
|
*/
|
|
107
|
-
static exec(command) {
|
|
109
|
+
static exec(command, outlvl, errlvl) {
|
|
108
110
|
return new Promise((resolve, reject) => {
|
|
109
111
|
cp.exec(command, (error, stdout, stderr) => {
|
|
110
112
|
if (error)
|
|
111
113
|
reject(error);
|
|
112
|
-
else
|
|
114
|
+
else {
|
|
115
|
+
if (stdout && outlvl)
|
|
116
|
+
UtilLogger_1.SLogger.log(outlvl, stdout);
|
|
117
|
+
if (stderr && errlvl)
|
|
118
|
+
UtilLogger_1.SLogger.log(errlvl, stderr);
|
|
113
119
|
resolve({ stdout, stderr });
|
|
120
|
+
}
|
|
114
121
|
});
|
|
115
122
|
});
|
|
116
123
|
}
|
|
@@ -389,9 +396,7 @@ class UtilFunc {
|
|
|
389
396
|
}
|
|
390
397
|
else if (procObj[t.status])
|
|
391
398
|
return procObj[t.status](t.status, t.result);
|
|
392
|
-
|
|
393
|
-
UtilLogger_1.SLogger.fatal(err);
|
|
394
|
-
throw err;
|
|
399
|
+
UtilFunc.throwError(`matchProc 传入了一个预料之外的值: ${String(t)}`, 'fatal');
|
|
395
400
|
}
|
|
396
401
|
/**根据典型的成功或失败状态运行函数
|
|
397
402
|
* @param t - 目标值
|
|
@@ -449,7 +454,7 @@ class UtilFunc {
|
|
|
449
454
|
*/
|
|
450
455
|
static expect(t, errLog) {
|
|
451
456
|
if (t === UtilSymbol_1.None)
|
|
452
|
-
|
|
457
|
+
UtilFunc.throwError(errLog ?? "expect验证了一个None值", "error");
|
|
453
458
|
return t;
|
|
454
459
|
}
|
|
455
460
|
/**验证一个变量的类型是否为 T
|
|
@@ -517,6 +522,22 @@ class UtilFunc {
|
|
|
517
522
|
const minIndent = Math.min(...lines.filter(line => line.trim() !== '').map(line => line.search(/\S/)));
|
|
518
523
|
return lines.map(line => line.slice(minIndent)).join('\n');
|
|
519
524
|
}
|
|
525
|
+
/**抛出错误
|
|
526
|
+
* @param message - 错误信息
|
|
527
|
+
* @param lvl - 日志等级
|
|
528
|
+
* @param opt - 额外参数
|
|
529
|
+
*/
|
|
530
|
+
static throwError(message, lvl, opt) {
|
|
531
|
+
const e = new Error(message);
|
|
532
|
+
const stackLines = e.stack.split('\n');
|
|
533
|
+
e.stack = [stackLines[0]].concat(stackLines.slice(2)).join('\n'); // 移除第一行的堆栈信息
|
|
534
|
+
Object.assign(e, opt);
|
|
535
|
+
if (lvl) {
|
|
536
|
+
//SLogger.log(lvl,message);
|
|
537
|
+
UtilLogger_1.SLogger.log(lvl, e.stack);
|
|
538
|
+
}
|
|
539
|
+
throw e;
|
|
540
|
+
}
|
|
520
541
|
}
|
|
521
542
|
exports.UtilFunc = UtilFunc;
|
|
522
543
|
__decorate([
|
package/dist/UtilLogger.js
CHANGED
|
@@ -234,7 +234,7 @@ class SLogger {
|
|
|
234
234
|
* @returns 格式化的时间字符串
|
|
235
235
|
*/
|
|
236
236
|
timeEnd(flag, level = "info") {
|
|
237
|
-
|
|
237
|
+
const start = SLogger.timeTable[flag];
|
|
238
238
|
if (start == null) {
|
|
239
239
|
this.warn("SLogger.timeEnd 错误 flag:" + flag + " 不存在");
|
|
240
240
|
return null;
|
|
@@ -304,7 +304,7 @@ class SLogger {
|
|
|
304
304
|
* @returns 自身
|
|
305
305
|
*/
|
|
306
306
|
static log(level, ...messages) {
|
|
307
|
-
level = level
|
|
307
|
+
level = level ?? "silly";
|
|
308
308
|
this.defaultInstance.log(level, ...messages);
|
|
309
309
|
return this.defaultInstance;
|
|
310
310
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.101",
|
|
4
4
|
"description": "my utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "call npm run compile && jest",
|
|
8
8
|
"postinstall": "start node ./scripts/postinstall.js",
|
|
9
9
|
"release": "call npm run compile && call node release.js && call npm publish --access public",
|
|
10
|
-
"compile": "
|
|
11
|
-
"watch": "
|
|
10
|
+
"compile": "powershell scripts/compile",
|
|
11
|
+
"watch": "powershell scripts/watch"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"zwa73"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# 定义一个函数来运行脚本
|
|
2
|
+
function New-Script {
|
|
3
|
+
param($command)
|
|
4
|
+
# 在后台运行命令
|
|
5
|
+
Start-Process -NoNewWindow -FilePath "powershell" -ArgumentList "-Command", $command
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
# 开始运行脚本
|
|
9
|
+
New-Script "tsc -w -p tsconfig.compile.json"
|
|
10
|
+
New-Script "tsc-alias -w -p tsconfig.compile.json"
|
package/src/QuickFunction.ts
CHANGED
package/src/UtilClass.ts
CHANGED
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
/**函数组合器 */
|
|
2
|
-
export class Composer<Result,PreArg = Result> {
|
|
3
|
-
/**组合函数列表 */
|
|
4
|
-
private funcs: Function[] = [];
|
|
5
|
-
private constructor(){};
|
|
6
|
-
/**添加单个参数与返回值不同的函数 */
|
|
7
|
-
public static push<Result,Arg>(func: (arg: Arg) => Result): Composer<Result,Arg>;
|
|
8
|
-
/**添加多个参数与返回值相同的函数 */
|
|
9
|
-
public static push<Result>(func:((arg: Result) => Result), ...funcs: ((arg: Result) => Result)[]): Composer<Result>;
|
|
10
|
-
public static push(...funcs: Function[]){
|
|
11
|
-
const newComposer = new Composer<any>();
|
|
12
|
-
newComposer.funcs = [...funcs];
|
|
13
|
-
return newComposer;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**添加单个参数与返回值不同的函数 */
|
|
17
|
-
public push<T>(func: (arg: T) => PreArg): Composer<Result,T>;
|
|
18
|
-
/**添加多个参数与返回值相同的函数 */
|
|
19
|
-
public push(func:((arg: Result) => Result), ...funcs: ((arg: PreArg) => PreArg)[]): Composer<Result,PreArg>;
|
|
20
|
-
public push(...funcs: Function[]): Composer<Result,any> {
|
|
21
|
-
const newComposer = new Composer<Result>();
|
|
22
|
-
newComposer.funcs = [...this.funcs, ...funcs];
|
|
23
|
-
return newComposer;
|
|
24
|
-
}
|
|
25
|
-
/**组合函数 */
|
|
26
|
-
public compose():(arg:PreArg)=>Result {
|
|
27
|
-
return (arg:PreArg) => this.funcs.reduceRight((value, func) => func(value), arg) as any as Result;
|
|
28
|
-
}
|
|
29
|
-
/**直接调用 */
|
|
30
|
-
public invoke(arg:PreArg):Result {
|
|
31
|
-
return this.funcs.reduceRight((value, func) => func(value), arg) as any as Result;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
1
|
/**函数管道器 */
|
|
35
2
|
export class Piper<Arg, Result = Arg> {
|
|
36
3
|
/**管道函数列表 */
|
package/src/UtilCom.ts
CHANGED
package/src/UtilDecorators.ts
CHANGED
|
@@ -78,8 +78,7 @@ export function LogErr():DTg{
|
|
|
78
78
|
const result = originalMethod.apply(this, args);
|
|
79
79
|
return result;
|
|
80
80
|
} catch(err) {
|
|
81
|
-
|
|
82
|
-
throw err;
|
|
81
|
+
UtilFunc.throwError(`函数出现错误: ${propertyKey}(${args}): ${err}`,'warn');
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
return descriptor;
|
|
@@ -95,8 +94,7 @@ export function LogErrAsync():DTg{
|
|
|
95
94
|
const result = await originalMethod.apply(this, args);
|
|
96
95
|
return result;
|
|
97
96
|
} catch(err) {
|
|
98
|
-
|
|
99
|
-
throw err;
|
|
97
|
+
UtilFunc.throwError(`函数出现错误: ${propertyKey}(${args}): ${err}`,'warn');
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
return descriptor;
|
package/src/UtilFileTools.ts
CHANGED
|
@@ -231,7 +231,7 @@ export function fileSearchGlob(globPattern:string|string[],ignore?:string|string
|
|
|
231
231
|
* @deprecated 请使用 fileSearchRegex 或 fileSearchGlob
|
|
232
232
|
*/
|
|
233
233
|
export function fileSearch(...patams:any[]){
|
|
234
|
-
|
|
234
|
+
UtilFunc.throwError("请使用 fileSearchRegex 或 fileSearchGlob",'fatal');
|
|
235
235
|
}
|
|
236
236
|
/**是一个有效的文件路径
|
|
237
237
|
* @param filePath - 需要验证的文件路径
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as crypto from "crypto";
|
|
2
2
|
import { AnyFunc, ComposedClass, ComposedMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, LiteralCheck, Matchable, MatchableFlag, Mixinable, Outcome, PromiseStat, PromiseVerifyFn, UnionToIntersection } from "@src/UtilInterfaces";
|
|
3
3
|
import * as cp from "child_process";
|
|
4
|
-
import { SLogger } from "@src/UtilLogger";
|
|
4
|
+
import { LogLevel, SLogger } from "@src/UtilLogger";
|
|
5
5
|
import { Completed, Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Terminated, Timeout } from "./UtilSymbol";
|
|
6
6
|
import { Catch, DeferAsync, LogTimeAsync } from "./UtilDecorators";
|
|
7
7
|
|
|
@@ -102,16 +102,21 @@ static async sleep<T>(timeMs: number, result?:T): Promise<T|undefined> {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**封装的 cp.exec 执行一段指令 指令完成后返回 Promise
|
|
105
|
-
* @param command 指令文本
|
|
105
|
+
* @param command - 指令文本
|
|
106
|
+
* @param outlvl - 普通输出的日志等级
|
|
107
|
+
* @param errlvl - 错误的日志等级
|
|
106
108
|
*/
|
|
107
|
-
static exec(command: string) {
|
|
109
|
+
static exec(command: string,outlvl?:LogLevel,errlvl?:LogLevel) {
|
|
108
110
|
return new Promise<{ stdout:string, stderr:string }>
|
|
109
111
|
((resolve, reject) => {
|
|
110
112
|
cp.exec(command, (error, stdout, stderr) => {
|
|
111
113
|
if (error)
|
|
112
114
|
reject(error);
|
|
113
|
-
else
|
|
115
|
+
else{
|
|
116
|
+
if(stdout && outlvl) SLogger.log(outlvl,stdout);
|
|
117
|
+
if(stderr && errlvl) SLogger.log(errlvl,stderr);
|
|
114
118
|
resolve({ stdout, stderr });
|
|
119
|
+
}
|
|
115
120
|
});
|
|
116
121
|
});
|
|
117
122
|
}
|
|
@@ -437,10 +442,7 @@ static matchProc<
|
|
|
437
442
|
}
|
|
438
443
|
else if ((procObj as any)[t.status])
|
|
439
444
|
return (procObj as any)[t.status](t.status,(t as any).result);
|
|
440
|
-
|
|
441
|
-
const err = new Error(`matchProc 传入了一个预料之外的值: ${String(t)}`);
|
|
442
|
-
SLogger.fatal(err);
|
|
443
|
-
throw err;
|
|
445
|
+
UtilFunc.throwError(`matchProc 传入了一个预料之外的值: ${String(t)}`,'fatal');
|
|
444
446
|
}
|
|
445
447
|
|
|
446
448
|
/**根据典型的成功或失败状态运行函数
|
|
@@ -509,7 +511,7 @@ static likeNone(t:unknown,strictLog=true):t is None{
|
|
|
509
511
|
* @returns 排除None的原值
|
|
510
512
|
*/
|
|
511
513
|
static expect<T>(t:T,errLog?:string):Exclude<T,None>{
|
|
512
|
-
if(t===None)
|
|
514
|
+
if(t===None) UtilFunc.throwError(errLog??"expect验证了一个None值","error");
|
|
513
515
|
return t as Exclude<T,None>;
|
|
514
516
|
}
|
|
515
517
|
|
|
@@ -584,6 +586,21 @@ static dedent(strings: TemplateStringsArray, ...values: any[]): string {
|
|
|
584
586
|
);
|
|
585
587
|
return lines.map(line => line.slice(minIndent)).join('\n');
|
|
586
588
|
}
|
|
587
|
-
|
|
589
|
+
/**抛出错误
|
|
590
|
+
* @param message - 错误信息
|
|
591
|
+
* @param lvl - 日志等级
|
|
592
|
+
* @param opt - 额外参数
|
|
593
|
+
*/
|
|
594
|
+
static throwError(message:string,lvl?:LogLevel,opt?:{}):never{
|
|
595
|
+
const e = new Error(message);
|
|
596
|
+
const stackLines = e.stack!.split('\n');
|
|
597
|
+
e.stack = [stackLines[0]].concat(stackLines.slice(2)).join('\n'); // 移除第一行的堆栈信息
|
|
598
|
+
Object.assign(e, opt);
|
|
599
|
+
if(lvl){
|
|
600
|
+
//SLogger.log(lvl,message);
|
|
601
|
+
SLogger.log(lvl,e.stack);
|
|
602
|
+
}
|
|
603
|
+
throw e;
|
|
604
|
+
}
|
|
588
605
|
|
|
589
606
|
}
|
package/src/UtilInterfaces.ts
CHANGED
package/src/UtilLogger.ts
CHANGED
|
@@ -226,7 +226,7 @@ export class SLogger{
|
|
|
226
226
|
* @returns 格式化的时间字符串
|
|
227
227
|
*/
|
|
228
228
|
timeEnd(flag:string,level:LogLevel|null="info"):string|null{
|
|
229
|
-
|
|
229
|
+
const start = SLogger.timeTable[flag];
|
|
230
230
|
if(start==null){
|
|
231
231
|
this.warn("SLogger.timeEnd 错误 flag:"+flag+" 不存在");
|
|
232
232
|
return null;
|
|
@@ -304,7 +304,7 @@ export class SLogger{
|
|
|
304
304
|
* @returns 自身
|
|
305
305
|
*/
|
|
306
306
|
static log(level: LogLevel, ...messages:Array<any>):SLogger{
|
|
307
|
-
level = level
|
|
307
|
+
level = level??"silly";
|
|
308
308
|
this.defaultInstance.log(level,...messages);
|
|
309
309
|
return this.defaultInstance;
|
|
310
310
|
}
|