Skip to content

Commit

Permalink
Release v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Aug 21, 2023
1 parent 3c8ab91 commit 367eda5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
9 changes: 5 additions & 4 deletions dist/copy-file.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//! copy-file-util v1.1.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
//! copy-file-util v1.1.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License

export type Settings = {
export type Options = {
cd: string;
targetFile: string;
targetFolder: string;
fileExtension: string;
move: boolean;
};
export type Options = Partial<Settings>;
export type Result = {
origin: string;
dest: string;
duration: number;
moved: boolean;
};
declare const copyFile: {
cp(sourceFile: string, options: Options): Result;
cp(sourceFile: string, options: Partial<Options>): Result;
};
export { copyFile };
14 changes: 9 additions & 5 deletions dist/copy-file.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//! copy-file-util v1.1.0 ~~ https://github.com/center-key/copy-file-util ~~ MIT License
//! copy-file-util v1.1.1 ~~ https://github.com/center-key/copy-file-util ~~ MIT License

import fs from 'fs';
import path from 'path';
import slash from 'slash';
const copyFile = {
cp(sourceFile, options) {
var _a;
const defaults = {
cd: null,
targetFile: null,
targetFolder: null,
fileExtension: null,
move: false,
};
const settings = Object.assign(Object.assign({}, defaults), options);
const settings = { ...defaults, ...options };
const startTime = Date.now();
const missingTarget = !settings.targetFile && !settings.targetFolder;
const ambiguousTarget = !!settings.targetFile && !!settings.targetFolder;
Expand All @@ -24,7 +24,7 @@ const copyFile = {
const sourceFilename = sourceIsFile ? path.basename(source) : null;
const targetPath = settings.targetFile ? path.dirname(settings.targetFile) : settings.targetFolder;
const targetFolder = targetPath ? normalize(startFolder + targetPath) : null;
const targetFile = (_a = settings.targetFile) !== null && _a !== void 0 ? _a : settings.targetFolder + '/' + sourceFilename;
const targetFile = settings.targetFile ?? settings.targetFolder + '/' + sourceFilename;
const target = normalize(startFolder + targetFile);
if (targetFolder)
fs.mkdirSync(targetFolder, { recursive: true });
Expand All @@ -39,10 +39,14 @@ const copyFile = {
null;
if (errorMessage)
throw Error('[copy-file-util] ' + errorMessage);
fs.copyFileSync(source, target);
if (settings.move)
fs.renameSync(source, target);
else
fs.copyFileSync(source, target);
return {
origin: source,
dest: target,
moved: settings.move,
duration: Date.now() - startTime,
};
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "copy-file-util",
"version": "1.1.0",
"version": "1.1.1",
"description": "Copy or rename a file with optional package version number (CLI tool designed for use in npm scripts)",
"license": "MIT",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2016",
"target": "ES2021",
"module": "ES2020",
"moduleResolution": "node",
"declaration": true,
Expand Down

0 comments on commit 367eda5

Please sign in to comment.