copy-file-util 0.1.5 → 0.1.6
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/bin/cli.js +15 -21
- package/dist/copy-file.d.ts +4 -4
- package/dist/copy-file.js +1 -1
- package/dist/copy-file.umd.cjs +1 -1
- package/package.json +6 -5
package/bin/cli.js
CHANGED
|
@@ -21,24 +21,18 @@
|
|
|
21
21
|
// $ node bin/cli.js --cd=spec/fixtures source/mock.html target/{{pkg.type}}/{{pkg.name}}-v{{pkg.version}}.html
|
|
22
22
|
|
|
23
23
|
// Imports
|
|
24
|
+
import { cliArgvUtil } from 'cli-argv-util';
|
|
24
25
|
import { copyFile } from '../dist/copy-file.js';
|
|
25
26
|
import { dna } from 'dna-engine';
|
|
26
27
|
import chalk from 'chalk';
|
|
27
28
|
import fs from 'fs';
|
|
28
29
|
import log from 'fancy-log';
|
|
29
30
|
|
|
30
|
-
// Parameters
|
|
31
|
-
const validFlags =
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const flagOn = Object.fromEntries(validFlags.map(flag => [flag, flag in flagMap]));
|
|
36
|
-
const invalidFlag = Object.keys(flagMap).find(key => !validFlags.includes(key));
|
|
37
|
-
const params = args.filter(arg => !/^--/.test(arg));
|
|
38
|
-
|
|
39
|
-
// Data
|
|
40
|
-
const source = params[0];
|
|
41
|
-
const target = params[1];
|
|
31
|
+
// Parameters and flags
|
|
32
|
+
const validFlags = ['cd', 'folder', 'note', 'quiet'];
|
|
33
|
+
const cli = cliArgvUtil.parse(validFlags);
|
|
34
|
+
const source = cli.params[0];
|
|
35
|
+
const target = cli.params[1];
|
|
42
36
|
|
|
43
37
|
// Utilities
|
|
44
38
|
const readPackage = () => JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
@@ -50,26 +44,26 @@ const printReport = (result) => {
|
|
|
50
44
|
const name = chalk.gray('copy-file');
|
|
51
45
|
const origin = chalk.blue.bold(result.origin);
|
|
52
46
|
const dest = chalk.magenta(result.dest);
|
|
53
|
-
const arrow = chalk.gray.bold('
|
|
47
|
+
const arrow = chalk.gray.bold('→');
|
|
54
48
|
const info = chalk.white(`(${result.duration}ms)`);
|
|
55
49
|
log(name, origin, arrow, dest, info);
|
|
56
50
|
};
|
|
57
51
|
|
|
58
52
|
// Copy File
|
|
59
53
|
const error =
|
|
60
|
-
invalidFlag ?
|
|
61
|
-
|
|
62
|
-
!source ?
|
|
63
|
-
!target && flagOn.folder ? 'Missing target folder.' :
|
|
64
|
-
!target ?
|
|
54
|
+
cli.invalidFlag ? cli.invalidFlagMsg :
|
|
55
|
+
cli.paramCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
|
|
56
|
+
!source ? 'Missing source file.' :
|
|
57
|
+
!target && cli.flagOn.folder ? 'Missing target folder.' :
|
|
58
|
+
!target ? 'Missing target file.' :
|
|
65
59
|
null;
|
|
66
60
|
if (error)
|
|
67
61
|
throw Error('[copy-file-util] ' + error);
|
|
68
|
-
const targetKey = flagOn.folder ? 'targetFolder' : 'targetFile';
|
|
62
|
+
const targetKey = cli.flagOn.folder ? 'targetFolder' : 'targetFile';
|
|
69
63
|
const options = {
|
|
70
|
-
cd: flagMap.cd ?? null,
|
|
64
|
+
cd: cli.flagMap.cd ?? null,
|
|
71
65
|
[targetKey]: target.replace(/{{[^{}]*}}/g, getPackageField),
|
|
72
66
|
};
|
|
73
67
|
const result = copyFile.cp(source, options);
|
|
74
|
-
if (!flagOn.quiet)
|
|
68
|
+
if (!cli.flagOn.quiet)
|
|
75
69
|
printReport(result);
|
package/dist/copy-file.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
//! copy-file-util v0.1.
|
|
1
|
+
//! copy-file-util v0.1.6 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type Settings = {
|
|
4
4
|
cd: string;
|
|
5
5
|
targetFile: string;
|
|
6
6
|
targetFolder: string;
|
|
7
7
|
fileExtension: string;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type Options = Partial<Settings>;
|
|
10
|
+
export type Result = {
|
|
11
11
|
origin: string;
|
|
12
12
|
dest: string;
|
|
13
13
|
duration: number;
|
package/dist/copy-file.js
CHANGED
package/dist/copy-file.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! copy-file-util v0.1.
|
|
1
|
+
//! copy-file-util v0.1.6 ~~ 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copy-file-util",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"chalk": "~5.1",
|
|
83
|
+
"cli-argv-util": "~0.1",
|
|
83
84
|
"dna-engine": "~2.2",
|
|
84
85
|
"fancy-log": "~2.0",
|
|
85
86
|
"slash": "~5.0"
|
|
@@ -87,16 +88,16 @@
|
|
|
87
88
|
"devDependencies": {
|
|
88
89
|
"@types/fancy-log": "~2.0",
|
|
89
90
|
"@types/node": "~18.11",
|
|
90
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
91
|
-
"@typescript-eslint/parser": "~5.
|
|
91
|
+
"@typescript-eslint/eslint-plugin": "~5.43",
|
|
92
|
+
"@typescript-eslint/parser": "~5.43",
|
|
92
93
|
"add-dist-header": "~0.3",
|
|
93
94
|
"assert-deep-strict-equal": "~1.0",
|
|
94
95
|
"cpy-cli": "~4.2",
|
|
95
|
-
"eslint": "~8.
|
|
96
|
+
"eslint": "~8.28",
|
|
96
97
|
"jshint": "~2.13",
|
|
97
98
|
"mocha": "~10.1",
|
|
98
99
|
"rimraf": "~3.0",
|
|
99
100
|
"run-scripts-util": "~0.1",
|
|
100
|
-
"typescript": "~4.
|
|
101
|
+
"typescript": "~4.9"
|
|
101
102
|
}
|
|
102
103
|
}
|