soda-nodejs 0.4.1 → 0.4.3

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,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from \"@utils/copy\"\nexport * from \"@utils/execAsync\"\nexport * from \"@utils/saveFile\"\nexport * from \"@utils/saveResponse\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],
4
+ "sourcesContent": ["export * from \"@/utils/copy\"\nexport * from \"@/utils/execAsync\"\nexport * from \"@/utils/saveFile\"\nexport * from \"@/utils/saveResponse\"\nexport * from \"@/utils/spawnAsync\"\nexport * from \"@/utils/unzip\"\nexport * from \"@/utils/zip\"\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,yBAAd;AACA,wBAAc,8BADd;AAEA,wBAAc,6BAFd;AAGA,wBAAc,iCAHd;AAIA,wBAAc,+BAJd;AAKA,wBAAc,0BALd;AAMA,wBAAc,wBANd;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/execAsync.ts"],
4
- "sourcesContent": ["import { exec, ExecOptions } from \"child_process\"\nimport { ObjectEncodingOptions } from \"fs\"\nimport iconv, { Options } from \"iconv-lite\"\n\nexport type IconvDecodeOptions = {\n encoding: string\n options?: Options\n}\n\nexport async function execAsync(command: string): Promise<string>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<Buffer>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string | Buffer>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>\nexport async function execAsync(\n command: string,\n options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null,\n): Promise<string>\nexport async function execAsync(command: string, options?: any) {\n const decode = options?.decode as IconvDecodeOptions | undefined\n if (typeof options === \"object\" && options !== null && options.decode) {\n const { decode, ...rest } = options as { decode: IconvDecodeOptions }\n options = rest\n }\n return await new Promise<string | Buffer>((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (error) return reject(error)\n // if (stderr) console.warn(stderr)\n if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))\n resolve(stdout)\n })\n })\n}\n"],
4
+ "sourcesContent": ["import { ExecOptions, exec } from \"child_process\"\nimport { ObjectEncodingOptions } from \"fs\"\nimport iconv, { Options } from \"iconv-lite\"\n\nexport type IconvDecodeOptions = {\n encoding: string\n options?: Options\n}\n\nexport async function execAsync(command: string): Promise<string>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<Buffer>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string | Buffer>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>\nexport async function execAsync(\n command: string,\n options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null,\n): Promise<string>\nexport async function execAsync(command: string, options?: any) {\n const decode = options?.decode as IconvDecodeOptions | undefined\n if (typeof options === \"object\" && options !== null && options.decode) {\n const { decode, ...rest } = options as { decode: IconvDecodeOptions }\n options = rest\n }\n return await new Promise<string | Buffer>((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (error) return reject(error)\n // if (stderr) console.warn(stderr)\n if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))\n resolve(stdout)\n })\n })\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAkC;AAElC,wBAA+B;AAmB/B,eAAsB,UAAU,SAAiB,SAAe;AAC5D,QAAM,SAAS,SAAS;AACxB,MAAI,OAAO,YAAY,YAAY,YAAY,QAAQ,QAAQ,QAAQ;AACnE,UAAM,EAAE,QAAAA,SAAQ,GAAG,KAAK,IAAI;AAC5B,cAAU;AAAA,EACd;AACA,SAAO,MAAM,IAAI,QAAyB,CAAC,SAAS,WAAW;AAC3D,mCAAK,SAAS,SAAS,CAAC,OAAO,QAAQ,WAAW;AAC9C,UAAI;AAAO,eAAO,OAAO,KAAK;AAE9B,UAAI,UAAU,kBAAkB;AAAQ,eAAO,QAAQ,kBAAAC,QAAM,OAAO,QAAQ,OAAO,UAAU,OAAO,OAAO,CAAC;AAC5G,cAAQ,MAAM;AAAA,IAClB,CAAC;AAAA,EACL,CAAC;AACL;",
6
6
  "names": ["decode", "iconv"]
7
7
  }
@@ -1,22 +1,27 @@
1
1
  /// <reference types="node" />
