copy-file-util 1.3.3 → 1.3.5

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
@@ -49,15 +49,16 @@ You can also install **copy-file-util** globally (`--global`) and then run it an
49
49
 
50
50
  ### 4. CLI flags
51
51
  Command-line flags:
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 |
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 |
61
62
 
62
63
  ### 5. Examples
63
64
  - `copy-file app.js app.mjs --quiet`<br>
@@ -82,12 +83,17 @@ Command-line flags:
82
83
  > [!NOTE]
83
84
  > _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
84
85
 
86
+ > [!NOTE]
87
+ > _To copy multiple files consider using_ [copy-folder-util](https://github.com/center-key/copy-folder-util).&nbsp;
88
+ > _It supports commands like the following to copy all **.jpg** files from one folder to another folder:<br>_
89
+ > `copy-folder src/website --ext=.jpg docs`
90
+
85
91
  ### 6. Template variables
86
92
  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.
87
93
 
88
94
  Example:
89
- - `copy-file build/app.js dist/app-v{{package.version}}.js`<br>
90
- Creates a copy of **app.js** named something like **app-v1.2.3.js** based on the version of your project.
95
+ - `copy-file build/my-app.js dist/my-app-v{{package.version}}.js`<br>
96
+ Creates a copy of **my-app.js** named something like **my-app-v1.2.3.js** based on the version of your project.
91
97
 
92
98
  ## C) Application Code
93
99
  Even though **copy-file-util** is primarily intended for build scripts, the package can be used programmatically in ESM and TypeScript projects.
@@ -105,17 +111,16 @@ See the **TypeScript Declarations** at the top of [copy-file.ts](src/copy-file.t
105
111
  <br>
106
112
 
107
113
  ---
108
- **CLI Build Tools for package.json**
109
- - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
110
- - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file with optional package version number_
111
- - 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):&nbsp; _Recursively copy files from one folder to another folder_
112
- - 🪺 [recursive-exec](https://github.com/center-key/recursive-exec):&nbsp; _Run a command on each file in a folder and its subfolders_
113
- - 🔍 [replacer-util](https://github.com/center-key/replacer-util):&nbsp; _Find and replace strings or template outputs in text files_
114
- - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
115
- - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):&nbsp; _Organize npm package.json scripts into groups of easy to manage commands_
116
- - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):&nbsp; _Check the markup validity of HTML files using the W3C validator_
117
-
118
- Feel free to submit questions at:<br>
119
- [github.com/center-key/copy-file-util/issues](https://github.com/center-key/copy-file-util/issues)
120
-
121
114
  [MIT License](LICENSE.txt)
115
+
116
+ [🛡️ npm Security Aggregator](https://center-key.github.io/npm-security-aggregator/?package=copy-file-util)
117
+
118
+ See the `runScriptsConfig` section of [`package.json`](package.json) for a clean way to organize build tasks:
119
+ - 🎋 [`add-dist-header`](https://github.com/center-key/add-dist-header) &mdash;&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
120
+ - 📄 [`copy-file-util`](https://github.com/center-key/copy-file-util) &mdash;&nbsp; _Copy or rename a file with optional package version number_
121
+ - 📂 [`copy-folder-util`](https://github.com/center-key/copy-folder-util) &mdash;&nbsp; _Recursively copy files from one folder to another folder_
122
+ - 🪺 [`recursive-exec`](https://github.com/center-key/recursive-exec) &mdash;&nbsp; _Run a command on each file in a folder and its subfolders_
123
+ - 🔍 [`replacer-util`](https://github.com/center-key/replacer-util) &mdash;&nbsp; _Find and replace strings or template outputs in text files_
124
+ - 🔢 [`rev-web-assets`](https://github.com/center-key/rev-web-assets) &mdash;&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
125
+ - 🚆 [`run-scripts-util`](https://github.com/center-key/run-scripts-util) &mdash;&nbsp; _Organize npm package.json scripts into groups of easy-to-manage commands_
126
+ - 🚦 [`w3c-html-validator`](https://github.com/center-key/w3c-html-validator) &mdash;&nbsp; _Check the markup validity of HTML files using the W3C validator_
@@ -1,4 +1,4 @@
1
- //! copy-file-util v1.3.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.3.5 ~~ 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;
package/dist/copy-file.js CHANGED
@@ -1,12 +1,12 @@
1
- //! copy-file-util v1.3.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.3.5 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  import { cliArgvUtil } from 'cli-argv-util';
4
- import { dna } from 'dna-engine';
5
- import { EOL } from 'node:os';
4
+ import { dna } from 'dna-dom';
6
5
  import chalk from 'chalk';
7
- import fs from 'fs';
6
+ import fs from 'node:fs';
8
7
  import log from 'fancy-log';
9
- import path from 'path';
8
+ import os from 'node:os';
9
+ import path from 'node:path';
10
10
  import slash from 'slash';
11
11
  const copyFile = {
12
12
  assert(ok, message) {
@@ -14,7 +14,8 @@ const copyFile = {
14
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];
@@ -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();
@@ -84,14 +87,21 @@ const copyFile = {
84
87
  badTargetFolder ? 'Target folder cannot be written to: ' + String(targetFolder) :
85
88
  null;
86
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, os.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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
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,23 +59,23 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "chalk": "~5.6",
62
- "cli-argv-util": "~1.4",
63
- "dna-engine": "~3.3",
62
+ "cli-argv-util": "~1.5",
63
+ "dna-dom": "~3.3",
64
64
  "fancy-log": "~2.0",
65
65
  "slash": "~5.1"
66
66
  },
67
67
  "devDependencies": {
68
- "@eslint/js": "~9.39",
68
+ "@eslint/js": "~10.0",
69
69
  "@types/fancy-log": "~2.0",
70
- "@types/node": "~25.0",
70
+ "@types/node": "~25.9",
71
71
  "add-dist-header": "~1.6",
72
72
  "assert-deep-strict-equal": "~1.2",
73
- "eslint": "~9.39",
73
+ "eslint": "~10.4",
74
74
  "jshint": "~2.13",
75
75
  "mocha": "~11.7",
76
76
  "rimraf": "~6.1",
77
77
  "run-scripts-util": "~1.3",
78
- "typescript": "~5.9",
79
- "typescript-eslint": "~8.50"
78
+ "typescript": "~6.0",
79
+ "typescript-eslint": "~8.60"
80
80
  }
81
81
  }