soda-nodejs 0.4.2 → 0.5.0

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.
@@ -1,22 +1,38 @@
1
1
  /// <reference types="node" />
2
- import { SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe } from "child_process";
3
- export declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>;
4
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>;
5
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>;
6
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>;
7
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>;
8
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>;
9
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>;
10
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>;
11
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>;
12
- export declare function spawnAsync(command: string, options: SpawnOptions): Promise<void>;
13
- export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>;
14
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>;
15
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>;
16
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>;
17
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>;
18
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>;
19
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>;
20
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>;
21
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>;
22
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>;
2
+ /// <reference types="node" />
3
+ import { ChildProcess, ChildProcessByStdio, ChildProcessWithoutNullStreams, SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe } from "child_process";
4
+ import { Readable, Writable } from "stream";
5
+ export interface PromiseWithChildProcess<T> extends Promise<T> {
6
+ child: T;
7
+ }
8
+ export type Options = SpawnOptionsWithoutStdio | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull> | SpawnOptions;
9
+ /**
10
+ * @description get default options for spawnAsync
11
+ * @returns {Options} options
12
+ */
13
+ export declare function getDefaultOptions(): Options;
14
+ /**
15
+ * @description set default options for spawnAsync
16
+ * @param {Options | ((prev: Options) => Options)} options
17
+ */
18
+ export declare function setDefaultOptions(options: Options | ((prev: Options) => Options)): SpawnOptions | undefined;
19
+ export declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
20
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
21
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
22
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
23
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
24
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
25
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
26
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
27
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
28
+ export declare function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
29
+ export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
30
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
31
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
32
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
33
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
34
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
35
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
36
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
37
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
38
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
@@ -19,24 +19,46 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/utils/spawnAsync.ts
20
20
  var spawnAsync_exports = {};
21
21
  __export(spawnAsync_exports, {
22
+ getDefaultOptions: () => getDefaultOptions,
23
+ setDefaultOptions: () => setDefaultOptions,
22
24
  spawnAsync: () => spawnAsync
23
25
  });
24
26
  module.exports = __toCommonJS(spawnAsync_exports);
25
27
  var import_child_process = require("child_process");
