copy-file-util 0.1.5 → 0.1.7
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/LICENSE.txt +1 -1
- package/README.md +2 -2
- 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 +9 -8
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022 Individual contributors to copy-file-util
|
|
3
|
+
Copyright (c) 2022-2023 Individual contributors to copy-file-util
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ $ npm install --global copy-file-util
|
|
|
45
45
|
$ copy-file src/web/api.html docs/api-manual.html
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
### 3. CLI
|
|
48
|
+
### 3. CLI flags
|
|
49
49
|
Command-line flags:
|
|
50
50
|
| Flag | Description | Values |
|
|
51
51
|
| ---------- | ---------------------------------------------- | ---------- |
|
|
@@ -58,7 +58,7 @@ Examples:
|
|
|
58
58
|
- `copy-file app.js app.mjs --quiet` Displays no output.
|
|
59
59
|
- `copy-file app.js --folder dist` Copies **app.js** into the **dist** folder.
|
|
60
60
|
|
|
61
|
-
### 4. Template
|
|
61
|
+
### 4. Template variables
|
|
62
62
|
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.
|
|
63
63
|
|
|
64
64
|
Example:
|
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.7 ~~ 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.7 ~~ 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.7",
|
|
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",
|
|
@@ -79,7 +79,8 @@
|
|
|
79
79
|
"test": "mocha spec/*.spec.js"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"chalk": "~5.
|
|
82
|
+
"chalk": "~5.2",
|
|
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.48",
|
|
92
|
+
"@typescript-eslint/parser": "~5.48",
|
|
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.31",
|
|
96
97
|
"jshint": "~2.13",
|
|
97
|
-
"mocha": "~10.
|
|
98
|
-
"rimraf": "~
|
|
98
|
+
"mocha": "~10.2",
|
|
99
|
+
"rimraf": "~4.0",
|
|
99
100
|
"run-scripts-util": "~0.1",
|
|
100
|
-
"typescript": "~4.
|
|
101
|
+
"typescript": "~4.9"
|
|
101
102
|
}
|
|
102
103
|
}
|