soda-nodejs 0.1.6 → 0.2.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.
package/README.md CHANGED
@@ -1,23 +1,23 @@
1
- # soda-node
2
-
3
- [![NPM version](https://img.shields.io/npm/v/soda-node.svg?style=flat)](https://npmjs.com/package/soda-node)
4
- [![NPM downloads](http://img.shields.io/npm/dm/soda-node.svg?style=flat)](https://npmjs.com/package/soda-node)
5
-
6
- ## Install
7
-
8
- ```bash
9
- $ pnpm install
10
- ```
11
-
12
- ```bash
13
- $ npm run dev
14
- $ npm run build
15
- ```
16
-
17
- ## Options
18
-
19
- TODO
20
-
21
- ## LICENSE
22
-
23
- MIT
1
+ # soda-node
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/soda-node.svg?style=flat)](https://npmjs.com/package/soda-node)
4
+ [![NPM downloads](http://img.shields.io/npm/dm/soda-node.svg?style=flat)](https://npmjs.com/package/soda-node)
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ $ pnpm install
10
+ ```
11
+
12
+ ```bash
13
+ $ npm run dev
14
+ $ npm run build
15
+ ```
16
+
17
+ ## Options
18
+
19
+ TODO
20
+
21
+ ## LICENSE
22
+
23
+ MIT
@@ -1,6 +1,4 @@
1
- export * from "./utils/check7zip";
2
1
  export * from "./utils/execAsync";
3
- export * from "./utils/install7zip";
4
2
  export * from "./utils/saveFile";
5
3
  export * from "./utils/spawnAsync";
6
4
  export * from "./utils/unzip";
package/dist/cjs/index.js CHANGED
@@ -16,18 +16,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  // src/index.ts
17
17
  var src_exports = {};
18
18
  module.exports = __toCommonJS(src_exports);
19
- __reExport(src_exports, require("./utils/check7zip"), module.exports);
20
19
  __reExport(src_exports, require("./utils/execAsync"), module.exports);
21
- __reExport(src_exports, require("./utils/install7zip"), module.exports);
22
20
  __reExport(src_exports, require("./utils/saveFile"), module.exports);
23
21
  __reExport(src_exports, require("./utils/spawnAsync"), module.exports);
24
22
  __reExport(src_exports, require("./utils/unzip"), module.exports);
25
23
  __reExport(src_exports, require("./utils/zip"), module.exports);
26
24
  // Annotate the CommonJS export names for ESM import in node:
27
25
  0 && (module.exports = {
28
- ...require("./utils/check7zip"),
29
26
  ...require("./utils/execAsync"),
30
- ...require("./utils/install7zip"),
31
27
  ...require("./utils/saveFile"),
32
28
  ...require("./utils/spawnAsync"),
33
29
  ...require("./utils/unzip"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from \"@utils/check7zip\"\nexport * from \"@utils/execAsync\"\nexport * from \"@utils/install7zip\"\nexport * from \"@utils/saveFile\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,8BADd;AAEA,wBAAc,gCAFd;AAGA,wBAAc,6BAHd;AAIA,wBAAc,+BAJd;AAKA,wBAAc,0BALd;AAMA,wBAAc,wBANd;",
4
+ "sourcesContent": ["export * from \"@utils/execAsync\"\nexport * from \"@utils/saveFile\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,8BAAd;AACA,wBAAc,6BADd;AAEA,wBAAc,+BAFd;AAGA,wBAAc,0BAHd;AAIA,wBAAc,wBAJd;",
6
6
  "names": []
7
7
  }
@@ -3,19 +3,33 @@
3
3
  /// <reference types="node" />
4
4
  import { ExecOptions } from "child_process";
5
5
  import { ObjectEncodingOptions } from "fs";
6
- export type ExecResult<T> = {
7
- stdout: T;
8
- stderr: T;
6
+ import { Options } from "iconv-lite";
7
+ export type IconvDecodeOptions = {
8
+ encoding: string;
9
+ options?: Options;
9
10
  };
10
- export declare function execAsync(command: string): Promise<ExecResult<string>>;
11
+ export declare function execAsync(command: string): Promise<string>;
11
12
  export declare function execAsync(command: string, options: {
12
13
  encoding: "buffer" | null;
13
- } & ExecOptions): Promise<ExecResult<Buffer>>;
14
+ } & ExecOptions): Promise<Buffer>;
15
+ export declare function execAsync(command: string, options: {
16
+ encoding: "buffer" | null;
17
+ } & ExecOptions & {
18
+ decode: IconvDecodeOptions;
19
+ }): Promise<string>;
20
+ export declare function execAsync(command: string, options: {
21
+ encoding: BufferEncoding;
22
+ } & ExecOptions): Promise<string>;
14
23
  export declare function execAsync(command: string, options: {
15
24
  encoding: BufferEncoding;
16
- } & ExecOptions): Promise<ExecResult<string>>;
25
+ } & ExecOptions): Promise<string | Buffer>;
17
26
  export declare function execAsync(command: string, options: {
18
27
  encoding: BufferEncoding;
19
- } & ExecOptions): Promise<ExecResult<string | Buffer>>;
20
- export declare function execAsync(command: string, options: ExecOptions): Promise<ExecResult<string>>;
21
- export declare function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<ExecResult<string | Buffer>>;
28
+ } & ExecOptions & {
29
+ decode: IconvDecodeOptions;
30
+ }): Promise<string>;
31
+ export declare function execAsync(command: string, options: ExecOptions): Promise<string>;
32
+ export declare function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>;
33
+ export declare function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions & {
34
+ decode: IconvDecodeOptions;
35
+ }) | undefined | null): Promise<string>;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/utils/execAsync.ts
@@ -23,14 +33,20 @@ __export(execAsync_exports, {
23
33
  });
24
34
  module.exports = __toCommonJS(execAsync_exports);
25
35
  var import_child_process = require("child_process");
36
+ var import_iconv_lite = __toESM(require("iconv-lite"));
26
37
  async function execAsync(command, options) {
38
+ const decode = options?.decode;
39
+ if (typeof options === "object" && options !== null && options.decode) {
40
+ const { decode: decode2, ...rest } = options;
41
+ options = rest;
42
+ }
27
43
  return await new Promise((resolve, reject) => {
28
44
  (0, import_child_process.exec)(command, options, (error, stdout, stderr) => {
29
- if (error) {
30
- reject(error);
31
- return;
32
- }
33
- resolve({ stdout, stderr });
45
+ if (error)
46
+ return reject(error);
47
+ if (decode && stdout instanceof Buffer)
48
+ return resolve(import_iconv_lite.default.decode(stdout, decode.encoding, decode.options));
49
+ resolve(stdout);
34
50
  });
35
51
  });
36
52
  }
@@ -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\"\r\nimport { ObjectEncodingOptions } from \"fs\"\r\n\r\nexport type ExecResult<T> = {\r\n stdout: T\r\n stderr: T\r\n}\r\n\r\nexport async function execAsync(command: string): Promise<ExecResult<string>>\r\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<ExecResult<Buffer>>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<ExecResult<string>>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<ExecResult<string | Buffer>>\r\nexport async function execAsync(command: string, options: ExecOptions): Promise<ExecResult<string>>\r\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<ExecResult<string | Buffer>>\r\nexport async function execAsync(command: string, options?: any) {\r\n return await new Promise<ExecResult<string | Buffer>>((resolve, reject) => {\r\n exec(command, options, (error, stdout, stderr) => {\r\n if (error) {\r\n reject(error)\r\n return\r\n }\r\n resolve({ stdout, stderr })\r\n })\r\n })\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAkC;AAclC,eAAsB,UAAU,SAAiB,SAAe;AAC5D,SAAO,MAAM,IAAI,QAAqC,CAAC,SAAS,WAAW;AACvE,mCAAK,SAAS,SAAS,CAAC,OAAO,QAAQ,WAAW;AAC9C,UAAI,OAAO;AACP,eAAO,KAAK;AACZ;AAAA,MACJ;AACA,cAAQ,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC9B,CAAC;AAAA,EACL,CAAC;AACL;",
6
- "names": []
4
+ "sourcesContent": ["import { exec, ExecOptions } from \"child_process\"\r\nimport { ObjectEncodingOptions } from \"fs\"\r\nimport iconv, { Options } from \"iconv-lite\"\r\n\r\nexport type IconvDecodeOptions = {\r\n encoding: string\r\n options?: Options\r\n}\r\n\r\nexport async function execAsync(command: string): Promise<string>\r\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<Buffer>\r\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string | Buffer>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\r\nexport async function execAsync(command: string, options: ExecOptions): Promise<string>\r\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>\r\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null): Promise<string>\r\nexport async function execAsync(command: string, options?: any) {\r\n const decode = options?.decode as IconvDecodeOptions | undefined\r\n if (typeof options === \"object\" && options !== null && options.decode) {\r\n const { decode, ...rest } = options as { decode: IconvDecodeOptions }\r\n options = rest\r\n }\r\n return await new Promise<string | Buffer>((resolve, reject) => {\r\n exec(command, options, (error, stdout, stderr) => {\r\n if (error) return reject(error)\r\n // if (stderr) console.warn(stderr)\r\n if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))\r\n resolve(stdout)\r\n })\r\n })\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAkC;AAElC,wBAA+B;AAgB/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
+ "names": ["decode", "iconv"]
7
7
  }
@@ -23,4 +23,4 @@ export type UnzipOptions = {
23
23
  * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
24
24
  * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
25
25
  */
26
- export declare function unzip({ input, output, cwd }: UnzipOptions): Promise<import("./execAsync").ExecResult<string>>;
26
+ export declare function unzip({ input, output, cwd }: UnzipOptions): Promise<string>;
@@ -35,4 +35,4 @@ export type ZipOptions = {
35
35
  * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
36
36
  * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
37
37
  */
38
- export declare function zip({ input, output, thread, level, password, cwd }: ZipOptions): Promise<import("./execAsync").ExecResult<string>>;
38
+ export declare function zip({ input, output, thread, level, password, cwd }: ZipOptions): Promise<string>;
@@ -1,6 +1,4 @@
1
- export * from "./utils/check7zip";
2
1
  export * from "./utils/execAsync";
3
- export * from "./utils/install7zip";
4
2
  export * from "./utils/saveFile";
5
3
  export * from "./utils/spawnAsync";
6
4
  export * from "./utils/unzip";
package/dist/esm/index.js CHANGED
@@ -1,6 +1,4 @@
1
- export * from "./utils/check7zip";
2
1
  export * from "./utils/execAsync";
3
- export * from "./utils/install7zip";
4
2
  export * from "./utils/saveFile";
5
3
  export * from "./utils/spawnAsync";
6
4
  export * from "./utils/unzip";
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"@utils/check7zip\"\nexport * from \"@utils/execAsync\"\nexport * from \"@utils/install7zip\"\nexport * from \"@utils/saveFile\"\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/execAsync\"\nexport * from \"@utils/saveFile\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA"}
@@ -3,19 +3,33 @@
3
3
  /// <reference types="node" />
4
4
  import { ExecOptions } from "child_process";
5
5
  import { ObjectEncodingOptions } from "fs";
6
- export type ExecResult<T> = {
7
- stdout: T;
8
- stderr: T;
6
+ import { Options } from "iconv-lite";
7
+ export type IconvDecodeOptions = {
8
+ encoding: string;
9
+ options?: Options;
9
10
  };
10
- export declare function execAsync(command: string): Promise<ExecResult<string>>;
11
+ export declare function execAsync(command: string): Promise<string>;
11
12
  export declare function execAsync(command: string, options: {
12
13
  encoding: "buffer" | null;
13
- } & ExecOptions): Promise<ExecResult<Buffer>>;
14
+ } & ExecOptions): Promise<Buffer>;
15
+ export declare function execAsync(command: string, options: {
16
+ encoding: "buffer" | null;
17
+ } & ExecOptions & {
18
+ decode: IconvDecodeOptions;
19
+ }): Promise<string>;
20
+ export declare function execAsync(command: string, options: {
21
+ encoding: BufferEncoding;
22
+ } & ExecOptions): Promise<string>;
14
23
  export declare function execAsync(command: string, options: {
15
24
  encoding: BufferEncoding;
16
- } & ExecOptions): Promise<ExecResult<string>>;
25
+ } & ExecOptions): Promise<string | Buffer>;
17
26
  export declare function execAsync(command: string, options: {
18
27
  encoding: BufferEncoding;
19
- } & ExecOptions): Promise<ExecResult<string | Buffer>>;
20
- export declare function execAsync(command: string, options: ExecOptions): Promise<ExecResult<string>>;
21
- export declare function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<ExecResult<string | Buffer>>;
28
+ } & ExecOptions & {
29
+ decode: IconvDecodeOptions;
30
+ }): Promise<string>;
31
+ export declare function execAsync(command: string, options: ExecOptions): Promise<string>;
32
+ export declare function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>;
33
+ export declare function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions & {
34
+ decode: IconvDecodeOptions;
35
+ }) | undefined | null): Promise<string>;
@@ -1,15 +1,20 @@
1
1
  import { exec } from "child_process";
2
+ import iconv from "iconv-lite";
2
3
  export async function execAsync(command, options) {
4
+ const decode = options?.decode;
5
+ if (typeof options === "object" && options !== null && options.decode) {
6
+ const {
7
+ decode,
8
+ ...rest
9
+ } = options;
10
+ options = rest;
11
+ }
3
12
  return await new Promise((resolve, reject) => {
4
13
  exec(command, options, (error, stdout, stderr) => {
5
- if (error) {
6
- reject(error);
7
- return;
8
- }
9
- resolve({
10
- stdout,
11
- stderr
12
- });
14
+ if (error) return reject(error);
15
+ // if (stderr) console.warn(stderr)
16
+ if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options));
17
+ resolve(stdout);
13
18
  });
14
19
  });
15
20
  }
@@ -1 +1 @@
1
- {"version":3,"names":["exec","execAsync","command","options","Promise","resolve","reject","error","stdout","stderr"],"sources":["../../../src/utils/execAsync.ts"],"sourcesContent":["import { exec, ExecOptions } from \"child_process\"\r\nimport { ObjectEncodingOptions } from \"fs\"\r\n\r\nexport type ExecResult<T> = {\r\n stdout: T\r\n stderr: T\r\n}\r\n\r\nexport async function execAsync(command: string): Promise<ExecResult<string>>\r\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<ExecResult<Buffer>>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<ExecResult<string>>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<ExecResult<string | Buffer>>\r\nexport async function execAsync(command: string, options: ExecOptions): Promise<ExecResult<string>>\r\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<ExecResult<string | Buffer>>\r\nexport async function execAsync(command: string, options?: any) {\r\n return await new Promise<ExecResult<string | Buffer>>((resolve, reject) => {\r\n exec(command, options, (error, stdout, stderr) => {\r\n if (error) {\r\n reject(error)\r\n return\r\n }\r\n resolve({ stdout, stderr })\r\n })\r\n })\r\n}\r\n"],"mappings":"AAAA,SAASA,IAAI,QAAqB,eAAe;AAcjD,OAAO,eAAeC,SAASA,CAACC,OAAe,EAAEC,OAAa,EAAE;EAC5D,OAAO,MAAM,IAAIC,OAAO,CAA8B,CAACC,OAAO,EAAEC,MAAM,KAAK;IACvEN,IAAI,CAACE,OAAO,EAAEC,OAAO,EAAE,CAACI,KAAK,EAAEC,MAAM,EAAEC,MAAM,KAAK;MAC9C,IAAIF,KAAK,EAAE;QACPD,MAAM,CAACC,KAAK,CAAC;QACb;MACJ;MACAF,OAAO,CAAC;QAAEG,MAAM;QAAEC;MAAO,CAAC,CAAC;IAC/B,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 { exec, ExecOptions } from \"child_process\"\r\nimport { ObjectEncodingOptions } from \"fs\"\r\nimport iconv, { Options } from \"iconv-lite\"\r\n\r\nexport type IconvDecodeOptions = {\r\n encoding: string\r\n options?: Options\r\n}\r\n\r\nexport async function execAsync(command: string): Promise<string>\r\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions): Promise<Buffer>\r\nexport async function execAsync(command: string, options: { encoding: \"buffer\" | null } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string | Buffer>\r\nexport async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>\r\nexport async function execAsync(command: string, options: ExecOptions): Promise<string>\r\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>\r\nexport async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null): Promise<string>\r\nexport async function execAsync(command: string, options?: any) {\r\n const decode = options?.decode as IconvDecodeOptions | undefined\r\n if (typeof options === \"object\" && options !== null && options.decode) {\r\n const { decode, ...rest } = options as { decode: IconvDecodeOptions }\r\n options = rest\r\n }\r\n return await new Promise<string | Buffer>((resolve, reject) => {\r\n exec(command, options, (error, stdout, stderr) => {\r\n if (error) return reject(error)\r\n // if (stderr) console.warn(stderr)\r\n if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))\r\n resolve(stdout)\r\n })\r\n })\r\n}\r\n"],"mappings":"AAAA,SAASA,IAAI,QAAqB,eAAe;AAEjD,OAAOC,KAAK,MAAmB,YAAY;AAgB3C,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"}
@@ -23,4 +23,4 @@ export type UnzipOptions = {
23
23
  * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
24
24
  * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
25
25
  */
26
- export declare function unzip({ input, output, cwd }: UnzipOptions): Promise<import("./execAsync").ExecResult<string>>;
26
+ export declare function unzip({ input, output, cwd }: UnzipOptions): Promise<string>;
@@ -35,4 +35,4 @@ export type ZipOptions = {
35
35
  * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
36
36
  * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
37
37
  */
38
- export declare function zip({ input, output, thread, level, password, cwd }: ZipOptions): Promise<import("./execAsync").ExecResult<string>>;
38
+ export declare function zip({ input, output, thread, level, password, cwd }: ZipOptions): Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soda-nodejs",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -28,6 +28,7 @@
28
28
  "father": "^4.5.0-rc.2"
29
29
  },
30
30
  "dependencies": {
31
+ "iconv-lite": "^0.6.3",
31
32
  "which": "^4.0.0"
32
33
  },
33
34
  "scripts": {
package/src/index.ts CHANGED
@@ -1,6 +1,4 @@
1
- export * from "@utils/check7zip"
2
1
  export * from "@utils/execAsync"
3
- export * from "@utils/install7zip"
4
2
  export * from "@utils/saveFile"
5
3
  export * from "@utils/spawnAsync"
6
4
  export * from "@utils/unzip"
@@ -1,25 +1,33 @@
1
1
  import { exec, ExecOptions } from "child_process"
2
2
  import { ObjectEncodingOptions } from "fs"
3
+ import iconv, { Options } from "iconv-lite"
3
4
 
4
- export type ExecResult<T> = {
5
- stdout: T
6
- stderr: T
5
+ export type IconvDecodeOptions = {
6
+ encoding: string
7
+ options?: Options
7
8
  }
8
9
 
9
- export async function execAsync(command: string): Promise<ExecResult<string>>
10
- export async function execAsync(command: string, options: { encoding: "buffer" | null } & ExecOptions): Promise<ExecResult<Buffer>>
11
- export async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<ExecResult<string>>
12
- export async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<ExecResult<string | Buffer>>
13
- export async function execAsync(command: string, options: ExecOptions): Promise<ExecResult<string>>
14
- export async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<ExecResult<string | Buffer>>
10
+ export async function execAsync(command: string): Promise<string>
11
+ export async function execAsync(command: string, options: { encoding: "buffer" | null } & ExecOptions): Promise<Buffer>
12
+ export async function execAsync(command: string, options: { encoding: "buffer" | null } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>
13
+ export async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string>
14
+ export async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<string | Buffer>
15
+ export async function execAsync(command: string, options: { encoding: BufferEncoding } & ExecOptions & { decode: IconvDecodeOptions }): Promise<string>
16
+ export async function execAsync(command: string, options: ExecOptions): Promise<string>
17
+ export async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions) | undefined | null): Promise<string | Buffer>
18
+ export async function execAsync(command: string, options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null): Promise<string>
15
19
  export async function execAsync(command: string, options?: any) {
16
- return await new Promise<ExecResult<string | Buffer>>((resolve, reject) => {
20
+ const decode = options?.decode as IconvDecodeOptions | undefined
21
+ if (typeof options === "object" && options !== null && options.decode) {
22
+ const { decode, ...rest } = options as { decode: IconvDecodeOptions }
23
+ options = rest
24
+ }
25
+ return await new Promise<string | Buffer>((resolve, reject) => {
17
26
  exec(command, options, (error, stdout, stderr) => {
18
- if (error) {
19
- reject(error)
20
- return
21
- }
22
- resolve({ stdout, stderr })
27
+ if (error) return reject(error)
28
+ // if (stderr) console.warn(stderr)
29
+ if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))
30
+ resolve(stdout)
23
31
  })
24
32
  })
25
33
  }
@@ -1,4 +0,0 @@
1
- /**
2
- * 检测 7z 命令是否存在
3
- */
4
- export declare function check7zip(): Promise<boolean>;
@@ -1,48 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/utils/check7zip.ts
30
- var check7zip_exports = {};
31
- __export(check7zip_exports, {
32
- check7zip: () => check7zip
33
- });
34
- module.exports = __toCommonJS(check7zip_exports);
35
- var import_which = __toESM(require("which"));
36
- async function check7zip() {
37
- try {
38
- await (0, import_which.default)("7z");
39
- return true;
40
- } catch (error) {
41
- return false;
42
- }
43
- }
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {
46
- check7zip
47
- });
48
- //# sourceMappingURL=check7zip.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/utils/check7zip.ts"],
4
- "sourcesContent": ["import which from \"which\"\r\n\r\n/**\r\n * 检测 7z 命令是否存在\r\n */\r\nexport async function check7zip() {\r\n try {\r\n await which(\"7z\")\r\n return true\r\n } catch (error) {\r\n return false\r\n }\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAKlB,eAAsB,YAAY;AAC9B,MAAI;AACA,cAAM,aAAAA,SAAM,IAAI;AAChB,WAAO;AAAA,EACX,SAAS,OAAP;AACE,WAAO;AAAA,EACX;AACJ;",
6
- "names": ["which"]
7
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * 检测到没有安装 7z 时的提示信息
3
- */
4
- export declare function install7zip(): void;
@@ -1,39 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/utils/install7zip.ts
20
- var install7zip_exports = {};
21
- __export(install7zip_exports, {
22
- install7zip: () => install7zip
23
- });
24
- module.exports = __toCommonJS(install7zip_exports);
25
- function install7zip() {
26
- console.log("检测到您的系统没有安装 7z,请先安装 7z 后再执行");
27
- console.log("下载地址:https://www.7-zip.org/download.html");
28
- console.log("如果已经安装,请按照以下步骤将 7z 添加到环境变量中");
29
- console.log("1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量");
30
- console.log("2. 在系统变量中找到并选中 Path,点击编辑");
31
- console.log("3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定");
32
- console.log("4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功");
33
- console.log("5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确");
34
- }
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- install7zip
38
- });
39
- //# sourceMappingURL=install7zip.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/utils/install7zip.ts"],
4
- "sourcesContent": ["/**\r\n * 检测到没有安装 7z 时的提示信息\r\n */\r\nexport function install7zip() {\r\n console.log(\"检测到您的系统没有安装 7z,请先安装 7z 后再执行\")\r\n console.log(\"下载地址:https://www.7-zip.org/download.html\")\r\n console.log(\"如果已经安装,请按照以下步骤将 7z 添加到环境变量中\")\r\n console.log(\"1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\")\r\n console.log(\"2. 在系统变量中找到并选中 Path,点击编辑\")\r\n console.log(\"3. 点击新建,输入 7z 的安装路径(默认是 C:\\\\Program Files\\\\7-Zip),点击确定\")\r\n console.log(\"4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\")\r\n console.log(\"5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\")\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,cAAc;AAC1B,UAAQ,IAAI,6BAA6B;AACzC,UAAQ,IAAI,0CAA0C;AACtD,UAAQ,IAAI,6BAA6B;AACzC,UAAQ,IAAI,qCAAqC;AACjD,UAAQ,IAAI,0BAA0B;AACtC,UAAQ,IAAI,wDAAwD;AACpE,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,IAAI,uCAAuC;AACvD;",
6
- "names": []
7
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * 检测 7z 命令是否存在
3
- */
4
- export declare function check7zip(): Promise<boolean>;
@@ -1,14 +0,0 @@
1
- import which from "which";
2
-
3
- /**
4
- * 检测 7z 命令是否存在
5
- */
6
- export async function check7zip() {
7
- try {
8
- await which("7z");
9
- return true;
10
- } catch (error) {
11
- return false;
12
- }
13
- }
14
- //# sourceMappingURL=check7zip.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["which","check7zip","error"],"sources":["../../../src/utils/check7zip.ts"],"sourcesContent":["import which from \"which\"\r\n\r\n/**\r\n * 检测 7z 命令是否存在\r\n */\r\nexport async function check7zip() {\r\n try {\r\n await which(\"7z\")\r\n return true\r\n } catch (error) {\r\n return false\r\n }\r\n}\r\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;;AAEzB;AACA;AACA;AACA,OAAO,eAAeC,SAASA,CAAA,EAAG;EAC9B,IAAI;IACA,MAAMD,KAAK,CAAC,IAAI,CAAC;IACjB,OAAO,IAAI;EACf,CAAC,CAAC,OAAOE,KAAK,EAAE;IACZ,OAAO,KAAK;EAChB;AACJ"}
@@ -1,4 +0,0 @@
1
- /**
2
- * 检测到没有安装 7z 时的提示信息
3
- */
4
- export declare function install7zip(): void;
@@ -1,14 +0,0 @@
1
- /**
2
- * 检测到没有安装 7z 时的提示信息
3
- */
4
- export function install7zip() {
5
- console.log("检测到您的系统没有安装 7z,请先安装 7z 后再执行");
6
- console.log("下载地址:https://www.7-zip.org/download.html");
7
- console.log("如果已经安装,请按照以下步骤将 7z 添加到环境变量中");
8
- console.log("1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量");
9
- console.log("2. 在系统变量中找到并选中 Path,点击编辑");
10
- console.log("3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定");
11
- console.log("4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功");
12
- console.log("5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确");
13
- }
14
- //# sourceMappingURL=install7zip.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["install7zip","console","log"],"sources":["../../../src/utils/install7zip.ts"],"sourcesContent":["/**\r\n * 检测到没有安装 7z 时的提示信息\r\n */\r\nexport function install7zip() {\r\n console.log(\"检测到您的系统没有安装 7z,请先安装 7z 后再执行\")\r\n console.log(\"下载地址:https://www.7-zip.org/download.html\")\r\n console.log(\"如果已经安装,请按照以下步骤将 7z 添加到环境变量中\")\r\n console.log(\"1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量\")\r\n console.log(\"2. 在系统变量中找到并选中 Path,点击编辑\")\r\n console.log(\"3. 点击新建,输入 7z 的安装路径(默认是 C:\\\\Program Files\\\\7-Zip),点击确定\")\r\n console.log(\"4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功\")\r\n console.log(\"5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确\")\r\n}\r\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAAA,EAAG;EAC1BC,OAAO,CAACC,GAAG,CAAC,6BAA6B,CAAC;EAC1CD,OAAO,CAACC,GAAG,CAAC,0CAA0C,CAAC;EACvDD,OAAO,CAACC,GAAG,CAAC,6BAA6B,CAAC;EAC1CD,OAAO,CAACC,GAAG,CAAC,qCAAqC,CAAC;EAClDD,OAAO,CAACC,GAAG,CAAC,0BAA0B,CAAC;EACvCD,OAAO,CAACC,GAAG,CAAC,wDAAwD,CAAC;EACrED,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;EAChDD,OAAO,CAACC,GAAG,CAAC,uCAAuC,CAAC;AACxD"}
@@ -1,13 +0,0 @@
1
- import which from "which"
2
-
3
- /**
4
- * 检测 7z 命令是否存在
5
- */
6
- export async function check7zip() {
7
- try {
8
- await which("7z")
9
- return true
10
- } catch (error) {
11
- return false
12
- }
13
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * 检测到没有安装 7z 时的提示信息
3
- */
4
- export function install7zip() {
5
- console.log("检测到您的系统没有安装 7z,请先安装 7z 后再执行")
6
- console.log("下载地址:https://www.7-zip.org/download.html")
7
- console.log("如果已经安装,请按照以下步骤将 7z 添加到环境变量中")
8
- console.log("1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量")
9
- console.log("2. 在系统变量中找到并选中 Path,点击编辑")
10
- console.log("3. 点击新建,输入 7z 的安装路径(默认是 C:\\Program Files\\7-Zip),点击确定")
11
- console.log("4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功")
12
- console.log("5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确")
13
- }