copy-file-util 0.1.1 → 0.1.2

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
@@ -32,6 +32,9 @@ Example **package.json** scripts:
32
32
  ```
33
33
  Try out the first script with the command: `npm run pub-license`
34
34
 
35
+ <img src=https://raw.githubusercontent.com/center-key/copy-file-util/main/screenshot.png
36
+ width=800 alt=screenshot>
37
+
35
38
  ### 2. Global
36
39
  You can install **copy-file-util** globally and then run it anywhere directly from the terminal.
37
40
 
@@ -1,4 +1,4 @@
1
- //! copy-file-util v0.1.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.2 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
2
2
 
3
3
  export declare type Options = {
4
4
  cd?: string;
package/dist/copy-file.js CHANGED
@@ -1,4 +1,4 @@
1
- //! copy-file-util v0.1.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.2 ~~ 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';
@@ -18,16 +18,17 @@ const copyFile = {
18
18
  const ambiguousTarget = !!settings.targetFile && !!settings.targetFolder;
19
19
  const normalize = (folder) => !folder ? '' : slash(path.normalize(folder)).replace(/\/$/, '');
20
20
  const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
21
- const source = normalize(startFolder + sourceFile);
22
- const sourceExists = fs.pathExistsSync(source);
21
+ const source = sourceFile ? normalize(startFolder + sourceFile) : '';
22
+ const sourceExists = source && fs.pathExistsSync(source);
23
23
  const sourceIsFile = sourceExists && fs.statSync(source).isFile();
24
+ const sourceFilename = sourceIsFile ? path.basename(source) : null;
24
25
  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);
26
+ const targetFolder = targetPath ? normalize(startFolder + targetPath) : null;
27
+ const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + sourceFilename;
27
28
  const target = normalize(startFolder + targetFile);
28
29
  if (targetFolder)
29
30
  fs.ensureDirSync(targetFolder);
30
- const badTargetFolder = !fs.pathExistsSync(targetFolder);
31
+ const badTargetFolder = !targetFolder || !fs.pathExistsSync(targetFolder);
31
32
  const errorMessage = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
32
33
  !sourceFile ? 'Must specify the source file.' :
33
34
  !sourceExists ? 'Source file does not exist: ' + source :
@@ -1,4 +1,4 @@
1
- //! copy-file-util v0.1.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
1
+ //! copy-file-util v0.1.2 ~~ 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 };
@@ -33,16 +33,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  const ambiguousTarget = !!settings.targetFile && !!settings.targetFolder;
34
34
  const normalize = (folder) => !folder ? '' : (0, slash_1.default)(path_1.default.normalize(folder)).replace(/\/$/, '');
35
35
  const startFolder = settings.cd ? normalize(settings.cd) + '/' : '';
36
- const source = normalize(startFolder + sourceFile);
37
- const sourceExists = fs_extra_1.default.pathExistsSync(source);
36
+ const source = sourceFile ? normalize(startFolder + sourceFile) : '';
37
+ const sourceExists = source && fs_extra_1.default.pathExistsSync(source);
38
38
  const sourceIsFile = sourceExists && fs_extra_1.default.statSync(source).isFile();
39
+ const sourceFilename = sourceIsFile ? path_1.default.basename(source) : null;
39
40
  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);
41
+ const targetFolder = targetPath ? normalize(startFolder + targetPath) : null;
42
+ const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + sourceFilename;
42
43
  const target = normalize(startFolder + targetFile);
43
44
  if (targetFolder)
44
45
  fs_extra_1.default.ensureDirSync(targetFolder);
45
- const badTargetFolder = !fs_extra_1.default.pathExistsSync(targetFolder);
46
+ const badTargetFolder = !targetFolder || !fs_extra_1.default.pathExistsSync(targetFolder);
46
47
  const errorMessage = settings.fileExtension ? 'Option "fileExtension" not yet implemented.' :
47
48
  !sourceFile ? 'Must specify the source file.' :
48
49
  !sourceExists ? 'Source file does not exist: ' + source :
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copy-file-util",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Copy or rename a file (CLI tool designed for use in npm scripts)",
5
5
  "license": "MIT",
6
6
  "type": "module",