copy-file-util 1.3.2 → 1.3.3
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 +13 -8
- package/bin/cli.js +0 -16
- package/dist/copy-file.d.ts +2 -2
- package/dist/copy-file.js +10 -12
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -20,13 +20,17 @@ $ npm install --save-dev copy-file-util
|
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## B) Usage
|
|
23
|
-
### 1.
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
### 1. Synopsis
|
|
24
|
+
```
|
|
25
|
+
copy-file [SOURCE] [TARGET]
|
|
26
|
+
```
|
|
26
27
|
Parameters:
|
|
27
28
|
* The **first** parameter is the *source* file.
|
|
28
29
|
* The **second** parameter is the *target* file or folder (use the `--folder` flag).
|
|
29
30
|
|
|
31
|
+
### 2. npm package.json scripts
|
|
32
|
+
Run `copy-file` from the `"scripts"` section of your **package.json** file.
|
|
33
|
+
|
|
30
34
|
Example **package.json** scripts:
|
|
31
35
|
```json
|
|
32
36
|
"scripts": {
|
|
@@ -35,7 +39,7 @@ Example **package.json** scripts:
|
|
|
35
39
|
},
|
|
36
40
|
```
|
|
37
41
|
|
|
38
|
-
###
|
|
42
|
+
### 3. Command-line npx
|
|
39
43
|
Example terminal commands:
|
|
40
44
|
```shell
|
|
41
45
|
$ npm install --save-dev copy-file-util
|
|
@@ -43,7 +47,7 @@ $ copy-file src/web/api.html docs/api-manual.html
|
|
|
43
47
|
```
|
|
44
48
|
You can also install **copy-file-util** globally (`--global`) and then run it anywhere directly from the terminal.
|
|
45
49
|
|
|
46
|
-
###
|
|
50
|
+
### 4. CLI flags
|
|
47
51
|
Command-line flags:
|
|
48
52
|
| Flag | Description | Values |
|
|
49
53
|
| ---------------- | ------------------------------------------------ | ---------- |
|
|
@@ -55,7 +59,7 @@ Command-line flags:
|
|
|
55
59
|
| `--platform-eol` | Save target file with OS dependent line endings. | N/A |
|
|
56
60
|
| `--quiet` | Suppress informational messages. | N/A |
|
|
57
61
|
|
|
58
|
-
###
|
|
62
|
+
### 5. Examples
|
|
59
63
|
- `copy-file app.js app.mjs --quiet`<br>
|
|
60
64
|
Displays no output.
|
|
61
65
|
|
|
@@ -75,9 +79,10 @@ Command-line flags:
|
|
|
75
79
|
- `copy-file default-config.json settings/config.json --no-overwrite`<br>
|
|
76
80
|
Performs a safe copy that aborts if the **settings/config.json** file already exists.
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
> [!NOTE]
|
|
83
|
+
> _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
|
|
79
84
|
|
|
80
|
-
###
|
|
85
|
+
### 6. Template variables
|
|
81
86
|
The *target* parameter can contain template variables, like `{{package.version}}` and `{{package.name}}`, which will be replaced with values with values from your project's **package.json** file.
|
|
82
87
|
|
|
83
88
|
Example:
|
package/bin/cli.js
CHANGED
|
@@ -4,22 +4,6 @@
|
|
|
4
4
|
// MIT License //
|
|
5
5
|
////////////////////
|
|
6
6
|
|
|
7
|
-
// Usage in package.json:
|
|
8
|
-
// "scripts": {
|
|
9
|
-
// "pub-license": "copy-file src/LICENSE doc/license.txt"
|
|
10
|
-
// },
|
|
11
|
-
//
|
|
12
|
-
// Usage from command line:
|
|
13
|
-
// $ npm install --save-dev copy-file-util
|
|
14
|
-
// $ copy-file src/LICENSE doc/license.txt
|
|
15
|
-
//
|
|
16
|
-
// Contributors to this project:
|
|
17
|
-
// $ cd copy-file-util
|
|
18
|
-
// $ npm install
|
|
19
|
-
// $ npm test
|
|
20
|
-
// $ node bin/cli.js --cd=spec/fixtures mock.html --folder target/to-folder
|
|
21
|
-
// $ node bin/cli.js --cd=spec/fixtures mock.html target/{{package.type}}/{{package.name}}-v{{package.version}}.html
|
|
22
|
-
|
|
23
7
|
import { copyFile } from '../dist/copy-file.js';
|
|
24
8
|
|
|
25
9
|
copyFile.cli();
|
package/dist/copy-file.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! copy-file-util v1.3.
|
|
1
|
+
//! copy-file-util v1.3.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type Settings = {
|
|
4
4
|
cd: string | null;
|
|
@@ -17,7 +17,7 @@ export type Result = {
|
|
|
17
17
|
skipped: boolean;
|
|
18
18
|
};
|
|
19
19
|
declare const copyFile: {
|
|
20
|
-
assert(
|
|
20
|
+
assert(ok: unknown, message: string | null): void;
|
|
21
21
|
cli(): void;
|
|
22
22
|
cp(sourceFile: string, options?: Partial<Settings>): Result;
|
|
23
23
|
reporter(result: Result): Result;
|
package/dist/copy-file.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! copy-file-util v1.3.
|
|
1
|
+
//! copy-file-util v1.3.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { cliArgvUtil } from 'cli-argv-util';
|
|
4
4
|
import { dna } from 'dna-engine';
|
|
@@ -9,9 +9,9 @@ import log from 'fancy-log';
|
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import slash from 'slash';
|
|
11
11
|
const copyFile = {
|
|
12
|
-
assert(
|
|
13
|
-
if (!
|
|
14
|
-
throw new Error(
|
|
12
|
+
assert(ok, message) {
|
|
13
|
+
if (!ok)
|
|
14
|
+
throw new Error(`[copy-file-util] ${message}`);
|
|
15
15
|
},
|
|
16
16
|
cli() {
|
|
17
17
|
const validFlags = ['cd', 'folder', 'move', 'no-overwrite', 'note', 'platform-eol', 'quiet'];
|
|
@@ -23,13 +23,13 @@ const copyFile = {
|
|
|
23
23
|
const value = dna.util.value({ package: pkg }, substring.replace(/[{}]/g, ''));
|
|
24
24
|
return value ?? 'MISSING-FIELD-ERROR';
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const error = cli.invalidFlag ? cli.invalidFlagMsg :
|
|
27
27
|
cli.paramCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
|
|
28
28
|
!source ? 'Missing source file.' :
|
|
29
29
|
!target && cli.flagOn.folder ? 'Missing target folder.' :
|
|
30
30
|
!target ? 'Missing target file.' :
|
|
31
31
|
null;
|
|
32
|
-
copyFile.assert(!
|
|
32
|
+
copyFile.assert(!error, error);
|
|
33
33
|
const templateVariables = /{{[^{}]*}}/g;
|
|
34
34
|
const targetValue = target.replace(templateVariables, getPkgField);
|
|
35
35
|
const options = {
|
|
@@ -75,7 +75,7 @@ const copyFile = {
|
|
|
75
75
|
if (targetFolder)
|
|
76
76
|
fs.mkdirSync(targetFolder, { recursive: true });
|
|
77
77
|
const badTargetFolder = !targetFolder || !fs.existsSync(targetFolder);
|
|
78
|
-
const
|
|
78
|
+
const error = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
|
|
79
79
|
!sourceFile ? 'Must specify the source file.' :
|
|
80
80
|
!sourceExists ? 'Source file does not exist: ' + source :
|
|
81
81
|
!sourceIsFile ? 'Source is not a file: ' + source :
|
|
@@ -83,7 +83,7 @@ const copyFile = {
|
|
|
83
83
|
doubleTarget ? 'Target cannot be both a file and a folder.' :
|
|
84
84
|
badTargetFolder ? 'Target folder cannot be written to: ' + String(targetFolder) :
|
|
85
85
|
null;
|
|
86
|
-
copyFile.assert(!
|
|
86
|
+
copyFile.assert(!error, error);
|
|
87
87
|
const createTarget = () => {
|
|
88
88
|
if (settings.move)
|
|
89
89
|
fs.renameSync(source, target);
|
|
@@ -105,12 +105,10 @@ const copyFile = {
|
|
|
105
105
|
},
|
|
106
106
|
reporter(result) {
|
|
107
107
|
const name = chalk.gray('copy-file');
|
|
108
|
-
const
|
|
109
|
-
const dest = chalk.magenta(result.dest);
|
|
110
|
-
const arrow = chalk.gray.bold('→');
|
|
108
|
+
const ancestor = cliArgvUtil.calcAncestor(result.origin, result.dest);
|
|
111
109
|
const status = result.skipped ? ', skip -- target exists' : result.moved ? ', move' : '';
|
|
112
110
|
const info = chalk.white(`(${result.duration}ms${status})`);
|
|
113
|
-
log(name,
|
|
111
|
+
log(name, ancestor.message, info);
|
|
114
112
|
return result;
|
|
115
113
|
},
|
|
116
114
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copy-file-util",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Copy or rename a file with optional package version number (CLI tool designed for use in npm package.json scripts)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"chalk": "~5.6",
|
|
62
|
-
"cli-argv-util": "~1.
|
|
62
|
+
"cli-argv-util": "~1.4",
|
|
63
63
|
"dna-engine": "~3.3",
|
|
64
64
|
"fancy-log": "~2.0",
|
|
65
65
|
"slash": "~5.1"
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@eslint/js": "~9.39",
|
|
69
69
|
"@types/fancy-log": "~2.0",
|
|
70
|
-
"@types/node": "~
|
|
70
|
+
"@types/node": "~25.0",
|
|
71
71
|
"add-dist-header": "~1.6",
|
|
72
72
|
"assert-deep-strict-equal": "~1.2",
|
|
73
73
|
"eslint": "~9.39",
|
|
@@ -76,6 +76,6 @@
|
|
|
76
76
|
"rimraf": "~6.1",
|
|
77
77
|
"run-scripts-util": "~1.3",
|
|
78
78
|
"typescript": "~5.9",
|
|
79
|
-
"typescript-eslint": "~8.
|
|
79
|
+
"typescript-eslint": "~8.50"
|
|
80
80
|
}
|
|
81
81
|
}
|