copy-file-util 1.3.2 → 1.3.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022-2025 Individual contributors to copy-file-util
3
+ Copyright (c) 2022-2026 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
@@ -20,13 +20,17 @@ $ npm install --save-dev copy-file-util
20
20
  ```
21
21
 
22
22
  ## B) Usage
23
- ### 1. npm package.json scripts
24
- Run `copy-file` from the `"scripts"` section of your **package.json** file.
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
- ### 2. Command-line npx
42
+ ### 3. Command-line npx
39
43
  Example terminal commands:
40
44
  ```shell
41
45
  $ npm install --save-dev copy-file-util
@@ -43,19 +47,20 @@ $ 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
- ### 3. CLI flags
50
+ ### 4. CLI flags
47
51
  Command-line flags:
48
- | Flag | Description | Values |
49
- | ---------------- | ------------------------------------------------ | ---------- |
50
- | `--cd` | Change working directory before starting copy. | **string** |
51
- | `--folder` | Indicates the target is a folder. | N/A |
52
- | `--move` | Delete the source file after copying it. | N/A |
53
- | `--no-overwrite` | Abort if target file already exists. | N/A |
54
- | `--note` | Place to add a comment only for humans. | **string** |
55
- | `--platform-eol` | Save target file with OS dependent line endings. | N/A |
56
- | `--quiet` | Suppress informational messages. | N/A |
57
-
58
- ### 4. Examples
52
+ | Flag | Description | Values |
53
+ | ------------------ | ------------------------------------------------ | ---------- |
54
+ | `--cd` | Change working directory before starting copy. | **string** |
55
+ | `--folder` | Indicates the target is a folder. | N/A |
56
+ | `--move` | Delete the source file after copying it. | N/A |
57
+ | `--no-overwrite` | Abort if target file already exists. | N/A |
58
+ | `--note` | Place to add a comment only for humans. | **string** |
59
+ | `--platform-eol` | Save target file with OS dependent line endings. | N/A |
60
+ | `--quiet` | Suppress informational messages. | N/A |
61
+ | `--remove-sem-ver` | Deletes text like 'v1.2.3' to avoid noisy diffs. | N/A |
62
+
63
+ ### 5. Examples
59
64
  - `copy-file app.js app.mjs --quiet`<br>
60
65
  Displays no output.
61
66
 
@@ -75,9 +80,10 @@ Command-line flags:
75
80
  - `copy-file default-config.json settings/config.json --no-overwrite`<br>
76
81
  Performs a safe copy that aborts if the **settings/config.json** file already exists.
77
82
 
78
- _**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
83
+ > [!NOTE]
84
+ > _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
79
85
 
80
- ### 5. Template variables
86
+ ### 6. Template variables
81
87
  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
88
 
83
89
  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();
@@ -1,4 +1,4 @@
1
- //! copy-file-util v1.3.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.3.4 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  export type Settings = {
4
4
  cd: string | null;
@@ -8,6 +8,7 @@ export type Settings = {
8
8
  move: boolean;
9
9
  overwrite: boolean;
10
10
  platformEol: boolean;
11
+ removeSemVer: boolean;
11
12
  };
