@zwa73/utils 1.0.36 → 1.0.37

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.
@@ -42,4 +42,11 @@ export declare namespace UtilFunc {
42
42
  * @returns {Promise<boolean>}
43
43
  */
44
44
  function sleep(timeMs: number): Promise<boolean>;
45
+ /**封装的 cp.exec 执行一段指令 指令完成后返回 Promise
46
+ * @param {string} command 指令文本
47
+ */
48
+ function exec(command: string): Promise<{
49
+ stdout: string;
50
+ stderr: string;
51
+ }>;
45
52
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UtilFunc = void 0;
4
4
  const crypto = require("crypto");
5
+ const cp = require("child_process");
5
6
  /**常用函数 */
6
7
  var UtilFunc;
7
8
  (function (UtilFunc) {
@@ -77,4 +78,18 @@ var UtilFunc;
77
78
  });
78
79
  }
79
80
  UtilFunc.sleep = sleep;
81
+ /**封装的 cp.exec 执行一段指令 指令完成后返回 Promise
82
+ * @param {string} command 指令文本
83
+ */
84
+ function exec(command) {
85
+ return new Promise((resolve, reject) => {
86
+ cp.exec(command, (error, stdout, stderr) => {
87
+ if (error)
88
+ reject(error);
89
+ else
90
+ resolve({ stdout, stderr });
91
+ });
92
+ });
93
+ }
94
+ UtilFunc.exec = exec;
80
95
  })(UtilFunc = exports.UtilFunc || (exports.UtilFunc = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  import * as crypto from "crypto";
2
2
  import { JToken } from "./UtilInterfaces";
3
+ import * as cp from "child_process";
3
4
 
4
5
  /**常用函数 */
5
6
  export namespace UtilFunc{
@@ -74,5 +75,21 @@ export async function sleep(timeMs: number): Promise<boolean> {
74
75
  }, timeMs);
75
76
  });
76
77
  }
78
+
79
+ /**封装的 cp.exec 执行一段指令 指令完成后返回 Promise
80
+ * @param {string} command 指令文本
81
+ */
82
+ export function exec(command: string) {
83
+ return new Promise<{ stdout:string, stderr:string }>
84
+ ((resolve, reject) => {
85
+ cp.exec(command, (error, stdout, stderr) => {
86
+ if (error)
87
+ reject(error);
88
+ else
89
+ resolve({ stdout, stderr });
90
+ });
91
+ });
92
+ }
93
+
77
94
  }
78
95