copy-file-util 1.2.2 → 1.3.0

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
@@ -45,14 +45,15 @@ You can also install **copy-file-util** globally (`--global`) and then run it an
45
45
 
46
46
  ### 3. CLI flags
47
47
  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
- | `--note` | Place to add a comment only for humans. | **string** |
54
- | `--quiet` | Suppress informational messages. | N/A |
55
- | `--no-overwrite` | Abort if target file already exists. | N/A |
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 |
56
57
 
57
58
  Examples:
58
59
  - `copy-file app.js app.mjs --quiet`<br>
@@ -64,6 +65,10 @@ Examples:
64
65
  - `copy-file 'src/Legal Notice.md' --folder dist`<br>
65
66
  Copies a file that has a space in its filename.
66
67
 
68
+ - `copy-file node_modules/ui-xlib/colors.less --platform-eol --folder src/css`<br>
69
+ Copies `colors.less` into your project and converts the file's EOL characters to `\n` for LF
70
+ on Unix and `\r\n` for CRLF on Windows.
71
+
67
72
  - `copy-file app.js --move --folder dist`<br>
68
73
  Like the `mv` Unix command.
69
74
 
@@ -90,7 +95,7 @@ const result = copyFile.cp('src/web/api.html' { targetFile: 'docs/api-manual.htm
90
95
  console.log('Execution time:', result.duration, 'ms');
91
96
  ```
92
97
 
93
- See the **TypeScript Declarations** at the top of [copy-file.ts](copy-file.ts) for documentation.
98
+ See the **TypeScript Declarations** at the top of [copy-file.ts](src/copy-file.ts) for documentation.
94
99
 
95
100
  <br>
96
101
 
package/bin/cli.js CHANGED
@@ -27,7 +27,7 @@ import { dna } from 'dna-engine';
27
27
  import fs from 'fs';
28
28
 
29
29
  // Parameters and flags
30
- const validFlags = ['cd', 'folder', 'move', 'no-overwrite', 'note', 'quiet'];
30
+ const validFlags = ['cd', 'folder', 'move', 'no-overwrite', 'note', 'platform-eol', 'quiet'];
31
31
  const cli = cliArgvUtil.parse(validFlags);
32
32
  const source = cli.params[0];
33
33
  const target = cli.params[1];
@@ -1,4 +1,4 @@
1
- //! copy-file-util v1.2.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.3.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  export type Settings = {
4
4
  cd: string;
@@ -7,6 +7,7 @@ export type Settings = {
7
7
  fileExtension: string;
8
8
  move: boolean;
9
9
  overwrite: boolean;
10
+ platformEol: boolean;
10
11
  };
11
12
  export type Result = {
12
13
  origin: string;
package/dist/copy-file.js CHANGED
@@ -1,5 +1,6 @@
1
- //! copy-file-util v1.2.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.3.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
+ import { EOL } from 'node:os';
3
4
  import chalk from 'chalk';
4
5
  import fs from 'fs';
5
6
  import log from 'fancy-log';
@@ -14,6 +15,7 @@ const copyFile = {
14
15
  fileExtension: null,
15
16
  move: false,
16
17
  overwrite: true,
18
+ platformEol: false,
17
19
  };
18
20
  const settings = { ...defaults, ...options };
19
21
  const startTime = Date.now();
@@ -44,10 +46,17 @@ const copyFile = {
44
46
  null;
45
47
  if (errorMessage)
46
48
  throw new Error('[copy-file-util] ' + errorMessage);
47
- if (!skip && settings.move)
48
- fs.renameSync(source, target);
49
- else if (!skip)
50
- fs.copyFileSync(source, target);
49
+ const createTarget = () => {
50
+ if (settings.move)
51
+ fs.renameSync(source, target);
52
+ else
53
+ fs.copyFileSync(source, target);
54
+ const osEol = (text) => text.replace(/\r?\n/g, EOL);
55
+ if (settings.platformEol)
56
+ fs.writeFileSync(target, osEol(fs.readFileSync(target, 'utf-8')));
57
+ };
58
+ if (!skip)
59
+ createTarget();
51
60
  return {
52
61
  origin: source,
53
62
  dest: target,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
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.4",
62
- "cli-argv-util": "~1.2",
62
+ "cli-argv-util": "~1.3",
63
63
  "dna-engine": "~3.2",
64
64
  "fancy-log": "~2.0",
65
65
  "slash": "~5.1"
66
66
  },
67
67
  "devDependencies": {
68
- "@eslint/js": "~9.21",
68
+ "@eslint/js": "~9.30",
69
69
  "@types/fancy-log": "~2.0",
70
- "@types/node": "~22.13",
70
+ "@types/node": "~24.0",
71
71
  "add-dist-header": "~1.4",
72
72
  "assert-deep-strict-equal": "~1.2",
73
- "eslint": "~9.21",
73
+ "eslint": "~9.30",
74
74
  "jshint": "~2.13",
75
- "mocha": "~11.1",
75
+ "mocha": "~11.7",
76
76
  "rimraf": "~6.0",
77
77
  "run-scripts-util": "~1.3",
78
- "typescript": "~5.7",
79
- "typescript-eslint": "~8.25"
78
+ "typescript": "~5.8",
79
+ "typescript-eslint": "~8.36"
80
80
  }
81
81
  }