12
13
  export type Result = {
13
14
  origin: string;
@@ -17,7 +18,7 @@ export type Result = {
17
18
  skipped: boolean;
18
19
  };
19
20
  declare const copyFile: {
20
- assert(condition: unknown, errorMessage: unknown): void;
21
+ assert(ok: unknown, message: string | null): void;
21
22
  cli(): void;
22
23
  cp(sourceFile: string, options?: Partial<Settings>): Result;
23
24
  reporter(result: Result): Result;
package/dist/copy-file.js CHANGED
@@ -1,4 +1,4 @@
1
- //! copy-file-util v1.3.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.3.4 ~~ 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,12 +9,13 @@ import log from 'fancy-log';
9
9
  import path from 'path';
10
10
  import slash from 'slash';
11
11
  const copyFile = {
12
- assert(condition, errorMessage) {
13
- if (!condition)
14
- throw new Error('[copy-file-util] ' + String(errorMessage));
12
+ assert(ok, message) {
13
+ if (!ok)
14
+ throw new Error(`[copy-file-util] ${message}`);
15
15
  },
16
16
  cli() {
17
- const validFlags = ['cd', 'folder', 'move', 'no-overwrite', 'note', 'platform-eol', 'quiet'];
17
+ const validFlags = ['cd', 'folder', 'move', 'no-overwrite', 'note', 'platform-eol',
18
+ 'quiet', 'remove-sem-ver'];
18
19
  const cli = cliArgvUtil.parse(validFlags);
19
20
  const source = cli.params[0];
20
21
  const target = cli.params[1];
@@ -23,13 +24,13 @@ const copyFile = {
23
24
  const value = dna.util.value({ package: pkg }, substring.replace(/[{}]/g, ''));
24
25
  return value ?? 'MISSING-FIELD-ERROR';
25
26
  };
26
- const errorMessage = cli.invalidFlag ? cli.invalidFlagMsg :
27
+ const error = cli.invalidFlag ? cli.invalidFlagMsg :
27
28
  cli.paramCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
28
29
  !source ? 'Missing source file.' :
29
30
  !target && cli.flagOn.folder ? 'Missing target folder.' :
30
31
  !target ? 'Missing target file.' :
31
32
  null;
32
- copyFile.assert(!errorMessage, errorMessage);
33
+ copyFile.assert(!error, error);
33
34
  const templateVariables = /{{[^{}]*}}/g;
34
35
  const targetValue = target.replace(templateVariables, getPkgField);
35
36
  const options = {
@@ -40,6 +41,7 @@ const copyFile = {
40
41
  move: !!cli.flagOn.move,
41
42
  overwrite: !cli.flagOn.noOverwrite,
42
43
  platformEol: !!cli.flagOn.platformEol,
44
+ removeSemVer: !!cli.flagOn.removeSemVer,
43
45
  };
44
46
  const result = copyFile.cp(source, options);
45
47
  if (!cli.flagOn.quiet)
@@ -54,6 +56,7 @@ const copyFile = {
54
56
  move: false,
55
57
  overwrite: true,
56
58
  platformEol: false,
59
+ removeSemVer: false,
57
60
  };
58
61
  const settings = { ...defaults, ...options };
59
62
  const startTime = Date.now();
@@ -75,7 +78,7 @@ const copyFile = {
75
78
  if (targetFolder)
76
79
  fs.mkdirSync(targetFolder, { recursive: true });
77
80
  const badTargetFolder = !targetFolder || !fs.existsSync(targetFolder);
78
- const errorMessage = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
81
+ const error = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
79
82
  !sourceFile ? 'Must specify the source file.' :
80
83
  !sourceExists ? 'Source file does not exist: ' + source :
81
84
  !sourceIsFile ? 'Source is not a file: ' + source :
@@ -83,15 +86,22 @@ const copyFile = {
83
86
  doubleTarget ? 'Target cannot be both a file and a folder.' :
84
87
  badTargetFolder ? 'Target folder cannot be written to: ' + String(targetFolder) :
85
88
  null;
86
- copyFile.assert(!errorMessage, errorMessage);
89
+ copyFile.assert(!error, error);
90
+ const rewriteTarget = () => {
91
+ const semVer = /\s+v[0-9]+\.[0-9]+\.[0-9]+\s+/;
92
+ const content1 = fs.readFileSync(target, 'utf-8');
93
+ const content2 = settings.platformEol ? content1.replace(/\r?\n/g, EOL) : content1;
94
+ const content3 = settings.removeSemVer ? content2.replace(semVer, ' ') : content2;
95
+ if (content1 !== content3)
96
+ fs.writeFileSync(target, content3);
97
+ };
87
98
  const createTarget = () => {
88
99
  if (settings.move)
89
100
  fs.renameSync(source, target);
90
101
  else
91
102
  fs.copyFileSync(source, target);
92
- const platformEol = (text) => text.replace(/\r?\n/g, EOL);
93
- if (settings.platformEol)
94
- fs.writeFileSync(target, platformEol(fs.readFileSync(target, 'utf-8')));
103
+ if (settings.platformEol || settings.removeSemVer)
104
+ rewriteTarget();
95
105
  };
96
106
  if (!skip)
97
107
  createTarget();
@@ -105,12 +115,10 @@ const copyFile = {
105
115
  },
106
116
  reporter(result) {
107
117
  const name = chalk.gray('copy-file');
108
- const origin = chalk.blue.bold(result.origin);
109
- const dest = chalk.magenta(result.dest);
110
- const arrow = chalk.gray.bold('→');
118
+ const ancestor = cliArgvUtil.calcAncestor(result.origin, result.dest);
111
119
  const status = result.skipped ? ', skip -- target exists' : result.moved ? ', move' : '';
112
120
  const info = chalk.white(`(${result.duration}ms${status})`);
113
- log(name, origin, arrow, dest, info);
121
+ log(name, ancestor.message, info);
114
122
  return result;
115
123
  },
116
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
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.3",
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": "~24.10",
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.46"
79
+ "typescript-eslint": "~8.52"
80
80
  }
81
81
  }