copy-file-util 0.0.2 → 0.1.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # copy-file-util
2
2
  <img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>
3
3
 
4
- _A file copy and rename cli tool designed for use in npm scripts_
4
+ _Copy or rename a file (CLI tool designed for use in npm scripts)_
5
5
 
6
6
  [![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/copy-file-util/blob/main/LICENSE.txt)
7
7
  [![npm](https://img.shields.io/npm/v/copy-file-util.svg)](https://www.npmjs.com/package/copy-file-util)
@@ -70,8 +70,12 @@ See the **TypeScript Declaration File** file [copy-file.d.ts](dist/copy-file.d.t
70
70
 
71
71
  ---
72
72
  **Build Tools**
73
- - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Adds a header comment to a file and saves it to your distribution folder_
74
- - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _A file copy and rename cli tool designed for use in npm scripts_
75
- - 📂 [copy-folder-cli](https://github.com/center-key/copy-folder-cli):&nbsp; _A recursive directory file copy utility designed for use in npm scripts_
73
+ - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line header comment (with license notice) to distribution files_
74
+ - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file (CLI tool designed for use in npm scripts)_
75
+ - 📂 [copy-folder-cli](https://github.com/center-key/copy-folder-cli):&nbsp; _Recursively copy a folder (CLI tool designed for use in npm scripts)_
76
+ - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):&nbsp; _Check the markup validity of HTML files using the W3C validator_
77
+
78
+ Feel free to submit questions at:<br>
79
+ [github.com/center-key/copy-file-util/issues](https://github.com/center-key/copy-file-util/issues)
76
80
 
77
81
  [MIT License](LICENSE.txt)
package/bin/cli.js CHANGED
@@ -17,7 +17,7 @@
17
17
  // $ cd copy-file-util
18
18
  // $ npm install
19
19
  // $ npm test
20
- // $ node bin/cli.js spec/fixtures/source/mock.txt --folder spec/fixtures/target/to-folder
20
+ // $ node bin/cli.js --cd=spec/fixtures source/mock.txt --folder target/to-folder
21
21
 
22
22
  // Imports
23
23
  import { copyFile } from '../dist/copy-file.js';
@@ -25,7 +25,7 @@ import chalk from 'chalk';
25
25
  import log from 'fancy-log';
26
26
 
27
27
  // Parameters
28
- const validFlags = ['folder', 'quiet'];
28
+ const validFlags = ['cd', 'folder', 'quiet'];
29
29
  const args = process.argv.slice(2);
30
30
  const flags = args.filter(arg => /^--/.test(arg));
31
31
  const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^--/, '').split('=')));
@@ -44,7 +44,6 @@ const printReport = (result) => {
44
44
  };
45
45
 
46
46
  // Copy File
47
- const exit = (message) => (console.error('[copy-file]', message), process.exit(1));
48
47
  const invalidFlag = Object.keys(flagMap).find(key => !validFlags.includes(key));
49
48
  const mode = { folder: 'folder' in flagMap, quiet: 'quiet' in flagMap };
50
49
  const error =
@@ -55,8 +54,12 @@ const error =
55
54
  !target ? 'Missing target file.' :
56
55
  null;
57
56
  if (error)
58
- exit(error);
59
- const options = mode.folder ? { targetFolder: target } : { targetFile: target };
57
+ throw Error('[copy-file] ' + error);
58
+ const targetKey = mode.folder ? 'targetFolder' : 'targetFile';
59
+ const options = {
60
+ cd: flagMap.cd ?? null,
61
+ [targetKey]: target,
62
+ };
60
63
  const result = copyFile.cp(source, options);
61
64
  if (!mode.quiet)
62
65
  printReport(result);
@@ -1,6 +1,7 @@
1
- //! copy-file-util v0.0.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  export declare type Options = {
4
+ cd?: string;
4
5
  targetFile?: string;
5
6
  targetFolder?: string;
6
7
  fileExtension?: string;
package/dist/copy-file.js CHANGED
@@ -1,4 +1,4 @@
1
- //! copy-file-util v0.0.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
@@ -7,6 +7,7 @@ const copyFile = {
7
7
  cp(sourceFile, options) {
8
8
  var _a;
9
9
  const defaults = {
10
+ cd: null,
10
11
  targetFile: null,
11
12
  targetFolder: null,
12
13
  fileExtension: null,
@@ -16,11 +17,14 @@ const copyFile = {
16
17
  const missingTarget = !settings.targetFile && !settings.targetFolder;
17
18
  const ambiguousTarget = !!settings.targetFile && !!settings.targetFolder;
18
19
  const normalize = (folder) => !folder ? '' : slash(path.normalize(folder)).replace(/\/$/, '');
19
- const source = normalize(sourceFile);
20
+ const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
21
+ const source = normalize(startFolder + sourceFile);
20
22
  const sourceExists = fs.pathExistsSync(source);
21
23
  const sourceIsFile = sourceExists && fs.statSync(source).isFile();
22
- const targetFolder = normalize(settings.targetFile ? path.dirname(settings.targetFile) : settings.targetFolder);
23
- const target = normalize((_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + path.basename(source));
24
+ const targetPath = settings.targetFile ? path.dirname(settings.targetFile) : settings.targetFolder;
25
+ const targetFolder = normalize(startFolder + targetPath);
26
+ const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + path.basename(source);
27
+ const target = normalize(startFolder + targetFile);
24
28
  if (targetFolder)
25
29
  fs.ensureDirSync(targetFolder);
26
30
  const badTargetFolder = !fs.pathExistsSync(targetFolder);
@@ -1,4 +1,4 @@
1
- //! copy-file-util v0.0.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.0 ~~ 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 };
@@ -22,6 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  cp(sourceFile, options) {
23
23
  var _a;
24
24
  const defaults = {
25
+ cd: null,
25
26
  targetFile: null,
26
27
  targetFolder: null,
27
28
  fileExtension: null,
@@ -31,11 +32,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
32
  const missingTarget = !settings.targetFile && !settings.targetFolder;
32
33
  const ambiguousTarget = !!settings.targetFile && !!settings.targetFolder;
33
34
  const normalize = (folder) => !folder ? '' : (0, slash_1.default)(path_1.default.normalize(folder)).replace(/\/$/, '');
34
- const source = normalize(sourceFile);
35
+ const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
36
+ const source = normalize(startFolder + sourceFile);
35
37
  const sourceExists = fs_extra_1.default.pathExistsSync(source);
36
38
  const sourceIsFile = sourceExists && fs_extra_1.default.statSync(source).isFile();
37
- const targetFolder = normalize(settings.targetFile ? path_1.default.dirname(settings.targetFile) : settings.targetFolder);
38
- const target = normalize((_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + path_1.default.basename(source));
39
+ const targetPath = settings.targetFile ? path_1.default.dirname(settings.targetFile) : settings.targetFolder;
40
+ const targetFolder = normalize(startFolder + targetPath);
41
+ const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + path_1.default.basename(source);
42
+ const target = normalize(startFolder + targetFile);
39
43
  if (targetFolder)
40
44
  fs_extra_1.default.ensureDirSync(targetFolder);
41
45
  const badTargetFolder = !fs_extra_1.default.pathExistsSync(targetFolder);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "0.0.2",
4
- "description": "A file copy and rename cli tool designed for use in npm scripts (written in functional TypeScript)",
3
+ "version": "0.1.0",
4
+ "description": "Copy or rename a file (CLI tool designed for use in npm scripts)",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "module": "dist/copy-file.js",
@@ -69,8 +69,7 @@
69
69
  "step:04": "tsc",
70
70
  "step:05": "tsc --module UMD --outDir build/umd",
71
71
  "step:06": "cpy build/umd/copy-file.js build --rename=copy-file.umd.cjs --flat=true",
72
- "step:07": "cpy build/copy-file.* dist --flat=true",
73
- "step:08": "add-dist-header build dist",
72
+ "step:07": "add-dist-header build dist",
74
73
  "pretest": "npm-run-all step:*",
75
74
  "test": "mocha spec/*.spec.js"
76
75
  },