textrun-workspace 0.3.1 → 0.4.1
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 +316 -63
- package/dist/actions/append-file.js +42 -0
- package/dist/actions/empty-file.js +4 -3
- package/dist/actions/existing-directory.js +4 -4
- package/dist/actions/existing-file-with-content.js +26 -11
- package/dist/actions/existing-file.js +3 -3
- package/dist/actions/new-directory.js +2 -2
- package/dist/actions/new-file.js +2 -2
- package/dist/actions/working-dir.js +2 -2
- package/dist/index.js +2 -2
- package/package.json +8 -9
- package/dist/actions/additional-file-content.js +0 -13
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ don't interfere with the codebase that you document. This package provides
|
|
|
6
6
|
[Text-Runner](https://github.com/kevgo/text-runner) actions for interacting with
|
|
7
7
|
this Text-Runner workspace.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## installation
|
|
10
10
|
|
|
11
11
|
<a type="npm/install">
|
|
12
12
|
|
|
@@ -16,51 +16,55 @@ npm i -D textrun-workspace
|
|
|
16
16
|
|
|
17
17
|
</a>
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
## new-file
|
|
20
20
|
|
|
21
|
-
The <b type="action/name-full">workspace/new-
|
|
22
|
-
|
|
21
|
+
The <b type="action/name-full">workspace/new-file</b> action creates a file in
|
|
22
|
+
the workspace. This action assumes that the documentation writes the filename in
|
|
23
|
+
_emphasized_ or **bold** text, or inside a `filename` attribute, and the file
|
|
24
|
+
content is a code block with one or three backticks. Here are a few examples
|
|
25
|
+
that all do the same thing. See if you can figure out what it does.
|
|
23
26
|
|
|
24
27
|
<a type="extension/runnable-region">
|
|
25
28
|
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
```markdown
|
|
30
|
+
<a type="workspace/new-file">
|
|
31
|
+
|
|
32
|
+
Create file _apples.txt_ with the content `Fuji apples are the best`.
|
|
29
33
|
|
|
30
34
|
</a>
|
|
35
|
+
```
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
<i type="workspace/existing-directory">utils</i> directory in the workspace,
|
|
34
|
-
just as the user would.
|
|
37
|
+
</a>
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
<a type="extension/runnable-region">
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
<
|
|
40
|
-
working directory of the test runner to the given directory inside the
|
|
41
|
-
workspace. To change into the directory the reader created above:
|
|
41
|
+
````markdown
|
|
42
|
+
<a type="workspace/new-file">
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
Create file **apples.txt** with the content:
|
|
44
45
|
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
<code type="workspace/working-dir">utils</code>
|
|
48
|
-
folder.
|
|
46
|
+
```
|
|
47
|
+
Fuji apples are the best
|
|
49
48
|
```
|
|
50
49
|
|
|
51
50
|
</a>
|
|
51
|
+
````
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
</a>
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
When executing the documentation, Text-Runner will create a file with name
|
|
56
|
+
<a type="workspace/existing-file-with-content">_apples.txt_ and content
|
|
57
|
+
`Fuji apples are the best`</a> in the workspace.
|
|
58
|
+
|
|
59
|
+
### "dir" attribute
|
|
60
|
+
|
|
61
|
+
You can override in which directory Text-Runner looks for the file to append
|
|
62
|
+
content to with the `dir` attribute:
|
|
59
63
|
|
|
60
64
|
<a type="extension/runnable-region">
|
|
61
65
|
|
|
62
66
|
```markdown
|
|
63
|
-
<a type="workspace/new-file">
|
|
67
|
+
<a type="workspace/new-file" dir="subdir">
|
|
64
68
|
|
|
65
69
|
Create file _apples.txt_ with the content `Fuji apples are the best`.
|
|
66
70
|
|
|
@@ -69,37 +73,109 @@ Create file _apples.txt_ with the content `Fuji apples are the best`.
|
|
|
69
73
|
|
|
70
74
|
</a>
|
|
71
75
|
|
|
76
|
+
When executing the documentation, Text-Runner will create a file with name
|
|
77
|
+
<a type="workspace/existing-file-with-content">_subdir/apples.txt_ and content
|
|
78
|
+
`Fuji apples are the best`</a> in the workspace.
|
|
79
|
+
|
|
80
|
+
### "filename" attribute
|
|
81
|
+
|
|
82
|
+
If you don't want to repeat the filename in the text too often, you can also
|
|
83
|
+
provide it invisibly through the `filename` attribute. In that case, the file
|
|
84
|
+
content is the entire content of the active region.
|
|
85
|
+
|
|
72
86
|
<a type="extension/runnable-region">
|
|
73
87
|
|
|
74
|
-
|
|
75
|
-
<
|
|
88
|
+
```html
|
|
89
|
+
<pre type="workspace/new-file" filename="apples.txt">
|
|
90
|
+
Gala aren't that bad either!
|
|
91
|
+
</pre>
|
|
92
|
+
```
|
|
76
93
|
|
|
77
|
-
|
|
94
|
+
</a>
|
|
95
|
+
|
|
96
|
+
When executing the documentation, Text-Runner will create a file with name
|
|
97
|
+
<a type="workspace/existing-file-with-content">_apples.txt_ and content
|
|
98
|
+
`Gala aren't that bad either!`</a> in the workspace.
|
|
99
|
+
|
|
100
|
+
## append-file
|
|
101
|
+
|
|
102
|
+
The <code type="action/name-full">workspace/append-file</code> action appends
|
|
103
|
+
the given text to the given file.
|
|
104
|
+
|
|
105
|
+
Assume the workspace contains file <a type="workspace/new-file">
|
|
106
|
+
_greeting/hello.txt_ with content `hello`</a>. Then you execute this
|
|
107
|
+
documentation:
|
|
108
|
+
|
|
109
|
+
<a type="extension/runnable-region">
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<a type="workspace/append-file">
|
|
113
|
+
|
|
114
|
+
Now append ` sun` to file _greeting/hello.txt_.
|
|
78
115
|
|
|
116
|
+
</a>.
|
|
79
117
|
```
|
|
80
|
-
|
|
118
|
+
|
|
119
|
+
</a>
|
|
120
|
+
|
|
121
|
+
<a type="workspace/existing-file-with-content">
|
|
122
|
+
|
|
123
|
+
Now file _greeting/hello.txt_ has content `hello sun`.
|
|
124
|
+
|
|
125
|
+
</a>
|
|
126
|
+
|
|
127
|
+
### "dir" attribute
|
|
128
|
+
|
|
129
|
+
You can override in which directory Text-Runner looks for the file to append
|
|
130
|
+
content to with the `dir` attribute:
|
|
131
|
+
|
|
132
|
+
<a type="extension/runnable-region">
|
|
133
|
+
|
|
134
|
+
```html
|
|
135
|
+
<a type="workspace/append-file" dir="greeting">
|
|
136
|
+
|
|
137
|
+
Now append ` and moon` to file _hello.txt_.
|
|
138
|
+
|
|
139
|
+
</a>.
|
|
81
140
|
```
|
|
82
141
|
|
|
83
142
|
</a>
|
|
84
|
-
|
|
143
|
+
|
|
144
|
+
<a type="workspace/existing-file-with-content">
|
|
145
|
+
|
|
146
|
+
Now file _greeting/hello.txt_ has content `hello sun and moon`.
|
|
85
147
|
|
|
86
148
|
</a>
|
|
87
149
|
|
|
88
|
-
|
|
89
|
-
<a type="workspace/existing-file-with-content">_apples.txt_ and content
|
|
90
|
-
`Fuji apples are the best`</a> in the workspace.
|
|
150
|
+
### "filename" attribute
|
|
91
151
|
|
|
92
|
-
|
|
152
|
+
If you don't want to repeat the filename in the text too often, you can also
|
|
153
|
+
provide it invisibly through the `filename` attribute. In that case, the file
|
|
154
|
+
content is the entire content of the active region.
|
|
93
155
|
|
|
94
|
-
|
|
95
|
-
|
|
156
|
+
<a type="extension/runnable-region">
|
|
157
|
+
|
|
158
|
+
```html
|
|
159
|
+
<code type="workspace/append-file" filename="greeting/hello.txt">light</code>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
</a>
|
|
96
163
|
|
|
97
|
-
|
|
164
|
+
<a type="workspace/existing-file-with-content">
|
|
165
|
+
|
|
166
|
+
Now file _greeting/hello.txt_ has content `hello sun and moonlight`.
|
|
167
|
+
|
|
168
|
+
</a>
|
|
169
|
+
|
|
170
|
+
## empty-file
|
|
171
|
+
|
|
172
|
+
The <b type="action/name-full">workspace/empty-file</b> action creates an empty
|
|
173
|
+
file. An example is this documentation:
|
|
98
174
|
|
|
99
175
|
<a type="extension/runnable-region">
|
|
100
176
|
|
|
101
177
|
```html
|
|
102
|
-
Please
|
|
178
|
+
Please a file <b type="workspace/empty-file">.gitkeep</b>. It's okay to leave it empty.
|
|
103
179
|
```
|
|
104
180
|
|
|
105
181
|
</a>
|
|
@@ -107,7 +183,38 @@ Please create an empty file <b type="workspace/empty-file">.gitkeep</b>.
|
|
|
107
183
|
When executing the documentation, Text-Runner will create a file with name
|
|
108
184
|
<i type="workspace/existing-file">.gitkeep</i> in the workspace.
|
|
109
185
|
|
|
110
|
-
###
|
|
186
|
+
### "dir" attribute
|
|
187
|
+
|
|
188
|
+
You can override in which directory to create the empty file by providing a
|
|
189
|
+
`dir` attribute:
|
|
190
|
+
|
|
191
|
+
<a type="extension/runnable-region">
|
|
192
|
+
|
|
193
|
+
```html
|
|
194
|
+
Please create an empty file <b type="workspace/empty-file" dir="subdir">.gitkeep</b>.
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
</a>
|
|
198
|
+
|
|
199
|
+
When executing the documentation, Text-Runner will create a file with name
|
|
200
|
+
<i type="workspace/existing-file">subdir/.gitkeep</i> in the workspace.
|
|
201
|
+
|
|
202
|
+
### "filename" attribute
|
|
203
|
+
|
|
204
|
+
You can provide the filename invisibly through the `filename` attribute.
|
|
205
|
+
|
|
206
|
+
<a type="extension/runnable-region">
|
|
207
|
+
|
|
208
|
+
```html
|
|
209
|
+
<code type="workspace/empty-file" filename="otherdir/.gitkeep"></code>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
</a>
|
|
213
|
+
|
|
214
|
+
When executing the documentation, Text-Runner will create a file with name
|
|
215
|
+
<i type="workspace/existing-file">otherdir/.gitkeep</i> in the workspace.
|
|
216
|
+
|
|
217
|
+
## existing-directory
|
|
111
218
|
|
|
112
219
|
The <b type="action/name-full">workspace/existing-directory</b> action verifies
|
|
113
220
|
that the workspace contains a directory with the given name. As an example,
|
|
@@ -116,53 +223,199 @@ consider this documentation snippet:
|
|
|
116
223
|
<a type="extension/runnable-region">
|
|
117
224
|
|
|
118
225
|
```html
|
|
119
|
-
Please run the command <code type="shell/command">mkdir images</code>.
|
|
120
|
-
|
|
121
|
-
|
|
226
|
+
Please run the command <code type="shell/command">mkdir images</code>.
|
|
227
|
+
|
|
228
|
+
If everything goes well, your computer will now have a new directory
|
|
229
|
+
<i type="workspace/existing-directory">images</i>.
|
|
122
230
|
```
|
|
123
231
|
|
|
124
232
|
</a>
|
|
125
233
|
|
|
126
|
-
###
|
|
234
|
+
### "dir" attribute
|
|
235
|
+
|
|
236
|
+
You can override in which subdirectory of the workspace to look for the
|
|
237
|
+
directory by providing a `dir` attribute:
|
|
238
|
+
|
|
239
|
+
<a type="extension/runnable-region">
|
|
240
|
+
|
|
241
|
+
```html
|
|
242
|
+
Please run the command <code type="shell/command">mkdir subdir/images</code>.
|
|
243
|
+
|
|
244
|
+
If everything goes well, your computer will now have a new directory
|
|
245
|
+
<i type="workspace/existing-directory" dir="subdir">images</i>.
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
</a>
|
|
249
|
+
|
|
250
|
+
## existing-file
|
|
127
251
|
|
|
128
252
|
The <b type="action/name-full">workspace/existing-file</b> action verifies that
|
|
129
|
-
a file with the given name exists
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
253
|
+
a file with the given name exists. As an example, assuming the workspace
|
|
254
|
+
contains a file
|
|
255
|
+
<em type="workspace/empty-file">hello.txt</em>, we can verify it's existence via
|
|
256
|
+
this action:
|
|
133
257
|
|
|
134
258
|
<a type="extension/runnable-region">
|
|
135
259
|
|
|
136
260
|
```markdown
|
|
137
|
-
|
|
138
|
-
|
|
261
|
+
<code type="workspace/existing-file">hello.txt</code>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
</a>
|
|
139
265
|
|
|
140
|
-
|
|
141
|
-
|
|
266
|
+
### "dir" attribute
|
|
267
|
+
|
|
268
|
+
By default, this action looks for files in the workspace. You can tell it to
|
|
269
|
+
look in a different directory inside the workspace by providing a `dir`
|
|
270
|
+
attribute. Assuming the workspace contains a file
|
|
271
|
+
<em type="workspace/empty-file">subdir/hello.txt</em>, we can verify it's
|
|
272
|
+
existence via this action:
|
|
273
|
+
|
|
274
|
+
<a type="extension/runnable-region">
|
|
275
|
+
|
|
276
|
+
```markdown
|
|
277
|
+
<code type="workspace/existing-file" dir="subdir">hello.txt</code>
|
|
142
278
|
```
|
|
143
279
|
|
|
144
|
-
|
|
280
|
+
</a>
|
|
281
|
+
|
|
282
|
+
## existing-file-with-content
|
|
145
283
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
the
|
|
284
|
+
The <b type="action/name-full">workspace/existing-file-with-content</b> action
|
|
285
|
+
verifies that a file with the given name exists in the workspace and has the
|
|
286
|
+
given content. This action assumes that the documentation contains the filename
|
|
287
|
+
as _emphasized_ or **strong** text and the file content as a code block with
|
|
288
|
+
single or triple backticks.
|
|
289
|
+
|
|
290
|
+
Assuming the workspace contains a file <a type="workspace/new-file">_hello.txt_
|
|
291
|
+
with content `hello world`</a>, we can verify it via this action:
|
|
150
292
|
|
|
151
293
|
<a type="extension/runnable-region">
|
|
152
294
|
|
|
153
295
|
```markdown
|
|
154
|
-
<a type="workspace/
|
|
296
|
+
<a type="workspace/existing-file-with-content">
|
|
155
297
|
|
|
156
|
-
|
|
298
|
+
The file _hello.txt_ now contains `hello world`.
|
|
157
299
|
|
|
158
300
|
</a>
|
|
159
301
|
```
|
|
160
302
|
|
|
161
303
|
</a>
|
|
162
304
|
|
|
163
|
-
|
|
305
|
+
### "dir" attribute
|
|
164
306
|
|
|
165
|
-
|
|
166
|
-
|
|
307
|
+
By default, this action creates the file in the workspace. To create it in a
|
|
308
|
+
different directory, provide a name of the directory using the `dir` attribute.
|
|
167
309
|
|
|
168
|
-
|
|
310
|
+
As an example, if the workspace contains file <a type="workspace/new-file">
|
|
311
|
+
_subdir/apples.txt_ with the content `Boskoop`</a>, we can verify it like this:
|
|
312
|
+
|
|
313
|
+
<a type="extension/runnable-region">
|
|
314
|
+
|
|
315
|
+
```markdown
|
|
316
|
+
<a type="workspace/existing-file-with-content" dir="subdir">
|
|
317
|
+
The file <em>apples.txt</em> now contains <code>Boskoop</code>.
|
|
318
|
+
</a>
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
</a>
|
|
322
|
+
|
|
323
|
+
### "filename" attribute
|
|
324
|
+
|
|
325
|
+
If you don't want to repeat the filename in the text too often, you can also
|
|
326
|
+
provide it invisibly through the `filename` attribute. In that case, the file
|
|
327
|
+
content is the entire content of the active region.
|
|
328
|
+
|
|
329
|
+
<a type="extension/runnable-region">
|
|
330
|
+
|
|
331
|
+
```markdown
|
|
332
|
+
<a type="workspace/existing-file-with-content" filename="hello.txt">
|
|
333
|
+
hello world
|
|
334
|
+
</a>
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
</a>
|
|
338
|
+
|
|
339
|
+
### "partial-match" attribute
|
|
340
|
+
|
|
341
|
+
By default, this action matches the entire file content. If you want to verify
|
|
342
|
+
only a part of the file content, like a single line, provide the `partial-match`
|
|
343
|
+
attribute.
|
|
344
|
+
|
|
345
|
+
<a type="workspace/new-file">
|
|
346
|
+
|
|
347
|
+
Consider the workspace contains file _findings.txt_ with content:
|
|
348
|
+
|
|
349
|
+
```
|
|
350
|
+
finding 1
|
|
351
|
+
|
|
352
|
+
# Additional findings
|
|
353
|
+
|
|
354
|
+
finding 2
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
</a>
|
|
358
|
+
|
|
359
|
+
We can verify the caption like this:
|
|
360
|
+
|
|
361
|
+
<a type="extension/runnable-region">
|
|
362
|
+
|
|
363
|
+
```markdown
|
|
364
|
+
<a type="workspace/existing-file-with-content" partial-match>
|
|
365
|
+
|
|
366
|
+
The file _findings.txt_ now contains `# Additional findings`.
|
|
367
|
+
</a>
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
</a>
|
|
371
|
+
|
|
372
|
+
## new-directory
|
|
373
|
+
|
|
374
|
+
The <b type="action/name-full">workspace/new-directory</b> action creates a
|
|
375
|
+
directory with the given name in the workspace. Here is a usage example:
|
|
376
|
+
|
|
377
|
+
<a type="extension/runnable-region">
|
|
378
|
+
|
|
379
|
+
```html
|
|
380
|
+
Create a directory named <b type="workspace/new-directory">utils</b>.
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
</a>
|
|
384
|
+
|
|
385
|
+
When executing this Markdown snippet, Text-Runner will create a
|
|
386
|
+
<i type="workspace/existing-directory">utils</i> directory in the workspace,
|
|
387
|
+
just as the user would.
|
|
388
|
+
|
|
389
|
+
### "dir" attribute
|
|
390
|
+
|
|
391
|
+
You can override in which directory the new directory gets created by providing
|
|
392
|
+
a `dir` attribute:
|
|
393
|
+
|
|
394
|
+
<a type="extension/runnable-region">
|
|
395
|
+
|
|
396
|
+
```html
|
|
397
|
+
Create a directory named <code type="workspace/new-directory" dir="subdir">utils</code>.
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
</a>
|
|
401
|
+
|
|
402
|
+
When executing this Markdown snippet, Text-Runner will create a
|
|
403
|
+
<i type="workspace/existing-directory">subdir/utils</i> directory in the
|
|
404
|
+
workspace.
|
|
405
|
+
|
|
406
|
+
## working-dir
|
|
407
|
+
|
|
408
|
+
Each Text-Runner test starts in the workspace directory. The
|
|
409
|
+
<b type="action/name-full">workspace/working-dir</b> action changes the working
|
|
410
|
+
directory of the test runner to another directory inside the workspace. To
|
|
411
|
+
change into the directory the reader created above:
|
|
412
|
+
|
|
413
|
+
<a type="extension/runnable-region">
|
|
414
|
+
|
|
415
|
+
```html
|
|
416
|
+
Please change into the
|
|
417
|
+
<code type="workspace/working-dir">utils</code>
|
|
418
|
+
folder.
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
</a>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as textRunner from "text-runner-engine";
|
|
5
|
+
export async function appendFile(action) {
|
|
6
|
+
action.name("append to existing file");
|
|
7
|
+
const fileNameAttribute = action.region[0].attributes["filename"];
|
|
8
|
+
if (fileNameAttribute === "") {
|
|
9
|
+
throw new textRunner.UserError(`attribute "filename" is empty`, "");
|
|
10
|
+
}
|
|
11
|
+
const fileName = fileNameAttribute || action.region.textInNodeOfType("em", "strong");
|
|
12
|
+
const dirAttribute = action.region[0].attributes["dir"];
|
|
13
|
+
if (dirAttribute === "") {
|
|
14
|
+
throw new textRunner.UserError(`attribute "dir" is empty`, "");
|
|
15
|
+
}
|
|
16
|
+
if (dirAttribute !== undefined) {
|
|
17
|
+
const dirPath = action.configuration.workspace.joinStr(dirAttribute);
|
|
18
|
+
try {
|
|
19
|
+
await fs.access(dirPath, fs.constants.F_OK);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (e instanceof Error) {
|
|
23
|
+
throw new textRunner.UserError(`dir "${dirAttribute}" doesn't exist`, e.message);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const fileRelPath = dirAttribute ? path.join(dirAttribute, fileName) : fileName;
|
|
28
|
+
action.name(`append to file ${styleText("cyan", fileRelPath)}`);
|
|
29
|
+
const fullPath = action.configuration.workspace.joinStr(fileRelPath);
|
|
30
|
+
try {
|
|
31
|
+
await fs.access(fullPath, fs.constants.F_OK);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
if (e instanceof Error) {
|
|
35
|
+
throw new textRunner.UserError(`file "${fileRelPath}" doesn't exist`, e.message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const content = fileNameAttribute ? action.region.text() : action.region.textInNodeOfType("fence", "code");
|
|
39
|
+
action.log(content);
|
|
40
|
+
await fs.appendFile(fullPath, content);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=append-file.js.map
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import * as color from "colorette";
|
|
2
1
|
import { promises as fs } from "fs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import * as textRunner from "text-runner-engine";
|
|
5
5
|
export async function emptyFile(action) {
|
|
6
6
|
var _a;
|
|
7
|
-
const
|
|
7
|
+
const fileNameAttribute = action.region[0].attributes["filename"];
|
|
8
|
+
const fileName = fileNameAttribute || action.region.text().trim();
|
|
8
9
|
if (fileName === "") {
|
|
9
10
|
throw new textRunner.UserError("No filename given", "");
|
|
10
11
|
}
|
|
11
12
|
const filePath = path.join((_a = action.region[0].attributes["dir"]) !== null && _a !== void 0 ? _a : ".", fileName);
|
|
12
|
-
action.name(`create file ${
|
|
13
|
+
action.name(`create file ${styleText("cyan", filePath)}`);
|
|
13
14
|
const fullPath = action.configuration.workspace.joinStr(filePath);
|
|
14
15
|
action.log(`create file ${filePath}`);
|
|
15
16
|
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as color from "colorette";
|
|
2
1
|
import { promises as fs } from "fs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
/**
|
|
5
5
|
* The "directory" action verifies that the test workspace
|
|
@@ -8,16 +8,16 @@ import * as path from "path";
|
|
|
8
8
|
export async function existingDirectory(action) {
|
|
9
9
|
const dirName = action.region.text();
|
|
10
10
|
const dirRelName = path.join(action.region[0].attributes["dir"] || ".", dirName);
|
|
11
|
-
action.name(`directory ${
|
|
11
|
+
action.name(`directory ${styleText("cyan", dirRelName)} exists in the workspace`);
|
|
12
12
|
const fullPath = action.configuration.workspace.joinStr(dirRelName);
|
|
13
13
|
try {
|
|
14
14
|
var stats = await fs.lstat(fullPath);
|
|
15
15
|
}
|
|
16
16
|
catch (err) {
|
|
17
|
-
throw new Error(`directory ${
|
|
17
|
+
throw new Error(`directory ${styleText(["cyan", "bold"], dirRelName)} does not exist in the workspace`);
|
|
18
18
|
}
|
|
19
19
|
if (!stats.isDirectory()) {
|
|
20
|
-
throw new Error(`${
|
|
20
|
+
throw new Error(`${styleText("cyan", dirRelName)} exists but is not a directory`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=existing-directory.js.map
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import * as assertNoDiff from "assert-no-diff";
|
|
2
|
-
import * as color from "colorette";
|
|
3
2
|
import { promises as fs } from "fs";
|
|
3
|
+
import { styleText } from "node:util";
|
|
4
4
|
import * as path from "path";
|
|
5
5
|
import * as textRunner from "text-runner-engine";
|
|
6
6
|
export async function existingFileWithContent(action) {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
7
|
+
const fileNameAttribute = action.region[0].attributes["filename"];
|
|
8
|
+
const fileName = fileNameAttribute || action.region.textInNodeOfType("em", "strong");
|
|
9
|
+
const dirAttribute = action.region[0].attributes["dir"];
|
|
10
|
+
const fileRelPath = dirAttribute ? path.join(dirAttribute, fileName) : fileName;
|
|
10
11
|
const fullPath = action.configuration.workspace.joinStr(fileRelPath);
|
|
11
|
-
const
|
|
12
|
-
action.
|
|
12
|
+
const partialMatch = action.region[0].attributes["partial-match"] !== undefined;
|
|
13
|
+
const expectedContent = fileNameAttribute ? action.region.text() : action.region.textInNodeOfType("fence", "code");
|
|
14
|
+
if (partialMatch) {
|
|
15
|
+
action.name(`file ${styleText("cyan", fileRelPath)} contains substring ${expectedContent}`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
action.name(`verify content of file ${styleText("cyan", fileRelPath)}`);
|
|
19
|
+
}
|
|
13
20
|
try {
|
|
14
21
|
var actualContent = await fs.readFile(fullPath, "utf-8");
|
|
15
22
|
}
|
|
@@ -18,18 +25,26 @@ export async function existingFileWithContent(action) {
|
|
|
18
25
|
throw e;
|
|
19
26
|
}
|
|
20
27
|
if (e.code === "ENOENT") {
|
|
21
|
-
const files = await fs.readdir(action.configuration.
|
|
28
|
+
const files = await fs.readdir(action.configuration.workspace.platformified());
|
|
22
29
|
throw new textRunner.UserError(`file not found: ${fileRelPath}`, `the workspace has these files: ${files.join(", ")}`);
|
|
23
30
|
}
|
|
24
31
|
else {
|
|
25
32
|
throw e;
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
if (partialMatch) {
|
|
36
|
+
if (!actualContent.includes(expectedContent)) {
|
|
37
|
+
throw new textRunner.UserError(`file ${styleText(["cyan", "bold"], fileRelPath)} does not contain "${expectedContent}"`, actualContent);
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
else {
|
|
41
|
+
try {
|
|
42
|
+
assertNoDiff.trimmedLines(actualContent.trim(), expectedContent.trim());
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
action.log(actualContent);
|
|
46
|
+
throw new textRunner.UserError(`mismatching content in ${styleText(["cyan", "bold"], fileRelPath)}`, textRunner.errorMessage(err));
|
|
47
|
+
}
|
|
33
48
|
}
|
|
34
49
|
}
|
|
35
50
|
//# sourceMappingURL=existing-file-with-content.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as color from "colorette";
|
|
2
1
|
import { promises as fs } from "fs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import * as textRunner from "text-runner-engine";
|
|
5
5
|
export async function existingFile(action) {
|
|
6
6
|
const fileName = action.region.text();
|
|
7
7
|
const fileRelPath = path.join(action.region[0].attributes["dir"] || ".", fileName);
|
|
8
|
-
action.name(`verify existence of file ${
|
|
8
|
+
action.name(`verify existence of file ${styleText("cyan", fileRelPath)}`);
|
|
9
9
|
const fullPath = action.configuration.workspace.joinStr(fileRelPath);
|
|
10
10
|
try {
|
|
11
11
|
await fs.stat(fullPath);
|
|
@@ -15,7 +15,7 @@ export async function existingFile(action) {
|
|
|
15
15
|
throw e;
|
|
16
16
|
}
|
|
17
17
|
if (e.code === "ENOENT") {
|
|
18
|
-
const files = await fs.readdir(action.configuration.
|
|
18
|
+
const files = await fs.readdir(action.configuration.workspace.platformified());
|
|
19
19
|
throw new textRunner.UserError(`file not found: ${fileRelPath}`, `the workspace has these files: ${files.join(", ")}`);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as color from "colorette";
|
|
2
1
|
import { promises as fs } from "fs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
export async function newDirectory(action) {
|
|
5
5
|
const dirName = action.region.text().trim();
|
|
@@ -7,7 +7,7 @@ export async function newDirectory(action) {
|
|
|
7
7
|
throw new Error("empty directory name given");
|
|
8
8
|
}
|
|
9
9
|
const dirRelName = path.join(action.region[0].attributes["dir"] || ".", dirName);
|
|
10
|
-
action.name(`create directory ${
|
|
10
|
+
action.name(`create directory ${styleText("cyan", dirRelName)}`);
|
|
11
11
|
const fullPath = action.configuration.workspace.joinStr(dirRelName);
|
|
12
12
|
await fs.mkdir(fullPath, { recursive: true });
|
|
13
13
|
}
|
package/dist/actions/new-file.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as color from "colorette";
|
|
2
1
|
import { promises as fs } from "fs";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import * as textRunner from "text-runner-engine";
|
|
5
5
|
export async function newFile(action) {
|
|
@@ -26,7 +26,7 @@ export async function newFile(action) {
|
|
|
26
26
|
throw new textRunner.UserError(e.message, guidance);
|
|
27
27
|
}
|
|
28
28
|
const filePath = path.join((_a = action.region[0].attributes["dir"]) !== null && _a !== void 0 ? _a : ".", fileName);
|
|
29
|
-
action.name(`create file ${
|
|
29
|
+
action.name(`create file ${styleText("cyan", filePath)}`);
|
|
30
30
|
const fullPath = action.configuration.workspace.joinStr(filePath);
|
|
31
31
|
action.log(`create file ${filePath}`);
|
|
32
32
|
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
2
|
import * as textRunner from "text-runner-engine";
|
|
3
3
|
/** The "cd" action changes the current working directory to the one given in the hyperlink or code block. */
|
|
4
4
|
export function workingDir(action) {
|
|
5
5
|
const directory = action.region.text();
|
|
6
|
-
action.name(`changing into the ${
|
|
6
|
+
action.name(`changing into the ${styleText("cyan", directory)} directory`);
|
|
7
7
|
const fullPath = action.configuration.workspace.joinStr(directory);
|
|
8
8
|
action.log(`cd ${fullPath}`);
|
|
9
9
|
try {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { appendFile } from "./actions/append-file.js";
|
|
2
2
|
import { emptyFile } from "./actions/empty-file.js";
|
|
3
3
|
import { existingDirectory } from "./actions/existing-directory.js";
|
|
4
4
|
import { existingFileWithContent } from "./actions/existing-file-with-content.js";
|
|
@@ -7,7 +7,7 @@ import { newDirectory } from "./actions/new-directory.js";
|
|
|
7
7
|
import { newFile } from "./actions/new-file.js";
|
|
8
8
|
import { workingDir } from "./actions/working-dir.js";
|
|
9
9
|
export const textrunActions = {
|
|
10
|
-
|
|
10
|
+
appendFile,
|
|
11
11
|
emptyFile,
|
|
12
12
|
existingDirectory,
|
|
13
13
|
existingFile,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textrun-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Text-Runner actions for the Text-Runner workspace",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -12,21 +12,20 @@
|
|
|
12
12
|
"build": "tsc -p tsconfig-build.json",
|
|
13
13
|
"cuke": "cucumber-js --format=progress",
|
|
14
14
|
"doc": "text-runner",
|
|
15
|
-
"fix": "eslint --fix --ignore-pattern=dist/ . && dprint fmt && sort-package-json --quiet",
|
|
15
|
+
"fix": "eslint --fix --ignore-pattern=dist/ . && dprint fmt && sort-package-json --quiet && ../tools/rta ghokin fmt replace features",
|
|
16
16
|
"lint": "dprint check && sort-package-json --check --quiet && eslint --ignore-pattern=dist/ . && depcheck",
|
|
17
17
|
"reset": "rm -rf dist && yarn run build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"assert-no-diff": "4.1.0",
|
|
21
|
-
"
|
|
22
|
-
"text-runner-engine": "7.1.2"
|
|
21
|
+
"text-runner-engine": "7.2.1"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
24
|
"shared-cucumber-steps": "*",
|
|
26
|
-
"text-runner": "7.1
|
|
27
|
-
"textrun-action": "0.
|
|
28
|
-
"textrun-extension": "0.
|
|
29
|
-
"tsx": "4.
|
|
25
|
+
"text-runner": "7.2.1",
|
|
26
|
+
"textrun-action": "0.4.1",
|
|
27
|
+
"textrun-extension": "0.4.1",
|
|
28
|
+
"tsx": "4.20.6"
|
|
30
29
|
},
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "d407abf5515e7fe37f886dc8d51014588fb929ad"
|
|
32
31
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as color from "colorette";
|
|
2
|
-
import { promises as fs } from "fs";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
export async function additionalFileContent(action) {
|
|
5
|
-
const fileName = action.region.textInNodeOfType("em", "strong");
|
|
6
|
-
const fileRelPath = path.join(action.region[0].attributes["dir"] || ".", fileName);
|
|
7
|
-
action.name(`append to file ${color.cyan(fileRelPath)}`);
|
|
8
|
-
const content = action.region.textInNodeOfType("fence", "code");
|
|
9
|
-
const fullPath = action.configuration.workspace.joinStr(fileRelPath);
|
|
10
|
-
action.log(content);
|
|
11
|
-
await fs.appendFile(fullPath, content);
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=additional-file-content.js.map
|