soda-nodejs 0.3.0 → 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/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/spawnAsync.js +1 -1
- package/dist/cjs/utils/spawnAsync.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/spawnAsync.js +1 -1
- package/dist/esm/utils/spawnAsync.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/utils/copy.ts +37 -0
- package/src/utils/spawnAsync.ts +1 -1
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\"\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
|
+
}
|
|
@@ -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(
|
|
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\"\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
|
}
|
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\"\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"}
|
|
@@ -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(
|
|
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
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/spawnAsync.ts
CHANGED
|
@@ -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()
|