@pipelab/plugin-filesystem 1.0.0-beta.1 → 1.0.0-beta.4
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/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/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipelab/plugin-filesystem",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"license": "FSL-1.1-MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/CynToolkit/pipelab.git",
|
|
8
8
|
"directory": "plugins/plugin-filesystem"
|
|
9
9
|
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
10
13
|
"type": "module",
|
|
11
14
|
"main": "./dist/index.cjs",
|
|
12
15
|
"module": "./dist/index.mjs",
|
|
@@ -17,14 +20,14 @@
|
|
|
17
20
|
"dependencies": {
|
|
18
21
|
"@types/node": "^24.12.2",
|
|
19
22
|
"node-stream-zip": "1.15.0",
|
|
20
|
-
"@pipelab/plugin-core": "1.0.0-beta.
|
|
23
|
+
"@pipelab/plugin-core": "1.0.0-beta.4"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
23
26
|
"tsdown": "0.21.2",
|
|
24
27
|
"typescript": "5.9.3",
|
|
25
28
|
"vitest": "3.1.4",
|
|
26
|
-
"@pipelab/test-utils": "1.0.0-beta.
|
|
27
|
-
"@pipelab/tsconfig": "1.0.0-beta.
|
|
29
|
+
"@pipelab/test-utils": "1.0.0-beta.4",
|
|
30
|
+
"@pipelab/tsconfig": "1.0.0-beta.2"
|
|
28
31
|
},
|
|
29
32
|
"test": {
|
|
30
33
|
"env": {
|
package/CHANGELOG.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# @pipelab/plugin-filesystem
|
|
2
|
-
|
|
3
|
-
## 1.0.0-beta.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- @pipelab/plugin-core@1.0.0-beta.1
|
|
8
|
-
|
|
9
|
-
## 1.0.0-beta.0
|
|
10
|
-
|
|
11
|
-
### Major Changes
|
|
12
|
-
|
|
13
|
-
- e1befbf: initial release
|
|
14
|
-
|
|
15
|
-
### Patch Changes
|
|
16
|
-
|
|
17
|
-
- Updated dependencies [e1befbf]
|
|
18
|
-
- @pipelab/plugin-core@1.0.0-beta.0
|
package/src/copy.spec.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { copyRunner } from "./copy.js";
|
|
3
|
-
import mock from "mock-fs";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
import { browserWindow } from "@pipelab/shared";
|
|
6
|
-
|
|
7
|
-
describe("copy", () => {
|
|
8
|
-
test("copy file to file", async () => {
|
|
9
|
-
const outputs: Record<string, unknown> = {};
|
|
10
|
-
|
|
11
|
-
const sourcePath = "/source/source-file.txt";
|
|
12
|
-
const sourceContent = "text";
|
|
13
|
-
|
|
14
|
-
const destinationPath = "/destination/destination-file.txt";
|
|
15
|
-
const files = {
|
|
16
|
-
[sourcePath]: sourceContent,
|
|
17
|
-
"/destination": {},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// mock(files)
|
|
21
|
-
|
|
22
|
-
// await copyRunner({
|
|
23
|
-
// cwd: '',
|
|
24
|
-
// inputs: {
|
|
25
|
-
// from: sourcePath,
|
|
26
|
-
// to: destinationPath,
|
|
27
|
-
// recursive: false
|
|
28
|
-
// },
|
|
29
|
-
// log: (...args) => {
|
|
30
|
-
// console.log(...args)
|
|
31
|
-
// },
|
|
32
|
-
// setOutput: (key, value) => {
|
|
33
|
-
// outputs[key] = value
|
|
34
|
-
// },
|
|
35
|
-
// meta: {
|
|
36
|
-
// definition: ''
|
|
37
|
-
// },
|
|
38
|
-
// setMeta: () => {
|
|
39
|
-
// console.log('set meta defined here')
|
|
40
|
-
// },
|
|
41
|
-
// paths: {
|
|
42
|
-
// assets: '',
|
|
43
|
-
// unpack: ''
|
|
44
|
-
// },
|
|
45
|
-
// api: undefined,
|
|
46
|
-
// browserWindow
|
|
47
|
-
// })
|
|
48
|
-
|
|
49
|
-
// const data = await readFile(destinationPath, 'utf-8')
|
|
50
|
-
|
|
51
|
-
// expect(data).toBe(sourceContent)
|
|
52
|
-
expect(true).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("copy file to file where parent folder doesn't exist", async () => {
|
|
56
|
-
const outputs: Record<string, unknown> = {};
|
|
57
|
-
|
|
58
|
-
const sourcePath = "/source/source-file.txt";
|
|
59
|
-
const sourceContent = "text";
|
|
60
|
-
|
|
61
|
-
const destinationPath = "/destination/destination-file.txt";
|
|
62
|
-
const files = {
|
|
63
|
-
[sourcePath]: sourceContent,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// mock(files)
|
|
67
|
-
|
|
68
|
-
// await copyRunner({
|
|
69
|
-
// cwd: '',
|
|
70
|
-
// inputs: {
|
|
71
|
-
// from: sourcePath,
|
|
72
|
-
// to: destinationPath,
|
|
73
|
-
// recursive: false
|
|
74
|
-
// },
|
|
75
|
-
// log: (...args) => {
|
|
76
|
-
// console.log(...args)
|
|
77
|
-
// },
|
|
78
|
-
// setOutput: (key, value) => {
|
|
79
|
-
// outputs[key] = value
|
|
80
|
-
// },
|
|
81
|
-
// meta: {
|
|
82
|
-
// definition: ''
|
|
83
|
-
// },
|
|
84
|
-
// setMeta: () => {
|
|
85
|
-
// console.log('set meta defined here')
|
|
86
|
-
// },
|
|
87
|
-
// paths: {
|
|
88
|
-
// assets: '',
|
|
89
|
-
// unpack: ''
|
|
90
|
-
// },
|
|
91
|
-
// api: undefined,
|
|
92
|
-
// browserWindow
|
|
93
|
-
// })
|
|
94
|
-
|
|
95
|
-
// const data = await readFile(destinationPath, 'utf-8')
|
|
96
|
-
|
|
97
|
-
// expect(data).toBe(sourceContent)
|
|
98
|
-
expect(true).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
});
|
package/src/copy.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { cp, mkdir, rm, stat } from "node:fs/promises";
|
|
2
|
-
import { basename, join, dirname } from "node:path";
|
|
3
|
-
import { createAction, createActionRunner, createPathParam } from "@pipelab/plugin-core";
|
|
4
|
-
|
|
5
|
-
export const ID = "fs:copy";
|
|
6
|
-
|
|
7
|
-
export const copy = createAction({
|
|
8
|
-
id: ID,
|
|
9
|
-
name: "Copy file/folder",
|
|
10
|
-
displayString:
|
|
11
|
-
'`Copy ${fmt.param(params.from, "primary", "Source")} to ${fmt.param(params.to, "primary", "Destination")}`',
|
|
12
|
-
params: {
|
|
13
|
-
from: createPathParam("", {
|
|
14
|
-
label: "From",
|
|
15
|
-
required: true,
|
|
16
|
-
control: {
|
|
17
|
-
type: "path",
|
|
18
|
-
options: {
|
|
19
|
-
properties: ["openFile", "openDirectory"],
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
}),
|
|
23
|
-
to: createPathParam("", {
|
|
24
|
-
label: "To",
|
|
25
|
-
required: true,
|
|
26
|
-
control: {
|
|
27
|
-
type: "path",
|
|
28
|
-
options: {
|
|
29
|
-
properties: ["openFile", "openDirectory", "createDirectory", "promptToCreate"],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
}),
|
|
33
|
-
recursive: {
|
|
34
|
-
label: "Recursive",
|
|
35
|
-
required: true,
|
|
36
|
-
value: true,
|
|
37
|
-
control: {
|
|
38
|
-
type: "boolean",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
overwrite: {
|
|
42
|
-
label: "Overwrite",
|
|
43
|
-
required: true,
|
|
44
|
-
value: true,
|
|
45
|
-
control: {
|
|
46
|
-
type: "boolean",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
cleanup: {
|
|
50
|
-
label: "Cleanup",
|
|
51
|
-
required: true,
|
|
52
|
-
description: "Whether to delete the original file/folder",
|
|
53
|
-
value: true,
|
|
54
|
-
control: {
|
|
55
|
-
type: "boolean",
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
outputs: {
|
|
61
|
-
output: {
|
|
62
|
-
label: "Output",
|
|
63
|
-
value: "",
|
|
64
|
-
description: "The copied file/folder",
|
|
65
|
-
},
|
|
66
|
-
input: {
|
|
67
|
-
label: "Input",
|
|
68
|
-
value: "",
|
|
69
|
-
description: "The original file/folder",
|
|
70
|
-
},
|
|
71
|
-
parentDirectory: {
|
|
72
|
-
label: "Parent directory",
|
|
73
|
-
value: "",
|
|
74
|
-
description: "The parent directory of the copied file/folder",
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
description: "Copy a file or a folder from one location to another",
|
|
78
|
-
icon: "",
|
|
79
|
-
meta: {},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
export const copyRunner = createActionRunner<typeof copy>(async ({ log, inputs, setOutput }) => {
|
|
83
|
-
log("");
|
|
84
|
-
|
|
85
|
-
const from = inputs.from;
|
|
86
|
-
let to = inputs.to;
|
|
87
|
-
|
|
88
|
-
let fromIsAFile = false;
|
|
89
|
-
try {
|
|
90
|
-
const stats = await stat(from);
|
|
91
|
-
if (stats.isFile()) {
|
|
92
|
-
fromIsAFile = true;
|
|
93
|
-
}
|
|
94
|
-
} catch (e) {
|
|
95
|
-
log("Error getting file stats", e);
|
|
96
|
-
throw e;
|
|
97
|
-
}
|
|
98
|
-
const fromFileName = fromIsAFile ? basename(from) : "";
|
|
99
|
-
|
|
100
|
-
if (!from) {
|
|
101
|
-
log("From", from);
|
|
102
|
-
throw new Error("Missing source");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!to) {
|
|
106
|
-
log("To", to);
|
|
107
|
-
throw new Error("Missing destination");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// if from is a file, we only add the file name to the destination if 'to' is an existing directory
|
|
111
|
-
if (fromIsAFile) {
|
|
112
|
-
try {
|
|
113
|
-
const toStats = await stat(to);
|
|
114
|
-
if (toStats.isDirectory()) {
|
|
115
|
-
to = join(to, fromFileName);
|
|
116
|
-
}
|
|
117
|
-
} catch (e) {
|
|
118
|
-
// If 'to' doesn't exist, we assume the user provided the full destination path (including filename)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
log("Copying", from, "to", to, "recursive", inputs.recursive, "overwrite", inputs.overwrite);
|
|
123
|
-
|
|
124
|
-
if (inputs.cleanup) {
|
|
125
|
-
try {
|
|
126
|
-
log("Cleaning up", to);
|
|
127
|
-
process.noAsar = true;
|
|
128
|
-
await rm(to, { recursive: true, force: true, maxRetries: 3 });
|
|
129
|
-
if (!fromIsAFile) {
|
|
130
|
-
await mkdir(to, { recursive: true });
|
|
131
|
-
}
|
|
132
|
-
process.noAsar = false;
|
|
133
|
-
} catch (e) {
|
|
134
|
-
log("Error cleaning up file", e);
|
|
135
|
-
throw e;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
process.noAsar = true;
|
|
141
|
-
await cp(from, to, {
|
|
142
|
-
recursive: inputs.recursive && !fromIsAFile,
|
|
143
|
-
force: inputs.overwrite,
|
|
144
|
-
});
|
|
145
|
-
process.noAsar = false;
|
|
146
|
-
setOutput("output", to);
|
|
147
|
-
setOutput("input", from);
|
|
148
|
-
setOutput("parentDirectory", dirname(to));
|
|
149
|
-
log("Copied", from, "to", to);
|
|
150
|
-
} catch (e) {
|
|
151
|
-
log("Error copying file", e);
|
|
152
|
-
throw e;
|
|
153
|
-
}
|
|
154
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { createNodeDefinition } from "@pipelab/plugin-core";
|
|
2
|
-
import { ListFilesAction, ListFilesActionRun } from "./list-files";
|
|
3
|
-
import { isFileCondition, isFileRunner } from "./is-file";
|
|
4
|
-
import { zipRunner, zip } from "./zip";
|
|
5
|
-
import { zipV2Runner, zipV2 } from "./zip-v2";
|
|
6
|
-
import { unzipRunner, unzip } from "./unzip";
|
|
7
|
-
import { copy, copyRunner } from "./copy";
|
|
8
|
-
import { remove, removeRunner } from "./remove";
|
|
9
|
-
import { run, runRunner } from "./run";
|
|
10
|
-
import { openInExplorer, openInExplorerRunner } from "./open";
|
|
11
|
-
|
|
12
|
-
export default createNodeDefinition({
|
|
13
|
-
description: "Filesystem",
|
|
14
|
-
id: "filesystem",
|
|
15
|
-
name: "Filesystem",
|
|
16
|
-
icon: {
|
|
17
|
-
type: "icon",
|
|
18
|
-
icon: "mdi-folder-zip-outline",
|
|
19
|
-
},
|
|
20
|
-
nodes: [
|
|
21
|
-
// {
|
|
22
|
-
// node: ListFilesAction,
|
|
23
|
-
// runner: ListFilesActionRun
|
|
24
|
-
// },
|
|
25
|
-
// {
|
|
26
|
-
// node: isFileCondition,
|
|
27
|
-
// runner: isFileRunner
|
|
28
|
-
// },
|
|
29
|
-
{
|
|
30
|
-
node: zip,
|
|
31
|
-
runner: zipRunner,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
node: zipV2,
|
|
35
|
-
runner: zipV2Runner,
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
node: unzip,
|
|
39
|
-
runner: unzipRunner,
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
node: copy,
|
|
43
|
-
runner: copyRunner,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
node: remove,
|
|
47
|
-
runner: removeRunner,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
node: run,
|
|
51
|
-
runner: runRunner,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
node: openInExplorer,
|
|
55
|
-
runner: openInExplorerRunner,
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
});
|
package/src/is-file.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { createCondition, createConditionRunner } from "@pipelab/plugin-core";
|
|
3
|
-
|
|
4
|
-
export const ID = "is-file";
|
|
5
|
-
|
|
6
|
-
export const isFileCondition = createCondition({
|
|
7
|
-
id: ID,
|
|
8
|
-
icon: "",
|
|
9
|
-
name: "Is file",
|
|
10
|
-
description: "",
|
|
11
|
-
displayString: "`If ${params.path} is a file`",
|
|
12
|
-
params: {
|
|
13
|
-
path: {
|
|
14
|
-
value: "",
|
|
15
|
-
label: "Path",
|
|
16
|
-
control: {
|
|
17
|
-
type: "input",
|
|
18
|
-
options: {
|
|
19
|
-
kind: "text",
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const isFileRunner = createConditionRunner<typeof isFileCondition>(
|
|
27
|
-
async ({ log, inputs }) => {
|
|
28
|
-
const path = inputs.path;
|
|
29
|
-
|
|
30
|
-
log("path", path);
|
|
31
|
-
|
|
32
|
-
const stats = await fs.stat(path);
|
|
33
|
-
|
|
34
|
-
return stats.isFile();
|
|
35
|
-
},
|
|
36
|
-
);
|
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
|
-
);
|
package/src/zip.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { createWriteStream } from "node:fs";
|
|
2
|
-
import archiver from "archiver";
|
|
3
|
-
import { createAction, createActionRunner, createPathParam } from "@pipelab/plugin-core";
|
|
4
|
-
|
|
5
|
-
export const ID = "zip-node";
|
|
6
|
-
|
|
7
|
-
export type MaybeArray<T> = T | T[];
|
|
8
|
-
|
|
9
|
-
export const getValue = <T>(array: MaybeArray<T>): T => {
|
|
10
|
-
if (Array.isArray(array)) {
|
|
11
|
-
return array[0];
|
|
12
|
-
} else {
|
|
13
|
-
return array;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const zip = createAction({
|
|
18
|
-
id: ID,
|
|
19
|
-
name: "Zip",
|
|
20
|
-
updateAvailable: true,
|
|
21
|
-
displayString:
|
|
22
|
-
'`Zip ${fmt.param(params.folder, "primary", "No folder specified")} to ${fmt.param(params.output, "secondary", "No output specified")}`',
|
|
23
|
-
params: {
|
|
24
|
-
folder: createPathParam("", {
|
|
25
|
-
required: true,
|
|
26
|
-
control: {
|
|
27
|
-
type: "path",
|
|
28
|
-
options: {
|
|
29
|
-
properties: ["openDirectory"],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
label: "Folder",
|
|
33
|
-
}),
|
|
34
|
-
output: createPathParam("", {
|
|
35
|
-
required: true,
|
|
36
|
-
control: {
|
|
37
|
-
type: "path",
|
|
38
|
-
options: {
|
|
39
|
-
properties: ["openFile", "promptToCreate"],
|
|
40
|
-
// must be zip file
|
|
41
|
-
filters: [
|
|
42
|
-
{
|
|
43
|
-
extensions: ["zip"],
|
|
44
|
-
name: "Zip file",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
label: "Folder",
|
|
50
|
-
}),
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
outputs: {
|
|
54
|
-
path: {
|
|
55
|
-
value: "",
|
|
56
|
-
label: "Path",
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
description: "Zip a folder into a .zip file",
|
|
60
|
-
icon: "",
|
|
61
|
-
meta: {},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
export const zipRunner = createActionRunner<typeof zip>(
|
|
65
|
-
async ({ log, inputs, setOutput, abortSignal }) => {
|
|
66
|
-
abortSignal.addEventListener("abort", () => {
|
|
67
|
-
throw new Error("Aborted");
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const output = createWriteStream(inputs.output);
|
|
71
|
-
|
|
72
|
-
const archive = archiver("zip", {
|
|
73
|
-
zlib: { level: 9 }, // Sets the compression level.
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
output.on("close", function () {
|
|
78
|
-
console.log(archive.pointer() + " total bytes");
|
|
79
|
-
console.log("archiver has been finalized and the output file descriptor has closed.");
|
|
80
|
-
|
|
81
|
-
setOutput("path", inputs.output);
|
|
82
|
-
resolve();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
output.on("end", function () {
|
|
86
|
-
console.log("Data has been drained");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
archive.on("warning", function (err) {
|
|
90
|
-
if (err.code === "ENOENT") {
|
|
91
|
-
console.log("Archiver warning: ENOENT");
|
|
92
|
-
} else {
|
|
93
|
-
reject(err);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
archive.on("error", function (err) {
|
|
98
|
-
reject(err);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// archive.on('data', function (data) {
|
|
102
|
-
// log('data', data)
|
|
103
|
-
// })
|
|
104
|
-
// archive.on('progress', function (data) {
|
|
105
|
-
// /* {
|
|
106
|
-
// entries:
|
|
107
|
-
// {
|
|
108
|
-
// total: 5012,
|
|
109
|
-
// processed: 5012
|
|
110
|
-
// },
|
|
111
|
-
// fs:
|
|
112
|
-
// {
|
|
113
|
-
// totalBytes: 318794388,
|
|
114
|
-
// processedBytes: 318794388
|
|
115
|
-
// }
|
|
116
|
-
// } */
|
|
117
|
-
// // log('progress', data.entries.processed + '/' + data.entries.total)
|
|
118
|
-
// })
|
|
119
|
-
archive.on("entry", function (data) {
|
|
120
|
-
log("Adding", data.name);
|
|
121
|
-
});
|
|
122
|
-
archive.on("finish", function () {
|
|
123
|
-
log("finish");
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
archive.pipe(output);
|
|
127
|
-
|
|
128
|
-
archive.directory(inputs.folder, false);
|
|
129
|
-
|
|
130
|
-
archive.finalize();
|
|
131
|
-
});
|
|
132
|
-
},
|
|
133
|
-
);
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { expect, test, describe, beforeAll, afterAll, afterEach } from "vitest";
|
|
2
|
-
import { mkdir, writeFile, readFile, access } from "node:fs/promises";
|
|
3
|
-
import { join, dirname } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { createSandbox, runAction } from "@pipelab/test-utils";
|
|
6
|
-
import { copyRunner } from "../../src/copy";
|
|
7
|
-
import { removeRunner } from "../../src/remove";
|
|
8
|
-
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = dirname(__filename);
|
|
11
|
-
|
|
12
|
-
describe("End-to-End: Filesystem Plugin", () => {
|
|
13
|
-
let sandbox: Awaited<ReturnType<typeof createSandbox>>;
|
|
14
|
-
|
|
15
|
-
afterEach(async () => {
|
|
16
|
-
if (sandbox) {
|
|
17
|
-
await sandbox.remove();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("should copy a file using 'copy' action", { timeout: 60000 }, async () => {
|
|
22
|
-
sandbox = await createSandbox("fs-copy-e2e");
|
|
23
|
-
const testPath = sandbox.path;
|
|
24
|
-
const sourcePath = join(testPath, "source");
|
|
25
|
-
const destPath = join(testPath, "destination");
|
|
26
|
-
await mkdir(sourcePath, { recursive: true });
|
|
27
|
-
await mkdir(destPath, { recursive: true });
|
|
28
|
-
|
|
29
|
-
const sourceFile = join(sourcePath, "file.txt");
|
|
30
|
-
const destFile = join(destPath, "file.txt");
|
|
31
|
-
await writeFile(sourceFile, "Hello World");
|
|
32
|
-
|
|
33
|
-
await runAction(copyRunner, {
|
|
34
|
-
inputs: {
|
|
35
|
-
from: sourceFile,
|
|
36
|
-
to: destFile,
|
|
37
|
-
recursive: false,
|
|
38
|
-
overwrite: false,
|
|
39
|
-
cleanup: false,
|
|
40
|
-
},
|
|
41
|
-
sandboxPath: testPath,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
await expect(access(destFile)).resolves.not.toThrow();
|
|
45
|
-
const content = await readFile(destFile, "utf-8");
|
|
46
|
-
expect(content).toBe("Hello World");
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("should move a file using 'copy' then 'remove' actions", { timeout: 60000 }, async () => {
|
|
50
|
-
sandbox = await createSandbox("fs-move-e2e");
|
|
51
|
-
const testPath = sandbox.path;
|
|
52
|
-
const sourcePath = join(testPath, "source");
|
|
53
|
-
const destPath = join(testPath, "destination");
|
|
54
|
-
await mkdir(sourcePath, { recursive: true });
|
|
55
|
-
await mkdir(destPath, { recursive: true });
|
|
56
|
-
|
|
57
|
-
const sourceFile = join(sourcePath, "file.txt");
|
|
58
|
-
const destFile = join(destPath, "file.txt");
|
|
59
|
-
await writeFile(sourceFile, "File to move");
|
|
60
|
-
|
|
61
|
-
// Copy
|
|
62
|
-
await runAction(copyRunner, {
|
|
63
|
-
inputs: {
|
|
64
|
-
from: sourceFile,
|
|
65
|
-
to: destFile,
|
|
66
|
-
recursive: false,
|
|
67
|
-
overwrite: false,
|
|
68
|
-
cleanup: false,
|
|
69
|
-
},
|
|
70
|
-
sandboxPath: testPath,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// Remove
|
|
74
|
-
await runAction(removeRunner, {
|
|
75
|
-
inputs: {
|
|
76
|
-
from: sourceFile,
|
|
77
|
-
recursive: true,
|
|
78
|
-
},
|
|
79
|
-
sandboxPath: testPath,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
await expect(access(destFile)).resolves.not.toThrow();
|
|
83
|
-
await expect(access(sourceFile)).rejects.toThrow();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("should delete a file using 'remove' action", { timeout: 60000 }, async () => {
|
|
87
|
-
sandbox = await createSandbox("fs-remove-e2e");
|
|
88
|
-
const testPath = sandbox.path;
|
|
89
|
-
await mkdir(testPath, { recursive: true });
|
|
90
|
-
const fileToDelete = join(testPath, "file_to_delete.txt");
|
|
91
|
-
await writeFile(fileToDelete, "Delete me");
|
|
92
|
-
|
|
93
|
-
await runAction(removeRunner, {
|
|
94
|
-
inputs: {
|
|
95
|
-
from: fileToDelete,
|
|
96
|
-
recursive: true,
|
|
97
|
-
},
|
|
98
|
-
sandboxPath: testPath,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
await expect(access(fileToDelete)).rejects.toThrow();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
fileParallelism: false,
|
|
6
|
-
testTimeout: 60000,
|
|
7
|
-
hookTimeout: 60000,
|
|
8
|
-
maxWorkers: 1,
|
|
9
|
-
minWorkers: 1,
|
|
10
|
-
poolOptions: {
|
|
11
|
-
forks: {
|
|
12
|
-
singleFork: true,
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
include: ["**/*.spec.ts"],
|
|
16
|
-
root: "tests/e2e",
|
|
17
|
-
environment: "node",
|
|
18
|
-
env: { NODE_ENV: "development", PIPELAB_DISABLE_HISTORY: "true" },
|
|
19
|
-
},
|
|
20
|
-
});
|
package/tsconfig.json
DELETED
package/tsdown.config.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsdown";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ["src/index.ts"],
|
|
5
|
-
format: ["esm", "cjs"],
|
|
6
|
-
dts: true,
|
|
7
|
-
clean: true,
|
|
8
|
-
loader: {
|
|
9
|
-
".webp": "dataurl",
|
|
10
|
-
".png": "dataurl",
|
|
11
|
-
".jpg": "dataurl",
|
|
12
|
-
".jpeg": "dataurl",
|
|
13
|
-
".svg": "dataurl",
|
|
14
|
-
},
|
|
15
|
-
});
|