@vanillaes/esmtk 0.23.0 → 0.23.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 CHANGED
@@ -15,12 +15,13 @@ ESMTK, essential tools for ECMAScript module development
15
15
  - [init](#init) - Create a package.json file for ECMAScript module development
16
16
  - [test](#test) - Run tests (using Tape-ES)
17
17
  - [lint](#lint) - Lint the source code (using StandardJS)
18
- - [types](#lint) - Type check the JSDoc typings (using Typescript)
18
+ - [types](#types) - Type check the JSDoc typings (using Typescript)
19
19
  - [bundle](#bundle) - Bundle the source code to an ECMAScript module (using ESBuild)
20
20
  - [minify](#minify) - Bundle and Minify the source code to an ECMAScript module (using ESBuild)
21
21
  - [commonjs](#commonjs) - Bundle the source code to a CommonJS module (using ESBuild)
22
22
  - [typings](#typings) - Generate Type Declarations (.d.ts) from JSDoc (using Typescript)
23
23
  - [clean](#clean) - Clean up build artifacts
24
+ - [preview](#preview) - Preview the package contents included during `npm publish`
24
25
  - [cp](#cp) - A cross-platform clone of the `cp` command in Linux
25
26
  - [rm](#rm) - A cross-platform clone of the `rm` command in Linux
26
27
 
@@ -240,6 +241,27 @@ esmtk clean --custom *.scss.css
240
241
  **Node: The `clean` command automatically ignores the contents of `node_modules/`**
241
242
 
242
243
 
244
+ ## Preview
245
+
246
+ Preview the package contents included during `npm publish`
247
+
248
+ ### Arguments
249
+
250
+ `esmtk preview`
251
+
252
+ - `-r` | `--root` - automatically fix problems
253
+
254
+ ### Usage
255
+
256
+ ```sh
257
+ # preview the package contents
258
+ esmtk preview
259
+
260
+ # preview the package contents (from another root directory)
261
+ esmtk preview --root some/other/dir
262
+ ```
263
+
264
+
243
265
  ## CP
244
266
 
245
267
  A cross-platform clone of the `cp` command in Linux
@@ -7,7 +7,7 @@ import { createRequire } from 'module'
7
7
  const require = createRequire(import.meta.url)
8
8
 
9
9
  /**
10
- * Preview the package contents on publish
10
+ * Preview the package contents included during 'npm publish'
11
11
  * @param {any} options preview options
12
12
  */
13
13
  export async function preview (options) {
package/bin/esmtk.js CHANGED
@@ -92,7 +92,7 @@ program.command('clean')
92
92
  })
93
93
 
94
94
  program.command('preview')
95
- .description('Preview the package contents on publish')
95
+ .description('Preview the package contents included during \'npm publish\'')
96
96
  .option('-r, --root <root>', 'the root path to run the tests from (default `process.cwd()`)', process.cwd())
97
97
  .action((options) => {
98
98
  preview(options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
6
  "ecmascript",
@@ -44,6 +44,7 @@
44
44
  "minify": "./bin/esmtk.js minify --platform=node src/index.js src/index.min.js",
45
45
  "typings": "./bin/esmtk.js typings src/index.js",
46
46
  "clean": "./bin/esmtk.js clean --typings",
47
+ "preview": "./bin/esmtk.js preview",
47
48
  "preversion": "npm run test && npm run lint && npm run types",
48
49
  "postversion": "git push --follow-tags"
49
50
  },
@@ -1,496 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "name": "Version",
6
- "type": "node",
7
- "request": "launch",
8
- "skipFiles": [
9
- "<node_internals>/**"
10
- ],
11
- "program": "${workspaceFolder}/bin/esmtk.js",
12
- "cwd": "${workspaceFolder}",
13
- "args": ["--version"],
14
- "console": "integratedTerminal",
15
- },
16
- {
17
- "name": "Init",
18
- "type": "node",
19
- "request": "launch",
20
- "skipFiles": [
21
- "<node_internals>/**"
22
- ],
23
- "program": "${workspaceFolder}/bin/esmtk.js",
24
- "cwd": "${workspaceFolder}",
25
- "args": ["init"],
26
- "console": "integratedTerminal",
27
- },
28
- {
29
- "name": "Test",
30
- "type": "node",
31
- "request": "launch",
32
- "skipFiles": [
33
- "<node_internals>/**"
34
- ],
35
- "program": "${workspaceFolder}/bin/esmtk.js",
36
- "cwd": "${workspaceFolder}",
37
- "args": ["test"],
38
- "console": "integratedTerminal",
39
- },
40
- {
41
- "name": "Test --ignore",
42
- "type": "node",
43
- "request": "launch",
44
- "skipFiles": [
45
- "<node_internals>/**"
46
- ],
47
- "program": "${workspaceFolder}/bin/esmtk.js",
48
- "cwd": "${workspaceFolder}",
49
- "args": ["test", "--ignore", "node_modules/**,src/util.spec.js"],
50
- "console": "integratedTerminal",
51
- },
52
- {
53
- "name": "Test --root",
54
- "type": "node",
55
- "request": "launch",
56
- "skipFiles": [
57
- "<node_internals>/**"
58
- ],
59
- "program": "${workspaceFolder}/bin/esmtk.js",
60
- "cwd": "${workspaceFolder}",
61
- "args": ["test", "--root", "src/"],
62
- "console": "integratedTerminal",
63
- },
64
- {
65
- "name": "Lint",
66
- "type": "node",
67
- "request": "launch",
68
- "skipFiles": [
69
- "<node_internals>/**"
70
- ],
71
- "program": "${workspaceFolder}/bin/esmtk.js",
72
- "cwd": "${workspaceFolder}",
73
- "args": ["lint"],
74
- "console": "integratedTerminal",
75
- },
76
- {
77
- "name": "Types",
78
- "type": "node",
79
- "request": "launch",
80
- "skipFiles": [
81
- "<node_internals>/**"
82
- ],
83
- "program": "${workspaceFolder}/bin/esmtk.js",
84
- "cwd": "${workspaceFolder}",
85
- "args": ["types", "./src/index.js"],
86
- "console": "integratedTerminal",
87
- },
88
- {
89
- "name": "Typings",
90
- "type": "node",
91
- "request": "launch",
92
- "skipFiles": [
93
- "<node_internals>/**"
94
- ],
95
- "program": "${workspaceFolder}/bin/esmtk.js",
96
- "cwd": "${workspaceFolder}",
97
- "args": ["typings", "./src/index.js"],
98
- "console": "integratedTerminal",
99
- },
100
- {
101
- "name": "Bundle",
102
- "type": "node",
103
- "request": "launch",
104
- "skipFiles": [
105
- "<node_internals>/**"
106
- ],
107
- "program": "${workspaceFolder}/bin/esmtk.js",
108
- "cwd": "${workspaceFolder}",
109
- "args": ["bundle", "--platform=node", "./src/index.js", "./dist/index.js"],
110
- "console": "integratedTerminal",
111
- },
112
- {
113
- "name": "Minify",
114
- "type": "node",
115
- "request": "launch",
116
- "skipFiles": [
117
- "<node_internals>/**"
118
- ],
119
- "program": "${workspaceFolder}/bin/esmtk.js",
120
- "cwd": "${workspaceFolder}",
121
- "args": ["minify", "--sourcemap", "--platform=node", "./src/index.js", "./dist/index.min.js"],
122
- "console": "integratedTerminal",
123
- },
124
- {
125
- "name": "CommonJS",
126
- "type": "node",
127
- "request": "launch",
128
- "skipFiles": [
129
- "<node_internals>/**"
130
- ],
131
- "program": "${workspaceFolder}/bin/esmtk.js",
132
- "cwd": "${workspaceFolder}",
133
- "args": ["commonjs", "--platform=node", "./src/index.js", "./dist/index.cjs"],
134
- "console": "integratedTerminal",
135
- },
136
- {
137
- "name": "Clean --bundle",
138
- "type": "node",
139
- "request": "launch",
140
- "skipFiles": [
141
- "<node_internals>/**"
142
- ],
143
- "program": "${workspaceFolder}/bin/esmtk.js",
144
- "cwd": "${workspaceFolder}",
145
- "args": ["clean", "--bundle"],
146
- "console": "integratedTerminal",
147
- },
148
- {
149
- "name": "Clean --bundle w/ override",
150
- "type": "node",
151
- "request": "launch",
152
- "skipFiles": [
153
- "<node_internals>/**"
154
- ],
155
- "program": "${workspaceFolder}/bin/esmtk.js",
156
- "cwd": "${workspaceFolder}",
157
- "args": ["clean", "--bundle", "**/*.js"],
158
- "console": "integratedTerminal",
159
- },
160
- {
161
- "name": "Clean --bundle w/ Error",
162
- "type": "node",
163
- "request": "launch",
164
- "skipFiles": [
165
- "<node_internals>/**"
166
- ],
167
- "program": "${workspaceFolder}/bin/esmtk.js",
168
- "cwd": "${workspaceFolder}",
169
- "args": ["clean", "--bundle", "**/*.mjs"],
170
- "console": "integratedTerminal",
171
- },
172
- {
173
- "name": "Clean --minify",
174
- "type": "node",
175
- "request": "launch",
176
- "skipFiles": [
177
- "<node_internals>/**"
178
- ],
179
- "program": "${workspaceFolder}/bin/esmtk.js",
180
- "cwd": "${workspaceFolder}",
181
- "args": ["clean", "--minify"],
182
- "console": "integratedTerminal",
183
- },
184
- {
185
- "name": "Clean --typings",
186
- "type": "node",
187
- "request": "launch",
188
- "skipFiles": [
189
- "<node_internals>/**"
190
- ],
191
- "program": "${workspaceFolder}/bin/esmtk.js",
192
- "cwd": "${workspaceFolder}",
193
- "args": ["clean", "--typings"],
194
- "console": "integratedTerminal",
195
- },
196
- {
197
- "name": "Clean All",
198
- "type": "node",
199
- "request": "launch",
200
- "skipFiles": [
201
- "<node_internals>/**"
202
- ],
203
- "program": "${workspaceFolder}/bin/esmtk.js",
204
- "cwd": "${workspaceFolder}",
205
- "args": ["clean", "--bundle", "--minify", "--typings"],
206
- "console": "integratedTerminal",
207
- },
208
- {
209
- "name": "Clean --custom",
210
- "type": "node",
211
- "request": "launch",
212
- "skipFiles": [
213
- "<node_internals>/**"
214
- ],
215
- "program": "${workspaceFolder}/bin/esmtk.js",
216
- "cwd": "${workspaceFolder}",
217
- "args": ["clean", "--custom", "**/*.min.js"],
218
- "console": "integratedTerminal",
219
- },
220
- {
221
- "name": "Preview",
222
- "type": "node",
223
- "request": "launch",
224
- "skipFiles": [
225
- "<node_internals>/**"
226
- ],
227
- "program": "${workspaceFolder}/bin/esmtk.js",
228
- "cwd": "${workspaceFolder}",
229
- "args": ["preview"],
230
- "console": "integratedTerminal",
231
- },
232
- {
233
- "name": "CopyFileToFile",
234
- "type": "node",
235
- "request": "launch",
236
- "skipFiles": [
237
- "<node_internals>/**"
238
- ],
239
- "program": "${workspaceFolder}/bin/esmtk.js",
240
- "cwd": "${workspaceFolder}",
241
- "args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
242
- "console": "integratedTerminal",
243
- },
244
- {
245
- "name": "CopyFileToFile - Error source doesn't exist",
246
- "type": "node",
247
- "request": "launch",
248
- "skipFiles": [
249
- "<node_internals>/**"
250
- ],
251
- "program": "${workspaceFolder}/bin/esmtk.js",
252
- "cwd": "${workspaceFolder}",
253
- "args": ["cp", "./test/cp/testx.txt", "./test/cp2/"],
254
- "console": "integratedTerminal",
255
- },
256
- {
257
- "name": "CopyFileToFile - Error source is a directory",
258
- "type": "node",
259
- "request": "launch",
260
- "skipFiles": [
261
- "<node_internals>/**"
262
- ],
263
- "program": "${workspaceFolder}/bin/esmtk.js",
264
- "cwd": "${workspaceFolder}",
265
- "args": ["cp", "./test/cp/", "./test/cp2/test1.txt"],
266
- "console": "integratedTerminal",
267
- },
268
- {
269
- "name": "CopyFileToFile - Error target directory doesn't exist",
270
- "type": "node",
271
- "request": "launch",
272
- "skipFiles": [
273
- "<node_internals>/**"
274
- ],
275
- "program": "${workspaceFolder}/bin/esmtk.js",
276
- "cwd": "${workspaceFolder}",
277
- "args": ["cp", "./test/cp/test1.txt", "./test/cpx/"],
278
- "console": "integratedTerminal",
279
- },
280
- {
281
- "name": "CopyFileToDirectory",
282
- "type": "node",
283
- "request": "launch",
284
- "skipFiles": [
285
- "<node_internals>/**"
286
- ],
287
- "program": "${workspaceFolder}/bin/esmtk.js",
288
- "cwd": "${workspaceFolder}",
289
- "args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
290
- "console": "integratedTerminal",
291
- },
292
- {
293
- "name": "CopyGlobToDirectory",
294
- "type": "node",
295
- "request": "launch",
296
- "skipFiles": [
297
- "<node_internals>/**"
298
- ],
299
- "program": "${workspaceFolder}/bin/esmtk.js",
300
- "cwd": "${workspaceFolder}",
301
- "args": ["cp", "./test/cp/*.js", "./test/cp2/"],
302
- "console": "integratedTerminal",
303
- },
304
- {
305
- "name": "CopyMultipleFiles",
306
- "type": "node",
307
- "request": "launch",
308
- "skipFiles": [
309
- "<node_internals>/**"
310
- ],
311
- "program": "${workspaceFolder}/bin/esmtk.js",
312
- "cwd": "${workspaceFolder}",
313
- "args": ["cp", "./test/cp/test1.txt", "./test/cp/test1.js", "./test/cp/test2.txt", "./test/cp/test2.js", "./test/cp2/"],
314
- "console": "integratedTerminal",
315
- },
316
- {
317
- "name": "CopyMultipleFiles - Error file doesn't exist",
318
- "type": "node",
319
- "request": "launch",
320
- "skipFiles": [
321
- "<node_internals>/**"
322
- ],
323
- "program": "${workspaceFolder}/bin/esmtk.js",
324
- "cwd": "${workspaceFolder}",
325
- "args": ["cp", "./test/cp/test1.ts", "./test/cp/test1.js", "./test/cp/test2.txt", "./test/cp/test2.js", "./test/cp2/"],
326
- "console": "integratedTerminal",
327
- },
328
- {
329
- "name": "CopyMultipleGlobs",
330
- "type": "node",
331
- "request": "launch",
332
- "skipFiles": [
333
- "<node_internals>/**"
334
- ],
335
- "program": "${workspaceFolder}/bin/esmtk.js",
336
- "cwd": "${workspaceFolder}",
337
- "args": ["cp", "./test/cp/*.txt", "./test/cp/*.js", "./test/cp2/"],
338
- "console": "integratedTerminal",
339
- },
340
- {
341
- "name": "CopyMultipleGlobs - Error glob not found",
342
- "type": "node",
343
- "request": "launch",
344
- "skipFiles": [
345
- "<node_internals>/**"
346
- ],
347
- "program": "${workspaceFolder}/bin/esmtk.js",
348
- "cwd": "${workspaceFolder}",
349
- "args": ["cp", "./test/cp/*.ts", "./test/cp/*.js", "./test/cp2/"],
350
- "console": "integratedTerminal",
351
- },
352
- {
353
- "name": "CopyMultipleMixed",
354
- "type": "node",
355
- "request": "launch",
356
- "skipFiles": [
357
- "<node_internals>/**"
358
- ],
359
- "program": "${workspaceFolder}/bin/esmtk.js",
360
- "cwd": "${workspaceFolder}",
361
- "args": ["cp", "./test/cp/test1.txt", "./test/cp/test2.txt", "./test/cp/*.js", "./test/cp2/"],
362
- "console": "integratedTerminal",
363
- },
364
- {
365
- "name": "CopyDirectoryRecursively",
366
- "type": "node",
367
- "request": "launch",
368
- "skipFiles": [
369
- "<node_internals>/**"
370
- ],
371
- "program": "${workspaceFolder}/bin/esmtk.js",
372
- "cwd": "${workspaceFolder}",
373
- "args": ["cp", "-r", "./test/cp/", "./test/cp2"],
374
- "console": "integratedTerminal",
375
- },
376
- {
377
- "name": "RemoveFile",
378
- "type": "node",
379
- "request": "launch",
380
- "skipFiles": [
381
- "<node_internals>/**"
382
- ],
383
- "program": "${workspaceFolder}/bin/esmtk.js",
384
- "cwd": "${workspaceFolder}",
385
- "args": ["rm", "./test/cp2/test1.txt"],
386
- "console": "integratedTerminal",
387
- },
388
- {
389
- "name": "RemoveFile - Error file is a directory",
390
- "type": "node",
391
- "request": "launch",
392
- "skipFiles": [
393
- "<node_internals>/**"
394
- ],
395
- "program": "${workspaceFolder}/bin/esmtk.js",
396
- "cwd": "${workspaceFolder}",
397
- "args": ["rm", "./test/cp2/"],
398
- "console": "integratedTerminal",
399
- },
400
- {
401
- "name": "RemoveGlob",
402
- "type": "node",
403
- "request": "launch",
404
- "skipFiles": [
405
- "<node_internals>/**"
406
- ],
407
- "program": "${workspaceFolder}/bin/esmtk.js",
408
- "cwd": "${workspaceFolder}",
409
- "args": ["rm", "./test/cp2/*.js"],
410
- "console": "integratedTerminal",
411
- },
412
- {
413
- "name": "RemoveGlob - Error glob not found",
414
- "type": "node",
415
- "request": "launch",
416
- "skipFiles": [
417
- "<node_internals>/**"
418
- ],
419
- "program": "${workspaceFolder}/bin/esmtk.js",
420
- "cwd": "${workspaceFolder}",
421
- "args": ["rm", "./test/cp2/*.ts"],
422
- "console": "integratedTerminal",
423
- },
424
- {
425
- "name": "RemoveDirectory",
426
- "type": "node",
427
- "request": "launch",
428
- "skipFiles": [
429
- "<node_internals>/**"
430
- ],
431
- "program": "${workspaceFolder}/bin/esmtk.js",
432
- "cwd": "${workspaceFolder}",
433
- "args": ["rm", "-r", "./test/cp2/"],
434
- "console": "integratedTerminal",
435
- },
436
- {
437
- "name": "RemoveMultipleFiles",
438
- "type": "node",
439
- "request": "launch",
440
- "skipFiles": [
441
- "<node_internals>/**"
442
- ],
443
- "program": "${workspaceFolder}/bin/esmtk.js",
444
- "cwd": "${workspaceFolder}",
445
- "args": ["rm", "./test/cp2/test1.txt", "./test/cp2/test2.txt"],
446
- "console": "integratedTerminal",
447
- },
448
- {
449
- "name": "RemoveMultipleGlobs",
450
- "type": "node",
451
- "request": "launch",
452
- "skipFiles": [
453
- "<node_internals>/**"
454
- ],
455
- "program": "${workspaceFolder}/bin/esmtk.js",
456
- "cwd": "${workspaceFolder}",
457
- "args": ["rm", "./test/cp2/*.txt", "./test/cp2/*.js"],
458
- "console": "integratedTerminal",
459
- },
460
- {
461
- "name": "RemoveMultipleGlobs - Error glob not found",
462
- "type": "node",
463
- "request": "launch",
464
- "skipFiles": [
465
- "<node_internals>/**"
466
- ],
467
- "program": "${workspaceFolder}/bin/esmtk.js",
468
- "cwd": "${workspaceFolder}",
469
- "args": ["rm", "./test/cp2/*.txt", "./test/cp2/*.ts"],
470
- "console": "integratedTerminal",
471
- },
472
- {
473
- "name": "RemoveMultipleMixed",
474
- "type": "node",
475
- "request": "launch",
476
- "skipFiles": [
477
- "<node_internals>/**"
478
- ],
479
- "program": "${workspaceFolder}/bin/esmtk.js",
480
- "cwd": "${workspaceFolder}",
481
- "args": ["rm", "./test/cp2/test1.txt", "./test/cp2/*.js"],
482
- "console": "integratedTerminal",
483
- },
484
- {
485
- "name": "Tape - Current File",
486
- "type": "node",
487
- "request": "launch",
488
- "skipFiles": [
489
- "<node_internals>/**"
490
- ],
491
- "program": "${file}",
492
- "cwd": "${workspaceFolder}",
493
- "console": "integratedTerminal",
494
- }
495
- ]
496
- }
@@ -1,68 +0,0 @@
1
- {
2
- "copyAsync": {
3
- "cp1": {
4
- "test1.txt": "test 1 text",
5
- "test2.txt": "test 2 text"
6
- },
7
- "cp2": {}
8
- },
9
- "copyAsyncExpect": {
10
- "cp1": {
11
- "test1.txt": "test 1 text",
12
- "test2.txt": "test 2 text"
13
- },
14
- "cp2": {
15
- "test1.txt": "test 1 text"
16
- }
17
- },
18
- "copyMultipleAsync": {
19
- "cp1": {
20
- "test1.txt": "test 1 text",
21
- "test2.txt": "test 2 text",
22
- "test1.js": "test 1 javascript",
23
- "test2.js": "test 2 javascript"
24
- },
25
- "cp2": {}
26
- },
27
- "copyMultipleAsyncExpect": {
28
- "cp1": {
29
- "test1.txt": "test 1 text",
30
- "test2.txt": "test 2 text",
31
- "test1.js": "test 1 javascript",
32
- "test2.js": "test 2 javascript"
33
- },
34
- "cp2": {
35
- "test1.txt": "test 1 text",
36
- "test1.js": "test 1 javascript"
37
- }
38
- },
39
- "copyRecursiveAsync": {
40
- "cp1": {
41
- "test1.txt": "test 1 text",
42
- "test1.js": "test 1 javascript",
43
- "sub": {
44
- "test2.txt": "test 2 text",
45
- "test2.js": "test 2 javascript"
46
- }
47
- },
48
- "cp2": {}
49
- },
50
- "copyRecursiveAsyncExpect": {
51
- "cp1": {
52
- "test1.txt": "test 1 text",
53
- "test1.js": "test 1 javascript",
54
- "sub": {
55
- "test2.txt": "test 2 text",
56
- "test2.js": "test 2 javascript"
57
- }
58
- },
59
- "cp2": {
60
- "test1.txt": "test 1 text",
61
- "test1.js": "test 1 javascript",
62
- "sub": {
63
- "test2.txt": "test 2 text",
64
- "test2.js": "test 2 javascript"
65
- }
66
- }
67
- }
68
- }
@@ -1,35 +0,0 @@
1
- {
2
- "removeAsync": {
3
- "test1.txt": "test 1 text",
4
- "test2.txt": "test 2 text"
5
- },
6
- "removeAsyncExpect": {
7
- "test2.txt": "test 2 text"
8
- },
9
- "removeMultipleAsync": {
10
- "test1.txt": "test 1 text",
11
- "test2.txt": "test 2 text",
12
- "test1.js": "test 1 javascript",
13
- "test2.js": "test 2 javascript"
14
- },
15
- "removeMultipleAsyncExpect": {
16
- "test2.txt": "test 2 text",
17
- "test2.js": "test 2 javascript"
18
- },
19
- "removeRecursiveAsync": {
20
- "directory1": {
21
- "test1.txt": "test 1 text",
22
- "test1.js": "test 1 javascript"
23
- },
24
- "directory2": {
25
- "test2.txt": "test 2 text",
26
- "test2.js": "test 2 javascript"
27
- }
28
- },
29
- "removeRecursiveAsyncExpect": {
30
- "directory2": {
31
- "test2.txt": "test 2 text",
32
- "test2.js": "test 2 javascript"
33
- }
34
- }
35
- }
@@ -1,96 +0,0 @@
1
- import { mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
2
- import { join } from 'node:path'
3
- import tapeTest from 'tape'
4
-
5
- export async function setup (fn) {
6
- tapeTest('Setup', function (t) {
7
- fn(t)
8
- })
9
- }
10
-
11
- export const skip = () => tapeTest.skip()
12
-
13
- export async function teardown (fn) {
14
- tapeTest('Teardown', function (t) {
15
- fn(t)
16
- })
17
- }
18
-
19
- export async function test (description, files = [], fn) {
20
- if (!files) {
21
- tapeTest(description, function (t) {
22
- fn(t)
23
- })
24
- return
25
- }
26
-
27
- tapeTest(description, function (t) {
28
- mkdirSync('test', { recursive: true })
29
- process.chdir('test')
30
-
31
- objectsλFiles(files)
32
-
33
- const oldEnd = t.end
34
- t.end = function () {
35
- oldEnd()
36
- process.chdir('..')
37
- rmSync('test', { recursive: true, force: true })
38
- }
39
-
40
- fn(t)
41
- })
42
- }
43
-
44
- export function objectsλFiles (obj, path = process.cwd()) {
45
- if (obj !== null && typeof obj === 'object') {
46
- Object.entries(obj).forEach(([key, value]) => {
47
- if (typeof value === 'object' && value !== null) {
48
- mkdirSync(join(path, key), { recursive: true })
49
- objectsλFiles(value, join(path, key))
50
- } else {
51
- writeFileSync(join(path, key), value)
52
- }
53
- })
54
- }
55
- }
56
-
57
- export function filesλobjects (dir = '.') {
58
- function walk (dir, fileList = []) {
59
- const files = readdirSync(dir)
60
- for (const file of files) {
61
- const filePath = join(dir, file)
62
- const stat = statSync(filePath)
63
- if (stat.isDirectory()) {
64
- walk(filePath, fileList)
65
- } else if (stat.isFile()) {
66
- fileList.push(filePath)
67
- }
68
- }
69
- return fileList
70
- }
71
-
72
- function treeify (files) {
73
- const tree = {}
74
- for (const path of files) {
75
- const parts = path.split('/')
76
- let currentLevel = tree
77
- parts.forEach((part, index, array) => {
78
- if (index === array.length - 1) {
79
- const contents = readFileSync(path, 'utf8')
80
- currentLevel[part] = contents
81
- } else {
82
- if (!currentLevel[part]) {
83
- currentLevel[part] = {}
84
- }
85
- currentLevel = currentLevel[part]
86
- }
87
- })
88
- }
89
- return tree
90
- }
91
-
92
- const files = walk(dir).reverse()
93
- const tree = treeify(files)
94
-
95
- return tree
96
- }
@@ -1,17 +0,0 @@
1
- {
2
- "expand": {
3
- "test1.txt": "test 1",
4
- "test2.txt": "test 2",
5
- "test1.js": "test 1 javascript",
6
- "test2.js": "test 2 javascript"
7
- },
8
- "fileExists": {
9
- "test1.txt": "test 1"
10
- },
11
- "match": {
12
- "test1.txt": "test 1",
13
- "test2.txt": "test 2",
14
- "test1.js": "test 1 javascript",
15
- "test2.js": "test 2 javascript"
16
- }
17
- }
package/src/cp.spec.js DELETED
@@ -1,106 +0,0 @@
1
- import { filesλobjects, setup, teardown, test } from './__test__/test.js'
2
- import { copyAsync, copyMultipleAsync, copyRecursiveAsync } from '@vanillaes/esmtk'
3
- import { rmSync } from 'node:fs'
4
-
5
- import { createRequire } from 'module'
6
- const require = createRequire(import.meta.url)
7
- const files = require('./__test__/cp.json')
8
- const processExit = process.exit
9
-
10
- setup(async (t) => {
11
- process.exit = function () {
12
- throw new Error('process.exit(1)')
13
- }
14
- process.chdir(process.cwd())
15
- rmSync('test', { recursive: true, force: true })
16
-
17
- t.end()
18
- })
19
-
20
- test('copyAsync - copy file-to-file', files.copyAsync, async (t) => {
21
- await copyAsync('cp1/test1.txt', 'cp2/test1.txt')
22
-
23
- const actual = filesλobjects()
24
- const expect = files.copyAsyncExpect
25
-
26
- t.deepEqual(actual, expect)
27
- t.end()
28
- })
29
-
30
- test('copyAsync - copy file-to-file - ERROR: no such file or directory (source)', files.copyAsync, async (t) => {
31
- try {
32
- await copyAsync('cp1/test1.ts', 'cp2/test1.ts')
33
- t.fail('Expected error was not thrown')
34
- } catch (err) {
35
- t.ok(err, 'Error was thrown as expected')
36
- }
37
- t.end()
38
- })
39
-
40
- test('copyAsync - copy file-to-file - ERROR: source is a directory', files.copyAsync, async (t) => {
41
- try {
42
- await copyAsync('cp1/', 'cp2/test1.txt')
43
- t.fail('Expected error was not thrown')
44
- } catch (err) {
45
- t.ok(err, 'Error was thrown as expected')
46
- }
47
- t.end()
48
- })
49
-
50
- test('copyAsync - copy file-to-directory', files.copyAsync, async (t) => {
51
- await copyAsync('cp1/test1.txt', 'cp2/')
52
-
53
- const actual = filesλobjects()
54
- const expect = files.copyAsyncExpect
55
-
56
- t.deepEqual(actual, expect)
57
- t.end()
58
- })
59
-
60
- test('copyAsync - copy file-to-directory - ERROR: no such file or directory (target)', files.copyAsync, async (t) => {
61
- try {
62
- await copyAsync('cp1/test1.txt', 'cpx/')
63
- t.fail('Expected error was not thrown')
64
- } catch (err) {
65
- t.ok(err, 'Error was thrown as expected')
66
- }
67
- t.end()
68
- })
69
-
70
- test('copyMultipleAsync - copy multiple files', files.copyMultipleAsync, async (t) => {
71
- await copyMultipleAsync(['cp1/test1.txt', 'cp1/test1.js'], 'cp2/')
72
-
73
- const actual = filesλobjects()
74
- const expect = files.copyMultipleAsyncExpect
75
-
76
- t.deepEqual(actual, expect)
77
- t.end()
78
- })
79
-
80
- test('copyMultipleAsync - copy multiple files - ERROR: no such file or directory (target)', files.copyMultipleAsync, async (t) => {
81
- try {
82
- await copyMultipleAsync(['cp1/test1.txt', 'cp1/test1.js'], 'cpx/')
83
- t.fail('Expected error was not thrown')
84
- } catch (err) {
85
- t.ok(err, 'Error was thrown as expected')
86
- }
87
- t.end()
88
- })
89
-
90
- test('copyRecursiveAsync - ', files.copyRecursiveAsync, async (t) => {
91
- await copyRecursiveAsync('cp1/', 'cp2/')
92
-
93
- const actual = filesλobjects()
94
- const expect = files.copyRecursiveAsyncExpect
95
-
96
- t.deepEqual(actual, expect)
97
- t.end()
98
- })
99
-
100
- teardown(async (t) => {
101
- process.exit = processExit
102
- process.chdir(process.cwd())
103
- rmSync('test', { recursive: true, force: true })
104
-
105
- t.end()
106
- })
package/src/rm.spec.js DELETED
@@ -1,76 +0,0 @@
1
- import { filesλobjects, setup, teardown, test } from './__test__/test.js'
2
- import { removeAsync, removeMultipleAsync, removeRecursiveAsync } from '@vanillaes/esmtk'
3
- import { rmSync } from 'node:fs'
4
-
5
- import { createRequire } from 'module'
6
- const require = createRequire(import.meta.url)
7
- const files = require('./__test__/rm.json')
8
- const processExit = process.exit
9
-
10
- setup(async (t) => {
11
- process.exit = function () {
12
- throw new Error('process.exit(1)')
13
- }
14
- process.chdir(process.cwd())
15
- rmSync('test', { recursive: true, force: true })
16
-
17
- t.end()
18
- })
19
-
20
- test('removeAsync - remove a file', files.removeAsync, async (t) => {
21
- await removeAsync('test1.txt')
22
-
23
- const actual = filesλobjects()
24
- const expect = files.removeAsyncExpect
25
-
26
- t.deepEqual(actual, expect)
27
- t.end()
28
- })
29
-
30
- test('removeAsync - ERROR: no such file or directory', files.removeAsync, async (t) => {
31
- try {
32
- await removeAsync('test1.ts')
33
- t.fail('Expected error was not thrown')
34
- } catch (err) {
35
- t.ok(err, 'Error was thrown as expected')
36
- }
37
- t.end()
38
- })
39
-
40
- test('removeAsync - ERROR: file is a directory', files.removeAsync, async (t) => {
41
- try {
42
- await removeAsync('directory/')
43
- t.fail('Expected error was not thrown')
44
- } catch (err) {
45
- t.ok(err, 'Error was thrown as expected')
46
- }
47
- t.end()
48
- })
49
-
50
- test('removeMultipleAsync - remove multiple files', files.removeMultipleAsync, async (t) => {
51
- await removeMultipleAsync(['test1.txt', 'test1.js'])
52
-
53
- const actual = filesλobjects()
54
- const expect = files.removeMultipleAsyncExpect
55
-
56
- t.deepEqual(actual, expect)
57
- t.end()
58
- })
59
-
60
- test('removeRecursiveAsync - ', files.removeRecursiveAsync, async (t) => {
61
- await removeRecursiveAsync('directory1')
62
-
63
- const actual = filesλobjects()
64
- const expect = files.removeRecursiveAsyncExpect
65
-
66
- t.deepEqual(actual, expect)
67
- t.end()
68
- })
69
-
70
- teardown(async (t) => {
71
- process.exit = processExit
72
- process.chdir(process.cwd())
73
- rmSync('test', { recursive: true, force: true })
74
-
75
- t.end()
76
- })
package/src/util.spec.js DELETED
@@ -1,55 +0,0 @@
1
- import { setup, teardown, test } from './__test__/test.js'
2
- import { expand, fileExists, match } from '@vanillaes/esmtk'
3
- import { rmSync } from 'node:fs'
4
-
5
- import { createRequire } from 'module'
6
- const require = createRequire(import.meta.url)
7
- const files = require('./__test__/util.json')
8
-
9
- setup(async (t) => {
10
- process.chdir(process.cwd())
11
- rmSync('test', { recursive: true, force: true })
12
-
13
- t.end()
14
- })
15
-
16
- test('expand #1 - match glob', files.expand, async (t) => {
17
- const actual = await expand('*.txt')
18
- const expect = ['test1.txt', 'test2.txt']
19
-
20
- t.deepEqual(actual, expect)
21
- t.end()
22
- })
23
-
24
- test('fileExists #1 - test to see if a file exists', files.fileExists, async (t) => {
25
- const actual = await fileExists('test1.txt')
26
- const expect = true
27
-
28
- t.equal(actual, expect)
29
-
30
- t.end()
31
- })
32
-
33
- test('fileExists #2 - test to see if a file does not exist', files.fileExists, async (t) => {
34
- const actual = await fileExists('test1.ts')
35
- const expect = false
36
-
37
- t.equal(actual, expect)
38
-
39
- t.end()
40
- })
41
-
42
- test('match #1 - match a file', files.match, async (t) => {
43
- const expect = ['test1.txt', 'test2.txt']
44
- const actual = await match('*.txt')
45
-
46
- t.deepEqual(actual, expect)
47
- t.end()
48
- })
49
-
50
- teardown(async (t) => {
51
- process.chdir(process.cwd())
52
- rmSync('test', { recursive: true, force: true })
53
-
54
- t.end()
55
- })