copy-file-util 1.2.0 → 1.2.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 +3 -3
- package/bin/cli.js +7 -5
- package/dist/copy-file.d.ts +1 -1
- package/dist/copy-file.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ _Copy or rename a file with optional package version number (CLI tool designed f
|
|
|
5
5
|
|
|
6
6
|
[](https://github.com/center-key/copy-file-util/blob/main/LICENSE.txt)
|
|
7
7
|
[](https://www.npmjs.com/package/copy-file-util)
|
|
8
|
-
[](https://github.com/center-key/copy-file-util/actions/workflows/run-spec-on-push.yaml)
|
|
9
9
|
|
|
10
10
|
**copy-file-util** takes a source file and copies it to a new destination.
|
|
11
11
|
The command's console output includes a timestamp and formatting helpful in build systems.
|
|
@@ -73,10 +73,10 @@ Examples:
|
|
|
73
73
|
_**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
|
|
74
74
|
|
|
75
75
|
### 4. Template variables
|
|
76
|
-
The *target* parameter can contain template variables, like `{{
|
|
76
|
+
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.
|
|
77
77
|
|
|
78
78
|
Example:
|
|
79
|
-
- `copy-file build/app.js dist/app-v{{
|
|
79
|
+
- `copy-file build/app.js dist/app-v{{package.version}}.js`<br>
|
|
80
80
|
Creates a copy of **app.js** named something like **app-v1.2.3.js** based on the version of your project.
|
|
81
81
|
|
|
82
82
|
## C) Application Code
|
package/bin/cli.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// $ npm install
|
|
19
19
|
// $ npm test
|
|
20
20
|
// $ node bin/cli.js --cd=spec/fixtures source/mock.html --folder target/to-folder
|
|
21
|
-
// $ node bin/cli.js --cd=spec/fixtures source/mock.html target/{{
|
|
21
|
+
// $ node bin/cli.js --cd=spec/fixtures source/mock.html target/{{package.type}}/{{package.name}}-v{{package.version}}.html
|
|
22
22
|
|
|
23
23
|
// Imports
|
|
24
24
|
import { cliArgvUtil } from 'cli-argv-util';
|
|
@@ -30,12 +30,13 @@ import fs from 'fs';
|
|
|
30
30
|
const validFlags = ['cd', 'folder', 'move', 'no-overwrite', 'note', 'quiet'];
|
|
31
31
|
const cli = cliArgvUtil.parse(validFlags);
|
|
32
32
|
const source = cli.params[0];
|
|
33
|
-
const target = cli.params[1];
|
|
33
|
+
//const target = cli.params[1];
|
|
34
|
+
const target = cli.params[1].replaceAll('{{pkg.', '{{package.'); //name "pkg" deprecated in favor of "package" for clarity
|
|
34
35
|
|
|
35
36
|
// Utilities
|
|
36
37
|
const readPackage = () => JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
37
|
-
const getPackageField = (match) =>
|
|
38
|
-
dna.util.value({
|
|
38
|
+
const getPackageField = (match) => //example: '{{package.version}}' --> '3.1.4'
|
|
39
|
+
dna.util.value({ package: readPackage() }, match.replace(/[{}]/g, '')) ?? 'MISSING-FIELD-ERROR';
|
|
39
40
|
|
|
40
41
|
// Copy File
|
|
41
42
|
const error =
|
|
@@ -48,11 +49,12 @@ const error =
|
|
|
48
49
|
if (error)
|
|
49
50
|
throw Error('[copy-file-util] ' + error);
|
|
50
51
|
const targetKey = cli.flagOn.folder ? 'targetFolder' : 'targetFile';
|
|
52
|
+
const templateVariables = /{{[^{}]*}}/g; //example match: "{{package.version}}"
|
|
51
53
|
const options = {
|
|
52
54
|
cd: cli.flagMap.cd ?? null,
|
|
53
55
|
move: cli.flagOn.move,
|
|
54
56
|
overwrite: !cli.flagOn.noOverwrite,
|
|
55
|
-
[targetKey]: target.replace(
|
|
57
|
+
[targetKey]: target.replace(templateVariables, getPackageField),
|
|
56
58
|
};
|
|
57
59
|
const result = copyFile.cp(source, options);
|
|
58
60
|
if (!cli.flagOn.quiet)
|
package/dist/copy-file.d.ts
CHANGED
package/dist/copy-file.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copy-file-util",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|
|
@@ -85,14 +85,14 @@
|
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@types/fancy-log": "~2.0",
|
|
88
|
-
"@types/node": "~20.
|
|
89
|
-
"@typescript-eslint/eslint-plugin": "~7.
|
|
90
|
-
"@typescript-eslint/parser": "~7.
|
|
88
|
+
"@types/node": "~20.12",
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "~7.7",
|
|
90
|
+
"@typescript-eslint/parser": "~7.7",
|
|
91
91
|
"add-dist-header": "~1.4",
|
|
92
92
|
"assert-deep-strict-equal": "~1.2",
|
|
93
|
-
"eslint": "
|
|
93
|
+
"eslint": "8.57.0",
|
|
94
94
|
"jshint": "~2.13",
|
|
95
|
-
"mocha": "~10.
|
|
95
|
+
"mocha": "~10.4",
|
|
96
96
|
"rimraf": "~5.0",
|
|
97
97
|
"run-scripts-util": "~1.2",
|
|
98
98
|
"typescript": "~5.4"
|