@zwa73/utils 1.0.100 → 1.0.102

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/UtilCom.js CHANGED
@@ -85,7 +85,7 @@ var UtilCom;
85
85
  });
86
86
  }
87
87
  catch (err) {
88
- UtilLogger_1.SLogger.warn(funcName + " 未知错误:" + err);
88
+ UtilLogger_1.SLogger.warn(`${funcName} 未知错误:${err}`);
89
89
  resolve(null);
90
90
  return;
91
91
  }
@@ -48,9 +48,11 @@ export declare class UtilFunc {
48
48
  */
49
49
  static sleep<T>(timeMs: number, result: T): Promise<T>;
50
50
  /**封装的 cp.exec 执行一段指令 指令完成后返回 Promise
51
- * @param command 指令文本
51
+ * @param command - 指令文本
52
+ * @param outlvl - 普通输出的日志等级
53
+ * @param errlvl - 错误的日志等级
52
54
  */
53
- static exec(command: string): Promise<{
55
+ static exec(command: string, outlvl?: LogLevel, errlvl?: LogLevel): Promise<{
54
56
  stdout: string;
55
57
  stderr: string;
56
58
  }>;
@@ -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
  }
@@ -526,7 +533,7 @@ class UtilFunc {
526
533
  e.stack = [stackLines[0]].concat(stackLines.slice(2)).join('\n'); // 移除第一行的堆栈信息
527
534
  Object.assign(e, opt);
528
535
  if (lvl) {
529
- UtilLogger_1.SLogger.log(lvl, message);
536
+ //SLogger.log(lvl,message);
530
537
  UtilLogger_1.SLogger.log(lvl, e.stack);
531
538
  }
532
539
  throw e;
package/package.json CHANGED
@@ -1,40 +1,41 @@
1
1
  {
2
- "name": "@zwa73/utils",
3
- "version": "1.0.100",
4
- "description": "my utils",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "call npm run compile && jest",
8
- "postinstall": "start node ./scripts/postinstall.js",
9
- "release": "call npm run compile && call node release.js && call npm publish --access public",
10
- "compile": "call tsc -p tsconfig.compile.json && call tsc-alias -p tsconfig.compile.json",
11
- "watch": "start tsc-alias -w -p tsconfig.compile.json && start tsc -w -p tsconfig.compile.json"
12
- },
13
- "keywords": [
14
- "zwa73"
15
- ],
16
- "author": "zwa73",
17
- "license": "ISC",
18
- "dependencies": {
19
- "@types/fluent-ffmpeg": "^2.1.21",
20
- "esm": "^3.2.25",
21
- "esm-resolve": "^1.0.8",
22
- "fluent-ffmpeg": "^2.1.2",
23
- "glob": "^10.3.10",
24
- "html-entities": "^2.3.3",
25
- "http-proxy-agent": "^5.0.0",
26
- "https-proxy-agent": "^5.0.1",
27
- "json5": "^2.2.3",
28
- "tiktoken": "^1.0.7",
29
- "winston": "^3.10.0",
30
- "winston-daily-rotate-file": "^4.7.1"
31
- },
32
- "devDependencies": {
33
- "@types/jest": "^29.5.12",
34
- "@types/node": "^18.16.3",
35
- "jest": "^29.7.0",
36
- "ts-jest": "^29.1.2",
37
- "tsc-alias": "^1.8.8",
38
- "typescript": "^5.3.3"
39
- }
2
+ "name": "@zwa73/utils",
3
+ "version": "1.0.102",
4
+ "description": "my utils",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "call npm run compile && jest",
8
+ "postinstall": "start node ./scripts/postinstall.js",
9
+ "release": "call npm run compile && call node release.js && call npm publish --access public",
10
+ "compile": "powershell scripts/compile",
11
+ "watch": "powershell scripts/watch"
12
+ },
13
+ "keywords": [
14
+ "zwa73"
15
+ ],
16
+ "author": "zwa73",
17
+ "license": "ISC",
18
+ "dependencies": {
19
+ "@types/fluent-ffmpeg": "^2.1.21",
20
+ "esm": "^3.2.25",
21
+ "esm-resolve": "^1.0.8",
22
+ "fluent-ffmpeg": "^2.1.2",
23
+ "glob": "^10.3.10",
24
+ "html-entities": "^2.3.3",
25
+ "http-proxy-agent": "^5.0.0",
26
+ "https-proxy-agent": "^5.0.1",
27
+ "json5": "^2.2.3",
28
+ "tiktoken": "^1.0.7",
29
+ "winston": "^3.10.0",
30
+ "winston-daily-rotate-file": "^4.7.1"
31
+ },
32
+ "devDependencies": {
33
+ "@types/jest": "^29.5.12",
34
+ "@types/node": "^18.16.3",
35
+ "@zwa73/dev-utils": "^1.0.13",
36
+ "jest": "^29.7.0",
37
+ "ts-jest": "^29.1.2",
38
+ "tsc-alias": "^1.8.8",
39
+ "typescript": "^5.3.3"
40
+ }
40
41
  }
@@ -0,0 +1,5 @@
1
+ Write-Output 开始删除原dist
2
+ Remove-Item -Recurse -Force dist
3
+ Write-Output 开始编译
4
+ tsc -p tsconfig.compile.json
5
+ tsc-alias -p tsconfig.compile.json
@@ -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/UtilCom.ts CHANGED
@@ -66,7 +66,7 @@ function sPost(posttype:"http"|"https",json:JObject,options:Object,timeLimit:num
66
66
  }
67
67
  });
68
68
  }catch(err){
69
- SLogger.warn(funcName+" 未知错误:"+err);
69
+ SLogger.warn(`${funcName} 未知错误:${err}`);
70
70
  resolve(null);
71
71
  return;
72
72
  }
@@ -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
  }
@@ -592,7 +597,7 @@ static throwError(message:string,lvl?:LogLevel,opt?:{}):never{
592
597
  e.stack = [stackLines[0]].concat(stackLines.slice(2)).join('\n'); // 移除第一行的堆栈信息
593
598
  Object.assign(e, opt);
594
599
  if(lvl){
595
- SLogger.log(lvl,message);
600
+ //SLogger.log(lvl,message);
596
601
  SLogger.log(lvl,e.stack);
597
602
  }
598
603
  throw e;