@vanillaes/esmtk 0.6.4 → 0.6.5
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 +13 -1
- package/bin/commands/cp.js +1 -87
- package/bin/commands/lint.js +15 -3
- package/package.json +5 -1
- package/src/cp.js +97 -0
- package/src/index.js +1 -0
package/.vscode/launch.json
CHANGED
|
@@ -36,6 +36,18 @@
|
|
|
36
36
|
"cwd": "${workspaceFolder}",
|
|
37
37
|
"args": ["cp", "-r", "./test/cp/", "./test/cp2"],
|
|
38
38
|
"console": "integratedTerminal",
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "Lint",
|
|
42
|
+
"type": "node",
|
|
43
|
+
"request": "launch",
|
|
44
|
+
"skipFiles": [
|
|
45
|
+
"<node_internals>/**"
|
|
46
|
+
],
|
|
47
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
48
|
+
"cwd": "${workspaceFolder}",
|
|
49
|
+
"args": ["lint"],
|
|
50
|
+
"console": "integratedTerminal",
|
|
51
|
+
},
|
|
40
52
|
]
|
|
41
53
|
}
|
package/bin/commands/cp.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { access, constants, cp as nodeCp, stat } from 'node:fs/promises'
|
|
1
|
+
import { copyAsync, copyRecursiveAsync } from '../../src/cp.js'
|
|
3
2
|
|
|
4
3
|
export async function cp (source, target, options) {
|
|
5
4
|
if (!options.recursive) {
|
|
@@ -10,88 +9,3 @@ export async function cp (source, target, options) {
|
|
|
10
9
|
await copyRecursiveAsync(source, target, options.force)
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
// copy a single file
|
|
15
|
-
async function copyAsync (source, target, force = false) {
|
|
16
|
-
const sExists = await fileExists(source)
|
|
17
|
-
if (!sExists) {
|
|
18
|
-
console.error(`cp: source ${source} does not exist`)
|
|
19
|
-
process.exit(1)
|
|
20
|
-
}
|
|
21
|
-
const sStats = await stat(source)
|
|
22
|
-
if (sStats.isSymbolicLink()) {
|
|
23
|
-
console.error(`cp: source ${source} is a sybolic link`)
|
|
24
|
-
process.exit(1)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const tDir = dirname(target)
|
|
28
|
-
const tDirExists = await fileExists(tDir)
|
|
29
|
-
if (!tDirExists) {
|
|
30
|
-
console.error(`cp: target directory ${tDir} does not exist`)
|
|
31
|
-
process.exit(1)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const tExists = await fileExists(target)
|
|
35
|
-
if (tExists) {
|
|
36
|
-
const tStats = await stat(target)
|
|
37
|
-
if (tStats.isSymbolicLink()) {
|
|
38
|
-
console.error(`cp: target ${target} is a sybolic link`)
|
|
39
|
-
process.exit(1)
|
|
40
|
-
}
|
|
41
|
-
if (tStats.isDirectory()) {
|
|
42
|
-
const sourceFile = basename(source)
|
|
43
|
-
target = target.endsWith('/') ? target.slice(0, -1) : target
|
|
44
|
-
target = `${target}/${sourceFile}`
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
await nodeCp(source, target, { force })
|
|
50
|
-
} catch (err) {
|
|
51
|
-
console.error(`cp: error ${err.message}`)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// copy a directory recursively
|
|
56
|
-
async function copyRecursiveAsync (source, target, force = false) {
|
|
57
|
-
const sExists = await fileExists(source)
|
|
58
|
-
if (!sExists) {
|
|
59
|
-
console.error(`cp: source ${source} does not exist`)
|
|
60
|
-
process.exit(1)
|
|
61
|
-
}
|
|
62
|
-
const sStats = await stat(source)
|
|
63
|
-
if (sStats.isSymbolicLink()) {
|
|
64
|
-
console.error(`cp: source ${source} is a sybolic link`)
|
|
65
|
-
process.exit(1)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const tExists = await fileExists(target)
|
|
69
|
-
if (!tExists) {
|
|
70
|
-
console.error(`cp: target directory ${target} does not exist`)
|
|
71
|
-
process.exit(1)
|
|
72
|
-
}
|
|
73
|
-
const tStats = await stat(target)
|
|
74
|
-
if (tStats.isSymbolicLink()) {
|
|
75
|
-
console.error(`cp: target ${target} is a sybolic link`)
|
|
76
|
-
process.exit(1)
|
|
77
|
-
}
|
|
78
|
-
if (!tStats.isDirectory()) {
|
|
79
|
-
console.error(`cp: target ${target} is not a directory`)
|
|
80
|
-
process.exit(1)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
await nodeCp(source, target, { force, recursive: true })
|
|
85
|
-
} catch (err) {
|
|
86
|
-
console.error(`cp": error ${err.message}`)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function fileExists (file) {
|
|
91
|
-
try {
|
|
92
|
-
await access(file, constants.F_OK)
|
|
93
|
-
return true
|
|
94
|
-
} catch (error) {
|
|
95
|
-
return false
|
|
96
|
-
}
|
|
97
|
-
}
|
package/bin/commands/lint.js
CHANGED
|
@@ -4,10 +4,22 @@ import { join } from 'path'
|
|
|
4
4
|
const BIN_PATH = join(process.cwd(), 'node_modules', '.bin', 'standard')
|
|
5
5
|
|
|
6
6
|
export async function lint (flags) {
|
|
7
|
-
spawn(BIN_PATH, flags, {
|
|
7
|
+
const child = spawn(BIN_PATH, flags, {
|
|
8
8
|
cwd: process.cwd(),
|
|
9
|
-
stdio: ['pipe',
|
|
9
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
10
10
|
}).on('error', err => {
|
|
11
|
-
console.error(err)
|
|
11
|
+
console.error(`test${err}`)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
child.stdout.on('data', (data) => {
|
|
15
|
+
process.stdout.write(`${data}`)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
child.stderr.on('data', (data) => {
|
|
19
|
+
if (data.toString() === 'standard: Run `standard --fix` to automatically fix some problems.\n') {
|
|
20
|
+
process.stderr.write('standard: Run `esmtk lint --fix` to automatically fix some problems.\n')
|
|
21
|
+
} else {
|
|
22
|
+
process.stderr.write(`${data}`)
|
|
23
|
+
}
|
|
12
24
|
})
|
|
13
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanillaes/esmtk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "ES Module Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esm",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"author": "Evan Plaice <evanplaice@gmail.com> (https://evanplaice.com/)",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./src/index.js",
|
|
18
|
+
"./cp": "./src/cp.js"
|
|
19
|
+
},
|
|
16
20
|
"bin": {
|
|
17
21
|
"esmtk": "bin/esmtk.js"
|
|
18
22
|
},
|
package/src/cp.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { basename, dirname } from 'node:path'
|
|
2
|
+
import { access, constants, cp, stat } from 'node:fs/promises'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copy a single file asynchronously
|
|
6
|
+
* @param {string} source The source file
|
|
7
|
+
* @param {string} target The target file
|
|
8
|
+
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
9
|
+
*/
|
|
10
|
+
export async function copyAsync (source, target, force = false) {
|
|
11
|
+
const sExists = await fileExists(source)
|
|
12
|
+
if (!sExists) {
|
|
13
|
+
console.error(`cp: source ${source} does not exist`)
|
|
14
|
+
process.exit(1)
|
|
15
|
+
}
|
|
16
|
+
const sStats = await stat(source)
|
|
17
|
+
if (sStats.isSymbolicLink()) {
|
|
18
|
+
console.error(`cp: source ${source} is a sybolic link`)
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const tDir = dirname(target)
|
|
23
|
+
const tDirExists = await fileExists(tDir)
|
|
24
|
+
if (!tDirExists) {
|
|
25
|
+
console.error(`cp: target directory ${tDir} does not exist`)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const tExists = await fileExists(target)
|
|
30
|
+
if (tExists) {
|
|
31
|
+
const tStats = await stat(target)
|
|
32
|
+
if (tStats.isSymbolicLink()) {
|
|
33
|
+
console.error(`cp: target ${target} is a sybolic link`)
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
if (tStats.isDirectory()) {
|
|
37
|
+
const sourceFile = basename(source)
|
|
38
|
+
target = target.endsWith('/') ? target.slice(0, -1) : target
|
|
39
|
+
target = `${target}/${sourceFile}`
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await cp(source, target, { force })
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.error(`cp: error ${err.message}`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Recursively copy a directory asynchronously
|
|
52
|
+
* @param {string} source The source directory
|
|
53
|
+
* @param {string} target The target directory
|
|
54
|
+
* @param {bool} force If the file already exists, overwrite it (default false)
|
|
55
|
+
*/
|
|
56
|
+
export async function copyRecursiveAsync (source, target, force = false) {
|
|
57
|
+
const sExists = await fileExists(source)
|
|
58
|
+
if (!sExists) {
|
|
59
|
+
console.error(`cp: source ${source} does not exist`)
|
|
60
|
+
process.exit(1)
|
|
61
|
+
}
|
|
62
|
+
const sStats = await stat(source)
|
|
63
|
+
if (sStats.isSymbolicLink()) {
|
|
64
|
+
console.error(`cp: source ${source} is a sybolic link`)
|
|
65
|
+
process.exit(1)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const tExists = await fileExists(target)
|
|
69
|
+
if (!tExists) {
|
|
70
|
+
console.error(`cp: target directory ${target} does not exist`)
|
|
71
|
+
process.exit(1)
|
|
72
|
+
}
|
|
73
|
+
const tStats = await stat(target)
|
|
74
|
+
if (tStats.isSymbolicLink()) {
|
|
75
|
+
console.error(`cp: target ${target} is a sybolic link`)
|
|
76
|
+
process.exit(1)
|
|
77
|
+
}
|
|
78
|
+
if (!tStats.isDirectory()) {
|
|
79
|
+
console.error(`cp: target ${target} is not a directory`)
|
|
80
|
+
process.exit(1)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
await cp(source, target, { force, recursive: true })
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error(`cp": error ${err.message}`)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function fileExists (file) {
|
|
91
|
+
try {
|
|
92
|
+
await access(file, constants.F_OK)
|
|
93
|
+
return true
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { copyAsync, copyRecursiveAsync } from './cp.js'
|