copy-folder-util 1.0.0 → 1.1.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
@@ -5,7 +5,6 @@ _Recursively copy files from one folder to another folder (CLI tool designed for
5
5
 
6
6
  [![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/copy-folder-util/blob/main/LICENSE.txt)
7
7
  [![npm](https://img.shields.io/npm/v/copy-folder-util.svg)](https://www.npmjs.com/package/copy-folder-util)
8
- [![Vulnerabilities](https://snyk.io/test/github/center-key/copy-folder-util/badge.svg)](https://snyk.io/test/github/center-key/copy-folder-util)
9
8
  [![Build](https://github.com/center-key/copy-folder-util/workflows/build/badge.svg)](https://github.com/center-key/copy-folder-util/actions/workflows/run-spec-on-push.yaml)
10
9
 
11
10
  **copy-folder-util** takes a source folder and copies its files and subfolders to a new destination. 
@@ -36,14 +35,13 @@ Example **package.json** scripts:
36
35
  },
37
36
  ```
38
37
 
39
- ### 2. Global
40
- You can install **copy-folder-util** globally and then run it anywhere directly from the terminal.
41
-
38
+ ### 2. Command-line npx
42
39
  Example terminal commands:
43
40
  ```shell
44
- $ npm install --global copy-folder-util
45
- $ copy-folder src/web ext=.html docs/api-manual
41
+ $ npm install --save-dev copy-folder-util
42
+ $ npx copy-folder src/web ext=.html docs/api-manual
46
43
  ```
44
+ You can also install **copy-folder-util** globally (`--global`) and then run it anywhere directly from the terminal.
47
45
 
48
46
  ### 3. CLI flags
49
47
  Command-line flags:
@@ -57,10 +55,17 @@ Command-line flags:
57
55
  | `--summary` | Only print out the single line summary message. | N/A |
58
56
 
59
57
  Examples:
60
- - `copy-folder build --basename=index dist`   Only copy files with filenames matching `index.*`.
61
- - `copy-folder -cd=spec fixtures mock1`   Copy the folder **spec/fixtures** to **spec/mock1**.
62
- - `copy-folder build dist --summary`   Displays the summary but not the individual files copied.
63
- - `copy-folder src/web --ext=.js,.html docs`   Copy only the JavaScript and HTML files to the **docs** folder.
58
+ - `copy-folder build --basename=index dist` <br>
59
+ Only copy files with filenames matching `index.*`.
60
+
61
+ - `copy-folder -cd=spec fixtures mock1`<br>
62
+ Copy the folder **spec/fixtures** to **spec/mock1**.
63
+
64
+ - `copy-folder build dist --summary`<br>
65
+ Displays the summary but not the individual files copied.
66
+
67
+ - `copy-folder src/web --ext=.js,.html docs`<br>
68
+ Copy only the JavaScript and HTML files to the **docs** folder.
64
69
 
65
70
  ## C) Application Code
66
71
  Even though **copy-folder-util** is primarily intended for build scripts, the package can easily be used programmatically in ESM and TypeScript projects.
@@ -68,6 +73,7 @@ Even though **copy-folder-util** is primarily intended for build scripts, the pa
68
73
  Example:
69
74
  ``` typescript
70
75
  import { copyFolder } from 'copy-folder-util';
76
+
71
77
  const options = { fileExtensions: ['.html', '.js'] };
72
78
  const results = copyFolder.cp('src/web', 'docs/api-manual', options);
73
79
  console.log('Number of files copied:', results.count);
@@ -82,6 +88,7 @@ See the **TypeScript Declarations** at the top of [copy-folder.ts](copy-folder.t
82
88
  - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
83
89
  - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file with optional package version number_
84
90
  - 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):&nbsp; _Recursively copy files from one folder to another folder_
91
+ - 🪺 [recursive-exec](https://github.com/center-key/recursive-exec):&nbsp; _Run a command on each file in a folder and its subfolders_
85
92
  - 🔍 [replacer-util](https://github.com/center-key/replacer-util):&nbsp; _Find and replace strings or template outputs in text files_
86
93
  - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
87
94
  - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):&nbsp; _Organize npm scripts into named groups of easy to manage commands_
package/bin/cli.js CHANGED
@@ -10,7 +10,7 @@
10
10
  // },
11
11
  //
12
12
  // Usage from command line:
13
- // $ npm install --global copy-folder-util
13
+ // $ npm install --save-dev copy-folder-util
14
14
  // $ copy-folder build dist
15
15
  // $ copy-folder src/web --ext=.js,.html docs
16
16
  //
@@ -1,4 +1,4 @@
1
- //! copy-folder-util v1.0.0 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
1
+ //! copy-folder-util v1.1.1 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
2
2
 
3
3
  export type Settings = {
4
4
  basename: string;
@@ -1,4 +1,4 @@
1
- //! copy-folder-util v1.0.0 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
1
+ //! copy-folder-util v1.1.1 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
2
2
 
3
3
  import fs from 'fs';
4
4
  import path from 'path';
@@ -12,7 +12,7 @@ const copyFolder = {
12
12
  cd: null,
13
13
  fileExtensions: [],
14
14
  };
15
- const settings = Object.assign(Object.assign({}, defaults), options);
15
+ const settings = { ...defaults, ...options };
16
16
  const startTime = Date.now();
17
17
  const normalize = (folder) => !folder ? '' : slash(path.normalize(folder)).replace(/\/$/, '');
18
18
  const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "copy-folder-util",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
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",
7
7
  "module": "dist/copy-folder.js",
8
- "main": "dist/copy-folder.umd.cjs",
8
+ "main": "dist/copy-folder.js",
9
9
  "types": "dist/copy-folder.d.ts",
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./dist/copy-folder.js",
16
- "require": "./dist/copy-folder.umd.cjs"
15
+ "import": "./dist/copy-folder.js"
17
16
  },
18
17
  "./": "./dist/"
19
18
  },
@@ -67,40 +66,41 @@
67
66
  }
68
67
  },
69
68
  "runScriptsConfig": {
70
- "build": [
71
- "rimraf build dist spec/fixtures/target **/.DS_Store",
69
+ "clean": [
70
+ "rimraf build dist spec/fixtures/target"
71
+ ],
72
+ "lint": [
72
73
  "jshint . --exclude-path .gitignore",
73
- "eslint --max-warnings 0 . --ext .ts",
74
+ "eslint --max-warnings 0 . --ext .ts"
75
+ ],
76
+ "build": [
74
77
  "tsc",
75
- "tsc --module UMD --outDir build/umd",
76
- "copy-file build/umd/copy-folder.js build/copy-folder.umd.cjs",
77
78
  "add-dist-header build dist"
78
79
  ]
79
80
  },
80
81
  "scripts": {
81
- "pretest": "run-scripts build",
82
+ "pretest": "run-scripts clean lint build",
82
83
  "test": "mocha spec/*.spec.js"
83
84
  },
84
85
  "dependencies": {
85
- "chalk": "~5.2",
86
- "cli-argv-util": "~1.0",
86
+ "chalk": "~5.3",
87
+ "cli-argv-util": "~1.2",
87
88
  "fancy-log": "~2.0",
88
- "slash": "~5.0"
89
+ "slash": "~5.1"
89
90
  },
90
91
  "devDependencies": {
91
92
  "@types/fancy-log": "~2.0",
92
- "@types/node": "~18.14",
93
- "@typescript-eslint/eslint-plugin": "~5.52",
94
- "@typescript-eslint/parser": "~5.52",
95
- "add-dist-header": "~1.0",
96
- "assert-deep-strict-equal": "~1.0",
97
- "copy-file-util": "~1.0",
98
- "eslint": "~8.34",
93
+ "@types/node": "~20.5",
94
+ "@typescript-eslint/eslint-plugin": "~6.4",
95
+ "@typescript-eslint/parser": "~6.4",
96
+ "add-dist-header": "~1.2",
97
+ "assert-deep-strict-equal": "~1.1",
98
+ "copy-file-util": "~1.1",
99
+ "eslint": "~8.47",
99
100
  "jshint": "~2.13",
100
101
  "mocha": "~10.2",
101
- "rev-web-assets": "~0.1",
102
- "rimraf": "3",
103
- "run-scripts-util": "~0.1",
104
- "typescript": "~4.9"
102
+ "rimraf": "~5.0",
103
+ "run-scripts-util": "~1.2",
104
+ "typescript": "~5.1"
105
105
  }
106
106
  }
@@ -1,81 +0,0 @@
1
- //! copy-folder-util v1.0.0 ~~ https://github.com/center-key/copy-folder-util ~~ MIT License
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- (function (factory) {
7
- if (typeof module === "object" && typeof module.exports === "object") {
8
- var v = factory(require, exports);
9
- if (v !== undefined) module.exports = v;
10
- }
11
- else if (typeof define === "function" && define.amd) {
12
- define(["require", "exports", "fs", "path", "slash"], factory);
13
- }
14
- })(function (require, exports) {
15
- "use strict";
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.copyFolder = void 0;
18
- const fs_1 = __importDefault(require("fs"));
19
- const path_1 = __importDefault(require("path"));
20
- const slash_1 = __importDefault(require("slash"));
21
- const extraneousFiles = ['.DS_Store', 'Thumbs.db', 'desktop.ini'];
22
- const extraneousFolders = ['.git', 'node_modules'];
23
- const copyFolder = {
24
- cp(sourceFolder, targetFolder, options) {
25
- const defaults = {
26
- basename: null,
27
- cd: null,
28
- fileExtensions: [],
29
- };
30
- const settings = Object.assign(Object.assign({}, defaults), options);
31
- const startTime = Date.now();
32
- const normalize = (folder) => !folder ? '' : (0, slash_1.default)(path_1.default.normalize(folder)).replace(/\/$/, '');
33
- const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
34
- const source = normalize(startFolder + sourceFolder);
35
- const target = normalize(startFolder + targetFolder);
36
- if (targetFolder)
37
- fs_1.default.mkdirSync(target, { recursive: true });
38
- const errorMessage = !sourceFolder ? 'Must specify the source folder path.' :
39
- !targetFolder ? 'Must specify the target folder path.' :
40
- !fs_1.default.existsSync(source) ? 'Source folder does not exist: ' + source :
41
- !fs_1.default.existsSync(target) ? 'Target folder cannot be created: ' + target :
42
- !fs_1.default.statSync(source).isDirectory() ? 'Source is not a folder: ' + source :
43
- !fs_1.default.statSync(target).isDirectory() ? 'Target is not a folder: ' + target :
44
- null;
45
- if (errorMessage)
46
- throw Error('[copy-folder-util] ' + errorMessage);
47
- const filterOff = {
48
- base: !settings.basename,
49
- ext: !settings.fileExtensions || settings.fileExtensions.length === 0,
50
- };
51
- const files = [];
52
- const posixPath = (nativePath) => (0, slash_1.default)(nativePath.replace(/.*:/, ''));
53
- const relativePath = (fullPath, start) => fullPath.substring(fullPath.indexOf(start) + start.length + 1);
54
- const filter = (origin, dest) => {
55
- const isFile = fs_1.default.statSync(origin).isFile();
56
- const name = path_1.default.basename(origin);
57
- const ext = path_1.default.extname(origin);
58
- const keepFolder = !isFile && !extraneousFolders.includes(name);
59
- const keepFile = isFile &&
60
- (filterOff.base || name.replace(/[.].*/, '') === settings.basename) &&
61
- (filterOff.ext || settings.fileExtensions.includes(ext)) &&
62
- !extraneousFiles.includes(name);
63
- if (keepFile)
64
- files.push({
65
- origin: relativePath(posixPath(origin), source),
66
- dest: relativePath(posixPath(dest), target),
67
- });
68
- return keepFolder || keepFile;
69
- };
70
- fs_1.default.cpSync(source, target, { filter: filter, recursive: true });
71
- return {
72
- source: source,
73
- target: target,
74
- count: files.length,
75
- duration: Date.now() - startTime,
76
- files: files,
77
- };
78
- },
79
- };
80
- exports.copyFolder = copyFolder;
81
- });