copy-folder-util 1.1.7 → 1.2.0

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
@@ -4,45 +4,6 @@
4
4
  // MIT License //
5
5
  //////////////////////
6
6
 
7
- // Usage in package.json:
8
- // "scripts": {
9
- // "make-dist": "copy-folder build dist"
10
- // },
11
- //
12
- // Usage from command line:
13
- // $ npm install --save-dev copy-folder-util
14
- // $ copy-folder build dist
15
- // $ copy-folder src/web --ext=.js,.html docs
16
- //
17
- // Contributors to this project:
18
- // $ cd copy-folder-util
19
- // $ npm install
20
- // $ npm test
21
- // $ node bin/cli.js --cd=spec/fixtures source --ext=.js target/ext-js
22
-
23
- // Imports
24
- import { cliArgvUtil } from 'cli-argv-util';
25
7
  import { copyFolder } from '../dist/copy-folder.js';
26
8
 
27
- // Parameters and Flags
28
- const validFlags = ['cd', 'ext', 'note', 'quiet', 'summary'];
29
- const cli = cliArgvUtil.parse(validFlags);
30
- const source = cli.params[0];
31
- const target = cli.params[1];
32
-
33
- // Copy Folder
34
- const error =
35
- cli.invalidFlag ? cli.invalidFlagMsg :
36
- !source ? 'Missing source folder.' :
37
- !target ? 'Missing target folder.' :
38
- cli.paramCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
39
- null;
40
- if (error)
41
- throw new Error('[copy-folder-util] ' + error);
42
- const options = {
43
- cd: cli.flagMap.cd ?? null,
44
- fileExtensions: cli.flagMap.ext?.split(',') ?? [],
45
- };
46
- const results = copyFolder.cp(source, target, options);
47
- if (!cli.flagOn.quiet)
48
- copyFolder.reporter(results, { summaryOnly: cli.flagOn.summary });
9
+ copyFolder.cli();
@@ -1,4 +1,4 @@
1
- //! copy-folder-util v1.1.7 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
1
+ //! copy-folder-util v1.2.0 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
2
2
 
3
3
  export type Settings = {
4
4
  basename: string | null;
@@ -24,6 +24,7 @@ declare const copyFolder: {
24
24
  folders: string[];
25
25
  };
26
26
  assert(ok: unknown, message: string | null): void;
27
+ cli(): void;
27
28
  cp(sourceFolder: string, targetFolder: string, options?: Partial<Settings>): Results;
28
29
  reporter(results: Results, options?: Partial<ReporterSettings>): Results;
29
30
  };
@@ -1,5 +1,6 @@
1
- //! copy-folder-util v1.1.7 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
1
+ //! copy-folder-util v1.2.0 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
2
2
 
3
+ import { cliArgvUtil } from 'cli-argv-util';
3
4
  import chalk from 'chalk';
4
5
  import fs from 'fs';
5
6
  import log from 'fancy-log';
@@ -14,6 +15,26 @@ const copyFolder = {
14
15
  if (!ok)
15
16
  throw new Error(`[copy-folder-util] ${message}`);
16
17
  },
18
+ cli() {
19
+ const validFlags = ['basename', 'cd', 'ext', 'note', 'quiet', 'summary'];
20
+ const cli = cliArgvUtil.parse(validFlags);
21
+ const source = cli.params[0];
22
+ const target = cli.params[1];
23
+ const error = cli.invalidFlag ? cli.invalidFlagMsg :
24
+ !source ? 'Missing source folder.' :
25
+ !target ? 'Missing target folder.' :
26
+ cli.paramCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
27
+ null;
28
+ copyFolder.assert(!error, error);
29
+ const options = {
30
+ basename: cli.flagMap.basename ?? null,
31
+ cd: cli.flagMap.cd ?? null,
32
+ fileExtensions: cli.flagMap.ext?.split(',') ?? [],
33
+ };
34
+ const results = copyFolder.cp(source, target, options);
35
+ if (!cli.flagOn.quiet)
36
+ copyFolder.reporter(results, { summaryOnly: cli.flagOn.summary });
37
+ },
17
38
  cp(sourceFolder, targetFolder, options) {
18
39
  const defaults = {
19
40
  basename: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copy-folder-util",
3
- "version": "1.1.7",
3
+ "version": "1.2.0",
4
4
  "description": "Recursively copy files from one folder to another folder (CLI tool designed for use in npm package.json scripts)",
5
5
  "license": "MIT",
6
6
  "type": "module",