@vanillaes/esmtk 0.22.0 → 0.23.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/.vscode/launch.json +69 -57
- package/bin/commands/index.js +1 -0
- package/bin/commands/preview.js +86 -0
- package/bin/esmtk.js +8 -1
- package/package.json +1 -1
- package/src/__test__/cp.json +68 -0
- package/src/cp.spec.js +106 -0
- package/src/index.js +1 -1
- package/src/rm.spec.js +1 -0
package/.vscode/launch.json
CHANGED
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"console": "integratedTerminal",
|
|
135
135
|
},
|
|
136
136
|
{
|
|
137
|
-
"name": "
|
|
137
|
+
"name": "Clean --bundle",
|
|
138
138
|
"type": "node",
|
|
139
139
|
"request": "launch",
|
|
140
140
|
"skipFiles": [
|
|
@@ -142,11 +142,11 @@
|
|
|
142
142
|
],
|
|
143
143
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
144
144
|
"cwd": "${workspaceFolder}",
|
|
145
|
-
"args": ["
|
|
145
|
+
"args": ["clean", "--bundle"],
|
|
146
146
|
"console": "integratedTerminal",
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
|
-
"name": "
|
|
149
|
+
"name": "Clean --bundle w/ override",
|
|
150
150
|
"type": "node",
|
|
151
151
|
"request": "launch",
|
|
152
152
|
"skipFiles": [
|
|
@@ -154,11 +154,11 @@
|
|
|
154
154
|
],
|
|
155
155
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
156
156
|
"cwd": "${workspaceFolder}",
|
|
157
|
-
"args": ["
|
|
157
|
+
"args": ["clean", "--bundle", "**/*.js"],
|
|
158
158
|
"console": "integratedTerminal",
|
|
159
159
|
},
|
|
160
|
-
|
|
161
|
-
"name": "
|
|
160
|
+
{
|
|
161
|
+
"name": "Clean --bundle w/ Error",
|
|
162
162
|
"type": "node",
|
|
163
163
|
"request": "launch",
|
|
164
164
|
"skipFiles": [
|
|
@@ -166,11 +166,11 @@
|
|
|
166
166
|
],
|
|
167
167
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
168
168
|
"cwd": "${workspaceFolder}",
|
|
169
|
-
"args": ["
|
|
169
|
+
"args": ["clean", "--bundle", "**/*.mjs"],
|
|
170
170
|
"console": "integratedTerminal",
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
|
-
"name": "
|
|
173
|
+
"name": "Clean --minify",
|
|
174
174
|
"type": "node",
|
|
175
175
|
"request": "launch",
|
|
176
176
|
"skipFiles": [
|
|
@@ -178,11 +178,11 @@
|
|
|
178
178
|
],
|
|
179
179
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
180
180
|
"cwd": "${workspaceFolder}",
|
|
181
|
-
"args": ["
|
|
181
|
+
"args": ["clean", "--minify"],
|
|
182
182
|
"console": "integratedTerminal",
|
|
183
183
|
},
|
|
184
184
|
{
|
|
185
|
-
"name": "
|
|
185
|
+
"name": "Clean --typings",
|
|
186
186
|
"type": "node",
|
|
187
187
|
"request": "launch",
|
|
188
188
|
"skipFiles": [
|
|
@@ -190,11 +190,11 @@
|
|
|
190
190
|
],
|
|
191
191
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
192
192
|
"cwd": "${workspaceFolder}",
|
|
193
|
-
"args": ["
|
|
193
|
+
"args": ["clean", "--typings"],
|
|
194
194
|
"console": "integratedTerminal",
|
|
195
195
|
},
|
|
196
196
|
{
|
|
197
|
-
"name": "
|
|
197
|
+
"name": "Clean All",
|
|
198
198
|
"type": "node",
|
|
199
199
|
"request": "launch",
|
|
200
200
|
"skipFiles": [
|
|
@@ -202,11 +202,11 @@
|
|
|
202
202
|
],
|
|
203
203
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
204
204
|
"cwd": "${workspaceFolder}",
|
|
205
|
-
"args": ["
|
|
205
|
+
"args": ["clean", "--bundle", "--minify", "--typings"],
|
|
206
206
|
"console": "integratedTerminal",
|
|
207
207
|
},
|
|
208
208
|
{
|
|
209
|
-
"name": "
|
|
209
|
+
"name": "Clean --custom",
|
|
210
210
|
"type": "node",
|
|
211
211
|
"request": "launch",
|
|
212
212
|
"skipFiles": [
|
|
@@ -214,11 +214,11 @@
|
|
|
214
214
|
],
|
|
215
215
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
216
216
|
"cwd": "${workspaceFolder}",
|
|
217
|
-
"args": ["
|
|
217
|
+
"args": ["clean", "--custom", "**/*.min.js"],
|
|
218
218
|
"console": "integratedTerminal",
|
|
219
219
|
},
|
|
220
220
|
{
|
|
221
|
-
"name": "
|
|
221
|
+
"name": "Preview",
|
|
222
222
|
"type": "node",
|
|
223
223
|
"request": "launch",
|
|
224
224
|
"skipFiles": [
|
|
@@ -226,11 +226,11 @@
|
|
|
226
226
|
],
|
|
227
227
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
228
228
|
"cwd": "${workspaceFolder}",
|
|
229
|
-
"args": ["
|
|
229
|
+
"args": ["preview"],
|
|
230
230
|
"console": "integratedTerminal",
|
|
231
231
|
},
|
|
232
232
|
{
|
|
233
|
-
"name": "
|
|
233
|
+
"name": "CopyFileToFile",
|
|
234
234
|
"type": "node",
|
|
235
235
|
"request": "launch",
|
|
236
236
|
"skipFiles": [
|
|
@@ -238,11 +238,11 @@
|
|
|
238
238
|
],
|
|
239
239
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
240
240
|
"cwd": "${workspaceFolder}",
|
|
241
|
-
"args": ["cp", "./test/cp/test1.
|
|
241
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
|
|
242
242
|
"console": "integratedTerminal",
|
|
243
243
|
},
|
|
244
244
|
{
|
|
245
|
-
"name": "
|
|
245
|
+
"name": "CopyFileToFile - Error source doesn't exist",
|
|
246
246
|
"type": "node",
|
|
247
247
|
"request": "launch",
|
|
248
248
|
"skipFiles": [
|
|
@@ -250,11 +250,11 @@
|
|
|
250
250
|
],
|
|
251
251
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
252
252
|
"cwd": "${workspaceFolder}",
|
|
253
|
-
"args": ["cp", "./test/cp
|
|
253
|
+
"args": ["cp", "./test/cp/testx.txt", "./test/cp2/"],
|
|
254
254
|
"console": "integratedTerminal",
|
|
255
255
|
},
|
|
256
256
|
{
|
|
257
|
-
"name": "
|
|
257
|
+
"name": "CopyFileToFile - Error source is a directory",
|
|
258
258
|
"type": "node",
|
|
259
259
|
"request": "launch",
|
|
260
260
|
"skipFiles": [
|
|
@@ -262,11 +262,11 @@
|
|
|
262
262
|
],
|
|
263
263
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
264
264
|
"cwd": "${workspaceFolder}",
|
|
265
|
-
"args": ["cp", "./test/cp
|
|
265
|
+
"args": ["cp", "./test/cp/", "./test/cp2/test1.txt"],
|
|
266
266
|
"console": "integratedTerminal",
|
|
267
267
|
},
|
|
268
268
|
{
|
|
269
|
-
"name": "
|
|
269
|
+
"name": "CopyFileToFile - Error target directory doesn't exist",
|
|
270
270
|
"type": "node",
|
|
271
271
|
"request": "launch",
|
|
272
272
|
"skipFiles": [
|
|
@@ -274,11 +274,11 @@
|
|
|
274
274
|
],
|
|
275
275
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
276
276
|
"cwd": "${workspaceFolder}",
|
|
277
|
-
"args": ["cp", "./test/cp/test1.txt", "./test/
|
|
277
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cpx/"],
|
|
278
278
|
"console": "integratedTerminal",
|
|
279
279
|
},
|
|
280
280
|
{
|
|
281
|
-
"name": "
|
|
281
|
+
"name": "CopyFileToDirectory",
|
|
282
282
|
"type": "node",
|
|
283
283
|
"request": "launch",
|
|
284
284
|
"skipFiles": [
|
|
@@ -286,11 +286,11 @@
|
|
|
286
286
|
],
|
|
287
287
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
288
288
|
"cwd": "${workspaceFolder}",
|
|
289
|
-
"args": ["
|
|
289
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
|
|
290
290
|
"console": "integratedTerminal",
|
|
291
291
|
},
|
|
292
292
|
{
|
|
293
|
-
"name": "
|
|
293
|
+
"name": "CopyGlobToDirectory",
|
|
294
294
|
"type": "node",
|
|
295
295
|
"request": "launch",
|
|
296
296
|
"skipFiles": [
|
|
@@ -298,11 +298,11 @@
|
|
|
298
298
|
],
|
|
299
299
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
300
300
|
"cwd": "${workspaceFolder}",
|
|
301
|
-
"args": ["
|
|
301
|
+
"args": ["cp", "./test/cp/*.js", "./test/cp2/"],
|
|
302
302
|
"console": "integratedTerminal",
|
|
303
303
|
},
|
|
304
304
|
{
|
|
305
|
-
"name": "
|
|
305
|
+
"name": "CopyMultipleFiles",
|
|
306
306
|
"type": "node",
|
|
307
307
|
"request": "launch",
|
|
308
308
|
"skipFiles": [
|
|
@@ -310,11 +310,11 @@
|
|
|
310
310
|
],
|
|
311
311
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
312
312
|
"cwd": "${workspaceFolder}",
|
|
313
|
-
"args": ["
|
|
313
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cp/test1.js", "./test/cp/test2.txt", "./test/cp/test2.js", "./test/cp2/"],
|
|
314
314
|
"console": "integratedTerminal",
|
|
315
315
|
},
|
|
316
316
|
{
|
|
317
|
-
"name": "
|
|
317
|
+
"name": "CopyMultipleFiles - Error file doesn't exist",
|
|
318
318
|
"type": "node",
|
|
319
319
|
"request": "launch",
|
|
320
320
|
"skipFiles": [
|
|
@@ -322,11 +322,11 @@
|
|
|
322
322
|
],
|
|
323
323
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
324
324
|
"cwd": "${workspaceFolder}",
|
|
325
|
-
"args": ["
|
|
325
|
+
"args": ["cp", "./test/cp/test1.ts", "./test/cp/test1.js", "./test/cp/test2.txt", "./test/cp/test2.js", "./test/cp2/"],
|
|
326
326
|
"console": "integratedTerminal",
|
|
327
327
|
},
|
|
328
328
|
{
|
|
329
|
-
"name": "
|
|
329
|
+
"name": "CopyMultipleGlobs",
|
|
330
330
|
"type": "node",
|
|
331
331
|
"request": "launch",
|
|
332
332
|
"skipFiles": [
|
|
@@ -334,11 +334,11 @@
|
|
|
334
334
|
],
|
|
335
335
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
336
336
|
"cwd": "${workspaceFolder}",
|
|
337
|
-
"args": ["
|
|
337
|
+
"args": ["cp", "./test/cp/*.txt", "./test/cp/*.js", "./test/cp2/"],
|
|
338
338
|
"console": "integratedTerminal",
|
|
339
339
|
},
|
|
340
340
|
{
|
|
341
|
-
"name": "
|
|
341
|
+
"name": "CopyMultipleGlobs - Error glob not found",
|
|
342
342
|
"type": "node",
|
|
343
343
|
"request": "launch",
|
|
344
344
|
"skipFiles": [
|
|
@@ -346,11 +346,11 @@
|
|
|
346
346
|
],
|
|
347
347
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
348
348
|
"cwd": "${workspaceFolder}",
|
|
349
|
-
"args": ["
|
|
349
|
+
"args": ["cp", "./test/cp/*.ts", "./test/cp/*.js", "./test/cp2/"],
|
|
350
350
|
"console": "integratedTerminal",
|
|
351
351
|
},
|
|
352
352
|
{
|
|
353
|
-
"name": "
|
|
353
|
+
"name": "CopyMultipleMixed",
|
|
354
354
|
"type": "node",
|
|
355
355
|
"request": "launch",
|
|
356
356
|
"skipFiles": [
|
|
@@ -358,11 +358,11 @@
|
|
|
358
358
|
],
|
|
359
359
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
360
360
|
"cwd": "${workspaceFolder}",
|
|
361
|
-
"args": ["
|
|
361
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cp/test2.txt", "./test/cp/*.js", "./test/cp2/"],
|
|
362
362
|
"console": "integratedTerminal",
|
|
363
363
|
},
|
|
364
364
|
{
|
|
365
|
-
"name": "
|
|
365
|
+
"name": "CopyDirectoryRecursively",
|
|
366
366
|
"type": "node",
|
|
367
367
|
"request": "launch",
|
|
368
368
|
"skipFiles": [
|
|
@@ -370,11 +370,11 @@
|
|
|
370
370
|
],
|
|
371
371
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
372
372
|
"cwd": "${workspaceFolder}",
|
|
373
|
-
"args": ["
|
|
373
|
+
"args": ["cp", "-r", "./test/cp/", "./test/cp2"],
|
|
374
374
|
"console": "integratedTerminal",
|
|
375
375
|
},
|
|
376
376
|
{
|
|
377
|
-
"name": "
|
|
377
|
+
"name": "RemoveFile",
|
|
378
378
|
"type": "node",
|
|
379
379
|
"request": "launch",
|
|
380
380
|
"skipFiles": [
|
|
@@ -382,11 +382,11 @@
|
|
|
382
382
|
],
|
|
383
383
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
384
384
|
"cwd": "${workspaceFolder}",
|
|
385
|
-
"args": ["rm", "./test/cp2/test1.txt"
|
|
385
|
+
"args": ["rm", "./test/cp2/test1.txt"],
|
|
386
386
|
"console": "integratedTerminal",
|
|
387
387
|
},
|
|
388
388
|
{
|
|
389
|
-
"name": "
|
|
389
|
+
"name": "RemoveFile - Error file is a directory",
|
|
390
390
|
"type": "node",
|
|
391
391
|
"request": "launch",
|
|
392
392
|
"skipFiles": [
|
|
@@ -394,11 +394,11 @@
|
|
|
394
394
|
],
|
|
395
395
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
396
396
|
"cwd": "${workspaceFolder}",
|
|
397
|
-
"args": ["
|
|
397
|
+
"args": ["rm", "./test/cp2/"],
|
|
398
398
|
"console": "integratedTerminal",
|
|
399
399
|
},
|
|
400
400
|
{
|
|
401
|
-
"name": "
|
|
401
|
+
"name": "RemoveGlob",
|
|
402
402
|
"type": "node",
|
|
403
403
|
"request": "launch",
|
|
404
404
|
"skipFiles": [
|
|
@@ -406,11 +406,11 @@
|
|
|
406
406
|
],
|
|
407
407
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
408
408
|
"cwd": "${workspaceFolder}",
|
|
409
|
-
"args": ["
|
|
409
|
+
"args": ["rm", "./test/cp2/*.js"],
|
|
410
410
|
"console": "integratedTerminal",
|
|
411
411
|
},
|
|
412
412
|
{
|
|
413
|
-
"name": "
|
|
413
|
+
"name": "RemoveGlob - Error glob not found",
|
|
414
414
|
"type": "node",
|
|
415
415
|
"request": "launch",
|
|
416
416
|
"skipFiles": [
|
|
@@ -418,11 +418,11 @@
|
|
|
418
418
|
],
|
|
419
419
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
420
420
|
"cwd": "${workspaceFolder}",
|
|
421
|
-
"args": ["
|
|
421
|
+
"args": ["rm", "./test/cp2/*.ts"],
|
|
422
422
|
"console": "integratedTerminal",
|
|
423
423
|
},
|
|
424
424
|
{
|
|
425
|
-
"name": "
|
|
425
|
+
"name": "RemoveDirectory",
|
|
426
426
|
"type": "node",
|
|
427
427
|
"request": "launch",
|
|
428
428
|
"skipFiles": [
|
|
@@ -430,11 +430,11 @@
|
|
|
430
430
|
],
|
|
431
431
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
432
432
|
"cwd": "${workspaceFolder}",
|
|
433
|
-
"args": ["
|
|
433
|
+
"args": ["rm", "-r", "./test/cp2/"],
|
|
434
434
|
"console": "integratedTerminal",
|
|
435
435
|
},
|
|
436
436
|
{
|
|
437
|
-
"name": "
|
|
437
|
+
"name": "RemoveMultipleFiles",
|
|
438
438
|
"type": "node",
|
|
439
439
|
"request": "launch",
|
|
440
440
|
"skipFiles": [
|
|
@@ -442,11 +442,11 @@
|
|
|
442
442
|
],
|
|
443
443
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
444
444
|
"cwd": "${workspaceFolder}",
|
|
445
|
-
"args": ["
|
|
445
|
+
"args": ["rm", "./test/cp2/test1.txt", "./test/cp2/test2.txt"],
|
|
446
446
|
"console": "integratedTerminal",
|
|
447
447
|
},
|
|
448
448
|
{
|
|
449
|
-
"name": "
|
|
449
|
+
"name": "RemoveMultipleGlobs",
|
|
450
450
|
"type": "node",
|
|
451
451
|
"request": "launch",
|
|
452
452
|
"skipFiles": [
|
|
@@ -454,11 +454,11 @@
|
|
|
454
454
|
],
|
|
455
455
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
456
456
|
"cwd": "${workspaceFolder}",
|
|
457
|
-
"args": ["
|
|
457
|
+
"args": ["rm", "./test/cp2/*.txt", "./test/cp2/*.js"],
|
|
458
458
|
"console": "integratedTerminal",
|
|
459
459
|
},
|
|
460
460
|
{
|
|
461
|
-
"name": "
|
|
461
|
+
"name": "RemoveMultipleGlobs - Error glob not found",
|
|
462
462
|
"type": "node",
|
|
463
463
|
"request": "launch",
|
|
464
464
|
"skipFiles": [
|
|
@@ -466,7 +466,19 @@
|
|
|
466
466
|
],
|
|
467
467
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
468
468
|
"cwd": "${workspaceFolder}",
|
|
469
|
-
"args": ["
|
|
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"],
|
|
470
482
|
"console": "integratedTerminal",
|
|
471
483
|
},
|
|
472
484
|
{
|
package/bin/commands/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { cp } from './cp.js'
|
|
|
5
5
|
export { init } from './init.js'
|
|
6
6
|
export { lint } from './lint.js'
|
|
7
7
|
export { minify } from './minify.js'
|
|
8
|
+
export { preview } from './preview.js'
|
|
8
9
|
export { rm } from './rm.js'
|
|
9
10
|
export { test } from './test.js'
|
|
10
11
|
export { types } from './types.js'
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { match } from '../../src/util.js'
|
|
2
|
+
import { statSync } from 'node:fs'
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
|
|
6
|
+
import { createRequire } from 'module'
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Preview the package contents on publish
|
|
11
|
+
* @param {any} options preview options
|
|
12
|
+
*/
|
|
13
|
+
export async function preview (options) {
|
|
14
|
+
let ignore = await readNPMIgnore(options.root)
|
|
15
|
+
ignore = `${ignore},node_modules/,package-lock.json`
|
|
16
|
+
|
|
17
|
+
let files = await match('**/*', options.root, ignore)
|
|
18
|
+
if (files.length === 0) {
|
|
19
|
+
console.log('preview: no files found')
|
|
20
|
+
process.exit(0)
|
|
21
|
+
}
|
|
22
|
+
files = files
|
|
23
|
+
.filter(path => statSync(path).isFile())
|
|
24
|
+
.sort((a, b) => fileCompare(a, b))
|
|
25
|
+
|
|
26
|
+
const pkg = require(join(options.root, 'package.json'))
|
|
27
|
+
|
|
28
|
+
console.log()
|
|
29
|
+
console.log(`📦 ${pkg.name}@${pkg.version}`)
|
|
30
|
+
for (const file of files) {
|
|
31
|
+
console.log(formatFile(file))
|
|
32
|
+
}
|
|
33
|
+
console.log()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Read .npmignore
|
|
38
|
+
* @param {*} root the root path
|
|
39
|
+
* @returns a comma-deliminated list of ignore globs
|
|
40
|
+
*/
|
|
41
|
+
async function readNPMIgnore (root) {
|
|
42
|
+
const path = join(root, '.npmignore')
|
|
43
|
+
const contents = await readFile(path, 'utf8')
|
|
44
|
+
return contents
|
|
45
|
+
.split('\n')
|
|
46
|
+
.map(line => line.trim())
|
|
47
|
+
.filter(line => line && !line.startsWith('#'))
|
|
48
|
+
.join(',')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* File list comparator
|
|
53
|
+
* @param {*} a file path a
|
|
54
|
+
* @param {*} b file path b
|
|
55
|
+
* @returns {number} 1 | -1
|
|
56
|
+
*/
|
|
57
|
+
function fileCompare (a, b) {
|
|
58
|
+
const dirA = dirname(a)
|
|
59
|
+
const dirB = dirname(b)
|
|
60
|
+
if (dirA !== '.' && dirB === '.') {
|
|
61
|
+
return -1
|
|
62
|
+
}
|
|
63
|
+
if (dirA === '.' && dirB !== '.') {
|
|
64
|
+
return 1
|
|
65
|
+
}
|
|
66
|
+
return a.localeCompare(b)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Format a file path to include file size
|
|
71
|
+
* @param {*} path the file path
|
|
72
|
+
* @returns file size followed by file path
|
|
73
|
+
*/
|
|
74
|
+
function formatFile (path) {
|
|
75
|
+
const size = statSync(path).size
|
|
76
|
+
if (size > 1024) {
|
|
77
|
+
const kilobytes = (size / 1024).toLocaleString('en-US', {
|
|
78
|
+
minimumFractionDigits: 1,
|
|
79
|
+
maximumFractionDigits: 1,
|
|
80
|
+
roundingMode: 'trunc'
|
|
81
|
+
})
|
|
82
|
+
return `${kilobytes} KB`.padEnd(10) + `${path}`
|
|
83
|
+
} else {
|
|
84
|
+
return `${size} B`.padEnd(10) + `${path}`
|
|
85
|
+
}
|
|
86
|
+
}
|
package/bin/esmtk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { bundle, clean, cp, commonjs, init, lint, minify, rm, test, types, typings } from './commands/index.js'
|
|
2
|
+
import { bundle, clean, cp, commonjs, init, lint, minify, preview, rm, test, types, typings } from './commands/index.js'
|
|
3
3
|
import { Command } from 'commander'
|
|
4
4
|
import { createRequire } from 'module'
|
|
5
5
|
const program = new Command()
|
|
@@ -91,6 +91,13 @@ program.command('clean')
|
|
|
91
91
|
clean(root, options)
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
+
program.command('preview')
|
|
95
|
+
.description('Preview the package contents on publish')
|
|
96
|
+
.option('-r, --root <root>', 'the root path to run the tests from (default `process.cwd()`)', process.cwd())
|
|
97
|
+
.action((options) => {
|
|
98
|
+
preview(options)
|
|
99
|
+
})
|
|
100
|
+
|
|
94
101
|
program.command('cp')
|
|
95
102
|
.usage(`[-r] source target
|
|
96
103
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
}
|
package/src/cp.spec.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
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/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { copyAsync, copyRecursiveAsync } from './cp.js'
|
|
1
|
+
export { copyAsync, copyMultipleAsync, copyRecursiveAsync } from './cp.js'
|
|
2
2
|
export { removeAsync, removeMultipleAsync, removeRecursiveAsync } from './rm.js'
|
|
3
3
|
export { expand, fileExists, installed, match, which } from './util.js'
|
package/src/rm.spec.js
CHANGED
|
@@ -30,6 +30,7 @@ test('removeAsync - remove a file', files.removeAsync, async (t) => {
|
|
|
30
30
|
test('removeAsync - ERROR: no such file or directory', files.removeAsync, async (t) => {
|
|
31
31
|
try {
|
|
32
32
|
await removeAsync('test1.ts')
|
|
33
|
+
t.fail('Expected error was not thrown')
|
|
33
34
|
} catch (err) {
|
|
34
35
|
t.ok(err, 'Error was thrown as expected')
|
|
35
36
|
}
|