copy-file-util 1.2.0 → 1.2.2
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/LICENSE.txt +1 -1
- package/README.md +4 -4
- package/bin/cli.js +6 -5
- package/dist/copy-file.d.ts +1 -1
- package/dist/copy-file.js +4 -4
- package/package.json +12 -31
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-
|
|
3
|
+
Copyright (c) 2022-2025 Individual contributors to copy-file-util
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
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
|
|
@@ -102,7 +102,7 @@ See the **TypeScript Declarations** at the top of [copy-file.ts](copy-file.ts) f
|
|
|
102
102
|
- 🪺 [recursive-exec](https://github.com/center-key/recursive-exec): _Run a command on each file in a folder and its subfolders_
|
|
103
103
|
- 🔍 [replacer-util](https://github.com/center-key/replacer-util): _Find and replace strings or template outputs in text files_
|
|
104
104
|
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
|
|
105
|
-
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into
|
|
105
|
+
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into groups of easy to manage commands_
|
|
106
106
|
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
107
107
|
|
|
108
108
|
Feel free to submit questions at:<br>
|
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';
|
|
@@ -34,8 +34,8 @@ const target = cli.params[1];
|
|
|
34
34
|
|
|
35
35
|
// Utilities
|
|
36
36
|
const readPackage = () => JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
37
|
-
const getPackageField = (match) =>
|
|
38
|
-
dna.util.value({
|
|
37
|
+
const getPackageField = (match) => //example: '{{package.version}}' --> '3.1.4'
|
|
38
|
+
dna.util.value({ package: readPackage() }, match.replace(/[{}]/g, '')) ?? 'MISSING-FIELD-ERROR';
|
|
39
39
|
|
|
40
40
|
// Copy File
|
|
41
41
|
const error =
|
|
@@ -46,13 +46,14 @@ const error =
|
|
|
46
46
|
!target ? 'Missing target file.' :
|
|
47
47
|
null;
|
|
48
48
|
if (error)
|
|
49
|
-
throw Error('[copy-file-util] ' + error);
|
|
49
|
+
throw new Error('[copy-file-util] ' + error);
|
|
50
50
|
const targetKey = cli.flagOn.folder ? 'targetFolder' : 'targetFile';
|
|
51
|
+
const templateVariables = /{{[^{}]*}}/g; //example match: "{{package.version}}"
|
|
51
52
|
const options = {
|
|
52
53
|
cd: cli.flagMap.cd ?? null,
|
|
53
54
|
move: cli.flagOn.move,
|
|
54
55
|
overwrite: !cli.flagOn.noOverwrite,
|
|
55
|
-
[targetKey]: target.replace(
|
|
56
|
+
[targetKey]: target.replace(templateVariables, getPackageField),
|
|
56
57
|
};
|
|
57
58
|
const result = copyFile.cp(source, options);
|
|
58
59
|
if (!cli.flagOn.quiet)
|
package/dist/copy-file.d.ts
CHANGED
package/dist/copy-file.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! copy-file-util v1.2.
|
|
1
|
+
//! copy-file-util v1.2.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import fs from 'fs';
|
|
@@ -27,7 +27,7 @@ const copyFile = {
|
|
|
27
27
|
const sourceFilename = sourceIsFile ? path.basename(source) : null;
|
|
28
28
|
const targetPath = settings.targetFile ? path.dirname(settings.targetFile) : settings.targetFolder;
|
|
29
29
|
const targetFolder = targetPath ? normalize(startFolder + targetPath) : null;
|
|
30
|
-
const targetFile = settings.targetFile ?? settings.targetFolder
|
|
30
|
+
const targetFile = settings.targetFile ?? `${settings.targetFolder}/${sourceFilename}`;
|
|
31
31
|
const target = normalize(startFolder + targetFile);
|
|
32
32
|
const targetExists = !missingTarget && fs.existsSync(target);
|
|
33
33
|
const skip = targetExists && !settings.overwrite;
|
|
@@ -40,10 +40,10 @@ const copyFile = {
|
|
|
40
40
|
!sourceIsFile ? 'Source is not a file: ' + source :
|
|
41
41
|
missingTarget ? 'Must specify a target file or folder.' :
|
|
42
42
|
ambiguousTarget ? 'Target cannot be both a file and a folder.' :
|
|
43
|
-
badTargetFolder ? 'Target folder cannot be written to: ' + targetFolder :
|
|
43
|
+
badTargetFolder ? 'Target folder cannot be written to: ' + String(targetFolder) :
|
|
44
44
|
null;
|
|
45
45
|
if (errorMessage)
|
|
46
|
-
throw Error('[copy-file-util] ' + errorMessage);
|
|
46
|
+
throw new Error('[copy-file-util] ' + errorMessage);
|
|
47
47
|
if (!skip && settings.move)
|
|
48
48
|
fs.renameSync(source, target);
|
|
49
49
|
else if (!skip)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copy-file-util",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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",
|
|
@@ -40,32 +40,13 @@
|
|
|
40
40
|
"node": true,
|
|
41
41
|
"mocha": true
|
|
42
42
|
},
|
|
43
|
-
"eslintConfig": {
|
|
44
|
-
"ignorePatterns": [
|
|
45
|
-
"build",
|
|
46
|
-
"dist",
|
|
47
|
-
"node_modules"
|
|
48
|
-
],
|
|
49
|
-
"root": true,
|
|
50
|
-
"parser": "@typescript-eslint/parser",
|
|
51
|
-
"plugins": [
|
|
52
|
-
"@typescript-eslint"
|
|
53
|
-
],
|
|
54
|
-
"extends": [
|
|
55
|
-
"eslint:recommended",
|
|
56
|
-
"plugin:@typescript-eslint/recommended"
|
|
57
|
-
],
|
|
58
|
-
"rules": {
|
|
59
|
-
"@typescript-eslint/no-non-null-assertion": "off"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
43
|
"runScriptsConfig": {
|
|
63
44
|
"clean": [
|
|
64
45
|
"rimraf build dist spec/fixtures/target"
|
|
65
46
|
],
|
|
66
47
|
"lint": [
|
|
67
48
|
"jshint . --exclude-path .gitignore",
|
|
68
|
-
"eslint --max-warnings 0
|
|
49
|
+
"eslint --max-warnings 0"
|
|
69
50
|
],
|
|
70
51
|
"build": [
|
|
71
52
|
"tsc",
|
|
@@ -77,24 +58,24 @@
|
|
|
77
58
|
"test": "mocha spec/*.spec.js"
|
|
78
59
|
},
|
|
79
60
|
"dependencies": {
|
|
80
|
-
"chalk": "~5.
|
|
61
|
+
"chalk": "~5.4",
|
|
81
62
|
"cli-argv-util": "~1.2",
|
|
82
|
-
"dna-engine": "~3.
|
|
63
|
+
"dna-engine": "~3.2",
|
|
83
64
|
"fancy-log": "~2.0",
|
|
84
65
|
"slash": "~5.1"
|
|
85
66
|
},
|
|
86
67
|
"devDependencies": {
|
|
68
|
+
"@eslint/js": "~9.21",
|
|
87
69
|
"@types/fancy-log": "~2.0",
|
|
88
|
-
"@types/node": "~
|
|
89
|
-
"@typescript-eslint/eslint-plugin": "~7.2",
|
|
90
|
-
"@typescript-eslint/parser": "~7.2",
|
|
70
|
+
"@types/node": "~22.13",
|
|
91
71
|
"add-dist-header": "~1.4",
|
|
92
72
|
"assert-deep-strict-equal": "~1.2",
|
|
93
|
-
"eslint": "~
|
|
73
|
+
"eslint": "~9.21",
|
|
94
74
|
"jshint": "~2.13",
|
|
95
|
-
"mocha": "~
|
|
96
|
-
"rimraf": "~
|
|
97
|
-
"run-scripts-util": "~1.
|
|
98
|
-
"typescript": "~5.
|
|
75
|
+
"mocha": "~11.1",
|
|
76
|
+
"rimraf": "~6.0",
|
|
77
|
+
"run-scripts-util": "~1.3",
|
|
78
|
+
"typescript": "~5.7",
|
|
79
|
+
"typescript-eslint": "~8.25"
|
|
99
80
|
}
|
|
100
81
|
}
|