2
- import { SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, 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 declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
9
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
10
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
11
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
12
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
13
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
14
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
15
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
16
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
17
+ export declare function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
18
+ export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
19
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
20
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
21
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
22
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
23
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
24
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
25
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
26
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
27
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
@@ -23,17 +23,19 @@ __export(spawnAsync_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(spawnAsync_exports);
25
25
  var import_child_process = require("child_process");
26
- async function spawnAsync(command, args, options) {
27
- await new Promise((resolve, reject) => {
26
+ function spawnAsync(command, args, options) {
27
+ const promise = new Promise((resolve, reject) => {
28
28
  const child = (0, import_child_process.spawn)(command, args, options);
29
+ promise.child = child;
29
30
  child.on("exit", (code) => {
30
- if (code !== 0) {
31
- reject(new Error(`"${command}" Command failed with code ${code}`));
32
- return;
33
- }
34
- resolve();
31
+ if (code === 0)
32
+ return resolve(child);
33
+ console.error(`"${command}" Command failed with code ${code}`);
34
+ reject(new Error(`"${command}" Command failed with code ${code}`));
35
+ return;
35
36
  });
36
37
  });
38
+ return promise;
37
39
  }
38
40
  // Annotate the CommonJS export names for ESM import in node:
39
41
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/spawnAsync.ts"],
4
- "sourcesContent": ["import { spawn, SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, StdioNull, StdioPipe } 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 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 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,2BAUO;AA4FA,SAAS,WAAW,SAAiB,MAAY,SAA6B;AACjF,QAAM,UAAU,IAAI,QAAa,CAAC,SAAS,WAAW;AAClD,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,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/unzip.ts"],
4
- "sourcesContent": ["import which from \"which\"\nimport { execAsync } from \"./execAsync\"\n\nexport type UnzipOptions = {\n /**\n * 要解压的文件\n */\n input: string\n /**\n * 解压到的目标文件夹位置\n */\n output: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令解压文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function unzip({ input, output, cwd }: UnzipOptions) {\n await which(\"7z\")\n return await execAsync(`7z x ${input} -o${output}`, { cwd })\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,uBAA0B;AA4B1B,eAAsB,MAAM,EAAE,OAAO,QAAQ,IAAI,GAAiB;AAC9D,YAAM,aAAAA,SAAM,IAAI;AAChB,SAAO,UAAM,4BAAU,QAAQ,WAAW,UAAU,EAAE,IAAI,CAAC;AAC/D;",
4
+ "sourcesContent": ["import which from \"which\"\n\nimport { execAsync } from \"./execAsync\"\n\nexport type UnzipOptions = {\n /**\n * 要解压的文件\n */\n input: string\n /**\n * 解压到的目标文件夹位置\n */\n output: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令解压文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function unzip({ input, output, cwd }: UnzipOptions) {\n await which(\"7z\")\n return await execAsync(`7z x ${input} -o${output}`, { cwd })\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,uBAA0B;AA4B1B,eAAsB,MAAM,EAAE,OAAO,QAAQ,IAAI,GAAiB;AAC9D,YAAM,aAAAA,SAAM,IAAI;AAChB,SAAO,UAAM,4BAAU,QAAQ,WAAW,UAAU,EAAE,IAAI,CAAC;AAC/D;",
6
6
  "names": ["which"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/utils/zip.ts"],
4
- "sourcesContent": ["import { cpus } from \"os\"\nimport which from \"which\"\nimport { execAsync } from \"./execAsync\"\n\nexport type ZipOptions = {\n /**\n * 要压缩的文件\n */\n input: string | string[]\n /**\n * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z\n */\n output: string\n /**\n * 线程数\n */\n thread?: number | \"auto\" | \"max\"\n /**\n * 压缩等级,0-9\n */\n level?: number\n /**\n * 是否加密\n */\n password?: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令压缩文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function zip({ input, output, thread = \"auto\", level, password, cwd }: ZipOptions) {\n await which(\"7z\")\n input = Array.isArray(input) ? input.join(\" \") : input\n if (thread === \"max\") thread = cpus().length\n return await execAsync(\n `7z a ${output} ${input} -mmt=${thread === \"auto\" ? \"on\" : thread}${typeof level === \"number\" ? ` -mx=${level}` : \"\"}${password ? ` -p${password}` : \"\"}`,\n { cwd },\n )\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqB;AACrB,mBAAkB;AAClB,uBAA0B;AAwC1B,eAAsB,IAAI,EAAE,OAAO,QAAQ,SAAS,QAAQ,OAAO,UAAU,IAAI,GAAe;AAC5F,YAAM,aAAAA,SAAM,IAAI;AAChB,UAAQ,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,GAAG,IAAI;AACjD,MAAI,WAAW;AAAO,iBAAS,gBAAK,EAAE;AACtC,SAAO,UAAM;AAAA,IACT,QAAQ,UAAU,cAAc,WAAW,SAAS,OAAO,SAAS,OAAO,UAAU,WAAW,QAAQ,UAAU,KAAK,WAAW,MAAM,aAAa;AAAA,IACrJ,EAAE,IAAI;AAAA,EACV;AACJ;",
4
+ "sourcesContent": ["import { cpus } from \"os\"\nimport which from \"which\"\n\nimport { execAsync } from \"./execAsync\"\n\nexport type ZipOptions = {\n /**\n * 要压缩的文件\n */\n input: string | string[]\n /**\n * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z\n */\n output: string\n /**\n * 线程数\n */\n thread?: number | \"auto\" | \"max\"\n /**\n * 压缩等级,0-9\n */\n level?: number\n /**\n * 是否加密\n */\n password?: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令压缩文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function zip({ input, output, thread = \"auto\", level, password, cwd }: ZipOptions) {\n await which(\"7z\")\n input = Array.isArray(input) ? input.join(\" \") : input\n if (thread === \"max\") thread = cpus().length\n return await execAsync(\n `7z a ${output} ${input} -mmt=${thread === \"auto\" ? \"on\" : thread}${typeof level === \"number\" ? ` -mx=${level}` : \"\"}${password ? ` -p${password}` : \"\"}`,\n { cwd },\n )\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAqB;AACrB,mBAAkB;AAElB,uBAA0B;AAwC1B,eAAsB,IAAI,EAAE,OAAO,QAAQ,SAAS,QAAQ,OAAO,UAAU,IAAI,GAAe;AAC5F,YAAM,aAAAA,SAAM,IAAI;AAChB,UAAQ,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,GAAG,IAAI;AACjD,MAAI,WAAW;AAAO,iBAAS,gBAAK,EAAE;AACtC,SAAO,UAAM;AAAA,IACT,QAAQ,UAAU,cAAc,WAAW,SAAS,OAAO,SAAS,OAAO,UAAU,WAAW,QAAQ,UAAU,KAAK,WAAW,MAAM,aAAa;AAAA,IACrJ,EAAE,IAAI;AAAA,EACV;AACJ;",
6
6
  "names": ["which"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"@utils/copy\"\nexport * from \"@utils/execAsync\"\nexport * from \"@utils/saveFile\"\nexport * from \"@utils/saveResponse\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"@/utils/copy\"\nexport * from \"@/utils/execAsync\"\nexport * from \"@/utils/saveFile\"\nexport * from \"@/utils/saveResponse\"\nexport * from \"@/utils/spawnAsync\"\nexport * from \"@/utils/unzip\"\nexport * from \"@/utils/zip\"\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1 +1 @@
1
- {"version":3,"names":["exec","iconv","execAsync","command","options","decode","rest","Promise","resolve","reject","error","stdout","stderr","Buffer","encoding"],"sources":["../../../src/utils/execAsync.ts"],"sourcesContent":["import { exec, ExecOptions } from \"child_process\"\nimport { ObjectEncodingOptions } from \"fs\"\nimport iconv, { Options } from \"iconv-lite\"\n\nexport type IconvDecodeOptions = {\n encoding: string\n options?: Options\n}\n\nexport async function execAsync(command: string): Promise<string>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<Buffer>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string | Buffer>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>\nexport async function execAsync(\n command: string,\n options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null,\n): Promise<string>\nexport async function execAsync(command: string, options?: any) {\n const decode = options?.decode as IconvDecodeOptions | undefined\n if (typeof options === \"object\" && options !== null && options.decode) {\n const { decode, ...rest } = options as { decode: IconvDecodeOptions }\n options = rest\n }\n return await new Promise<string | Buffer>((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (error) return reject(error)\n // if (stderr) console.warn(stderr)\n if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))\n resolve(stdout)\n })\n })\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAqB,eAAe;AAEjD,OAAOC,KAAK,MAAmB,YAAY;AAmB3C,OAAO,eAAeC,SAASA,CAACC,OAAe,EAAEC,OAAa,EAAE;EAC5D,MAAMC,MAAM,GAAGD,OAAO,EAAEC,MAAwC;EAChE,IAAI,OAAOD,OAAO,KAAK,QAAQ,IAAIA,OAAO,KAAK,IAAI,IAAIA,OAAO,CAACC,MAAM,EAAE;IACnE,MAAM;MAAEA,MAAM;MAAE,GAAGC;IAAK,CAAC,GAAGF,OAAyC;IACrEA,OAAO,GAAGE,IAAI;EAClB;EACA,OAAO,MAAM,IAAIC,OAAO,CAAkB,CAACC,OAAO,EAAEC,MAAM,KAAK;IAC3DT,IAAI,CAACG,OAAO,EAAEC,OAAO,EAAE,CAACM,KAAK,EAAEC,MAAM,EAAEC,MAAM,KAAK;MAC9C,IAAIF,KAAK,EAAE,OAAOD,MAAM,CAACC,KAAK,CAAC;MAC/B;MACA,IAAIL,MAAM,IAAIM,MAAM,YAAYE,MAAM,EAAE,OAAOL,OAAO,CAACP,KAAK,CAACI,MAAM,CAACM,MAAM,EAAEN,MAAM,CAACS,QAAQ,EAAET,MAAM,CAACD,OAAO,CAAC,CAAC;MAC7GI,OAAO,CAACG,MAAM,CAAC;IACnB,CAAC,CAAC;EACN,CAAC,CAAC;AACN"}
1
+ {"version":3,"names":["exec","iconv","execAsync","command","options","decode","rest","Promise","resolve","reject","error","stdout","stderr","Buffer","encoding"],"sources":["../../../src/utils/execAsync.ts"],"sourcesContent":["import { ExecOptions, exec } from \"child_process\"\nimport { ObjectEncodingOptions } from \"fs\"\nimport iconv, { Options } from \"iconv-lite\"\n\nexport type IconvDecodeOptions = {\n encoding: string\n options?: Options\n}\n\nexport async function execAsync(command: string): Promise<string>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<Buffer>\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string | Buffer>\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\nexport async function execAsync(command: string, options: ExecOptions): Promise<string>\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>\nexport async function execAsync(\n command: string,\n options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null,\n): Promise<string>\nexport async function execAsync(command: string, options?: any) {\n const decode = options?.decode as IconvDecodeOptions | undefined\n if (typeof options === \"object\" && options !== null && options.decode) {\n const { decode, ...rest } = options as { decode: IconvDecodeOptions }\n options = rest\n }\n return await new Promise<string | Buffer>((resolve, reject) => {\n exec(command, options, (error, stdout, stderr) => {\n if (error) return reject(error)\n // if (stderr) console.warn(stderr)\n if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))\n resolve(stdout)\n })\n })\n}\n"],"mappings":"AAAA,SAAsBA,IAAI,QAAQ,eAAe;AAEjD,OAAOC,KAAK,MAAmB,YAAY;AAmB3C,OAAO,eAAeC,SAASA,CAACC,OAAe,EAAEC,OAAa,EAAE;EAC5D,MAAMC,MAAM,GAAGD,OAAO,EAAEC,MAAwC;EAChE,IAAI,OAAOD,OAAO,KAAK,QAAQ,IAAIA,OAAO,KAAK,IAAI,IAAIA,OAAO,CAACC,MAAM,EAAE;IACnE,MAAM;MAAEA,MAAM;MAAE,GAAGC;IAAK,CAAC,GAAGF,OAAyC;IACrEA,OAAO,GAAGE,IAAI;EAClB;EACA,OAAO,MAAM,IAAIC,OAAO,CAAkB,CAACC,OAAO,EAAEC,MAAM,KAAK;IAC3DT,IAAI,CAACG,OAAO,EAAEC,OAAO,EAAE,CAACM,KAAK,EAAEC,MAAM,EAAEC,MAAM,KAAK;MAC9C,IAAIF,KAAK,EAAE,OAAOD,MAAM,CAACC,KAAK,CAAC;MAC/B;MACA,IAAIL,MAAM,IAAIM,MAAM,YAAYE,MAAM,EAAE,OAAOL,OAAO,CAACP,KAAK,CAACI,MAAM,CAACM,MAAM,EAAEN,MAAM,CAACS,QAAQ,EAAET,MAAM,CAACD,OAAO,CAAC,CAAC;MAC7GI,OAAO,CAACG,MAAM,CAAC;IACnB,CAAC,CAAC;EACN,CAAC,CAAC;AACN"}
@@ -1,22 +1,27 @@
1
1
  /// <reference types="node" />
2
- import { SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, 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 declare function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
9
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
10
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
11
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
12
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
13
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
14
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
15
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
16
+ export declare function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
17
+ export declare function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
18
+ export declare function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>;
19
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>;
20
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>;
21
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>;
22
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>;
23
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>;
24
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>;
25
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>;
26
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>;
27
+ export declare function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>;
@@ -1,14 +1,19 @@
1
1
  import { spawn } from "child_process";
2
- export async function spawnAsync(command, args, options) {
3
- await new Promise((resolve, reject) => {
2
+ /**
3
+ * @description wait for the command to exit
4
+ * @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.
5
+ */
6
+ export function spawnAsync(command, args, options) {
7
+ const promise = new Promise((resolve, reject) => {
4
8
  const child = spawn(command, args, options);
9
+ promise.child = child;
5
10
  child.on("exit", code => {
6
- if (code !== 0) {
7
- reject(new Error(`"${command}" Command failed with code ${code}`));
8
- return;
9
- }
10
- resolve();
11
+ if (code === 0) return resolve(child);
12
+ console.error(`"${command}" Command failed with code ${code}`);
13
+ reject(new Error(`"${command}" Command failed with code ${code}`));
14
+ return;
11
15
  });
12
16
  });
17
+ return promise;
13
18
  }
14
19
  //# 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 { spawn, SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, StdioNull, StdioPipe } 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,SAASA,KAAK,QAAkG,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","spawnAsync","command","args","options","promise","Promise","resolve","reject","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 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 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;AAwFtB;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,OAAe,EAAEC,IAAU,EAAEC,OAAa,EAAgB;EACjF,MAAMC,OAAO,GAAG,IAAIC,OAAO,CAAM,CAACC,OAAO,EAAEC,MAAM,KAAK;IAClD,MAAMC,KAAK,GAAGT,KAAK,CAACE,OAAO,EAAEC,IAAI,EAAEC,OAAO,CAAC;IAC3CC,OAAO,CAACI,KAAK,GAAGA,KAAK;IACrBA,KAAK,CAACC,EAAE,CAAC,MAAM,EAAEC,IAAI,IAAI;MACrB,IAAIA,IAAI,KAAK,CAAC,EAAE,OAAOJ,OAAO,CAACE,KAAK,CAAC;MACrCG,OAAO,CAACC,KAAK,CAAE,IAAGX,OAAQ,8BAA6BS,IAAK,EAAC,CAAC;MAC9DH,MAAM,CAAC,IAAIM,KAAK,CAAE,IAAGZ,OAAQ,8BAA6BS,IAAK,EAAC,CAAC,CAAC;MAClE;IACJ,CAAC,CAAC;EACN,CAAC,CAAiC;EAClC,OAAON,OAAO;AAClB"}
@@ -1 +1 @@
1
- {"version":3,"names":["which","execAsync","unzip","input","output","cwd"],"sources":["../../../src/utils/unzip.ts"],"sourcesContent":["import which from \"which\"\nimport { execAsync } from \"./execAsync\"\n\nexport type UnzipOptions = {\n /**\n * 要解压的文件\n */\n input: string\n /**\n * 解压到的目标文件夹位置\n */\n output: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令解压文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function unzip({ input, output, cwd }: UnzipOptions) {\n await which(\"7z\")\n return await execAsync(`7z x ${input} -o${output}`, { cwd })\n}\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS;AAiBlB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,KAAKA,CAAC;EAAEC,KAAK;EAAEC,MAAM;EAAEC;AAAkB,CAAC,EAAE;EAC9D,MAAML,KAAK,CAAC,IAAI,CAAC;EACjB,OAAO,MAAMC,SAAS,CAAE,QAAOE,KAAM,MAAKC,MAAO,EAAC,EAAE;IAAEC;EAAI,CAAC,CAAC;AAChE"}
1
+ {"version":3,"names":["which","execAsync","unzip","input","output","cwd"],"sources":["../../../src/utils/unzip.ts"],"sourcesContent":["import which from \"which\"\n\nimport { execAsync } from \"./execAsync\"\n\nexport type UnzipOptions = {\n /**\n * 要解压的文件\n */\n input: string\n /**\n * 解压到的目标文件夹位置\n */\n output: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令解压文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function unzip({ input, output, cwd }: UnzipOptions) {\n await which(\"7z\")\n return await execAsync(`7z x ${input} -o${output}`, { cwd })\n}\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,SAAS;AAiBlB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,KAAKA,CAAC;EAAEC,KAAK;EAAEC,MAAM;EAAEC;AAAkB,CAAC,EAAE;EAC9D,MAAML,KAAK,CAAC,IAAI,CAAC;EACjB,OAAO,MAAMC,SAAS,CAAE,QAAOE,KAAM,MAAKC,MAAO,EAAC,EAAE;IAAEC;EAAI,CAAC,CAAC;AAChE"}
@@ -1 +1 @@
1
- {"version":3,"names":["cpus","which","execAsync","zip","input","output","thread","level","password","cwd","Array","isArray","join","length"],"sources":["../../../src/utils/zip.ts"],"sourcesContent":["import { cpus } from \"os\"\nimport which from \"which\"\nimport { execAsync } from \"./execAsync\"\n\nexport type ZipOptions = {\n /**\n * 要压缩的文件\n */\n input: string | string[]\n /**\n * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z\n */\n output: string\n /**\n * 线程数\n */\n thread?: number | \"auto\" | \"max\"\n /**\n * 压缩等级,0-9\n */\n level?: number\n /**\n * 是否加密\n */\n password?: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令压缩文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function zip({ input, output, thread = \"auto\", level, password, cwd }: ZipOptions) {\n await which(\"7z\")\n input = Array.isArray(input) ? input.join(\" \") : input\n if (thread === \"max\") thread = cpus().length\n return await execAsync(\n `7z a ${output} ${input} -mmt=${thread === \"auto\" ? \"on\" : thread}${typeof level === \"number\" ? ` -mx=${level}` : \"\"}${password ? ` -p${password}` : \"\"}`,\n { cwd },\n )\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,IAAI;AACzB,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS;AA6BlB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,GAAGA,CAAC;EAAEC,KAAK;EAAEC,MAAM;EAAEC,MAAM,GAAG,MAAM;EAAEC,KAAK;EAAEC,QAAQ;EAAEC;AAAgB,CAAC,EAAE;EAC5F,MAAMR,KAAK,CAAC,IAAI,CAAC;EACjBG,KAAK,GAAGM,KAAK,CAACC,OAAO,CAACP,KAAK,CAAC,GAAGA,KAAK,CAACQ,IAAI,CAAC,GAAG,CAAC,GAAGR,KAAK;EACtD,IAAIE,MAAM,KAAK,KAAK,EAAEA,MAAM,GAAGN,IAAI,CAAC,CAAC,CAACa,MAAM;EAC5C,OAAO,MAAMX,SAAS,CACjB,QAAOG,MAAO,IAAGD,KAAM,SAAQE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAGA,MAAO,GAAE,OAAOC,KAAK,KAAK,QAAQ,GAAI,QAAOA,KAAM,EAAC,GAAG,EAAG,GAAEC,QAAQ,GAAI,MAAKA,QAAS,EAAC,GAAG,EAAG,EAAC,EACzJ;IAAEC;EAAI,CACV,CAAC;AACL"}
1
+ {"version":3,"names":["cpus","which","execAsync","zip","input","output","thread","level","password","cwd","Array","isArray","join","length"],"sources":["../../../src/utils/zip.ts"],"sourcesContent":["import { cpus } from \"os\"\nimport which from \"which\"\n\nimport { execAsync } from \"./execAsync\"\n\nexport type ZipOptions = {\n /**\n * 要压缩的文件\n */\n input: string | string[]\n /**\n * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z\n */\n output: string\n /**\n * 线程数\n */\n thread?: number | \"auto\" | \"max\"\n /**\n * 压缩等级,0-9\n */\n level?: number\n /**\n * 是否加密\n */\n password?: string\n /**\n * 压缩文件时的工作目录\n */\n cwd?: string\n}\n\n/**\n * 使用 7z 命令压缩文件\n * - 如果没有安装 7z,请先安装 7z 后再执行\n * - 下载地址:https://www.7-zip.org/download.html\n * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中\n * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\n * 2. 在系统变量中找到并选中 Path,点击编辑\n * 3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定\n * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\n * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\n */\nexport async function zip({ input, output, thread = \"auto\", level, password, cwd }: ZipOptions) {\n await which(\"7z\")\n input = Array.isArray(input) ? input.join(\" \") : input\n if (thread === \"max\") thread = cpus().length\n return await execAsync(\n `7z a ${output} ${input} -mmt=${thread === \"auto\" ? \"on\" : thread}${typeof level === \"number\" ? ` -mx=${level}` : \"\"}${password ? ` -p${password}` : \"\"}`,\n { cwd },\n )\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,IAAI;AACzB,OAAOC,KAAK,MAAM,OAAO;AAEzB,SAASC,SAAS;AA6BlB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,GAAGA,CAAC;EAAEC,KAAK;EAAEC,MAAM;EAAEC,MAAM,GAAG,MAAM;EAAEC,KAAK;EAAEC,QAAQ;EAAEC;AAAgB,CAAC,EAAE;EAC5F,MAAMR,KAAK,CAAC,IAAI,CAAC;EACjBG,KAAK,GAAGM,KAAK,CAACC,OAAO,CAACP,KAAK,CAAC,GAAGA,KAAK,CAACQ,IAAI,CAAC,GAAG,CAAC,GAAGR,KAAK;EACtD,IAAIE,MAAM,KAAK,KAAK,EAAEA,MAAM,GAAGN,IAAI,CAAC,CAAC,CAACa,MAAM;EAC5C,OAAO,MAAMX,SAAS,CACjB,QAAOG,MAAO,IAAGD,KAAM,SAAQE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAGA,MAAO,GAAE,OAAOC,KAAK,KAAK,QAAQ,GAAI,QAAOA,KAAM,EAAC,GAAG,EAAG,GAAEC,QAAQ,GAAI,MAAKA,QAAS,EAAC,GAAG,EAAG,EAAC,EACzJ;IAAEC;EAAI,CACV,CAAC;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soda-nodejs",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from "@utils/copy"
2
- export * from "@utils/execAsync"
3
- export * from "@utils/saveFile"
4
- export * from "@utils/saveResponse"
5
- export * from "@utils/spawnAsync"
6
- export * from "@utils/unzip"
7
- export * from "@utils/zip"
1
+ export * from "@/utils/copy"
2
+ export * from "@/utils/execAsync"
3
+ export * from "@/utils/saveFile"
4
+ export * from "@/utils/saveResponse"
5
+ export * from "@/utils/spawnAsync"
6
+ export * from "@/utils/unzip"
7
+ export * from "@/utils/zip"
@@ -1,4 +1,4 @@
1
- import { exec, ExecOptions } from "child_process"
1
+ import { ExecOptions, exec } from "child_process"
2
2
  import { ObjectEncodingOptions } from "fs"
3
3
  import iconv, { Options } from "iconv-lite"
4
4
 
@@ -1,34 +1,115 @@
1
- import { spawn, SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, StdioNull, StdioPipe } 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 function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): PromiseWithChildProcess<ChildProcessWithoutNullStreams>
19
+ export function spawnAsync(
20
+ command: string,
21
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
22
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>
23
+ export function spawnAsync(
24
+ command: string,
25
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
26
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>
27
+ export function spawnAsync(
28
+ command: string,
29
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
30
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>
31
+ export function spawnAsync(
32
+ command: string,
33
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
34
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>
35
+ export function spawnAsync(
36
+ command: string,
37
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
38
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>
39
+ export function spawnAsync(
40
+ command: string,
41
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
42
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>
43
+ export function spawnAsync(
44
+ command: string,
45
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
46
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>
47
+ export function spawnAsync(
48
+ command: string,
49
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
50
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>
51
+ export function spawnAsync(command: string, options: SpawnOptions): PromiseWithChildProcess<ChildProcess>
52
+ export function spawnAsync(
53
+ command: string,
54
+ args?: readonly string[],
55
+ options?: SpawnOptionsWithoutStdio,
56
+ ): PromiseWithChildProcess<ChildProcessWithoutNullStreams>
57
+ export function spawnAsync(
58
+ command: string,
59
+ args: readonly string[],
60
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
61
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, Readable>>
62
+ export function spawnAsync(
63
+ command: string,
64
+ args: readonly string[],
65
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
66
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, Readable, null>>
67
+ export function spawnAsync(
68
+ command: string,
69
+ args: readonly string[],
70
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
71
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, Readable>>
72
+ export function spawnAsync(
73
+ command: string,
74
+ args: readonly string[],
75
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
76
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, Readable>>
77
+ export function spawnAsync(
78
+ command: string,
79
+ args: readonly string[],
80
+ options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
81
+ ): PromiseWithChildProcess<ChildProcessByStdio<Writable, null, null>>
82
+ export function spawnAsync(
83
+ command: string,
84
+ args: readonly string[],
85
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
86
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, Readable, null>>
87
+ export function spawnAsync(
88
+ command: string,
89
+ args: readonly string[],
90
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
91
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, Readable>>
92
+ export function spawnAsync(
93
+ command: string,
94
+ args: readonly string[],
95
+ options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
96
+ ): PromiseWithChildProcess<ChildProcessByStdio<null, null, null>>
97
+ export function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): PromiseWithChildProcess<ChildProcess>
98
+
99
+ /**
100
+ * @description wait for the command to exit
101
+ * @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.
102
+ */
103
+ export function spawnAsync(command: string, args?: any, options?: any): Promise<any> {
104
+ const promise = new Promise<any>((resolve, reject) => {
25
105
  const child = spawn(command, args, options)
106
+ promise.child = child
26
107
  child.on("exit", code => {
27
- if (code !== 0) {
28
- reject(new Error(`"${command}" Command failed with code ${code}`))
29
- return
30
- }
31
- resolve()
108
+ if (code === 0) return resolve(child)
109
+ console.error(`"${command}" Command failed with code ${code}`)
110
+ reject(new Error(`"${command}" Command failed with code ${code}`))
111
+ return
32
112
  })
33
- })
113
+ }) as PromiseWithChildProcess<any>
114
+ return promise
34
115
  }
@@ -1,4 +1,5 @@
1
1
  import which from "which"
2
+
2
3
  import { execAsync } from "./execAsync"
3
4
 
4
5
  export type UnzipOptions = {
package/src/utils/zip.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { cpus } from "os"
2
2
  import which from "which"
3
+
3
4
  import { execAsync } from "./execAsync"
4
5
 
5
6
  export type ZipOptions = {