@vanillaes/esmtk 0.6.5 → 0.6.6
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 +24 -0
- package/README.md +20 -2
- package/bin/commands/cp.js +4 -4
- package/bin/commands/index.js +1 -0
- package/bin/commands/rm.js +11 -0
- package/bin/esmtk.js +12 -3
- package/package.json +3 -2
- package/src/index.js +1 -0
- package/src/rm.js +58 -0
package/.vscode/launch.json
CHANGED
|
@@ -49,5 +49,29 @@
|
|
|
49
49
|
"args": ["lint"],
|
|
50
50
|
"console": "integratedTerminal",
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
"name": "RemoveFile",
|
|
54
|
+
"type": "node",
|
|
55
|
+
"request": "launch",
|
|
56
|
+
"skipFiles": [
|
|
57
|
+
"<node_internals>/**"
|
|
58
|
+
],
|
|
59
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
60
|
+
"cwd": "${workspaceFolder}",
|
|
61
|
+
"args": ["rm", "./test/cp2/test1.txt"],
|
|
62
|
+
"console": "integratedTerminal",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "RemoveDirectory",
|
|
66
|
+
"type": "node",
|
|
67
|
+
"request": "launch",
|
|
68
|
+
"skipFiles": [
|
|
69
|
+
"<node_internals>/**"
|
|
70
|
+
],
|
|
71
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
72
|
+
"cwd": "${workspaceFolder}",
|
|
73
|
+
"args": ["rm", "-r", "./test/cp2/"],
|
|
74
|
+
"console": "integratedTerminal",
|
|
75
|
+
}
|
|
52
76
|
]
|
|
53
77
|
}
|
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ esmtk commonjs src/sample.js bundle.cjs
|
|
|
78
78
|
|
|
79
79
|
## Copy
|
|
80
80
|
|
|
81
|
-
Copy
|
|
81
|
+
Copy is a cross-platform clone of the `cp` command in Linux
|
|
82
82
|
|
|
83
83
|
### Arguments
|
|
84
84
|
|
|
@@ -86,11 +86,29 @@ Copy us a cross-platform clone of the `cp` command in Linux
|
|
|
86
86
|
|
|
87
87
|
- `[source]` - the source file/glob
|
|
88
88
|
- `[destination]` - the destination file/directory
|
|
89
|
+
- `-f --force` - ignore exceptions if the file doesn't exist
|
|
89
90
|
- `-r, --recursive` - copy files/directories recursively
|
|
90
|
-
- `-f --force` - force overwrite existing files
|
|
91
91
|
|
|
92
92
|
### Usage
|
|
93
93
|
|
|
94
94
|
```sh
|
|
95
95
|
esmtk cp -r src/ dest/
|
|
96
96
|
```
|
|
97
|
+
|
|
98
|
+
## Remove
|
|
99
|
+
|
|
100
|
+
Remove is a cross-platform clone of the `rm` command in Linux
|
|
101
|
+
|
|
102
|
+
### Arguments
|
|
103
|
+
|
|
104
|
+
`esmtk rm [-rf] [file|directory]`
|
|
105
|
+
|
|
106
|
+
- `[file|directory]` - the source file/glob
|
|
107
|
+
- `-f --force` - force remove existing file(s)
|
|
108
|
+
- `-r, --recursive` - remove files/directories recursively
|
|
109
|
+
|
|
110
|
+
### Usage
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
esmtk rm -r src/
|
|
114
|
+
```
|
package/bin/commands/cp.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { copyAsync, copyRecursiveAsync } from '../../src/cp.js'
|
|
2
2
|
|
|
3
3
|
export async function cp (source, target, options) {
|
|
4
|
-
if (!options
|
|
5
|
-
await copyAsync(source, target, options
|
|
4
|
+
if (!options?.recursive) {
|
|
5
|
+
await copyAsync(source, target, options?.force)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
if (options
|
|
9
|
-
await copyRecursiveAsync(source, target, options
|
|
8
|
+
if (options?.recursive) {
|
|
9
|
+
await copyRecursiveAsync(source, target, options?.force)
|
|
10
10
|
}
|
|
11
11
|
}
|
package/bin/commands/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { removeAsync, removeRecursiveAsync } from '../../src/rm.js'
|
|
2
|
+
|
|
3
|
+
export async function rm (path, options) {
|
|
4
|
+
if (!options?.recursive) {
|
|
5
|
+
await removeAsync(path, options?.force)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (options?.recursive) {
|
|
9
|
+
await removeRecursiveAsync(path, options?.force)
|
|
10
|
+
}
|
|
11
|
+
}
|
package/bin/esmtk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { bundle, cp, commonjs, lint, minify } from './commands/index.js'
|
|
2
|
+
import { bundle, cp, commonjs, lint, minify, rm } from './commands/index.js'
|
|
3
3
|
import { Command } from 'commander'
|
|
4
4
|
import { createRequire } from 'module'
|
|
5
5
|
const program = new Command()
|
|
@@ -37,10 +37,19 @@ program.command('minify <input> <output>')
|
|
|
37
37
|
program.command('cp <source> <target>')
|
|
38
38
|
.usage('[-rf] source target')
|
|
39
39
|
.description('Copy files from the source to the target')
|
|
40
|
-
.option('-f, --force', 'do not prompt before overwriting')
|
|
41
|
-
.option('-r, --recursive', 'copy directories recursively')
|
|
40
|
+
.option('-f, --force', 'do not prompt before overwriting', false)
|
|
41
|
+
.option('-r, --recursive', 'copy directories recursively', false)
|
|
42
42
|
.action((source, target, options) => {
|
|
43
43
|
cp(source, target, options)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
+
program.command('rm <path>')
|
|
47
|
+
.usage('[-rf] file|directory')
|
|
48
|
+
.description('Remove a file|directory')
|
|
49
|
+
.option('-f, --force', 'do not prompt before overwriting', false)
|
|
50
|
+
.option('-r, --recursive', 'remove directories recursively', false)
|
|
51
|
+
.action((path, options) => {
|
|
52
|
+
rm(path, options)
|
|
53
|
+
})
|
|
54
|
+
|
|
46
55
|
program.parse(process.argv)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanillaes/esmtk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "ES Module Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esm",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": "./src/index.js",
|
|
18
|
-
"./cp": "./src/cp.js"
|
|
18
|
+
"./cp": "./src/cp.js",
|
|
19
|
+
"./rm": "./src/rm.js"
|
|
19
20
|
},
|
|
20
21
|
"bin": {
|
|
21
22
|
"esmtk": "bin/esmtk.js"
|
package/src/index.js
CHANGED
package/src/rm.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { access, constants, rm, stat } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Remove a file asynchronously
|
|
5
|
+
* @param {string} path The file to delete
|
|
6
|
+
* @param {boolean} force Ignore exceptions if the file doesn't exist (default false)
|
|
7
|
+
*/
|
|
8
|
+
export async function removeAsync (path, force = false) {
|
|
9
|
+
const exists = await fileExists(path)
|
|
10
|
+
if (!exists) {
|
|
11
|
+
console.error(`rm: path ${path} does not exist`)
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|
|
14
|
+
const stats = await stat(path)
|
|
15
|
+
if (stats.isSymbolicLink()) {
|
|
16
|
+
console.error(`rm: path ${path} is a sybolic link`)
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await rm(path, { force })
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error(`rm: error ${err.message}`)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Recursively remove a file|directory asynchronously
|
|
29
|
+
* @param {string} path The file|directory to remove
|
|
30
|
+
* @param {bool} force Ignore exceptions if the file|directory doesn't exist (default false)
|
|
31
|
+
*/
|
|
32
|
+
export async function removeRecursiveAsync (path, force = false) {
|
|
33
|
+
const exists = await fileExists(path)
|
|
34
|
+
if (!exists) {
|
|
35
|
+
console.error(`rm: path ${path} does not exist`)
|
|
36
|
+
process.exit(1)
|
|
37
|
+
}
|
|
38
|
+
const stats = await stat(path)
|
|
39
|
+
if (stats.isSymbolicLink()) {
|
|
40
|
+
console.error(`rm: path ${path} is a sybolic link`)
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
await rm(path, { force, recursive: true })
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error(`rm": error ${err.message}`)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function fileExists (file) {
|
|
52
|
+
try {
|
|
53
|
+
await access(file, constants.F_OK)
|
|
54
|
+
return true
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
}
|