Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
7a32835a74 | |||
e78682d9b4 | |||
8dceea67be | |||
40018532a7 |
12
changelog.md
12
changelog.md
@ -1,5 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-01-29 - 11.2.0 - feat(fs)
|
||||
Enhanced copy method with optional replaceTargetDir option for directory replacement
|
||||
|
||||
- Added optional 'replaceTargetDir' option to 'copy' and 'copySync' methods in 'fs.ts'.
|
||||
- The 'replaceTargetDir' option allows replacing the target directory if both source and target are directories.
|
||||
|
||||
## 2025-01-29 - 11.1.9 - fix(fs)
|
||||
Fix directory handling in copy and copySync functions
|
||||
|
||||
- Ensured existing directories at destination are removed before copying over them in async copy.
|
||||
- Added a similar check and handling for synchronous copySync when destination is a directory.
|
||||
|
||||
## 2025-01-29 - 11.1.8 - fix(fs)
|
||||
Fixed copy and copySync functions to ensure they always overwrite files.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@push.rocks/smartfile",
|
||||
"private": false,
|
||||
"version": "11.1.8",
|
||||
"version": "11.2.0",
|
||||
"description": "Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartfile',
|
||||
version: '11.1.8',
|
||||
version: '11.2.0',
|
||||
description: 'Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.'
|
||||
}
|
||||
|
14
ts/fs.ts
14
ts/fs.ts
@ -74,15 +74,21 @@ export const isFile = (pathArg): boolean => {
|
||||
/**
|
||||
* copies a file or directory from A to B on the local disk
|
||||
*/
|
||||
export const copy = async (fromArg: string, toArg: string): Promise<void> => {
|
||||
return await plugins.fsExtra.copy(fromArg, toArg, {overwrite: true});
|
||||
export const copy = async (fromArg: string, toArg: string, optionsArg?: plugins.fsExtra.CopyOptions & { replaceTargetDir?: boolean }): Promise<void> => {
|
||||
if (optionsArg?.replaceTargetDir && isDirectory(fromArg) && isDirectory(toArg)) {
|
||||
await remove(toArg);
|
||||
}
|
||||
return await plugins.fsExtra.copy(fromArg, toArg, optionsArg as plugins.fsExtra.CopyOptions);
|
||||
};
|
||||
|
||||
/**
|
||||
* copies a file or directory SYNCHRONOUSLY from A to B on the local disk
|
||||
*/
|
||||
export const copySync = (fromArg: string, toArg: string): void => {
|
||||
return plugins.fsExtra.copySync(fromArg, toArg, {overwrite: true});
|
||||
export const copySync = (fromArg: string, toArg: string, optionsArg?: plugins.fsExtra.CopyOptionsSync & { replaceTargetDir?: boolean }): void => {
|
||||
if (optionsArg?.replaceTargetDir && isDirectory(fromArg) && isDirectory(toArg)) {
|
||||
removeSync(toArg);
|
||||
}
|
||||
return plugins.fsExtra.copySync(fromArg, toArg, optionsArg as plugins.fsExtra.CopyOptionsSync);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user