26
- async function spawnAsync(command, args, options) {
27
- await new Promise((resolve, reject) => {
28
+ var defaultOptions = {};
29
+ function getDefaultOptions() {
30
+ return defaultOptions;
31
+ }
32
+ function setDefaultOptions(options) {
33
+ if (typeof options === "function") {
34
+ defaultOptions = options(defaultOptions);
35
+ return;
36
+ }
37
+ defaultOptions = options;
38
+ return defaultOptions;
39
+ }
40
+ function spawnAsync(command, args, options) {
41
+ const promise = new Promise((resolve, reject) => {
42
+ if (Array.isArray(args))
43
+ options = { ...defaultOptions, ...options };
44
+ else
45
+ args = { ...defaultOptions, ...args };
28
46
  const child = (0, import_child_process.spawn)(command, args, options);
47
+ promise.child = child;
29
48
  child.on("exit", (code) => {
30
- if (code !== 0) {
31
- reject(new Error(`"${command}" Command failed with code ${code}`));
32
- return;
33
- }
34
- resolve();
49
+ if (code === 0)
50
+ return resolve(child);
51
+ console.error(`"${command}" Command failed with code ${code}`);
52
+ reject(new Error(`"${command}" Command failed with code ${code}`));
53
+ return;
35
54
  });
36
55
  });
56
+ return promise;
37
57
  }
38
58
  // Annotate the CommonJS export names for ESM import in node:
39
59
  0 && (module.exports = {
60
+ getDefaultOptions,
61
+ setDefaultOptions,
40
62
  spawnAsync
41
63
  });
42
64
  //# sourceMappingURL=spawnAsync.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/spawnAsync.ts"],
4
- "sourcesContent": ["import { SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe, spawn } from \"child_process\"\n\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptions): Promise<void>\nexport function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>\nexport async function spawnAsync(command: string, args?: any, options?: any) {\n await new Promise<void>((resolve, reject) => {\n const child = spawn(command, args, options)\n child.on(\"exit\", code => {\n if (code !== 0) {\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\n return\n }\n resolve()\n })\n })\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAgH;AAsBhH,eAAsB,WAAW,SAAiB,MAAY,SAAe;AACzE,QAAM,IAAI,QAAc,CAAC,SAAS,WAAW;AACzC,UAAM,YAAQ,4BAAM,SAAS,MAAM,OAAO;AAC1C,UAAM,GAAG,QAAQ,UAAQ;AACrB,UAAI,SAAS,GAAG;AACZ,eAAO,IAAI,MAAM,IAAI,qCAAqC,MAAM,CAAC;AACjE;AAAA,MACJ;AACA,cAAQ;AAAA,IACZ,CAAC;AAAA,EACL,CAAC;AACL;",
4
+ "sourcesContent": ["import {\n ChildProcess,\n ChildProcessByStdio,\n ChildProcessWithoutNullStreams,\n SpawnOptions,\n SpawnOptionsWithStdioTuple,\n SpawnOptionsWithoutStdio,\n StdioNull,\n StdioPipe,\n spawn,\n} from \"child_process\"\nimport { Readable, Writable } from \"stream\"\n\nexport interface PromiseWithChildProcess<T> extends Promise<T> {\n child: T\n}\n\nexport type Options =\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n\nlet defaultOptions: Options = {}\n\n/**\n * @description get default options for spawnAsync\n * @returns {Options} options\n */\nexport function getDefaultOptions(): Options {\n return defaultOptions\n}\n\n/**\n * @description set default options for spawnAsync\n * @param {Options | ((prev: Options) => Options)} options\n */\nexport function setDefaultOptions(options: Options | ((prev: Options) => Options)) {\n if (typeof options === \"function\") {\n defaultOptions = options(defaultOptions)\n return\n }\n defaultOptions = options\n return defaultOptions\n}\n\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\nexport function spawnAsync(\n command: string,\n args?: readonly string[],\n options?: SpawnOptionsWithoutStdio,\n): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\n\n/**\n * @description wait for the command to exit\n * @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.\n */\nexport function spawnAsync(command: string, args?: any, options?: any): Promise<any> {\n const promise = new Promise<any>((resolve, reject) => {\n if (Array.isArray(args)) options = { ...defaultOptions, ...options }\n else args = { ...defaultOptions, ...args }\n const child = spawn(command, args, options)\n promise.child = child\n child.on(\"exit\", code => {\n if (code === 0) return resolve(child)\n console.error(`\"${command}\" Command failed with code ${code}`)\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\n return\n })\n }) as PromiseWithChildProcess<any>\n return promise\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAUO;AAmBP,IAAI,iBAA0B,CAAC;AAMxB,SAAS,oBAA6B;AACzC,SAAO;AACX;AAMO,SAAS,kBAAkB,SAAiD;AAC/E,MAAI,OAAO,YAAY,YAAY;AAC/B,qBAAiB,QAAQ,cAAc;AACvC;AAAA,EACJ;AACA,mBAAiB;AACjB,SAAO;AACX;AAuFO,SAAS,WAAW,SAAiB,MAAY,SAA6B;AACjF,QAAM,UAAU,IAAI,QAAa,CAAC,SAAS,WAAW;AAClD,QAAI,MAAM,QAAQ,IAAI;AAAG,gBAAU,EAAE,GAAG,gBAAgB,GAAG,QAAQ;AAAA;AAC9D,aAAO,EAAE,GAAG,gBAAgB,GAAG,KAAK;AACzC,UAAM,YAAQ,4BAAM,SAAS,MAAM,OAAO;AAC1C,YAAQ,QAAQ;AAChB,UAAM,GAAG,QAAQ,UAAQ;AACrB,UAAI,SAAS;AAAG,eAAO,QAAQ,KAAK;AACpC,cAAQ,MAAM,IAAI,qCAAqC,MAAM;AAC7D,aAAO,IAAI,MAAM,IAAI,qCAAqC,MAAM,CAAC;AACjE;AAAA,IACJ,CAAC;AAAA,EACL,CAAC;AACD,SAAO;AACX;",
6
6
  "names": []
7
7
  }
@@ -1,22 +1,38 @@
1
1
  /// <reference types="node" />
2
- import { SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe } from "child_process";
3
- export declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>;
4
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>;
5
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>;
6
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>;
7
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>;
8
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>;
9
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>;
10
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>;
11
- export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>;
12
- export declare function spawnAsync(command: string, options: SpawnOptions): Promise<void>;
13
- export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>;
14
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>;
15
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>;
16
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>;
17
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>;
18
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>;
19
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>;
20
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>;
21
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>;
22
- export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>;
2
+ /// <reference types="node" />
3
+ import { ChildProcess, ChildProcessByStdio, ChildProcessWithoutNullStreams, SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe } from "child_process";
4
+ import { Readable, Writable } from "stream";
5
+ export interface PromiseWithChildProcess<T> extends Promise<T> {
6
+ child: T;
7
+ }
8
+ export type Options = SpawnOptionsWithoutStdio | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull> | SpawnOptions;
9
+ /**
10
+ * @description get default options for spawnAsync
11
+ * @returns {Options} options
12
+ */
13
+ export declare function getDefaultOptions(): Options;
14
+ /**
15
+ * @description set default options for spawnAsync
16
+ * @param {Options | ((prev: Options) => Options)} options
17
+ */
18
+ export declare function setDefaultOptions(options: Options | ((prev: Options) => Options)): SpawnOptions | undefined;
19
+ export declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
20
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
21
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
22
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
23
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
24
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
25
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
26
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
27
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
28
+ export declare function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
29
+ export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
30
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
31
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
32
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
33
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
34
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
35
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
36
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
37
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
38
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
@@ -1,14 +1,48 @@
1
1
  import { spawn } from "child_process";
2
- export async function spawnAsync(command, args, options) {
3
- await new Promise((resolve, reject) => {
2
+ let defaultOptions = {};
3
+
4
+ /**
5
+ * @description get default options for spawnAsync
6
+ * @returns {Options} options
7
+ */
8
+ export function getDefaultOptions() {
9
+ return defaultOptions;
10
+ }
11
+
12
+ /**
13
+ * @description set default options for spawnAsync
14
+ * @param {Options | ((prev: Options) => Options)} options
15
+ */
16
+ export function setDefaultOptions(options) {
17
+ if (typeof options === "function") {
18
+ defaultOptions = options(defaultOptions);
19
+ return;
20
+ }
21
+ defaultOptions = options;
22
+ return defaultOptions;
23
+ }
24
+ /**
25
+ * @description wait for the command to exit
26
+ * @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.
27
+ */
28
+ export function spawnAsync(command, args, options) {
29
+ const promise = new Promise((resolve, reject) => {
30
+ if (Array.isArray(args)) options = {
31
+ ...defaultOptions,
32
+ ...options
33
+ };else args = {
34
+ ...defaultOptions,
35
+ ...args
36
+ };
4
37
  const child = spawn(command, args, options);
38
+ promise.child = child;
5
39
  child.on("exit", code => {
6
- if (code !== 0) {
7
- reject(new Error(`"${command}" Command failed with code ${code}`));
8
- return;
9
- }
10
- resolve();
40
+ if (code === 0) return resolve(child);
41
+ console.error(`"${command}" Command failed with code ${code}`);
42
+ reject(new Error(`"${command}" Command failed with code ${code}`));
43
+ return;
11
44
  });
12
45
  });
46
+ return promise;
13
47
  }
14
48
  //# sourceMappingURL=spawnAsync.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["spawn","spawnAsync","command","args","options","Promise","resolve","reject","child","on","code","Error"],"sources":["../../../src/utils/spawnAsync.ts"],"sourcesContent":["import { SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe, spawn } from \"child_process\"\n\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, options: SpawnOptions): Promise<void>\nexport function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>\nexport async function spawnAsync(command: string, args?: any, options?: any) {\n await new Promise<void>((resolve, reject) => {\n const child = spawn(command, args, options)\n child.on(\"exit\", code => {\n if (code !== 0) {\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\n return\n }\n resolve()\n })\n })\n}\n"],"mappings":"AAAA,SAAmGA,KAAK,QAAQ,eAAe;AAsB/H,OAAO,eAAeC,UAAUA,CAACC,OAAe,EAAEC,IAAU,EAAEC,OAAa,EAAE;EACzE,MAAM,IAAIC,OAAO,CAAO,CAACC,OAAO,EAAEC,MAAM,KAAK;IACzC,MAAMC,KAAK,GAAGR,KAAK,CAACE,OAAO,EAAEC,IAAI,EAAEC,OAAO,CAAC;IAC3CI,KAAK,CAACC,EAAE,CAAC,MAAM,EAAEC,IAAI,IAAI;MACrB,IAAIA,IAAI,KAAK,CAAC,EAAE;QACZH,MAAM,CAAC,IAAII,KAAK,CAAE,IAAGT,OAAQ,8BAA6BQ,IAAK,EAAC,CAAC,CAAC;QAClE;MACJ;MACAJ,OAAO,CAAC,CAAC;IACb,CAAC,CAAC;EACN,CAAC,CAAC;AACN"}
1
+ {"version":3,"names":["spawn","defaultOptions","getDefaultOptions","setDefaultOptions","options","spawnAsync","command","args","promise","Promise","resolve","reject","Array","isArray","child","on","code","console","error","Error"],"sources":["../../../src/utils/spawnAsync.ts"],"sourcesContent":["import {\n ChildProcess,\n ChildProcessByStdio,\n ChildProcessWithoutNullStreams,\n SpawnOptions,\n SpawnOptionsWithStdioTuple,\n SpawnOptionsWithoutStdio,\n StdioNull,\n StdioPipe,\n spawn,\n} from \"child_process\"\nimport { Readable, Writable } from \"stream\"\n\nexport interface PromiseWithChildProcess<T> extends Promise<T> {\n child: T\n}\n\nexport type Options =\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n\nlet defaultOptions: Options = {}\n\n/**\n * @description get default options for spawnAsync\n * @returns {Options} options\n */\nexport function getDefaultOptions(): Options {\n return defaultOptions\n}\n\n/**\n * @description set default options for spawnAsync\n * @param {Options | ((prev: Options) => Options)} options\n */\nexport function setDefaultOptions(options: Options | ((prev: Options) => Options)) {\n if (typeof options === \"function\") {\n defaultOptions = options(defaultOptions)\n return\n }\n defaultOptions = options\n return defaultOptions\n}\n\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\nexport function spawnAsync(\n command: string,\n args?: readonly string[],\n options?: SpawnOptionsWithoutStdio,\n): PromiseWithChildProcess<ChildProcessWithoutNullStreams>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>\nexport function spawnAsync(\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,\n): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>\n\n/**\n * @description wait for the command to exit\n * @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.\n */\nexport function spawnAsync(command: string, args?: any, options?: any): Promise<any> {\n const promise = new Promise<any>((resolve, reject) => {\n if (Array.isArray(args)) options = { ...defaultOptions, ...options }\n else args = { ...defaultOptions, ...args }\n const child = spawn(command, args, options)\n promise.child = child\n child.on(\"exit\", code => {\n if (code === 0) return resolve(child)\n console.error(`\"${command}\" Command failed with code ${code}`)\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\n return\n })\n }) as PromiseWithChildProcess<any>\n return promise\n}\n"],"mappings":"AAAA,SASIA,KAAK,QACF,eAAe;AAmBtB,IAAIC,cAAuB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAA,EAAY;EACzC,OAAOD,cAAc;AACzB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASE,iBAAiBA,CAACC,OAA+C,EAAE;EAC/E,IAAI,OAAOA,OAAO,KAAK,UAAU,EAAE;IAC/BH,cAAc,GAAGG,OAAO,CAACH,cAAc,CAAC;IACxC;EACJ;EACAA,cAAc,GAAGG,OAAO;EACxB,OAAOH,cAAc;AACzB;AAmFA;AACA;AACA;AACA;AACA,OAAO,SAASI,UAAUA,CAACC,OAAe,EAAEC,IAAU,EAAEH,OAAa,EAAgB;EACjF,MAAMI,OAAO,GAAG,IAAIC,OAAO,CAAM,CAACC,OAAO,EAAEC,MAAM,KAAK;IAClD,IAAIC,KAAK,CAACC,OAAO,CAACN,IAAI,CAAC,EAAEH,OAAO,GAAG;MAAE,GAAGH,cAAc;MAAE,GAAGG;IAAQ,CAAC,MAC/DG,IAAI,GAAG;MAAE,GAAGN,cAAc;MAAE,GAAGM;IAAK,CAAC;IAC1C,MAAMO,KAAK,GAAGd,KAAK,CAACM,OAAO,EAAEC,IAAI,EAAEH,OAAO,CAAC;IAC3CI,OAAO,CAACM,KAAK,GAAGA,KAAK;IACrBA,KAAK,CAACC,EAAE,CAAC,MAAM,EAAEC,IAAI,IAAI;MACrB,IAAIA,IAAI,KAAK,CAAC,EAAE,OAAON,OAAO,CAACI,KAAK,CAAC;MACrCG,OAAO,CAACC,KAAK,CAAE,IAAGZ,OAAQ,8BAA6BU,IAAK,EAAC,CAAC;MAC9DL,MAAM,CAAC,IAAIQ,KAAK,CAAE,IAAGb,OAAQ,8BAA6BU,IAAK,EAAC,CAAC,CAAC;MAClE;IACJ,CAAC,CAAC;EACN,CAAC,CAAiC;EAClC,OAAOR,OAAO;AAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soda-nodejs",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,34 +1,152 @@
1
- import { SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe, spawn } from "child_process"
1
+ import {
2
+ ChildProcess,
3
+ ChildProcessByStdio,
4
+ ChildProcessWithoutNullStreams,
5
+ SpawnOptions,
6
+ SpawnOptionsWithStdioTuple,
7
+ SpawnOptionsWithoutStdio,
8
+ StdioNull,
9
+ StdioPipe,
10
+ spawn,
11
+ } from "child_process"
12
+ import { Readable, Writable } from "stream"
2
13
 
3
- export function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>
4
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>
5
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>
6
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>
7
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>
8
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>
9
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>
10
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>
11
- export function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>
12
- export function spawnAsync(command: string, options: SpawnOptions): Promise<void>
13
- export function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>
14
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>
15
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>
16
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>
17
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>
18
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>
19
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>
20
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>
21
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>
22
- export function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>
23
- export async function spawnAsync(command: string, args?: any, options?: any) {
24
- await new Promise<void>((resolve, reject) => {
14
+ export interface PromiseWithChildProcess<T> extends Promise<T> {
15
+ child: T
16
+ }
17
+
18
+ export type Options =
19
+ | SpawnOptionsWithoutStdio
20
+ | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>
21
+ | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>
22
+ | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>
23
+ | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>
24
+ | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>
25
+ | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>
26
+ | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>
27
+ | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>
28
+ | SpawnOptions
29
+
30
+ let defaultOptions: Options = {}
31
+
32
+ /**
33
+ * @description get default options for spawnAsync
34
+ * @returns {Options} options
35
+ */
36
+ export function getDefaultOptions(): Options {
37
+ return defaultOptions
38
+ }
39
+
40
+ /**
41
+ * @description set default options for spawnAsync
42
+ * @param {Options | ((prev: Options) => Options)} options
43
+ */
44
+ export function setDefaultOptions(options: Options | ((prev: Options) => Options)) {
45
+ if (typeof options === "function") {
46
+ defaultOptions = options(defaultOptions)
47
+ return
48
+ }
49
+ defaultOptions = options
50
+ return defaultOptions
51
+ }
52
+
53
+ export function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>
54
+ export function spawnAsync(
55
+ command: string,
56
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
57
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>
58
+ export function spawnAsync(
59
+ command: string,
60
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
61
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>
62
+ export function spawnAsync(
63
+ command: string,
64
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
65
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>
66
+ export function spawnAsync(
67
+ command: string,
68
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
69
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>
70
+ export function spawnAsync(
71
+ command: string,
72
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
73
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>
74
+ export function spawnAsync(
75
+ command: string,
76
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
77
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>
78
+ export function spawnAsync(
79
+ command: string,
80
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
81
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>
82
+ export function spawnAsync(
83
+ command: string,
84
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
85
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>
86
+ export function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>
87
+ export function spawnAsync(
88
+ command: string,
89
+ args?: readonly string[],
90
+ options?: SpawnOptionsWithoutStdio,
91
+ ): PromiseWithChildProcess<ChildProcessWithoutNullStreams>
92
+ export function spawnAsync(
93
+ command: string,
94
+ args: readonly string[],
95
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
96
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>
97
+ export function spawnAsync(
98
+ command: string,
99
+ args: readonly string[],
100
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
101
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>
102
+ export function spawnAsync(
103
+ command: string,
104
+ args: readonly string[],
105
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
106
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>
107
+ export function spawnAsync(
108
+ command: string,
109
+ args: readonly string[],
110
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
111
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>
112
+ export function spawnAsync(
113
+ command: string,
114
+ args: readonly string[],
115
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
116
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>
117
+ export function spawnAsync(
118
+ command: string,
119
+ args: readonly string[],
120
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
121
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>
122
+ export function spawnAsync(
123
+ command: string,
124
+ args: readonly string[],
125
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
126
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>
127
+ export function spawnAsync(
128
+ command: string,
129
+ args: readonly string[],
130
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
131
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>
132
+ export function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>
133
+
134
+ /**
135
+ * @description wait for the command to exit
136
+ * @returns a promise that resolves with the child process when the command exits successfully. Also, the child process is attached to the promise as a property.
137
+ */
138
+ export function spawnAsync(command: string, args?: any, options?: any): Promise<any> {
139
+ const promise = new Promise<any>((resolve, reject) => {
140
+ if (Array.isArray(args)) options = { ...defaultOptions, ...options }
141
+ else args = { ...defaultOptions, ...args }
25
142
  const child = spawn(command, args, options)
143
+ promise.child = child
26
144
  child.on("exit", code => {
27
- if (code !== 0) {
28
- reject(new Error(`"${command}" Command failed with code ${code}`))
29
- return
30
- }
31
- resolve()
145
+ if (code === 0) return resolve(child)
146
+ console.error(`"${command}" Command failed with code ${code}`)
147
+ reject(new Error(`"${command}" Command failed with code ${code}`))
148
+ return
32
149
  })
33
- })
150
+ }) as PromiseWithChildProcess<any>
151
+ return promise
34
152
  }