@pipelab/plugin-filesystem 1.0.0-beta.1 → 1.0.0-beta.11
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/chunk-jjyMKrWZ.cjs +64 -0
- package/dist/chunk-kImr3pkf.mjs +37 -0
- package/dist/index.cjs +146547 -25213
- package/dist/index.mjs +146563 -25231
- package/dist/index.mjs.map +1 -1
- package/dist/p-map-BLUi4UZH.cjs +105 -0
- package/dist/p-map-Cq4VbU2A.mjs +107 -0
- package/dist/p-map-Cq4VbU2A.mjs.map +1 -0
- package/package.json +7 -4
- package/CHANGELOG.md +0 -18
- package/src/copy.spec.ts +0 -100
- package/src/copy.ts +0 -154
- package/src/index.ts +0 -58
- package/src/is-file.ts +0 -36
- package/src/list-files.ts +0 -70
- package/src/open.ts +0 -67
- package/src/remove.ts +0 -58
- package/src/run.ts +0 -138
- package/src/temporary-folder.ts +0 -50
- package/src/unzip.spec.ts +0 -33
- package/src/unzip.ts +0 -58
- package/src/zip-v2.ts +0 -120
- package/src/zip.ts +0 -133
- package/tests/e2e/filesystem.spec.ts +0 -103
- package/tests/e2e/vitest.config.mts +0 -20
- package/tsconfig.json +0 -8
- package/tsdown.config.ts +0 -15
package/src/list-files.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { createAction, createActionRunner } from "@pipelab/plugin-core";
|
|
4
|
-
export const ID = "list-files-node";
|
|
5
|
-
|
|
6
|
-
export const ListFilesAction = createAction({
|
|
7
|
-
id: ID,
|
|
8
|
-
name: "List files",
|
|
9
|
-
displayString:
|
|
10
|
-
"`List files \"${params.recursive ? 'recursively' : ''}\" from \"${params.folder}`",
|
|
11
|
-
params: {
|
|
12
|
-
folder: {
|
|
13
|
-
control: {
|
|
14
|
-
type: "path",
|
|
15
|
-
options: {
|
|
16
|
-
properties: ["openDirectory"],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
value: "",
|
|
20
|
-
label: "Folder",
|
|
21
|
-
},
|
|
22
|
-
recursive: {
|
|
23
|
-
control: {
|
|
24
|
-
type: "boolean",
|
|
25
|
-
},
|
|
26
|
-
value: false,
|
|
27
|
-
label: "Recursive",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
outputs: {
|
|
32
|
-
paths: {
|
|
33
|
-
value: [] as Array<string>,
|
|
34
|
-
label: "Paths",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
description: "List files from a folder",
|
|
38
|
-
icon: "",
|
|
39
|
-
meta: {},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const ListFilesActionRun = createActionRunner<typeof ListFilesAction>(
|
|
43
|
-
async ({ log, inputs, setOutput }) => {
|
|
44
|
-
const readdir = fs.readdir;
|
|
45
|
-
|
|
46
|
-
log("");
|
|
47
|
-
|
|
48
|
-
log("inputs", inputs);
|
|
49
|
-
|
|
50
|
-
const folder = inputs.folder;
|
|
51
|
-
const recursive = inputs.recursive;
|
|
52
|
-
|
|
53
|
-
log("folder", folder);
|
|
54
|
-
|
|
55
|
-
const response = await readdir(folder, {
|
|
56
|
-
withFileTypes: true,
|
|
57
|
-
recursive,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
log("response", response);
|
|
61
|
-
|
|
62
|
-
const files = response;
|
|
63
|
-
|
|
64
|
-
log("-- setValue('paths')");
|
|
65
|
-
setOutput(
|
|
66
|
-
"paths",
|
|
67
|
-
files.map((x) => path.join(x.path, x.name)),
|
|
68
|
-
);
|
|
69
|
-
},
|
|
70
|
-
);
|
package/src/open.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { exec } from "node:child_process";
|
|
2
|
-
import { platform } from "node:os";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import { createAction, createActionRunner, createPathParam } from "@pipelab/plugin-core";
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
// import displayString from './displayStringRun.lua?raw'
|
|
8
|
-
|
|
9
|
-
export const ID = "fs:open-in-explorer";
|
|
10
|
-
|
|
11
|
-
export const openInExplorer = createAction({
|
|
12
|
-
id: ID,
|
|
13
|
-
name: "Open path in explorer",
|
|
14
|
-
displayString: "`Open ${fmt.param(params.path, 'primary', 'No path set')} in explorer`",
|
|
15
|
-
params: {
|
|
16
|
-
path: createPathParam("", {
|
|
17
|
-
required: true,
|
|
18
|
-
label: "Path",
|
|
19
|
-
control: {
|
|
20
|
-
type: "path",
|
|
21
|
-
options: {
|
|
22
|
-
properties: ["openDirectory", "openFile"],
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
}),
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
outputs: {
|
|
29
|
-
message: {
|
|
30
|
-
label: "Message",
|
|
31
|
-
value: "",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
description: "Open a file or folder in your explorer",
|
|
35
|
-
icon: "",
|
|
36
|
-
meta: {},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export const openInExplorerRunner = createActionRunner<typeof openInExplorer>(
|
|
40
|
-
async ({ log, inputs, setOutput }) => {
|
|
41
|
-
log(`Opening ${inputs.path}`);
|
|
42
|
-
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
let command = "";
|
|
45
|
-
const p = platform();
|
|
46
|
-
|
|
47
|
-
if (p === "win32") {
|
|
48
|
-
command = `start "" "${inputs.path}"`;
|
|
49
|
-
} else if (p === "darwin") {
|
|
50
|
-
command = `open "${inputs.path}"`;
|
|
51
|
-
} else {
|
|
52
|
-
command = `xdg-open "${inputs.path}"`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
exec(command, (error) => {
|
|
56
|
-
if (error) {
|
|
57
|
-
log(`Error opening path: ${error.message}`);
|
|
58
|
-
setOutput("message", error.message);
|
|
59
|
-
resolve();
|
|
60
|
-
} else {
|
|
61
|
-
setOutput("message", "success");
|
|
62
|
-
resolve();
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
);
|
package/src/remove.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { rm } from "node:fs/promises";
|
|
2
|
-
import { createAction, createActionRunner, createPathParam } from "@pipelab/plugin-core";
|
|
3
|
-
|
|
4
|
-
export const ID = "fs:remove";
|
|
5
|
-
|
|
6
|
-
export const remove = createAction({
|
|
7
|
-
id: ID,
|
|
8
|
-
name: "Remove file/folder",
|
|
9
|
-
displayString: '`Remove ${fmt.param(params.from, "primary")}`',
|
|
10
|
-
params: {
|
|
11
|
-
from: createPathParam("", {
|
|
12
|
-
label: "Path",
|
|
13
|
-
required: true,
|
|
14
|
-
control: {
|
|
15
|
-
type: "path",
|
|
16
|
-
options: {
|
|
17
|
-
properties: ["openFile"],
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
}),
|
|
21
|
-
recursive: {
|
|
22
|
-
label: "Recursive",
|
|
23
|
-
required: true,
|
|
24
|
-
value: true,
|
|
25
|
-
control: {
|
|
26
|
-
type: "boolean",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
outputs: {},
|
|
32
|
-
description: "Remove a file or a folder",
|
|
33
|
-
icon: "",
|
|
34
|
-
meta: {},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const removeRunner = createActionRunner<typeof remove>(async ({ log, inputs }) => {
|
|
38
|
-
log("");
|
|
39
|
-
|
|
40
|
-
const from = inputs.from;
|
|
41
|
-
|
|
42
|
-
log("Removing", from, inputs.recursive);
|
|
43
|
-
|
|
44
|
-
if (!from) {
|
|
45
|
-
log("From", from);
|
|
46
|
-
throw new Error("Missing source");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
process.noAsar = true;
|
|
51
|
-
await rm(from, { recursive: true, force: true, maxRetries: 3 });
|
|
52
|
-
process.noAsar = false;
|
|
53
|
-
log("Removed", from);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
log("Error removeing file", e);
|
|
56
|
-
throw e;
|
|
57
|
-
}
|
|
58
|
-
});
|
package/src/run.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createAction,
|
|
3
|
-
createActionRunner,
|
|
4
|
-
createPathParam,
|
|
5
|
-
createStringParam,
|
|
6
|
-
runWithLiveLogs,
|
|
7
|
-
} from "@pipelab/plugin-core";
|
|
8
|
-
|
|
9
|
-
export const ID = "fs:run";
|
|
10
|
-
|
|
11
|
-
export const run = createAction({
|
|
12
|
-
id: ID,
|
|
13
|
-
name: "Invoke file",
|
|
14
|
-
displayString:
|
|
15
|
-
"`Invoke ${fmt.param(params.command, 'primary')} ${(params.parameters ?? []).map(x => fmt.param(x)).join(' ')}`",
|
|
16
|
-
// displayString: displayString,
|
|
17
|
-
params: {
|
|
18
|
-
command: createStringParam("", {
|
|
19
|
-
required: true,
|
|
20
|
-
description: "The command to run",
|
|
21
|
-
label: "Command",
|
|
22
|
-
}),
|
|
23
|
-
parameters: {
|
|
24
|
-
required: true,
|
|
25
|
-
description: "The command's parameters",
|
|
26
|
-
label: "Arguments",
|
|
27
|
-
value: [],
|
|
28
|
-
control: {
|
|
29
|
-
type: "array",
|
|
30
|
-
options: {
|
|
31
|
-
kind: "text",
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
workingDirectory: createPathParam("", {
|
|
36
|
-
required: false,
|
|
37
|
-
description: "The directory to run the command in. Default to current task directory",
|
|
38
|
-
label: "Working directory",
|
|
39
|
-
control: {
|
|
40
|
-
type: "path",
|
|
41
|
-
options: {
|
|
42
|
-
properties: ["createDirectory", "openDirectory"],
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}),
|
|
46
|
-
stopOnError: {
|
|
47
|
-
required: false,
|
|
48
|
-
description: "Stop the task if the command fails",
|
|
49
|
-
label: "Stop on error",
|
|
50
|
-
value: false,
|
|
51
|
-
control: {
|
|
52
|
-
type: "boolean",
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
outputs: {
|
|
58
|
-
stdout: {
|
|
59
|
-
label: "Standard output",
|
|
60
|
-
description: "Standard output of the command",
|
|
61
|
-
value: "",
|
|
62
|
-
},
|
|
63
|
-
stderr: {
|
|
64
|
-
label: "Error output",
|
|
65
|
-
value: "",
|
|
66
|
-
},
|
|
67
|
-
exitCode: {
|
|
68
|
-
label: "Exit code",
|
|
69
|
-
value: 0,
|
|
70
|
-
},
|
|
71
|
-
duration: {
|
|
72
|
-
label: "Duration",
|
|
73
|
-
value: 0,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
description: "Invoke an arbitrary executable",
|
|
77
|
-
icon: "",
|
|
78
|
-
meta: {},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
export const runRunner = createActionRunner<typeof run>(
|
|
82
|
-
async ({ log, inputs, setOutput, abortSignal }) => {
|
|
83
|
-
const str = `${inputs.command} ${inputs.parameters.join(" ")}`;
|
|
84
|
-
|
|
85
|
-
log(`Running ${str}`);
|
|
86
|
-
|
|
87
|
-
let stdout: string = "";
|
|
88
|
-
let stderr: string = "";
|
|
89
|
-
let exitCode: number = 0;
|
|
90
|
-
const durationMs: number = 0;
|
|
91
|
-
|
|
92
|
-
const wd = inputs.workingDirectory ?? process.cwd();
|
|
93
|
-
log(`Working directory: ${wd}`);
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
await runWithLiveLogs(
|
|
97
|
-
inputs.command,
|
|
98
|
-
inputs.parameters,
|
|
99
|
-
{
|
|
100
|
-
cwd: wd,
|
|
101
|
-
cancelSignal: abortSignal,
|
|
102
|
-
},
|
|
103
|
-
log,
|
|
104
|
-
{
|
|
105
|
-
onStdout: (data) => {
|
|
106
|
-
stdout += data.toString();
|
|
107
|
-
log(data.toString());
|
|
108
|
-
},
|
|
109
|
-
onStderr: (data) => {
|
|
110
|
-
stderr += data.toString();
|
|
111
|
-
log(data.toString());
|
|
112
|
-
},
|
|
113
|
-
onExit(code) {
|
|
114
|
-
exitCode = code;
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
setOutput("exitCode", exitCode === undefined ? -1 : exitCode);
|
|
120
|
-
setOutput("stdout", stdout);
|
|
121
|
-
setOutput("stderr", stderr);
|
|
122
|
-
setOutput("duration", durationMs);
|
|
123
|
-
if ((exitCode > 0 || exitCode === undefined) && inputs.stopOnError === true) {
|
|
124
|
-
throw new Error(`Command failed with exit code ${exitCode}`);
|
|
125
|
-
}
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.log("error", error);
|
|
128
|
-
if (inputs.stopOnError === true) {
|
|
129
|
-
throw error;
|
|
130
|
-
} else if (error /* instanceof ExecaError */) {
|
|
131
|
-
setOutput("exitCode", error.exitCode === undefined ? -1 : error.exitCode);
|
|
132
|
-
setOutput("stdout", error.stdout ?? "");
|
|
133
|
-
setOutput("stderr", error.stderr ?? "");
|
|
134
|
-
setOutput("duration", error.durationMs ?? 0);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
);
|
package/src/temporary-folder.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// import { ComputeOutput, Context, CynNode, IODef, createDefinition, path, schema } from '@pipelab/plugin-core';
|
|
2
|
-
// import { nanoid } from 'nanoid'
|
|
3
|
-
|
|
4
|
-
// export const ID = 'temporary-folder'
|
|
5
|
-
|
|
6
|
-
// export type Data = {
|
|
7
|
-
// }
|
|
8
|
-
|
|
9
|
-
// export const definition = createDefinition({
|
|
10
|
-
// inputs: {
|
|
11
|
-
|
|
12
|
-
// },
|
|
13
|
-
// outputs: {
|
|
14
|
-
// value: {
|
|
15
|
-
// type: 'data',
|
|
16
|
-
// schema: schema.string()
|
|
17
|
-
// }
|
|
18
|
-
// }
|
|
19
|
-
// } satisfies IODef)
|
|
20
|
-
|
|
21
|
-
// export class TemporaryFolderNode extends CynNode<Data, typeof ID, typeof definition> {
|
|
22
|
-
// width = 180;
|
|
23
|
-
// height = 250;
|
|
24
|
-
|
|
25
|
-
// path: string | undefined
|
|
26
|
-
|
|
27
|
-
// constructor(context: Context) {
|
|
28
|
-
// super(ID, "Temporary folder", context);
|
|
29
|
-
|
|
30
|
-
// const value = new ClassicPreset.Output(path(), "Valeur")
|
|
31
|
-
// this.addOutput('value', value);
|
|
32
|
-
// }
|
|
33
|
-
// run() { }
|
|
34
|
-
// compute(): ComputeOutput<typeof definition> {
|
|
35
|
-
// if (!this.path) {
|
|
36
|
-
// this.path = nanoid()
|
|
37
|
-
// }
|
|
38
|
-
// return {
|
|
39
|
-
// value: this.path
|
|
40
|
-
// };
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// load(data: Data) {
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// save() {
|
|
47
|
-
// return {
|
|
48
|
-
// }
|
|
49
|
-
// }
|
|
50
|
-
// }
|
package/src/unzip.spec.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import { unzipRunner } from "./unzip.js";
|
|
3
|
-
import { browserWindow } from "@pipelab/shared";
|
|
4
|
-
|
|
5
|
-
test("adds 1 + 2 to equal 3", async () => {
|
|
6
|
-
const outputs: Record<string, unknown> = {};
|
|
7
|
-
// await unzipRunner({
|
|
8
|
-
// inputs: {
|
|
9
|
-
// file: ''
|
|
10
|
-
// },
|
|
11
|
-
// log: (...args) => {
|
|
12
|
-
// console.log(...args)
|
|
13
|
-
// },
|
|
14
|
-
// setOutput: (key, value) => {
|
|
15
|
-
// outputs[key] = value
|
|
16
|
-
// },
|
|
17
|
-
// meta: {
|
|
18
|
-
// definition: ''
|
|
19
|
-
// },
|
|
20
|
-
// setMeta: () => {
|
|
21
|
-
// console.log('set meta defined here')
|
|
22
|
-
// },
|
|
23
|
-
// cwd: '',
|
|
24
|
-
// paths: {
|
|
25
|
-
// assets: '',
|
|
26
|
-
// unpack: ''
|
|
27
|
-
// },
|
|
28
|
-
// api: undefined,
|
|
29
|
-
// browserWindow,
|
|
30
|
-
// })
|
|
31
|
-
console.log("outputs", outputs);
|
|
32
|
-
expect(true).toBe(true);
|
|
33
|
-
}, 120_000);
|
package/src/unzip.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import StreamZip from "node-stream-zip";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { createAction, createActionRunner, createPathParam } from "@pipelab/plugin-core";
|
|
4
|
-
|
|
5
|
-
export const ID = "unzip-file-node";
|
|
6
|
-
|
|
7
|
-
export const unzip = createAction({
|
|
8
|
-
id: ID,
|
|
9
|
-
name: "Unzip file",
|
|
10
|
-
displayString: '`Unzip ${fmt.param(params.file, "primary", "No file specified")}`',
|
|
11
|
-
params: {
|
|
12
|
-
file: createPathParam("", {
|
|
13
|
-
required: true,
|
|
14
|
-
control: {
|
|
15
|
-
type: "path",
|
|
16
|
-
options: {
|
|
17
|
-
properties: ["openFile"],
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
label: "File",
|
|
21
|
-
}),
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
outputs: {
|
|
25
|
-
output: {
|
|
26
|
-
value: "",
|
|
27
|
-
label: "Output",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
description: "Unzip a file to a specified folder",
|
|
31
|
-
icon: "",
|
|
32
|
-
meta: {},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const unzipRunner = createActionRunner<typeof unzip>(
|
|
36
|
-
async ({ log, inputs, setOutput, cwd }) => {
|
|
37
|
-
console.log("inputs", inputs);
|
|
38
|
-
|
|
39
|
-
console.log("inputs.file", inputs.file);
|
|
40
|
-
const file = inputs.file;
|
|
41
|
-
console.log("file", file);
|
|
42
|
-
const output = join(cwd);
|
|
43
|
-
|
|
44
|
-
console.log("file", file);
|
|
45
|
-
console.log("output", output);
|
|
46
|
-
|
|
47
|
-
log("Unzip file", inputs.file, "to", output);
|
|
48
|
-
|
|
49
|
-
const zip = new StreamZip.async({ file });
|
|
50
|
-
|
|
51
|
-
const bytes = await zip.extract(null, output);
|
|
52
|
-
await zip.close();
|
|
53
|
-
|
|
54
|
-
console.log("bytes", bytes);
|
|
55
|
-
|
|
56
|
-
setOutput("output", output);
|
|
57
|
-
},
|
|
58
|
-
);
|
package/src/zip-v2.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { createWriteStream } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import archiver from "archiver";
|
|
4
|
-
import { createAction, createActionRunner, createPathParam } from "@pipelab/plugin-core";
|
|
5
|
-
|
|
6
|
-
export const ID = "zip-v2-node";
|
|
7
|
-
|
|
8
|
-
export type MaybeArray<T> = T | T[];
|
|
9
|
-
|
|
10
|
-
export const getValue = <T>(array: MaybeArray<T>): T => {
|
|
11
|
-
if (Array.isArray(array)) {
|
|
12
|
-
return array[0];
|
|
13
|
-
} else {
|
|
14
|
-
return array;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const zipV2 = createAction({
|
|
19
|
-
id: ID,
|
|
20
|
-
name: "Zip",
|
|
21
|
-
displayString: '`Zip ${fmt.param(params.folder, "primary", "No folder specified")}`',
|
|
22
|
-
params: {
|
|
23
|
-
folder: createPathParam("", {
|
|
24
|
-
required: true,
|
|
25
|
-
control: {
|
|
26
|
-
type: "path",
|
|
27
|
-
options: {
|
|
28
|
-
properties: ["openDirectory"],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
label: "Folder",
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
outputs: {
|
|
36
|
-
path: {
|
|
37
|
-
value: "",
|
|
38
|
-
label: "Path",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
description: "Zip a folder into a .zip file",
|
|
42
|
-
icon: "",
|
|
43
|
-
meta: {},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export const zipV2Runner = createActionRunner<typeof zipV2>(
|
|
47
|
-
async ({ log, inputs, setOutput, abortSignal, paths }) => {
|
|
48
|
-
abortSignal.addEventListener("abort", () => {
|
|
49
|
-
throw new Error("Aborted");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const outputDir = paths.cache;
|
|
53
|
-
const outputFile = join(outputDir, "output.zip");
|
|
54
|
-
|
|
55
|
-
console.log("outputFile", outputFile);
|
|
56
|
-
|
|
57
|
-
const output = createWriteStream(outputFile);
|
|
58
|
-
|
|
59
|
-
const archive = archiver("zip", {
|
|
60
|
-
zlib: { level: 9 }, // Sets the compression level.
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
output.on("close", function () {
|
|
65
|
-
console.log(archive.pointer() + " total bytes");
|
|
66
|
-
console.log("archiver has been finalized and the output file descriptor has closed.");
|
|
67
|
-
|
|
68
|
-
setOutput("path", outputFile);
|
|
69
|
-
resolve();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
output.on("end", function () {
|
|
73
|
-
console.log("Data has been drained");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
archive.on("warning", function (err) {
|
|
77
|
-
if (err.code === "ENOENT") {
|
|
78
|
-
console.log("Archiver warning: ENOENT");
|
|
79
|
-
} else {
|
|
80
|
-
reject(err);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
archive.on("error", function (err) {
|
|
85
|
-
reject(err);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// archive.on('data', function (data) {
|
|
89
|
-
// log('data', data)
|
|
90
|
-
// })
|
|
91
|
-
// archive.on('progress', function (data) {
|
|
92
|
-
// /* {
|
|
93
|
-
// entries:
|
|
94
|
-
// {
|
|
95
|
-
// total: 5012,
|
|
96
|
-
// processed: 5012
|
|
97
|
-
// },
|
|
98
|
-
// fs:
|
|
99
|
-
// {
|
|
100
|
-
// totalBytes: 318794388,
|
|
101
|
-
// processedBytes: 318794388
|
|
102
|
-
// }
|
|
103
|
-
// } */
|
|
104
|
-
// // log('progress', data.entries.processed + '/' + data.entries.total)
|
|
105
|
-
// })
|
|
106
|
-
archive.on("entry", function (data) {
|
|
107
|
-
log("Adding", data.name);
|
|
108
|
-
});
|
|
109
|
-
archive.on("finish", function () {
|
|
110
|
-
log("finish");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
archive.pipe(output);
|
|
114
|
-
|
|
115
|
-
archive.directory(inputs.folder, false);
|
|
116
|
-
|
|
117
|
-
archive.finalize();
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
);
|