copy-folder-util 1.1.7 → 1.2.1

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
@@ -20,13 +20,17 @@ $ npm install --save-dev copy-folder-util
20
20
  ```
21
21
 
22
22
  ## B) Usage
23
- ### 1. npm package.json scripts
24
- Run `copy-folder` from the `"scripts"` section of your **package.json** file.
25
-
23
+ ### 1. Synopsis
24
+ ```
25
+ copy-folder [SOURCE] [TARGET]
26
+ ```
26
27
  Parameters:
27
28
  * The **first** parameter is the *source* folder.
28
29
  * The **second** parameter is the *target* folder.
29
30
 
31
+ ### 2. npm package.json scripts
32
+ Run `copy-folder` from the `"scripts"` section of your **package.json** file.
33
+
30
34
  Example **package.json** scripts:
31
35
  ```json
32
36
  "scripts": {
@@ -35,7 +39,7 @@ Example **package.json** scripts:
35
39
  },
36
40
  ```
37
41
 
38
- ### 2. Command-line npx
42
+ ### 3. Command-line npx
39
43
  Example terminal commands:
40
44
  ```shell
41
45
  $ npm install --save-dev copy-folder-util
@@ -43,7 +47,7 @@ $ npx copy-folder src/web ext=.html docs/api-manual
43
47
  ```
44
48
  You can also install **copy-folder-util** globally (`--global`) and then run it anywhere directly from the terminal.
45
49
 
46
- ### 3. CLI flags
50
+ ### 4. CLI flags
47
51
  Command-line flags:
48
52
  | Flag | Description | Value |
49
53
  | ------------ | ----------------------------------------------------- | ---------- |
@@ -54,7 +58,7 @@ Command-line flags:
54
58
  | `--quiet` | Suppress informational messages. | N/A |
55
59
  | `--summary` | Only print out the single line summary message. | N/A |
56
60
 
57
- ### 4. Examples
61
+ ### 5. Examples
58
62
  - `copy-folder build --basename=index dist` <br>
59
63
  Only copies files with filenames matching `index.*`.
60
64
 
@@ -62,7 +66,7 @@ Command-line flags:
62
66
  Copies the folder **spec/fixtures** to **spec/mock1**.
63
67
 
64
68
  - `copy-folder build dist --summary`<br>
65
- Displays the summary but not the individual files copied.
69
+ Displays the summary informaion but not informaion about individual files copied.
66
70
 
67
71
  - `copy-folder 'src/Legal Notices' dist --summary`<br>
68
72
  Copies a folder that has a space in its name.
@@ -70,7 +74,8 @@ Command-line flags:
70
74
  - `copy-folder src/web --ext=.js,.html docs`<br>
71
75
  Copies only the JavaScript and HTML files to the **docs** folder.
72
76
 
73
- _**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
77
+ > [!NOTE]
78
+ > _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
74
79
 
75
80
  ## C) Application Code
76
81
  Even though **copy-folder-util** is primarily intended for build scripts, the package can be used programmatically in ESM and TypeScript projects.
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.1 ~~ 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.1 ~~ 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,
@@ -74,13 +95,12 @@ const copyFolder = {
74
95
  };
75
96
  const settings = { ...defaults, ...options };
76
97
  const name = chalk.gray('copy-folder');
77
- const source = chalk.blue.bold(results.source);
78
- const target = chalk.magenta(results.target);
79
- const arrow = { big: chalk.gray.bold(' ⟹ '), little: chalk.gray.bold('→') };
98
+ const indent = chalk.gray('|');
99
+ const ancestor = cliArgvUtil.calcAncestor(results.source, results.target);
80
100
  const infoColor = results.count ? chalk.white : chalk.red.bold;
81
101
  const info = infoColor(`(files: ${results.count}, ${results.duration}ms)`);
82
- log(name, source, arrow.big, target, info);
83
- const logFile = (file) => log(name, chalk.white(file.origin), arrow.little, chalk.green(file.dest));
102
+ log(name, ancestor.message, info);
103
+ const logFile = (file) => log(name, indent, cliArgvUtil.calcAncestor(file.origin, file.dest).message);
84
104
  if (!settings.summaryOnly)
85
105
  results.files.forEach(logFile);
86
106
  return results;
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.1",
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",
@@ -58,18 +58,19 @@
58
58
  },
59
59
  "scripts": {
60
60
  "pretest": "run-scripts clean lint build",
61
- "test": "mocha spec/*.spec.js"
61
+ "test": "mocha spec/*.spec.js",
62
+ "posttest": "html-validator spec"
62
63
  },
63
64
  "dependencies": {
64
65
  "chalk": "~5.6",
65
- "cli-argv-util": "~1.3",
66
+ "cli-argv-util": "~1.4",
66
67
  "fancy-log": "~2.0",
67
68
  "slash": "~5.1"
68
69
  },
69
70
  "devDependencies": {
70
71
  "@eslint/js": "~9.39",
71
72
  "@types/fancy-log": "~2.0",
72
- "@types/node": "~24.10",
73
+ "@types/node": "~25.0",
73
74
  "add-dist-header": "~1.6",
74
75
  "assert-deep-strict-equal": "~1.2",
75
76
  "copy-file-util": "~1.3",
@@ -79,6 +80,7 @@
79
80
  "rimraf": "~6.1",
80
81
  "run-scripts-util": "~1.3",
81
82
  "typescript": "~5.9",
82
- "typescript-eslint": "~8.46"
83
+ "typescript-eslint": "~8.50",
84
+ "w3c-html-validator": "~2.0"
83
85
  }
84
86
  }