copy-file-util 0.1.4 → 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/README.md CHANGED
@@ -51,10 +51,11 @@ Command-line flags:
51
51
  | ---------- | ---------------------------------------------- | ---------- |
52
52
  | `--cd` | Change working directory before starting copy. | **string** |
53
53
  | `--folder` | Indicates the target is a folder. | N/A |
54
+ | `--note` | Place to add a comment only for humans. | **string** |
54
55
  | `--quiet` | Suppress informational messages. | N/A |
55
56
 
56
57
  Examples:
57
- - `copy-file app.js app.mjs --quite`   Displays no output.
58
+ - `copy-file app.js app.mjs --quiet`   Displays no output.
58
59
  - `copy-file app.js --folder dist`   Copies **app.js** into the **dist** folder.
59
60
 
60
61
  ### 4. Template Variables
@@ -84,6 +85,7 @@ See the **TypeScript Declarations** at the top of [copy-file.ts](copy-file.ts) f
84
85
  - 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):  _Recursively copy files from one folder to another folder_
85
86
  - 🔍 [replacer-util](https://github.com/center-key/replacer-util):  _Find and replace strings or template outputs in text files_
86
87
  - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):  _Revision web asset filenames with cache busting content hash fingerprints_
88
+ - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):  _Organize npm scripts into named groups of easy to manage commands_
87
89
  - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):  _Check the markup validity of HTML files using the W3C validator_
88
90
 
89
91
  Feel free to submit questions at:<br>
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 = ['cd', 'folder', 'quiet'];
32
- const args = process.argv.slice(2);
33
- const flags = args.filter(arg => /^--/.test(arg));
34
- const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^--/, '').split('=')));
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(''); //extra space for alignment
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 ? 'Invalid flag: ' + invalidFlag :
61
- params.length > 2 ? 'Extraneous parameter: ' + params[2] :
62
- !source ? 'Missing source file.' :
63
- !target && flagOn.folder ? 'Missing target folder.' :
64
- !target ? 'Missing target file.' :
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);
@@ -1,13 +1,13 @@
1
- //! copy-file-util v0.1.4 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.6 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
- export declare type Settings = {
3
+ export type Settings = {
4
4
  cd: string;
5
5
  targetFile: string;
6
6
  targetFolder: string;
7
7
  fileExtension: string;
8
8
  };
9
- export declare type Options = Partial<Settings>;
10
- export declare type Result = {
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
@@ -1,4 +1,4 @@
1
- //! copy-file-util v0.1.4 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.6 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  import fs from 'fs';
4
4
  import path from 'path';
@@ -1,4 +1,4 @@
1
- //! copy-file-util v0.1.4 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
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.4",
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",
@@ -63,36 +63,41 @@
63
63
  "@typescript-eslint/no-non-null-assertion": "off"
64
64
  }
65
65
  },
66
+ "runScriptsConfig": {
67
+ "build": [
68
+ "rimraf build dist spec/fixtures/target **/.DS_Store",
69
+ "jshint . --exclude-path .gitignore",
70
+ "eslint --max-warnings 0 . --ext .ts",
71
+ "tsc",
72
+ "tsc --module UMD --outDir build/umd",
73
+ "cpy build/umd/copy-file.js build --rename=copy-file.umd.cjs --flat=true",
74
+ "add-dist-header build dist"
75
+ ]
76
+ },
66
77
  "scripts": {
67
- "step:01": "rimraf build dist spec/fixtures/target **/.DS_Store",
68
- "step:02": "jshint . --exclude-path .gitignore",
69
- "step:03": "eslint --max-warnings 0 . --ext .ts",
70
- "step:04": "tsc",
71
- "step:05": "tsc --module UMD --outDir build/umd",
72
- "step:06": "cpy build/umd/copy-file.js build --rename=copy-file.umd.cjs --flat=true",
73
- "step:07": "add-dist-header build dist",
74
- "pretest": "npm-run-all step:*",
78
+ "pretest": "run-scripts build",
75
79
  "test": "mocha spec/*.spec.js"
76
80
  },
77
81
  "dependencies": {
78
82
  "chalk": "~5.1",
83
+ "cli-argv-util": "~0.1",
79
84
  "dna-engine": "~2.2",
80
85
  "fancy-log": "~2.0",
81
86
  "slash": "~5.0"
82
87
  },
83
88
  "devDependencies": {
84
89
  "@types/fancy-log": "~2.0",
85
- "@types/node": "~18.8",
86
- "@typescript-eslint/eslint-plugin": "~5.40",
87
- "@typescript-eslint/parser": "~5.40",
90
+ "@types/node": "~18.11",
91
+ "@typescript-eslint/eslint-plugin": "~5.43",
92
+ "@typescript-eslint/parser": "~5.43",
88
93
  "add-dist-header": "~0.3",
89
94
  "assert-deep-strict-equal": "~1.0",
90
95
  "cpy-cli": "~4.2",
91
- "eslint": "~8.25",
96
+ "eslint": "~8.28",
92
97
  "jshint": "~2.13",
93
- "mocha": "~10.0",
94
- "npm-run-all2": "~6.0",
98
+ "mocha": "~10.1",
95
99
  "rimraf": "~3.0",
96
- "typescript": "~4.8"
100
+ "run-scripts-util": "~0.1",
101
+ "typescript": "~4.9"
97
102
  }
98
103
  }