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 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 Flags
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 Variables
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 = ['cd', 'folder', 'note', '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.5 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.7 ~~ 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.5 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.7 ~~ 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.5 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
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.5",
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.1",
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.42",
91
- "@typescript-eslint/parser": "~5.42",
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.27",
96
+ "eslint": "~8.31",
96
97
  "jshint": "~2.13",
97
- "mocha": "~10.1",
98
- "rimraf": "~3.0",
98
+ "mocha": "~10.2",
99
+ "rimraf": "~4.0",
99
100
  "run-scripts-util": "~0.1",
100
- "typescript": "~4.8"
101
+ "typescript": "~4.9"
101
102
  }
102
103
  }