soda-nodejs 0.3.0 → 0.4.1
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 +23 -23
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utils/copy.d.ts +9 -0
- package/dist/cjs/utils/copy.js +58 -0
- package/dist/cjs/utils/copy.js.map +7 -0
- package/dist/cjs/utils/execAsync.d.ts +1 -0
- package/dist/cjs/utils/execAsync.js.map +2 -2
- package/dist/cjs/utils/saveFile.js.map +1 -1
- package/dist/cjs/utils/saveResponse.js.map +1 -1
- package/dist/cjs/utils/spawnAsync.js +1 -1
- package/dist/cjs/utils/spawnAsync.js.map +2 -2
- package/dist/cjs/utils/unzip.js.map +1 -1
- package/dist/cjs/utils/zip.js +4 -1
- package/dist/cjs/utils/zip.js.map +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/copy.d.ts +9 -0
- package/dist/esm/utils/copy.js +44 -0
- package/dist/esm/utils/copy.js.map +1 -0
- package/dist/esm/utils/execAsync.d.ts +1 -0
- package/dist/esm/utils/execAsync.js.map +1 -1
- package/dist/esm/utils/saveFile.js +2 -2
- package/dist/esm/utils/saveFile.js.map +1 -1
- package/dist/esm/utils/saveResponse.js +4 -4
- package/dist/esm/utils/saveResponse.js.map +1 -1
- package/dist/esm/utils/spawnAsync.js +1 -1
- package/dist/esm/utils/spawnAsync.js.map +1 -1
- package/dist/esm/utils/unzip.js +10 -10
- package/dist/esm/utils/unzip.js.map +1 -1
- package/dist/esm/utils/zip.js +10 -10
- package/dist/esm/utils/zip.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -0
- package/src/utils/copy.ts +37 -0
- package/src/utils/execAsync.ts +36 -33
- package/src/utils/saveFile.ts +22 -22
- package/src/utils/saveResponse.ts +17 -17
- package/src/utils/spawnAsync.ts +34 -34
- package/src/utils/unzip.ts +33 -33
- package/src/utils/zip.ts +51 -48
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
# soda-node
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.com/package/soda-node)
|
|
4
|
-
[](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
|
+
[](https://npmjs.com/package/soda-node)
|
|
4
|
+
[](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
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -16,6 +16,7 @@ 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);
|
|
21
22
|
__reExport(src_exports, require("./utils/saveResponse"), module.exports);
|
|
@@ -24,6 +25,7 @@ __reExport(src_exports, require("./utils/unzip"), module.exports);
|
|
|
24
25
|
__reExport(src_exports, require("./utils/zip"), module.exports);
|
|
25
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
27
|
0 && (module.exports = {
|
|
28
|
+
...require("./utils/copy"),
|
|
27
29
|
...require("./utils/execAsync"),
|
|
28
30
|
...require("./utils/saveFile"),
|
|
29
31
|
...require("./utils/saveResponse"),
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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/saveResponse\"\nexport * from \"@utils/spawnAsync\"\nexport * from \"@utils/unzip\"\nexport * from \"@utils/zip\"\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,
|
|
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,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\"\nimport { copyFile, mkdir, readdir, stat } from \"fs/promises\"\nimport { join, parse } from \"path\"\n\nexport type CopyOptions = {\n /** 源文件夹 */\n input: string | string[]\n /** 存放的文件夹 */\n output: string\n /** 文件权限 */\n mode?: number\n}\n\nexport async function copy({ input, output, mode }: CopyOptions) {\n if (Array.isArray(input)) {\n for (const item of input) await copy({ input: item, output, mode })\n return\n }\n if (!existsSync(output)) await mkdir(output, { recursive: true })\n const status = await stat(input)\n const { base } = parse(input)\n if (status.isFile()) {\n await copyFile(input, join(output, base), mode)\n return\n }\n if (status.isDirectory()) {\n await mkdir(join(output, base), { recursive: true })\n const entries = await readdir(input, { withFileTypes: true })\n for (const entry of entries) {\n await copy({\n input: join(input, entry.name),\n output: join(output, base),\n mode,\n })\n }\n }\n}\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
|
+
}
|
|
@@ -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\"\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAkC;AAElC,wBAA+B;
|
|
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"],
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/saveFile.ts"],
|
|
4
|
-
"sourcesContent": ["import { createWriteStream } from \"fs\"\
|
|
4
|
+
"sourcesContent": ["import { createWriteStream } from \"fs\"\nimport { Readable } from \"stream\"\n\nexport type SaveFileOptions = {\n /** 要保存的文件 */\n input: File\n /** 保存文件的目标位置 */\n output: string\n}\n\n/**\n * 保存文件\n */\nexport async function saveFile({ input, output }: SaveFileOptions) {\n await new Promise((resolve, reject) => {\n const writeAble = createWriteStream(output)\n Readable.fromWeb(input.stream() as any)\n .pipe(writeAble)\n .on(\"finish\", resolve)\n .on(\"error\", reject)\n })\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAkC;AAClC,oBAAyB;AAYzB,eAAsB,SAAS,EAAE,OAAO,OAAO,GAAoB;AAC/D,QAAM,IAAI,QAAQ,CAAC,SAAS,WAAW;AACnC,UAAM,gBAAY,6BAAkB,MAAM;AAC1C,2BAAS,QAAQ,MAAM,OAAO,CAAQ,EACjC,KAAK,SAAS,EACd,GAAG,UAAU,OAAO,EACpB,GAAG,SAAS,MAAM;AAAA,EAC3B,CAAC;AACL;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/saveResponse.ts"],
|
|
4
|
-
"sourcesContent": ["import { createWriteStream } from \"fs\"\
|
|
4
|
+
"sourcesContent": ["import { createWriteStream } from \"fs\"\nimport { Readable } from \"stream\"\n\n/**\n * 从 Response 对象中下载文件\n * @param response Response 对象\n * @param file 文件路径\n */\nexport async function saveResponse(response: Response, file: string) {\n const writeable = createWriteStream(file)\n await new Promise((resolve, reject) =>\n Readable.fromWeb(response.body! as any)\n .pipe(writeable)\n .on(\"close\", resolve)\n .on(\"error\", reject),\n )\n}\n"],
|
|
5
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
6
|
"names": []
|
|
7
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\"\
|
|
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,
|
|
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;",
|
|
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\"\
|
|
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
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;",
|
|
6
6
|
"names": ["which"]
|
|
7
7
|
}
|
package/dist/cjs/utils/zip.js
CHANGED
|
@@ -40,7 +40,10 @@ async function zip({ input, output, thread = "auto", level, password, cwd }) {
|
|
|
40
40
|
input = Array.isArray(input) ? input.join(" ") : input;
|
|
41
41
|
if (thread === "max")
|
|
42
42
|
thread = (0, import_os.cpus)().length;
|
|
43
|
-
return await (0, import_execAsync.execAsync)(
|
|
43
|
+
return await (0, import_execAsync.execAsync)(
|
|
44
|
+
`7z a ${output} ${input} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`,
|
|
45
|
+
{ cwd }
|
|
46
|
+
);
|
|
44
47
|
}
|
|
45
48
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
49
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/zip.ts"],
|
|
4
|
-
"sourcesContent": ["import { cpus } from \"os\"\
|
|
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,
|
|
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;",
|
|
6
6
|
"names": ["which"]
|
|
7
7
|
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * 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"}
|
|
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,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\"\nimport { copyFile, mkdir, readdir, stat } from \"fs/promises\"\nimport { join, parse } from \"path\"\n\nexport type CopyOptions = {\n /** 源文件夹 */\n input: string | string[]\n /** 存放的文件夹 */\n output: string\n /** 文件权限 */\n mode?: number\n}\n\nexport async function copy({ input, output, mode }: CopyOptions) {\n if (Array.isArray(input)) {\n for (const item of input) await copy({ input: item, output, mode })\n return\n }\n if (!existsSync(output)) await mkdir(output, { recursive: true })\n const status = await stat(input)\n const { base } = parse(input)\n if (status.isFile()) {\n await copyFile(input, join(output, base), mode)\n return\n }\n if (status.isDirectory()) {\n await mkdir(join(output, base), { recursive: true })\n const entries = await readdir(input, { withFileTypes: true })\n for (const entry of entries) {\n await copy({\n input: join(input, entry.name),\n output: join(output, base),\n mode,\n })\n }\n }\n}\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"}
|
|
@@ -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\"\
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createWriteStream","Readable","saveFile","input","output","Promise","resolve","reject","writeAble","fromWeb","stream","pipe","on"],"sources":["../../../src/utils/saveFile.ts"],"sourcesContent":["import { createWriteStream } from \"fs\"\
|
|
1
|
+
{"version":3,"names":["createWriteStream","Readable","saveFile","input","output","Promise","resolve","reject","writeAble","fromWeb","stream","pipe","on"],"sources":["../../../src/utils/saveFile.ts"],"sourcesContent":["import { createWriteStream } from \"fs\"\nimport { Readable } from \"stream\"\n\nexport type SaveFileOptions = {\n /** 要保存的文件 */\n input: File\n /** 保存文件的目标位置 */\n output: string\n}\n\n/**\n * 保存文件\n */\nexport async function saveFile({ input, output }: SaveFileOptions) {\n await new Promise((resolve, reject) => {\n const writeAble = createWriteStream(output)\n Readable.fromWeb(input.stream() as any)\n .pipe(writeAble)\n .on(\"finish\", resolve)\n .on(\"error\", reject)\n })\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,IAAI;AACtC,SAASC,QAAQ,QAAQ,QAAQ;AASjC;AACA;AACA;AACA,OAAO,eAAeC,QAAQA,CAAC;EAAEC,KAAK;EAAEC;AAAwB,CAAC,EAAE;EAC/D,MAAM,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACnC,MAAMC,SAAS,GAAGR,iBAAiB,CAACI,MAAM,CAAC;IAC3CH,QAAQ,CAACQ,OAAO,CAACN,KAAK,CAACO,MAAM,CAAC,CAAQ,CAAC,CAClCC,IAAI,CAACH,SAAS,CAAC,CACfI,EAAE,CAAC,QAAQ,EAAEN,OAAO,CAAC,CACrBM,EAAE,CAAC,OAAO,EAAEL,MAAM,CAAC;EAC5B,CAAC,CAAC;AACN"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createWriteStream } from "fs";
|
|
2
2
|
import { Readable } from "stream";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* 从 Response 对象中下载文件
|
|
6
|
-
* @param response Response 对象
|
|
7
|
-
* @param file 文件路径
|
|
4
|
+
/**
|
|
5
|
+
* 从 Response 对象中下载文件
|
|
6
|
+
* @param response Response 对象
|
|
7
|
+
* @param file 文件路径
|
|
8
8
|
*/
|
|
9
9
|
export async function saveResponse(response, file) {
|
|
10
10
|
const writeable = createWriteStream(file);
|
|
@@ -1 +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\"\
|
|
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\"\nimport { Readable } from \"stream\"\n\n/**\n * 从 Response 对象中下载文件\n * @param response Response 对象\n * @param file 文件路径\n */\nexport async function saveResponse(response: Response, file: string) {\n const writeable = createWriteStream(file)\n await new Promise((resolve, reject) =>\n Readable.fromWeb(response.body! as any)\n .pipe(writeable)\n .on(\"close\", resolve)\n .on(\"error\", reject),\n )\n}\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\"\
|
|
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"}
|
package/dist/esm/utils/unzip.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import which from "which";
|
|
2
2
|
import { execAsync } from "./execAsync";
|
|
3
|
-
/**
|
|
4
|
-
* 使用 7z 命令解压文件
|
|
5
|
-
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
6
|
-
* - 下载地址:https://www.7-zip.org/download.html
|
|
7
|
-
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
8
|
-
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
9
|
-
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
10
|
-
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
11
|
-
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
12
|
-
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
3
|
+
/**
|
|
4
|
+
* 使用 7z 命令解压文件
|
|
5
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
6
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
7
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
8
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
9
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
10
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
11
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
12
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
13
13
|
*/
|
|
14
14
|
export async function unzip({
|
|
15
15
|
input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["which","execAsync","unzip","input","output","cwd"],"sources":["../../../src/utils/unzip.ts"],"sourcesContent":["import which from \"which\"\
|
|
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"}
|
package/dist/esm/utils/zip.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { cpus } from "os";
|
|
2
2
|
import which from "which";
|
|
3
3
|
import { execAsync } from "./execAsync";
|
|
4
|
-
/**
|
|
5
|
-
* 使用 7z 命令压缩文件
|
|
6
|
-
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
7
|
-
* - 下载地址:https://www.7-zip.org/download.html
|
|
8
|
-
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
9
|
-
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
10
|
-
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
11
|
-
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
12
|
-
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
13
|
-
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
4
|
+
/**
|
|
5
|
+
* 使用 7z 命令压缩文件
|
|
6
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
7
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
8
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
9
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
10
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
11
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
12
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
13
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
14
14
|
*/
|
|
15
15
|
export async function zip({
|
|
16
16
|
input,
|
|
@@ -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\"\
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soda-nodejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/1adybug/deepsea/tree/main/packages/soda-nodejs",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/node": "^20.
|
|
26
|
+
"@types/node": "^20.17.6",
|
|
27
27
|
"@types/which": "^3.0.4"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"dev": "father dev",
|
|
35
35
|
"build": "father build",
|
|
36
|
+
"prebuild": "tsx scripts/export.ts",
|
|
36
37
|
"build:deps": "father prebundle"
|
|
37
38
|
}
|
|
38
39
|
}
|
package/src/index.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/utils/execAsync.ts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import { exec, ExecOptions } from "child_process"
|
|
2
|
-
import { ObjectEncodingOptions } from "fs"
|
|
3
|
-
import iconv, { Options } from "iconv-lite"
|
|
4
|
-
|
|
5
|
-
export type IconvDecodeOptions = {
|
|
6
|
-
encoding: string
|
|
7
|
-
options?: Options
|
|
8
|
-
}
|
|
9
|
-
|
|
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(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { exec, ExecOptions } from "child_process"
|
|
2
|
+
import { ObjectEncodingOptions } from "fs"
|
|
3
|
+
import iconv, { Options } from "iconv-lite"
|
|
4
|
+
|
|
5
|
+
export type IconvDecodeOptions = {
|
|
6
|
+
encoding: string
|
|
7
|
+
options?: Options
|
|
8
|
+
}
|
|
9
|
+
|
|
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(
|
|
19
|
+
command: string,
|
|
20
|
+
options: (ObjectEncodingOptions & ExecOptions & { decode: IconvDecodeOptions }) | undefined | null,
|
|
21
|
+
): Promise<string>
|
|
22
|
+
export async function execAsync(command: string, options?: any) {
|
|
23
|
+
const decode = options?.decode as IconvDecodeOptions | undefined
|
|
24
|
+
if (typeof options === "object" && options !== null && options.decode) {
|
|
25
|
+
const { decode, ...rest } = options as { decode: IconvDecodeOptions }
|
|
26
|
+
options = rest
|
|
27
|
+
}
|
|
28
|
+
return await new Promise<string | Buffer>((resolve, reject) => {
|
|
29
|
+
exec(command, options, (error, stdout, stderr) => {
|
|
30
|
+
if (error) return reject(error)
|
|
31
|
+
// if (stderr) console.warn(stderr)
|
|
32
|
+
if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))
|
|
33
|
+
resolve(stdout)
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
}
|
package/src/utils/saveFile.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { createWriteStream } from "fs"
|
|
2
|
-
import { Readable } from "stream"
|
|
3
|
-
|
|
4
|
-
export type SaveFileOptions = {
|
|
5
|
-
/** 要保存的文件 */
|
|
6
|
-
input: File
|
|
7
|
-
/** 保存文件的目标位置 */
|
|
8
|
-
output: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 保存文件
|
|
13
|
-
*/
|
|
14
|
-
export async function saveFile({ input, output }: SaveFileOptions) {
|
|
15
|
-
await new Promise((resolve, reject) => {
|
|
16
|
-
const writeAble = createWriteStream(output)
|
|
17
|
-
Readable.fromWeb(input.stream() as any)
|
|
18
|
-
.pipe(writeAble)
|
|
19
|
-
.on("finish", resolve)
|
|
20
|
-
.on("error", reject)
|
|
21
|
-
})
|
|
22
|
-
}
|
|
1
|
+
import { createWriteStream } from "fs"
|
|
2
|
+
import { Readable } from "stream"
|
|
3
|
+
|
|
4
|
+
export type SaveFileOptions = {
|
|
5
|
+
/** 要保存的文件 */
|
|
6
|
+
input: File
|
|
7
|
+
/** 保存文件的目标位置 */
|
|
8
|
+
output: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 保存文件
|
|
13
|
+
*/
|
|
14
|
+
export async function saveFile({ input, output }: SaveFileOptions) {
|
|
15
|
+
await new Promise((resolve, reject) => {
|
|
16
|
+
const writeAble = createWriteStream(output)
|
|
17
|
+
Readable.fromWeb(input.stream() as any)
|
|
18
|
+
.pipe(writeAble)
|
|
19
|
+
.on("finish", resolve)
|
|
20
|
+
.on("error", reject)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -1,17 +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
|
-
}
|
|
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
|
+
}
|
package/src/utils/spawnAsync.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { spawn, SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, StdioNull, StdioPipe } from "child_process"
|
|
2
|
-
|
|
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) => {
|
|
25
|
-
const child = spawn(command, args, options)
|
|
26
|
-
child.on("exit", code => {
|
|
27
|
-
if (code !== 0) {
|
|
28
|
-
reject(new Error(`Command failed with code ${code}`))
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
resolve()
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
}
|
|
1
|
+
import { spawn, SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, StdioNull, StdioPipe } from "child_process"
|
|
2
|
+
|
|
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) => {
|
|
25
|
+
const child = spawn(command, args, options)
|
|
26
|
+
child.on("exit", code => {
|
|
27
|
+
if (code !== 0) {
|
|
28
|
+
reject(new Error(`"${command}" Command failed with code ${code}`))
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
resolve()
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
}
|
package/src/utils/unzip.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import which from "which"
|
|
2
|
-
import { execAsync } from "./execAsync"
|
|
3
|
-
|
|
4
|
-
export type UnzipOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* 要解压的文件
|
|
7
|
-
*/
|
|
8
|
-
input: string
|
|
9
|
-
/**
|
|
10
|
-
* 解压到的目标文件夹位置
|
|
11
|
-
*/
|
|
12
|
-
output: string
|
|
13
|
-
/**
|
|
14
|
-
* 压缩文件时的工作目录
|
|
15
|
-
*/
|
|
16
|
-
cwd?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 使用 7z 命令解压文件
|
|
21
|
-
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
22
|
-
* - 下载地址:https://www.7-zip.org/download.html
|
|
23
|
-
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
24
|
-
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
25
|
-
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
26
|
-
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
27
|
-
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
28
|
-
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
29
|
-
*/
|
|
30
|
-
export async function unzip({ input, output, cwd }: UnzipOptions) {
|
|
31
|
-
await which("7z")
|
|
32
|
-
return await execAsync(`7z x ${input} -o${output}`, { cwd })
|
|
33
|
-
}
|
|
1
|
+
import which from "which"
|
|
2
|
+
import { execAsync } from "./execAsync"
|
|
3
|
+
|
|
4
|
+
export type UnzipOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* 要解压的文件
|
|
7
|
+
*/
|
|
8
|
+
input: string
|
|
9
|
+
/**
|
|
10
|
+
* 解压到的目标文件夹位置
|
|
11
|
+
*/
|
|
12
|
+
output: string
|
|
13
|
+
/**
|
|
14
|
+
* 压缩文件时的工作目录
|
|
15
|
+
*/
|
|
16
|
+
cwd?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 使用 7z 命令解压文件
|
|
21
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
22
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
23
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
24
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
25
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
26
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
27
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
28
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
29
|
+
*/
|
|
30
|
+
export async function unzip({ input, output, cwd }: UnzipOptions) {
|
|
31
|
+
await which("7z")
|
|
32
|
+
return await execAsync(`7z x ${input} -o${output}`, { cwd })
|
|
33
|
+
}
|
package/src/utils/zip.ts
CHANGED
|
@@ -1,48 +1,51 @@
|
|
|
1
|
-
import { cpus } from "os"
|
|
2
|
-
import which from "which"
|
|
3
|
-
import { execAsync } from "./execAsync"
|
|
4
|
-
|
|
5
|
-
export type ZipOptions = {
|
|
6
|
-
/**
|
|
7
|
-
* 要压缩的文件
|
|
8
|
-
*/
|
|
9
|
-
input: string | string[]
|
|
10
|
-
/**
|
|
11
|
-
* 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z
|
|
12
|
-
*/
|
|
13
|
-
output: string
|
|
14
|
-
/**
|
|
15
|
-
* 线程数
|
|
16
|
-
*/
|
|
17
|
-
thread?: number | "auto" | "max"
|
|
18
|
-
/**
|
|
19
|
-
* 压缩等级,0-9
|
|
20
|
-
*/
|
|
21
|
-
level?: number
|
|
22
|
-
/**
|
|
23
|
-
* 是否加密
|
|
24
|
-
*/
|
|
25
|
-
password?: string
|
|
26
|
-
/**
|
|
27
|
-
* 压缩文件时的工作目录
|
|
28
|
-
*/
|
|
29
|
-
cwd?: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 使用 7z 命令压缩文件
|
|
34
|
-
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
35
|
-
* - 下载地址:https://www.7-zip.org/download.html
|
|
36
|
-
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
37
|
-
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
38
|
-
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
39
|
-
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
40
|
-
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
41
|
-
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
42
|
-
*/
|
|
43
|
-
export async function zip({ input, output, thread = "auto", level, password, cwd }: ZipOptions) {
|
|
44
|
-
await which("7z")
|
|
45
|
-
input = Array.isArray(input) ? input.join(" ") : input
|
|
46
|
-
if (thread === "max") thread = cpus().length
|
|
47
|
-
return await execAsync(
|
|
48
|
-
}
|
|
1
|
+
import { cpus } from "os"
|
|
2
|
+
import which from "which"
|
|
3
|
+
import { execAsync } from "./execAsync"
|
|
4
|
+
|
|
5
|
+
export type ZipOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* 要压缩的文件
|
|
8
|
+
*/
|
|
9
|
+
input: string | string[]
|
|
10
|
+
/**
|
|
11
|
+
* 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z
|
|
12
|
+
*/
|
|
13
|
+
output: string
|
|
14
|
+
/**
|
|
15
|
+
* 线程数
|
|
16
|
+
*/
|
|
17
|
+
thread?: number | "auto" | "max"
|
|
18
|
+
/**
|
|
19
|
+
* 压缩等级,0-9
|
|
20
|
+
*/
|
|
21
|
+
level?: number
|
|
22
|
+
/**
|
|
23
|
+
* 是否加密
|
|
24
|
+
*/
|
|
25
|
+
password?: string
|
|
26
|
+
/**
|
|
27
|
+
* 压缩文件时的工作目录
|
|
28
|
+
*/
|
|
29
|
+
cwd?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 使用 7z 命令压缩文件
|
|
34
|
+
* - 如果没有安装 7z,请先安装 7z 后再执行
|
|
35
|
+
* - 下载地址:https://www.7-zip.org/download.html
|
|
36
|
+
* - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
|
|
37
|
+
* 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
|
|
38
|
+
* 2. 在系统变量中找到并选中 Path,点击编辑
|
|
39
|
+
* 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
|
|
40
|
+
* 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
|
|
41
|
+
* 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
|
|
42
|
+
*/
|
|
43
|
+
export async function zip({ input, output, thread = "auto", level, password, cwd }: ZipOptions) {
|
|
44
|
+
await which("7z")
|
|
45
|
+
input = Array.isArray(input) ? input.join(" ") : input
|
|
46
|
+
if (thread === "max") thread = cpus().length
|
|
47
|
+
return await execAsync(
|
|
48
|
+
`7z a ${output} ${input} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`,
|
|
49
|
+
{ cwd },
|
|
50
|
+
)
|
|
51
|
+
}
|