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 CHANGED
@@ -5,7 +5,7 @@ _Copy or rename a file with optional package version number (CLI tool designed f
5
5
 
6
6
  [![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/copy-file-util/blob/main/LICENSE.txt)
7
7
  [![npm](https://img.shields.io/npm/v/copy-file-util.svg)](https://www.npmjs.com/package/copy-file-util)
8
- [![Build](https://github.com/center-key/copy-file-util/workflows/build/badge.svg)](https://github.com/center-key/copy-file-util/actions/workflows/run-spec-on-push.yaml)
8
+ [![Build](https://github.com/center-key/copy-file-util/actions/workflows/run-spec-on-push.yaml/badge.svg)](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 `{{pkg.version}}` and `{{pkg.name}}`, which will be replaced with values with values from your project's **package.json** file.
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{{pkg.version}}.js`<br>
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/{{pkg.type}}/{{pkg.name}}-v{{pkg.version}}.html
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({ pkg: readPackage() }, match.replace(/[{}]/g, '')) ?? 'MISSING-FIELD-ERROR';
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(/{{[^{}]*}}/g, getPackageField),
57
+ [targetKey]: target.replace(templateVariables, getPackageField),
56
58
  };
57
59
  const result = copyFile.cp(source, options);
58
60
  if (!cli.flagOn.quiet)
@@ -1,4 +1,4 @@
1
- //! copy-file-util v1.2.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.2.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  export type Settings = {
4
4
  cd: string;
package/dist/copy-file.js CHANGED
@@ -1,4 +1,4 @@
1
- //! copy-file-util v1.2.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.2.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  import chalk from 'chalk';
4
4
  import fs from 'fs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "1.2.0",
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.11",
89
- "@typescript-eslint/eslint-plugin": "~7.2",
90
- "@typescript-eslint/parser": "~7.2",
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": "~8.57",
93
+ "eslint": "8.57.0",
94
94
  "jshint": "~2.13",
95
- "mocha": "~10.3",
95
+ "mocha": "~10.4",
96
96
  "rimraf": "~5.0",
97
97
  "run-scripts-util": "~1.2",
98
98
  "typescript": "~5.4"