copy-folder-util 0.2.2 → 0.2.4

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 CHANGED
@@ -21,50 +21,44 @@
21
21
  // $ node bin/cli.js --cd=spec/fixtures source --ext=.js target/ext-js
22
22
 
23
23
  // Imports
24
+ import { cliArgvUtil } from 'cli-argv-util';
24
25
  import { copyFolder } from '../dist/copy-folder.js';
25
26
  import chalk from 'chalk';
26
27
  import log from 'fancy-log';
27
28
 
28
- // Parameters
29
- const validFlags = ['cd', 'ext', 'note', 'quiet', 'summary'];
30
- const args = process.argv.slice(2);
31
- const flags = args.filter(arg => /^--/.test(arg));
32
- const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^--/, '').split('=')));
33
- const flagOn = Object.fromEntries(validFlags.map(flag => [flag, flag in flagMap]));
34
- const invalidFlag = Object.keys(flagMap).find(key => !validFlags.includes(key));
35
- const params = args.filter(arg => !/^--/.test(arg));
36
-
37
- // Data
38
- const source = params[0];
39
- const target = params[1];
29
+ // Parameters and flags
30
+ const validFlags = ['cd', 'ext', 'note', 'quiet', 'summary'];
31
+ const cli = cliArgvUtil.parse(validFlags);
32
+ const source = cli.params[0];
33
+ const target = cli.params[1];
40
34
 
41
35
  // Reporting
42
36
  const printReport = (results) => {
43
37
  const name = chalk.gray('copy-folder');
44
38
  const source = chalk.blue.bold(results.source);
45
39
  const target = chalk.magenta(results.target);
46
- const arrow = { big: chalk.gray.bold('➤➤➤'), little: chalk.gray.bold('') }; //extra space for alignment
40
+ const arrow = { big: chalk.gray.bold(''), little: chalk.gray.bold('') };
47
41
  const infoColor = results.count ? chalk.white : chalk.red.bold;
48
42
  const info = infoColor(`(files: ${results.count}, ${results.duration}ms)`);
49
43
  const logFile = (file) => log(name, chalk.white(file.origin), arrow.little, chalk.green(file.dest));
50
44
  log(name, source, arrow.big, target, info);
51
- if (!flagOn.summary)
45
+ if (!cli.flagOn.summary)
52
46
  results.files.forEach(logFile);
53
47
  };
54
48
 
55
49
  // Copy Folder
56
50
  const error =
57
- invalidFlag ? 'Invalid flag: ' + invalidFlag :
58
- !source ? 'Missing source folder.' :
59
- !target ? 'Missing target folder.' :
60
- params.length > 2 ? 'Extraneous parameter: ' + params[2] :
51
+ cli.invalidFlag ? cli.invalidFlagMsg :
52
+ !source ? 'Missing source folder.' :
53
+ !target ? 'Missing target folder.' :
54
+ cli.paramsCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
61
55
  null;
62
56
  if (error)
63
57
  throw Error('[copy-folder-util] ' + error);
64
58
  const options = {
65
- cd: flagMap.cd ?? null,
66
- fileExtensions: flagMap.ext?.split(',') ?? [],
59
+ cd: cli.flagMap.cd ?? null,
60
+ fileExtensions: cli.flagMap.ext?.split(',') ?? [],
67
61
  };
68
62
  const results = copyFolder.cp(source, target, options);
69
- if (!flagOn.quiet)
63
+ if (!cli.flagOn.quiet)
70
64
  printReport(results);
@@ -1,12 +1,12 @@
1
- //! copy-folder-util v0.2.2 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
1
+ //! copy-folder-util v0.2.4 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
2
2
 
3
- export declare type Settings = {
3
+ export type Settings = {
4
4
  basename: string;
5
5
  cd: string;
6
6
  fileExtensions: string[];
7
7
  };
8
- export declare type Options = Partial<Settings>;
9
- export declare type Results = {
8
+ export type Options = Partial<Settings>;
9
+ export type Results = {
10
10
  source: string;
11
11
  target: string;
12
12
  count: number;
@@ -1,4 +1,4 @@
1
- //! copy-folder-util v0.2.2 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
1
+ //! copy-folder-util v0.2.4 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
2
2
 
3
3
  import fs from 'fs';
4
4
  import path from 'path';
@@ -1,4 +1,4 @@
1
- //! copy-folder-util v0.2.2 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
1
+ //! copy-folder-util v0.2.4 ~~ https://github.com/center-key/copy-folder-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-folder-util",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Recursively copy files from one folder to another folder (CLI tool designed for use in npm scripts)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -83,23 +83,24 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "chalk": "~5.1",
86
+ "cli-argv-util": "~0.1",
86
87
  "fancy-log": "~2.0",
87
88
  "slash": "~5.0"
88
89
  },
89
90
  "devDependencies": {
90
91
  "@types/fancy-log": "~2.0",
91
92
  "@types/node": "~18.11",
92
- "@typescript-eslint/eslint-plugin": "~5.42",
93
- "@typescript-eslint/parser": "~5.42",
93
+ "@typescript-eslint/eslint-plugin": "~5.43",
94
+ "@typescript-eslint/parser": "~5.43",
94
95
  "add-dist-header": "~0.3",
95
96
  "assert-deep-strict-equal": "~1.0",
96
97
  "copy-file-util": "~0.1",
97
- "eslint": "~8.27",
98
+ "eslint": "~8.28",
98
99
  "jshint": "~2.13",
99
100
  "mocha": "~10.1",
100
101
  "rev-web-assets": "~0.1",
101
102
  "rimraf": "~3.0",
102
103
  "run-scripts-util": "~0.1",
103
- "typescript": "~4.8"
104
+ "typescript": "~4.9"
104
105
  }
105
106
  }