copy-file-util 0.1.2 → 0.1.3
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 +11 -9
- package/bin/cli.js +8 -3
- package/dist/copy-file.d.ts +7 -6
- package/dist/copy-file.js +6 -6
- package/dist/copy-file.umd.cjs +8 -8
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -8,7 +8,10 @@ _Copy or rename a file (CLI tool designed for use in npm scripts)_
|
|
|
8
8
|
[](https://snyk.io/test/github/center-key/copy-file-util)
|
|
9
9
|
[](https://github.com/center-key/copy-file-util/actions/workflows/run-spec-on-push.yaml)
|
|
10
10
|
|
|
11
|
-
**copy-file-util** takes a source file and copies it to a new destination. The console output includes a timestamp and formatting helpful in build systems.
|
|
11
|
+
**copy-file-util** takes a source file and copies it to a new destination. The command's console output includes a timestamp and formatting helpful in build systems.
|
|
12
|
+
|
|
13
|
+
<img src=https://raw.githubusercontent.com/center-key/copy-file-util/main/screenshot.png
|
|
14
|
+
width=800 alt=screenshot>
|
|
12
15
|
|
|
13
16
|
## A) Setup
|
|
14
17
|
Install package for node:
|
|
@@ -32,9 +35,6 @@ Example **package.json** scripts:
|
|
|
32
35
|
```
|
|
33
36
|
Try out the first script with the command: `npm run pub-license`
|
|
34
37
|
|
|
35
|
-
<img src=https://raw.githubusercontent.com/center-key/copy-file-util/main/screenshot.png
|
|
36
|
-
width=800 alt=screenshot>
|
|
37
|
-
|
|
38
38
|
### 2. Global
|
|
39
39
|
You can install **copy-file-util** globally and then run it anywhere directly from the terminal.
|
|
40
40
|
|
|
@@ -46,10 +46,11 @@ $ copy-file src/web/api.html docs/api-manual.html
|
|
|
46
46
|
|
|
47
47
|
### 3. CLI Flags
|
|
48
48
|
Command-line flags:
|
|
49
|
-
| Flag | Description
|
|
50
|
-
| ---------- |
|
|
51
|
-
| `--
|
|
52
|
-
| `--
|
|
49
|
+
| Flag | Description | Values |
|
|
50
|
+
| ---------- | ---------------------------------------------- | ---------- |
|
|
51
|
+
| `--cd` | Change working directory before starting copy. | **string** |
|
|
52
|
+
| `--folder` | Indicates the target is a folder. | N/A |
|
|
53
|
+
| `--quiet` | Suppress informational messages. | N/A |
|
|
53
54
|
|
|
54
55
|
Examples:
|
|
55
56
|
- `copy-file app.js app.mjs --quite` Displays no output.
|
|
@@ -71,9 +72,10 @@ See the **TypeScript Declarations** at the top of [copy-file.ts](copy-file.ts) f
|
|
|
71
72
|
|
|
72
73
|
---
|
|
73
74
|
**Build Tools**
|
|
74
|
-
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header): _Prepend a one-line
|
|
75
|
+
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header): _Prepend a one-line banner comment (with license notice) to distribution files_
|
|
75
76
|
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util): _Copy or rename a file (CLI tool designed for use in npm scripts)_
|
|
76
77
|
- 📂 [copy-folder-cli](https://github.com/center-key/copy-folder-cli): _Recursively copy a folder (CLI tool designed for use in npm scripts)_
|
|
78
|
+
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
|
|
77
79
|
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
78
80
|
|
|
79
81
|
Feel free to submit questions at:<br>
|
package/bin/cli.js
CHANGED
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
|
|
22
22
|
// Imports
|
|
23
23
|
import { copyFile } from '../dist/copy-file.js';
|
|
24
|
-
import chalk
|
|
25
|
-
import
|
|
24
|
+
import chalk from 'chalk';
|
|
25
|
+
import fs from 'fs';
|
|
26
|
+
import log from 'fancy-log';
|
|
26
27
|
|
|
27
28
|
// Parameters
|
|
28
29
|
const validFlags = ['cd', 'folder', 'quiet'];
|
|
@@ -37,6 +38,10 @@ const source = params[0];
|
|
|
37
38
|
const target = params[1];
|
|
38
39
|
const mode = { folder: 'folder' in flagMap, quiet: 'quiet' in flagMap };
|
|
39
40
|
|
|
41
|
+
// Utilities
|
|
42
|
+
const getPackageVersion = () => !fs.existsSync('package.json') ? 'ERROR' :
|
|
43
|
+
JSON.parse(fs.readFileSync('package.json', 'utf-8')).version;
|
|
44
|
+
|
|
40
45
|
// Reporting
|
|
41
46
|
const printReport = (result) => {
|
|
42
47
|
const name = chalk.gray('copy-file');
|
|
@@ -60,7 +65,7 @@ if (error)
|
|
|
60
65
|
const targetKey = mode.folder ? 'targetFolder' : 'targetFile';
|
|
61
66
|
const options = {
|
|
62
67
|
cd: flagMap.cd ?? null,
|
|
63
|
-
[targetKey]: target,
|
|
68
|
+
[targetKey]: target.replace(/{{{pkg.version}}}/, getPackageVersion),
|
|
64
69
|
};
|
|
65
70
|
const result = copyFile.cp(source, options);
|
|
66
71
|
if (!mode.quiet)
|
package/dist/copy-file.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
//! copy-file-util v0.1.
|
|
1
|
+
//! copy-file-util v0.1.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
|
|
2
2
|
|
|
3
|
-
export declare type
|
|
4
|
-
cd
|
|
5
|
-
targetFile
|
|
6
|
-
targetFolder
|
|
7
|
-
fileExtension
|
|
3
|
+
export declare type Settings = {
|
|
4
|
+
cd: string;
|
|
5
|
+
targetFile: string;
|
|
6
|
+
targetFolder: string;
|
|
7
|
+
fileExtension: string;
|
|
8
8
|
};
|
|
9
|
+
export declare type Options = Partial<Settings>;
|
|
9
10
|
export declare type Result = {
|
|
10
11
|
origin: string;
|
|
11
12
|
dest: string;
|
package/dist/copy-file.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
//! copy-file-util v0.1.
|
|
1
|
+
//! copy-file-util v0.1.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
|
|
2
2
|
|
|
3
|
-
import fs from 'fs
|
|
3
|
+
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import slash from 'slash';
|
|
6
6
|
const copyFile = {
|
|
@@ -19,7 +19,7 @@ const copyFile = {
|
|
|
19
19
|
const normalize = (folder) => !folder ? '' : slash(path.normalize(folder)).replace(/\/$/, '');
|
|
20
20
|
const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
|
|
21
21
|
const source = sourceFile ? normalize(startFolder + sourceFile) : '';
|
|
22
|
-
const sourceExists = source && fs.
|
|
22
|
+
const sourceExists = source && fs.existsSync(source);
|
|
23
23
|
const sourceIsFile = sourceExists && fs.statSync(source).isFile();
|
|
24
24
|
const sourceFilename = sourceIsFile ? path.basename(source) : null;
|
|
25
25
|
const targetPath = settings.targetFile ? path.dirname(settings.targetFile) : settings.targetFolder;
|
|
@@ -27,8 +27,8 @@ const copyFile = {
|
|
|
27
27
|
const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + sourceFilename;
|
|
28
28
|
const target = normalize(startFolder + targetFile);
|
|
29
29
|
if (targetFolder)
|
|
30
|
-
fs.
|
|
31
|
-
const badTargetFolder = !targetFolder || !fs.
|
|
30
|
+
fs.mkdirSync(targetFolder, { recursive: true });
|
|
31
|
+
const badTargetFolder = !targetFolder || !fs.existsSync(targetFolder);
|
|
32
32
|
const errorMessage = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
|
|
33
33
|
!sourceFile ? 'Must specify the source file.' :
|
|
34
34
|
!sourceExists ? 'Source file does not exist: ' + source :
|
|
@@ -39,7 +39,7 @@ const copyFile = {
|
|
|
39
39
|
null;
|
|
40
40
|
if (errorMessage)
|
|
41
41
|
throw Error('[copy-file-util] ' + errorMessage);
|
|
42
|
-
fs.
|
|
42
|
+
fs.copyFileSync(source, target);
|
|
43
43
|
return {
|
|
44
44
|
origin: source,
|
|
45
45
|
dest: target,
|
package/dist/copy-file.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! copy-file-util v0.1.
|
|
1
|
+
//! copy-file-util v0.1.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -9,13 +9,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
if (v !== undefined) module.exports = v;
|
|
10
10
|
}
|
|
11
11
|
else if (typeof define === "function" && define.amd) {
|
|
12
|
-
define(["require", "exports", "fs
|
|
12
|
+
define(["require", "exports", "fs", "path", "slash"], factory);
|
|
13
13
|
}
|
|
14
14
|
})(function (require, exports) {
|
|
15
15
|
"use strict";
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.copyFile = void 0;
|
|
18
|
-
const
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const slash_1 = __importDefault(require("slash"));
|
|
21
21
|
const copyFile = {
|
|
@@ -34,16 +34,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
34
34
|
const normalize = (folder) => !folder ? '' : (0, slash_1.default)(path_1.default.normalize(folder)).replace(/\/$/, '');
|
|
35
35
|
const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
|
|
36
36
|
const source = sourceFile ? normalize(startFolder + sourceFile) : '';
|
|
37
|
-
const sourceExists = source &&
|
|
38
|
-
const sourceIsFile = sourceExists &&
|
|
37
|
+
const sourceExists = source && fs_1.default.existsSync(source);
|
|
38
|
+
const sourceIsFile = sourceExists && fs_1.default.statSync(source).isFile();
|
|
39
39
|
const sourceFilename = sourceIsFile ? path_1.default.basename(source) : null;
|
|
40
40
|
const targetPath = settings.targetFile ? path_1.default.dirname(settings.targetFile) : settings.targetFolder;
|
|
41
41
|
const targetFolder = targetPath ? normalize(startFolder + targetPath) : null;
|
|
42
42
|
const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + sourceFilename;
|
|
43
43
|
const target = normalize(startFolder + targetFile);
|
|
44
44
|
if (targetFolder)
|
|
45
|
-
|
|
46
|
-
const badTargetFolder = !targetFolder || !
|
|
45
|
+
fs_1.default.mkdirSync(targetFolder, { recursive: true });
|
|
46
|
+
const badTargetFolder = !targetFolder || !fs_1.default.existsSync(targetFolder);
|
|
47
47
|
const errorMessage = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
|
|
48
48
|
!sourceFile ? 'Must specify the source file.' :
|
|
49
49
|
!sourceExists ? 'Source file does not exist: ' + source :
|
|
@@ -54,7 +54,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
54
54
|
null;
|
|
55
55
|
if (errorMessage)
|
|
56
56
|
throw Error('[copy-file-util] ' + errorMessage);
|
|
57
|
-
|
|
57
|
+
fs_1.default.copyFileSync(source, target);
|
|
58
58
|
return {
|
|
59
59
|
origin: source,
|
|
60
60
|
dest: target,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copy-file-util",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Copy or rename a file (CLI tool designed for use in npm scripts)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -77,16 +77,14 @@
|
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"chalk": "~5.0",
|
|
79
79
|
"fancy-log": "~2.0",
|
|
80
|
-
"
|
|
81
|
-
"slash": "~4.0"
|
|
80
|
+
"slash": "~5.0"
|
|
82
81
|
},
|
|
83
82
|
"devDependencies": {
|
|
84
83
|
"@types/fancy-log": "~2.0",
|
|
85
|
-
"@types/
|
|
86
|
-
"@
|
|
87
|
-
"@typescript-eslint/
|
|
88
|
-
"
|
|
89
|
-
"add-dist-header": "~0.2",
|
|
84
|
+
"@types/node": "~18.8",
|
|
85
|
+
"@typescript-eslint/eslint-plugin": "~5.39",
|
|
86
|
+
"@typescript-eslint/parser": "~5.39",
|
|
87
|
+
"add-dist-header": "~0.3",
|
|
90
88
|
"assert-deep-strict-equal": "~1.0",
|
|
91
89
|
"cpy-cli": "~4.2",
|
|
92
90
|
"eslint": "~8.24",
|