soda-nodejs 0.2.1 → 0.4.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,5 +1,7 @@
1
+ export * from "./utils/copy";
1
2
  export * from "./utils/execAsync";
2
3
  export * from "./utils/saveFile";
4
+ export * from "./utils/saveResponse";
3
5
  export * from "./utils/spawnAsync";
4
6
  export * from "./utils/unzip";
5
7
  export * from "./utils/zip";
package/dist/cjs/index.js CHANGED
@@ -16,15 +16,19 @@ 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/copy"), module.exports);
19
20
  __reExport(src_exports, require("./utils/execAsync"), module.exports);
20
21
  __reExport(src_exports, require("./utils/saveFile"), module.exports);
22
+ __reExport(src_exports, require("./utils/saveResponse"), module.exports);
21
23
  __reExport(src_exports, require("./utils/spawnAsync"), module.exports);
22
24
  __reExport(src_exports, require("./utils/unzip"), module.exports);
23
25
  __reExport(src_exports, require("./utils/zip"), module.exports);
24
26
  // Annotate the CommonJS export names for ESM import in node:
25
27
  0 && (module.exports = {
28
+ ...require("./utils/copy"),
26
29
  ...require("./utils/execAsync"),
27
30
  ...require("./utils/saveFile"),
31
+ ...require("./utils/saveResponse"),
28
32
  ...require("./utils/spawnAsync"),
29
33
  ...require("./utils/unzip"),
30
34
  ...require("./utils/zip")
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
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;",
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
+ "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
  }
@@ -0,0 +1,9 @@
1
+ export type CopyOptions = {
2
+ /** 源文件夹 */
3
+ input: string | string[];
4
+ /** 存放的文件夹 */
5
+ output: string;
6
+ /** 文件权限 */
7
+ mode?: number;
8
+ };
9
+ export declare function copy({ input, output, mode }: CopyOptions): Promise<void>;
@@ -0,0 +1,58 @@
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/copy.ts
20
+ var copy_exports = {};
21
+ __export(copy_exports, {
22
+ copy: () => copy
23
+ });
24
+ module.exports = __toCommonJS(copy_exports);
25
+ var import_fs = require("fs");
26
+ var import_promises = require("fs/promises");
27
+ var import_path = require("path");
28
+ async function copy({ input, output, mode }) {
29
+ if (Array.isArray(input)) {
30
+ for (const item of input)
31
+ await copy({ input: item, output, mode });
32
+ return;
33
+ }
34
+ if (!(0, import_fs.existsSync)(output))
35
+ await (0, import_promises.mkdir)(output, { recursive: true });
36
+ const status = await (0, import_promises.stat)(input);
37
+ const { base } = (0, import_path.parse)(input);
38
+ if (status.isFile()) {
39
+ await (0, import_promises.copyFile)(input, (0, import_path.join)(output, base), mode);
40
+ return;
41
+ }
42
+ if (status.isDirectory()) {
43
+ await (0, import_promises.mkdir)((0, import_path.join)(output, base), { recursive: true });
44
+ const entries = await (0, import_promises.readdir)(input, { withFileTypes: true });
45
+ for (const entry of entries) {
46
+ await copy({
47
+ input: (0, import_path.join)(input, entry.name),
48
+ output: (0, import_path.join)(output, base),
49
+ mode
50
+ });
51
+ }
52
+ }
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ copy
57
+ });
58
+ //# sourceMappingURL=copy.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/utils/copy.ts"],
4
+ "sourcesContent": ["import { existsSync } from \"fs\"\r\nimport { copyFile, mkdir, readdir, stat } from \"fs/promises\"\r\nimport { join, parse } from \"path\"\r\n\r\nexport type CopyOptions = {\r\n /** 源文件夹 */\r\n input: string | string[]\r\n /** 存放的文件夹 */\r\n output: string\r\n /** 文件权限 */\r\n mode?: number\r\n}\r\n\r\nexport async function copy({ input, output, mode }: CopyOptions) {\r\n if (Array.isArray(input)) {\r\n for (const item of input) await copy({ input: item, output, mode })\r\n return\r\n }\r\n if (!existsSync(output)) await mkdir(output, { recursive: true })\r\n const status = await stat(input)\r\n const { base } = parse(input)\r\n if (status.isFile()) {\r\n await copyFile(input, join(output, base), mode)\r\n return\r\n }\r\n if (status.isDirectory()) {\r\n await mkdir(join(output, base), { recursive: true })\r\n const entries = await readdir(input, { withFileTypes: true })\r\n for (const entry of entries) {\r\n await copy({\r\n input: join(input, entry.name),\r\n output: join(output, base),\r\n mode\r\n })\r\n }\r\n }\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,sBAA+C;AAC/C,kBAA4B;AAW5B,eAAsB,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAgB;AAC7D,MAAI,MAAM,QAAQ,KAAK,GAAG;AACtB,eAAW,QAAQ;AAAO,YAAM,KAAK,EAAE,OAAO,MAAM,QAAQ,KAAK,CAAC;AAClE;AAAA,EACJ;AACA,MAAI,KAAC,sBAAW,MAAM;AAAG,cAAM,uBAAM,QAAQ,EAAE,WAAW,KAAK,CAAC;AAChE,QAAM,SAAS,UAAM,sBAAK,KAAK;AAC/B,QAAM,EAAE,KAAK,QAAI,mBAAM,KAAK;AAC5B,MAAI,OAAO,OAAO,GAAG;AACjB,cAAM,0BAAS,WAAO,kBAAK,QAAQ,IAAI,GAAG,IAAI;AAC9C;AAAA,EACJ;AACA,MAAI,OAAO,YAAY,GAAG;AACtB,cAAM,2BAAM,kBAAK,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AACnD,UAAM,UAAU,UAAM,yBAAQ,OAAO,EAAE,eAAe,KAAK,CAAC;AAC5D,eAAW,SAAS,SAAS;AACzB,YAAM,KAAK;AAAA,QACP,WAAO,kBAAK,OAAO,MAAM,IAAI;AAAA,QAC7B,YAAQ,kBAAK,QAAQ,IAAI;AAAA,QACzB;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 从 Response 对象中下载文件
3
+ * @param response Response 对象
4
+ * @param file 文件路径
5
+ */
6
+ export declare function saveResponse(response: Response, file: string): Promise<void>;
@@ -0,0 +1,37 @@
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/saveResponse.ts
20
+ var saveResponse_exports = {};
21
+ __export(saveResponse_exports, {
22
+ saveResponse: () => saveResponse
23
+ });
24
+ module.exports = __toCommonJS(saveResponse_exports);
25
+ var import_fs = require("fs");
26
+ var import_stream = require("stream");
27
+ async function saveResponse(response, file) {
28
+ const writeable = (0, import_fs.createWriteStream)(file);
29
+ await new Promise(
30
+ (resolve, reject) => import_stream.Readable.fromWeb(response.body).pipe(writeable).on("close", resolve).on("error", reject)
31
+ );
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ saveResponse
36
+ });
37
+ //# sourceMappingURL=saveResponse.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/utils/saveResponse.ts"],
4
+ "sourcesContent": ["import { createWriteStream } from \"fs\"\r\nimport { Readable } from \"stream\"\r\n\r\n/**\r\n * 从 Response 对象中下载文件\r\n * @param response Response 对象\r\n * @param file 文件路径\r\n */\r\nexport async function saveResponse(response: Response, file: string) {\r\n const writeable = createWriteStream(file)\r\n await new Promise((resolve, reject) =>\r\n Readable.fromWeb(response.body! as any)\r\n .pipe(writeable)\r\n .on(\"close\", resolve)\r\n .on(\"error\", reject)\r\n )\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,oBAAyB;AAOzB,eAAsB,aAAa,UAAoB,MAAc;AACjE,QAAM,gBAAY,6BAAkB,IAAI;AACxC,QAAM,IAAI;AAAA,IAAQ,CAAC,SAAS,WACxB,uBAAS,QAAQ,SAAS,IAAY,EACjC,KAAK,SAAS,EACd,GAAG,SAAS,OAAO,EACnB,GAAG,SAAS,MAAM;AAAA,EAC3B;AACJ;",
6
+ "names": []
7
+ }
@@ -28,7 +28,7 @@ async function spawnAsync(command, args, options) {
28
28
  const child = (0, import_child_process.spawn)(command, args, options);
29
29
  child.on("exit", (code) => {
30
30
  if (code !== 0) {
31
- reject(new Error(`Command failed with code ${code}`));
31
+ reject(new Error(`"${command}" Command failed with code ${code}`));
32
32
  return;
33
33
  }
34
34
  resolve();
@@ -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\"\r\n\r\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptions): Promise<void>\r\nexport function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>\r\nexport async function spawnAsync(command: string, args?: any, options?: any) {\r\n await new Promise<void>((resolve, reject) => {\r\n const child = spawn(command, args, options)\r\n child.on(\"exit\", code => {\r\n if (code !== 0) {\r\n reject(new Error(`Command failed with code ${code}`))\r\n return\r\n }\r\n resolve()\r\n })\r\n })\r\n}\r\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,4BAA4B,MAAM,CAAC;AACpD;AAAA,MACJ;AACA,cAAQ;AAAA,IACZ,CAAC;AAAA,EACL,CAAC;AACL;",
4
+ "sourcesContent": ["import { spawn, SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, StdioNull, StdioPipe } from \"child_process\"\r\n\r\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptions): Promise<void>\r\nexport function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>\r\nexport async function spawnAsync(command: string, args?: any, options?: any) {\r\n await new Promise<void>((resolve, reject) => {\r\n const child = spawn(command, args, options)\r\n child.on(\"exit\", code => {\r\n if (code !== 0) {\r\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\r\n return\r\n }\r\n resolve()\r\n })\r\n })\r\n}\r\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;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,7 @@
1
+ export * from "./utils/copy";
1
2
  export * from "./utils/execAsync";
2
3
  export * from "./utils/saveFile";
4
+ export * from "./utils/saveResponse";
3
5
  export * from "./utils/spawnAsync";
4
6
  export * from "./utils/unzip";
5
7
  export * from "./utils/zip";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,7 @@
1
+ export * from "./utils/copy";
1
2
  export * from "./utils/execAsync";
2
3
  export * from "./utils/saveFile";
4
+ export * from "./utils/saveResponse";
3
5
  export * from "./utils/spawnAsync";
4
6
  export * from "./utils/unzip";
5
7
  export * from "./utils/zip";
@@ -1 +1 @@
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"}
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"}
@@ -0,0 +1,9 @@
1
+ export type CopyOptions = {
2
+ /** 源文件夹 */
3
+ input: string | string[];
4
+ /** 存放的文件夹 */
5
+ output: string;
6
+ /** 文件权限 */
7
+ mode?: number;
8
+ };
9
+ export declare function copy({ input, output, mode }: CopyOptions): Promise<void>;
@@ -0,0 +1,44 @@
1
+ import { existsSync } from "fs";
2
+ import { copyFile, mkdir, readdir, stat } from "fs/promises";
3
+ import { join, parse } from "path";
4
+ export async function copy({
5
+ input,
6
+ output,
7
+ mode
8
+ }) {
9
+ if (Array.isArray(input)) {
10
+ for (const item of input) await copy({
11
+ input: item,
12
+ output,
13
+ mode
14
+ });
15
+ return;
16
+ }
17
+ if (!existsSync(output)) await mkdir(output, {
18
+ recursive: true
19
+ });
20
+ const status = await stat(input);
21
+ const {
22
+ base
23
+ } = parse(input);
24
+ if (status.isFile()) {
25
+ await copyFile(input, join(output, base), mode);
26
+ return;
27
+ }
28
+ if (status.isDirectory()) {
29
+ await mkdir(join(output, base), {
30
+ recursive: true
31
+ });
32
+ const entries = await readdir(input, {
33
+ withFileTypes: true
34
+ });
35
+ for (const entry of entries) {
36
+ await copy({
37
+ input: join(input, entry.name),
38
+ output: join(output, base),
39
+ mode
40
+ });
41
+ }
42
+ }
43
+ }
44
+ //# sourceMappingURL=copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["existsSync","copyFile","mkdir","readdir","stat","join","parse","copy","input","output","mode","Array","isArray","item","recursive","status","base","isFile","isDirectory","entries","withFileTypes","entry","name"],"sources":["../../../src/utils/copy.ts"],"sourcesContent":["import { existsSync } from \"fs\"\r\nimport { copyFile, mkdir, readdir, stat } from \"fs/promises\"\r\nimport { join, parse } from \"path\"\r\n\r\nexport type CopyOptions = {\r\n /** 源文件夹 */\r\n input: string | string[]\r\n /** 存放的文件夹 */\r\n output: string\r\n /** 文件权限 */\r\n mode?: number\r\n}\r\n\r\nexport async function copy({ input, output, mode }: CopyOptions) {\r\n if (Array.isArray(input)) {\r\n for (const item of input) await copy({ input: item, output, mode })\r\n return\r\n }\r\n if (!existsSync(output)) await mkdir(output, { recursive: true })\r\n const status = await stat(input)\r\n const { base } = parse(input)\r\n if (status.isFile()) {\r\n await copyFile(input, join(output, base), mode)\r\n return\r\n }\r\n if (status.isDirectory()) {\r\n await mkdir(join(output, base), { recursive: true })\r\n const entries = await readdir(input, { withFileTypes: true })\r\n for (const entry of entries) {\r\n await copy({\r\n input: join(input, entry.name),\r\n output: join(output, base),\r\n mode\r\n })\r\n }\r\n }\r\n}\r\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,IAAI;AAC/B,SAASC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,IAAI,QAAQ,aAAa;AAC5D,SAASC,IAAI,EAAEC,KAAK,QAAQ,MAAM;AAWlC,OAAO,eAAeC,IAAIA,CAAC;EAAEC,KAAK;EAAEC,MAAM;EAAEC;AAAkB,CAAC,EAAE;EAC7D,IAAIC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;IACtB,KAAK,MAAMK,IAAI,IAAIL,KAAK,EAAE,MAAMD,IAAI,CAAC;MAAEC,KAAK,EAAEK,IAAI;MAAEJ,MAAM;MAAEC;IAAK,CAAC,CAAC;IACnE;EACJ;EACA,IAAI,CAACV,UAAU,CAACS,MAAM,CAAC,EAAE,MAAMP,KAAK,CAACO,MAAM,EAAE;IAAEK,SAAS,EAAE;EAAK,CAAC,CAAC;EACjE,MAAMC,MAAM,GAAG,MAAMX,IAAI,CAACI,KAAK,CAAC;EAChC,MAAM;IAAEQ;EAAK,CAAC,GAAGV,KAAK,CAACE,KAAK,CAAC;EAC7B,IAAIO,MAAM,CAACE,MAAM,CAAC,CAAC,EAAE;IACjB,MAAMhB,QAAQ,CAACO,KAAK,EAAEH,IAAI,CAACI,MAAM,EAAEO,IAAI,CAAC,EAAEN,IAAI,CAAC;IAC/C;EACJ;EACA,IAAIK,MAAM,CAACG,WAAW,CAAC,CAAC,EAAE;IACtB,MAAMhB,KAAK,CAACG,IAAI,CAACI,MAAM,EAAEO,IAAI,CAAC,EAAE;MAAEF,SAAS,EAAE;IAAK,CAAC,CAAC;IACpD,MAAMK,OAAO,GAAG,MAAMhB,OAAO,CAACK,KAAK,EAAE;MAAEY,aAAa,EAAE;IAAK,CAAC,CAAC;IAC7D,KAAK,MAAMC,KAAK,IAAIF,OAAO,EAAE;MACzB,MAAMZ,IAAI,CAAC;QACPC,KAAK,EAAEH,IAAI,CAACG,KAAK,EAAEa,KAAK,CAACC,IAAI,CAAC;QAC9Bb,MAAM,EAAEJ,IAAI,CAACI,MAAM,EAAEO,IAAI,CAAC;QAC1BN;MACJ,CAAC,CAAC;IACN;EACJ;AACJ"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 从 Response 对象中下载文件
3
+ * @param response Response 对象
4
+ * @param file 文件路径
5
+ */
6
+ export declare function saveResponse(response: Response, file: string): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import { createWriteStream } from "fs";
2
+ import { Readable } from "stream";
3
+
4
+ /**
5
+ * 从 Response 对象中下载文件
6
+ * @param response Response 对象
7
+ * @param file 文件路径
8
+ */
9
+ export async function saveResponse(response, file) {
10
+ const writeable = createWriteStream(file);
11
+ await new Promise((resolve, reject) => Readable.fromWeb(response.body).pipe(writeable).on("close", resolve).on("error", reject));
12
+ }
13
+ //# sourceMappingURL=saveResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createWriteStream","Readable","saveResponse","response","file","writeable","Promise","resolve","reject","fromWeb","body","pipe","on"],"sources":["../../../src/utils/saveResponse.ts"],"sourcesContent":["import { createWriteStream } from \"fs\"\r\nimport { Readable } from \"stream\"\r\n\r\n/**\r\n * 从 Response 对象中下载文件\r\n * @param response Response 对象\r\n * @param file 文件路径\r\n */\r\nexport async function saveResponse(response: Response, file: string) {\r\n const writeable = createWriteStream(file)\r\n await new Promise((resolve, reject) =>\r\n Readable.fromWeb(response.body! as any)\r\n .pipe(writeable)\r\n .on(\"close\", resolve)\r\n .on(\"error\", reject)\r\n )\r\n}\r\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,IAAI;AACtC,SAASC,QAAQ,QAAQ,QAAQ;;AAEjC;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAACC,QAAkB,EAAEC,IAAY,EAAE;EACjE,MAAMC,SAAS,GAAGL,iBAAiB,CAACI,IAAI,CAAC;EACzC,MAAM,IAAIE,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAC9BP,QAAQ,CAACQ,OAAO,CAACN,QAAQ,CAACO,IAAY,CAAC,CAClCC,IAAI,CAACN,SAAS,CAAC,CACfO,EAAE,CAAC,OAAO,EAAEL,OAAO,CAAC,CACpBK,EAAE,CAAC,OAAO,EAAEJ,MAAM,CAC3B,CAAC;AACL"}
@@ -4,7 +4,7 @@ export async function spawnAsync(command, args, options) {
4
4
  const child = spawn(command, args, options);
5
5
  child.on("exit", code => {
6
6
  if (code !== 0) {
7
- reject(new Error(`Command failed with code ${code}`));
7
+ reject(new Error(`"${command}" Command failed with code ${code}`));
8
8
  return;
9
9
  }
10
10
  resolve();
@@ -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\"\r\n\r\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptions): Promise<void>\r\nexport function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>\r\nexport async function spawnAsync(command: string, args?: any, options?: any) {\r\n await new Promise<void>((resolve, reject) => {\r\n const child = spawn(command, args, options)\r\n child.on(\"exit\", code => {\r\n if (code !== 0) {\r\n reject(new Error(`Command failed with code ${code}`))\r\n return\r\n }\r\n resolve()\r\n })\r\n })\r\n}\r\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,4BAA2BD,IAAK,EAAC,CAAC,CAAC;QACrD;MACJ;MACAJ,OAAO,CAAC,CAAC;IACb,CAAC,CAAC;EACN,CAAC,CAAC;AACN"}
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\"\r\n\r\nexport function spawnAsync(command: string, options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, options: SpawnOptions): Promise<void>\r\nexport function spawnAsync(command: string, args?: readonly string[], options?: SpawnOptionsWithoutStdio): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>): Promise<void>\r\nexport function spawnAsync(command: string, args: readonly string[], options: SpawnOptions): Promise<void>\r\nexport async function spawnAsync(command: string, args?: any, options?: any) {\r\n await new Promise<void>((resolve, reject) => {\r\n const child = spawn(command, args, options)\r\n child.on(\"exit\", code => {\r\n if (code !== 0) {\r\n reject(new Error(`\"${command}\" Command failed with code ${code}`))\r\n return\r\n }\r\n resolve()\r\n })\r\n })\r\n}\r\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soda-nodejs",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/index.ts CHANGED
@@ -1,5 +1,7 @@
1
+ export * from "@utils/copy"
1
2
  export * from "@utils/execAsync"
2
3
  export * from "@utils/saveFile"
4
+ export * from "@utils/saveResponse"
3
5
  export * from "@utils/spawnAsync"
4
6
  export * from "@utils/unzip"
5
7
  export * from "@utils/zip"
@@ -0,0 +1,37 @@
1
+ import { existsSync } from "fs"
2
+ import { copyFile, mkdir, readdir, stat } from "fs/promises"
3
+ import { join, parse } from "path"
4
+
5
+ export type CopyOptions = {
6
+ /** 源文件夹 */
7
+ input: string | string[]
8
+ /** 存放的文件夹 */
9
+ output: string
10
+ /** 文件权限 */
11
+ mode?: number
12
+ }
13
+
14
+ export async function copy({ input, output, mode }: CopyOptions) {
15
+ if (Array.isArray(input)) {
16
+ for (const item of input) await copy({ input: item, output, mode })
17
+ return
18
+ }
19
+ if (!existsSync(output)) await mkdir(output, { recursive: true })
20
+ const status = await stat(input)
21
+ const { base } = parse(input)
22
+ if (status.isFile()) {
23
+ await copyFile(input, join(output, base), mode)
24
+ return
25
+ }
26
+ if (status.isDirectory()) {
27
+ await mkdir(join(output, base), { recursive: true })
28
+ const entries = await readdir(input, { withFileTypes: true })
29
+ for (const entry of entries) {
30
+ await copy({
31
+ input: join(input, entry.name),
32
+ output: join(output, base),
33
+ mode
34
+ })
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,17 @@
1
+ import { createWriteStream } from "fs"
2
+ import { Readable } from "stream"
3
+
4
+ /**
5
+ * 从 Response 对象中下载文件
6
+ * @param response Response 对象
7
+ * @param file 文件路径
8
+ */
9
+ export async function saveResponse(response: Response, file: string) {
10
+ const writeable = createWriteStream(file)
11
+ await new Promise((resolve, reject) =>
12
+ Readable.fromWeb(response.body! as any)
13
+ .pipe(writeable)
14
+ .on("close", resolve)
15
+ .on("error", reject)
16
+ )
17
+ }
@@ -25,7 +25,7 @@ export async function spawnAsync(command: string, args?: any, options?: any) {
25
25
  const child = spawn(command, args, options)
26
26
  child.on("exit", code => {
27
27
  if (code !== 0) {
28
- reject(new Error(`Command failed with code ${code}`))
28
+ reject(new Error(`"${command}" Command failed with code ${code}`))
29
29
  return
30
30
  }
31
31
  resolve()