@pipelab/plugin-filesystem 1.0.0-beta.0 → 1.0.0-beta.10

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/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
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "@pipelab/tsconfig/vue.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src"
6
- },
7
- "include": ["src"]
8
- }
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
- });