From 5fc834c47527657030726be7cfb23e8caa784357 Mon Sep 17 00:00:00 2001 From: dpilafian Date: Sun, 17 Mar 2024 01:09:06 -0700 Subject: [PATCH] Release v1.2.0 #1 --- dist/copy-file.d.ts | 4 +++- dist/copy-file.js | 13 +++++++++---- package.json | 2 +- ...-util-v1.1.3.html => copy-file-util-v1.2.0.html} | 0 4 files changed, 13 insertions(+), 6 deletions(-) rename spec/fixtures/target/module/{copy-file-util-v1.1.3.html => copy-file-util-v1.2.0.html} (100%) diff --git a/dist/copy-file.d.ts b/dist/copy-file.d.ts index 9d8eaa1..d146ed8 100644 --- a/dist/copy-file.d.ts +++ b/dist/copy-file.d.ts @@ -1,4 +1,4 @@ -//! copy-file-util v1.1.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License +//! copy-file-util v1.2.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License export type Settings = { cd: string; @@ -6,12 +6,14 @@ export type Settings = { targetFolder: string; fileExtension: string; move: boolean; + overwrite: boolean; }; export type Result = { origin: string; dest: string; duration: number; moved: boolean; + skipped: boolean; }; declare const copyFile: { cp(sourceFile: string, options?: Partial): Result; diff --git a/dist/copy-file.js b/dist/copy-file.js index 6a3b51b..5ced7cd 100644 --- a/dist/copy-file.js +++ b/dist/copy-file.js @@ -1,4 +1,4 @@ -//! copy-file-util v1.1.3 ~~ https://github.com/center-key/copy-file-util ~~ MIT License +//! copy-file-util v1.2.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License import chalk from 'chalk'; import fs from 'fs'; @@ -13,6 +13,7 @@ const copyFile = { targetFolder: null, fileExtension: null, move: false, + overwrite: true, }; const settings = { ...defaults, ...options }; const startTime = Date.now(); @@ -28,6 +29,8 @@ const copyFile = { const targetFolder = targetPath ? normalize(startFolder + targetPath) : null; const targetFile = settings.targetFile ?? settings.targetFolder + '/' + sourceFilename; const target = normalize(startFolder + targetFile); + const targetExists = !missingTarget && fs.existsSync(target); + const skip = targetExists && !settings.overwrite; if (targetFolder) fs.mkdirSync(targetFolder, { recursive: true }); const badTargetFolder = !targetFolder || !fs.existsSync(targetFolder); @@ -41,14 +44,15 @@ const copyFile = { null; if (errorMessage) throw Error('[copy-file-util] ' + errorMessage); - if (settings.move) + if (!skip && settings.move) fs.renameSync(source, target); - else + else if (!skip) fs.copyFileSync(source, target); return { origin: source, dest: target, moved: settings.move, + skipped: skip, duration: Date.now() - startTime, }; }, @@ -57,7 +61,8 @@ const copyFile = { const origin = chalk.blue.bold(result.origin); const dest = chalk.magenta(result.dest); const arrow = chalk.gray.bold('→'); - const info = chalk.white(`(${result.duration}ms${result.moved ? ', move' : ''})`); + const status = result.skipped ? ', skip -- target exists' : result.moved ? ', move' : ''; + const info = chalk.white(`(${result.duration}ms${status})`); log(name, origin, arrow, dest, info); return result; }, diff --git a/package.json b/package.json index 3bd5233..8c28928 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "copy-file-util", - "version": "1.1.3", + "version": "1.2.0", "description": "Copy or rename a file with optional package version number (CLI tool designed for use in npm package.json scripts)", "license": "MIT", "type": "module", diff --git a/spec/fixtures/target/module/copy-file-util-v1.1.3.html b/spec/fixtures/target/module/copy-file-util-v1.2.0.html similarity index 100% rename from spec/fixtures/target/module/copy-file-util-v1.1.3.html rename to spec/fixtures/target/module/copy-file-util-v1.2.0.html