textrun-workspace 0.5.0 → 0.7.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/README.md +40 -0
- package/dist/actions/compare-files.js +43 -0
- package/dist/actions/copy-file.js +26 -0
- package/dist/index.js +4 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -167,6 +167,46 @@ Now file _greeting/hello.txt_ has content `hello sun and moonlight`.
|
|
|
167
167
|
|
|
168
168
|
</a>
|
|
169
169
|
|
|
170
|
+
## compare-files
|
|
171
|
+
|
|
172
|
+
The <code type="action/name-full">workspace/compare-files</code> action compares
|
|
173
|
+
the content of the given files.
|
|
174
|
+
|
|
175
|
+
Assume the workspace contains file <a type="workspace/new-file"> _one.txt_, with
|
|
176
|
+
content `hello`</a>, and file <a type="workspace/new-file"> _two.txt_, also with
|
|
177
|
+
content `hello`</a>. Then this documentation passes:
|
|
178
|
+
|
|
179
|
+
<a type="extension/runnable-region">
|
|
180
|
+
|
|
181
|
+
```html
|
|
182
|
+
<a type="workspace/compare-files" have="one.txt" want="two.txt"></a>.
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
</a>
|
|
186
|
+
|
|
187
|
+
## copy-file
|
|
188
|
+
|
|
189
|
+
The <code type="action/name-full">workspace/copy-file</code> action copies the
|
|
190
|
+
given file.
|
|
191
|
+
|
|
192
|
+
Assume the workspace contains file <a type="workspace/new-file">
|
|
193
|
+
_greeting/hello.txt_ with content `hello`</a>. Then you execute this
|
|
194
|
+
documentation:
|
|
195
|
+
|
|
196
|
+
<a type="extension/runnable-region">
|
|
197
|
+
|
|
198
|
+
```html
|
|
199
|
+
<a type="workspace/copy-file" src="greeting/hello.txt" dst="new.txt"></a>.
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
</a>
|
|
203
|
+
|
|
204
|
+
<a type="workspace/existing-file-with-content">
|
|
205
|
+
|
|
206
|
+
Now your workspace contains a new file _new.txt_ with content `hello`.
|
|
207
|
+
|
|
208
|
+
</a>
|
|
209
|
+
|
|
170
210
|
## empty-file
|
|
171
211
|
|
|
172
212
|
The <b type="action/name-full">workspace/empty-file</b> action creates an empty
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as assertNoDiff from "assert-no-diff";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import { styleText } from "node:util";
|
|
4
|
+
import * as textRunner from "text-runner-engine";
|
|
5
|
+
export async function compareFiles(action) {
|
|
6
|
+
const have = action.region[0].attributes["have"];
|
|
7
|
+
if (!have) {
|
|
8
|
+
throw new textRunner.UserError("Missing attribute: have", 'Please provide the file to verify via the "have" attribute');
|
|
9
|
+
}
|
|
10
|
+
const want = action.region[0].attributes["want"];
|
|
11
|
+
if (!want) {
|
|
12
|
+
throw new textRunner.UserError("Missing attribute: want", 'Please provide the golden file via the "want" attribute');
|
|
13
|
+
}
|
|
14
|
+
action.name(`compare files ${styleText("cyan", have)} and ${styleText("cyan", want)}`);
|
|
15
|
+
const haveContent = await readFile(have, action.configuration.workspace);
|
|
16
|
+
const wantContent = await readFile(want, action.configuration.workspace);
|
|
17
|
+
try {
|
|
18
|
+
assertNoDiff.trimmedLines(haveContent.trim(), wantContent.trim());
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
action.log(haveContent);
|
|
22
|
+
throw new textRunner.UserError(`mismatching content`, textRunner.errorMessage(err));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function readFile(fileName, workspace) {
|
|
26
|
+
const filePath = workspace.joinStr(fileName);
|
|
27
|
+
try {
|
|
28
|
+
return await fs.readFile(filePath, "utf-8");
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (!textRunner.isFsError(e)) {
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
if (e.code === "ENOENT") {
|
|
35
|
+
const files = await fs.readdir(workspace.platformified());
|
|
36
|
+
throw new textRunner.UserError(`file not found: ${fileName}`, `the workspace has these files: ${files.join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=compare-files.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import * as textRunner from "text-runner-engine";
|
|
4
|
+
export async function copyFile(action) {
|
|
5
|
+
const src = action.region[0].attributes["src"];
|
|
6
|
+
if (!src) {
|
|
7
|
+
throw new textRunner.UserError("No src given", 'Please provide the file to copy via the "src" attribute');
|
|
8
|
+
}
|
|
9
|
+
const dst = action.region[0].attributes["dst"];
|
|
10
|
+
if (!dst) {
|
|
11
|
+
throw new textRunner.UserError("No dst given", 'Please provide the destination filename via the "dst" attribute');
|
|
12
|
+
}
|
|
13
|
+
action.name(`copy file ${styleText("cyan", src)} to ${styleText("cyan", dst)}`);
|
|
14
|
+
const srcPath = action.configuration.workspace.joinStr(src);
|
|
15
|
+
try {
|
|
16
|
+
await fs.access(srcPath, fs.constants.F_OK);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
if (e instanceof Error) {
|
|
20
|
+
throw new textRunner.UserError(`file "${src}" doesn't exist`, e.message);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const dstPath = action.configuration.workspace.joinStr(dst);
|
|
24
|
+
await fs.copyFile(srcPath, dstPath);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=copy-file.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { appendFile } from "./actions/append-file.js";
|
|
2
|
+
import { compareFiles } from "./actions/compare-files.js";
|
|
3
|
+
import { copyFile } from "./actions/copy-file.js";
|
|
2
4
|
import { emptyFile } from "./actions/empty-file.js";
|
|
3
5
|
import { existingDirectory } from "./actions/existing-directory.js";
|
|
4
6
|
import { existingFileWithContent } from "./actions/existing-file-with-content.js";
|
|
@@ -8,6 +10,8 @@ import { newFile } from "./actions/new-file.js";
|
|
|
8
10
|
import { workingDir } from "./actions/working-dir.js";
|
|
9
11
|
export const textrunActions = {
|
|
10
12
|
appendFile,
|
|
13
|
+
compareFiles,
|
|
14
|
+
copyFile,
|
|
11
15
|
emptyFile,
|
|
12
16
|
existingDirectory,
|
|
13
17
|
existingFile,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textrun-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Text-Runner actions for the Text-Runner workspace",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"assert-no-diff": "4.1.0",
|
|
21
|
-
"text-runner-engine": "7.
|
|
21
|
+
"text-runner-engine": "7.5.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"shared-cucumber-steps": "*",
|
|
25
|
-
"text-runner": "7.
|
|
26
|
-
"textrun-action": "0.
|
|
27
|
-
"textrun-extension": "0.
|
|
28
|
-
"tsx": "4.
|
|
25
|
+
"text-runner": "7.5.0",
|
|
26
|
+
"textrun-action": "0.7.0",
|
|
27
|
+
"textrun-extension": "0.7.0",
|
|
28
|
+
"tsx": "4.21.0"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "2373b67fd1ca2e81853cf50828376fcb6e6c8d85"
|
|
31
31
|
}
|