copy-file-util 1.0.0 → 1.1.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
@@ -55,8 +55,11 @@ Command-line flags:
55
55
  | `--quiet` | Suppress informational messages. | N/A |
56
56
 
57
57
  Examples:
58
- - `copy-file app.js app.mjs --quiet`   Displays no output.
59
- - `copy-file app.js --folder dist`   Copies **app.js** into the **dist** folder.
58
+ - `copy-file app.js app.mjs --quiet`<br>
59
+ Displays no output.
60
+
61
+ - `copy-file app.js --folder dist`<br>
62
+ Copies **app.js** into the **dist** folder.
60
63
 
61
64
  ### 4. Template variables
62
65
  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.
@@ -70,6 +73,7 @@ Even though **copy-file-util** is primarily intended for build scripts, the pack
70
73
  Example:
71
74
  ``` typescript
72
75
  import { copyFile } from 'copy-file-util';
76
+
73
77
  const result = copyFile.cp('src/web/api.html' { targetFile: 'docs/api-manual.html' });
74
78
  console.log('Execution time:', result.duration, 'ms');
75
79
  ```
@@ -1,4 +1,4 @@
1
- //! copy-file-util v1.0.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.1.0 ~~ 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.0.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v1.1.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  import fs from 'fs';
4
4
  import path from 'path';
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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",
7
7
  "module": "dist/copy-file.js",
8
- "main": "dist/copy-file.umd.cjs",
8
+ "main": "dist/copy-file.js",
9
9
  "types": "dist/copy-file.d.ts",
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./dist/copy-file.js",
16
- "require": "./dist/copy-file.umd.cjs"
15
+ "import": "./dist/copy-file.js"
17
16
  },
18
17
  "./": "./dist/"
19
18
  },
@@ -64,40 +63,40 @@
64
63
  }
65
64
  },
66
65
  "runScriptsConfig": {
66
+ "clean": [
67
+ "rimraf build dist spec/fixtures/target"
68
+ ],
67
69
  "build": [
68
- "rimraf build dist spec/fixtures/target **/.DS_Store",
69
70
  "jshint . --exclude-path .gitignore",
70
71
  "eslint --max-warnings 0 . --ext .ts",
71
72
  "tsc",
72
- "tsc --module UMD --outDir build/umd",
73
- "cpy build/umd/copy-file.js build --rename=copy-file.umd.cjs --flat=true",
74
73
  "add-dist-header build dist"
75
74
  ]
76
75
  },
77
76
  "scripts": {
78
- "pretest": "run-scripts build",
77
+ "pretest": "run-scripts clean build",
79
78
  "test": "mocha spec/*.spec.js"
80
79
  },
81
80
  "dependencies": {
82
81
  "chalk": "~5.2",
83
82
  "cli-argv-util": "~1.0",
84
- "dna-engine": "~2.3",
83
+ "dna-engine": "~3.0",
85
84
  "fancy-log": "~2.0",
86
- "slash": "~5.0"
85
+ "slash": "~5.1"
87
86
  },
88
87
  "devDependencies": {
89
88
  "@types/fancy-log": "~2.0",
90
- "@types/node": "~18.14",
91
- "@typescript-eslint/eslint-plugin": "~5.52",
92
- "@typescript-eslint/parser": "~5.52",
89
+ "@types/node": "~20.3",
90
+ "@typescript-eslint/eslint-plugin": "~5.60",
91
+ "@typescript-eslint/parser": "~5.60",
93
92
  "add-dist-header": "~1.0",
94
93
  "assert-deep-strict-equal": "~1.0",
95
94
  "cpy-cli": "~4.2",
96
- "eslint": "~8.34",
95
+ "eslint": "~8.43",
97
96
  "jshint": "~2.13",
98
97
  "mocha": "~10.2",
99
- "rimraf": "3",
100
- "run-scripts-util": "~0.1",
101
- "typescript": "~4.9"
98
+ "rimraf": "~5.0",
99
+ "run-scripts-util": "~1.1",
100
+ "typescript": "~5.1"
102
101
  }
103
102
  }
@@ -1,66 +0,0 @@
1
- //! copy-file-util v1.0.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- (function (factory) {
7
- if (typeof module === "object" && typeof module.exports === "object") {
8
- var v = factory(require, exports);
9
- if (v !== undefined) module.exports = v;
10
- }
11
- else if (typeof define === "function" && define.amd) {
12
- define(["require", "exports", "fs", "path", "slash"], factory);
13
- }
14
- })(function (require, exports) {
15
- "use strict";
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.copyFile = void 0;
18
- const fs_1 = __importDefault(require("fs"));
19
- const path_1 = __importDefault(require("path"));
20
- const slash_1 = __importDefault(require("slash"));
21
- const copyFile = {
22
- cp(sourceFile, options) {
23
- var _a;
24
- const defaults = {
25
- cd: null,
26
- targetFile: null,
27
- targetFolder: null,
28
- fileExtension: null,
29
- };
30
- const settings = Object.assign(Object.assign({}, defaults), options);
31
- const startTime = Date.now();
32
- const missingTarget = !settings.targetFile && !settings.targetFolder;
33
- const ambiguousTarget = !!settings.targetFile && !!settings.targetFolder;
34
- const normalize = (folder) => !folder ? '' : (0, slash_1.default)(path_1.default.normalize(folder)).replace(/\/$/, '');
35
- const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
36
- const source = sourceFile ? normalize(startFolder + sourceFile) : '';
37
- const sourceExists = source && fs_1.default.existsSync(source);
38
- const sourceIsFile = sourceExists && fs_1.default.statSync(source).isFile();
39
- const sourceFilename = sourceIsFile ? path_1.default.basename(source) : null;
40
- const targetPath = settings.targetFile ? path_1.default.dirname(settings.targetFile) : settings.targetFolder;
41
- const targetFolder = targetPath ? normalize(startFolder + targetPath) : null;
42
- const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + sourceFilename;
43
- const target = normalize(startFolder + targetFile);
44
- if (targetFolder)
45
- fs_1.default.mkdirSync(targetFolder, { recursive: true });
46
- const badTargetFolder = !targetFolder || !fs_1.default.existsSync(targetFolder);
47
- const errorMessage = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
48
- !sourceFile ? 'Must specify the source file.' :
49
- !sourceExists ? 'Source file does not exist: ' + source :
50
- !sourceIsFile ? 'Source is not a file: ' + source :
51
- missingTarget ? 'Must specify a target file or folder.' :
52
- ambiguousTarget ? 'Target cannot be both a file and a folder.' :
53
- badTargetFolder ? 'Target folder cannot be written to: ' + targetFolder :
54
- null;
55
- if (errorMessage)
56
- throw Error('[copy-file-util] ' + errorMessage);
57
- fs_1.default.copyFileSync(source, target);
58
- return {
59
- origin: source,
60
- dest: target,
61
- duration: Date.now() - startTime,
62
- };
63
- },
64
- };
65
- exports.copyFile = copyFile;
66
- });