copy-file-util 1.1.0 → 1.1.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,6 @@ _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
- [![Vulnerabilities](https://snyk.io/test/github/center-key/copy-file-util/badge.svg)](https://snyk.io/test/github/center-key/copy-file-util)
9
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)
10
9
 
11
10
  **copy-file-util** takes a source file and copies it to a new destination. 
@@ -36,14 +35,13 @@ Example **package.json** scripts:
36
35
  },
37
36
  ```
38
37
 
39
- ### 2. Global
40
- You can install **copy-file-util** globally and then run it anywhere directly from the terminal.
41
-
38
+ ### 2. Command-line npx
42
39
  Example terminal commands:
43
40
  ```shell
44
- $ npm install --global copy-file-util
41
+ $ npm install --save-dev copy-file-util
45
42
  $ copy-file src/web/api.html docs/api-manual.html
46
43
  ```
44
+ You can also install **copy-file-util** globally (`--global`) and then run it anywhere directly from the terminal.
47
45
 
48
46
  ### 3. CLI flags
49
47
  Command-line flags:
@@ -51,6 +49,7 @@ Command-line flags:
51
49
  | ---------- | ---------------------------------------------- | ---------- |
52
50
  | `--cd` | Change working directory before starting copy. | **string** |
53
51
  | `--folder` | Indicates the target is a folder. | N/A |
52
+ | `--move` | Delete the source file after copying it. | N/A |
54
53
  | `--note` | Place to add a comment only for humans. | **string** |
55
54
  | `--quiet` | Suppress informational messages. | N/A |
56
55
 
@@ -61,11 +60,15 @@ Examples:
61
60
  - `copy-file app.js --folder dist`<br>
62
61
  Copies **app.js** into the **dist** folder.
63
62
 
63
+ - `copy-file app.js --move --folder dist`<br>
64
+ Like the `mv` Unix command.
65
+
64
66
  ### 4. Template variables
65
67
  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.
66
68
 
67
69
  Example:
68
- - `copy-file build/app.js dist/app-v{{pkg.version}}.js` &nbsp; Creates a copy of **app.js** named something like **app-v1.2.3.js** based on the version of your project.
70
+ - `copy-file build/app.js dist/app-v{{pkg.version}}.js`<br>
71
+ Creates a copy of **app.js** named something like **app-v1.2.3.js** based on the version of your project.
69
72
 
70
73
  ## C) Application Code
71
74
  Even though **copy-file-util** is primarily intended for build scripts, the package can easily be used programmatically in ESM and TypeScript projects.
@@ -87,6 +90,7 @@ See the **TypeScript Declarations** at the top of [copy-file.ts](copy-file.ts) f
87
90
  - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
88
91
  - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file with optional package version number_
89
92
  - 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):&nbsp; _Recursively copy files from one folder to another folder_
93
+ - 🪺 [recursive-exec](https://github.com/center-key/recursive-exec):&nbsp; _Run a command on each file in a folder and its subfolders_
90
94
  - 🔍 [replacer-util](https://github.com/center-key/replacer-util):&nbsp; _Find and replace strings or template outputs in text files_
91
95
  - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
92
96
  - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):&nbsp; _Organize npm scripts into named groups of easy to manage commands_
package/bin/cli.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // },
11
11
  //
12
12
  // Usage from command line:
13
- // $ npm install --global copy-file-util
13
+ // $ npm install --save-dev copy-file-util
14
14
  // $ copy-file src/LICENSE doc/license.txt
15
15
  //
16
16
  // Contributors to this project:
@@ -29,7 +29,7 @@ import fs from 'fs';
29
29
  import log from 'fancy-log';
30
30
 
31
31
  // Parameters and flags
32
- const validFlags = ['cd', 'folder', 'note', 'quiet'];
32
+ const validFlags = ['cd', 'folder', 'move', 'note', 'quiet'];
33
33
  const cli = cliArgvUtil.parse(validFlags);
34
34
  const source = cli.params[0];
35
35
  const target = cli.params[1];
@@ -45,7 +45,7 @@ const printReport = (result) => {
45
45
  const origin = chalk.blue.bold(result.origin);
46
46
  const dest = chalk.magenta(result.dest);
47
47
  const arrow = chalk.gray.bold('→');
48
- const info = chalk.white(`(${result.duration}ms)`);
48
+ const info = chalk.white(`(${result.duration}ms${result.moved ? ', move' : ''})`);
49
49
  log(name, origin, arrow, dest, info);
50
50
  };
51
51
 
@@ -62,6 +62,7 @@ if (error)
62
62
  const targetKey = cli.flagOn.folder ? 'targetFolder' : 'targetFile';
63
63
  const options = {
64
64
  cd: cli.flagMap.cd ?? null,
65
+ move: cli.flagOn.move,
65
66
  [targetKey]: target.replace(/{{[^{}]*}}/g, getPackageField),
66
67
  };
67
68
  const result = copyFile.cp(source, options);
@@ -1,18 +1,19 @@
1
- //! copy-file-util v1.1.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.1.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
- export type Settings = {
3
+ export type Options = {
4
4
  cd: string;
5
5
  targetFile: string;
6
6
  targetFolder: string;
7
7
  fileExtension: string;
8
+ move: boolean;
8
9
  };
9
- export type Options = Partial<Settings>;
10
10
  export type Result = {
11
11
  origin: string;
12
12
  dest: string;
13
13
  duration: number;
14
+ moved: boolean;
14
15
  };
15
16
  declare const copyFile: {
16
- cp(sourceFile: string, options: Options): Result;
17
+ cp(sourceFile: string, options: Partial<Options>): Result;
17
18
  };
18
19
  export { copyFile };
package/dist/copy-file.js CHANGED
@@ -1,18 +1,18 @@
1
- //! copy-file-util v1.1.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.1.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
  import slash from 'slash';
6
6
  const copyFile = {
7
7
  cp(sourceFile, options) {
8
- var _a;
9
8
  const defaults = {
10
9
  cd: null,
11
10
  targetFile: null,
12
11
  targetFolder: null,
13
12
  fileExtension: null,
13
+ move: false,
14
14
  };
15
- const settings = Object.assign(Object.assign({}, defaults), options);
15
+ const settings = { ...defaults, ...options };
16
16
  const startTime = Date.now();
17
17
  const missingTarget = !settings.targetFile && !settings.targetFolder;
18
18
  const ambiguousTarget = !!settings.targetFile && !!settings.targetFolder;
@@ -24,7 +24,7 @@ const copyFile = {
24
24
  const sourceFilename = sourceIsFile ? path.basename(source) : null;
25
25
  const targetPath = settings.targetFile ? path.dirname(settings.targetFile) : settings.targetFolder;
26
26
  const targetFolder = targetPath ? normalize(startFolder + targetPath) : null;
27
- const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + sourceFilename;
27
+ const targetFile = settings.targetFile ?? settings.targetFolder + '/' + sourceFilename;
28
28
  const target = normalize(startFolder + targetFile);
29
29
  if (targetFolder)
30
30
  fs.mkdirSync(targetFolder, { recursive: true });
@@ -39,10 +39,14 @@ const copyFile = {
39
39
  null;
40
40
  if (errorMessage)
41
41
  throw Error('[copy-file-util] ' + errorMessage);
42
- fs.copyFileSync(source, target);
42
+ if (settings.move)
43
+ fs.renameSync(source, target);
44
+ else
45
+ fs.copyFileSync(source, target);
43
46
  return {
44
47
  origin: source,
45
48
  dest: target,
49
+ moved: settings.move,
46
50
  duration: Date.now() - startTime,
47
51
  };
48
52
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Copy or rename a file with optional package version number (CLI tool designed for use in npm scripts)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -66,37 +66,38 @@
66
66
  "clean": [
67
67
  "rimraf build dist spec/fixtures/target"
68
68
  ],
69
- "build": [
69
+ "lint": [
70
70
  "jshint . --exclude-path .gitignore",
71
- "eslint --max-warnings 0 . --ext .ts",
71
+ "eslint --max-warnings 0 . --ext .ts"
72
+ ],
73
+ "build": [
72
74
  "tsc",
73
75
  "add-dist-header build dist"
74
76
  ]
75
77
  },
76
78
  "scripts": {
77
- "pretest": "run-scripts clean build",
79
+ "pretest": "run-scripts clean lint build",
78
80
  "test": "mocha spec/*.spec.js"
79
81
  },
80
82
  "dependencies": {
81
- "chalk": "~5.2",
82
- "cli-argv-util": "~1.0",
83
+ "chalk": "~5.3",
84
+ "cli-argv-util": "~1.2",
83
85
  "dna-engine": "~3.0",
84
86
  "fancy-log": "~2.0",
85
87
  "slash": "~5.1"
86
88
  },
87
89
  "devDependencies": {
88
90
  "@types/fancy-log": "~2.0",
89
- "@types/node": "~20.3",
90
- "@typescript-eslint/eslint-plugin": "~5.60",
91
- "@typescript-eslint/parser": "~5.60",
92
- "add-dist-header": "~1.0",
93
- "assert-deep-strict-equal": "~1.0",
94
- "cpy-cli": "~4.2",
95
- "eslint": "~8.43",
91
+ "@types/node": "~20.5",
92
+ "@typescript-eslint/eslint-plugin": "~6.4",
93
+ "@typescript-eslint/parser": "~6.4",
94
+ "add-dist-header": "~1.2",
95
+ "assert-deep-strict-equal": "~1.1",
96
+ "eslint": "~8.47",
96
97
  "jshint": "~2.13",
97
98
  "mocha": "~10.2",
98
99
  "rimraf": "~5.0",
99
- "run-scripts-util": "~1.1",
100
+ "run-scripts-util": "~1.2",
100
101
  "typescript": "~5.1"
101
102
  }
102
103
  }