Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
7a32835a74 | |||
e78682d9b4 | |||
8dceea67be | |||
40018532a7 | |||
f6fb28d32f | |||
2d1ac0bd50 | |||
04a25221a5 | |||
13081b7344 | |||
0abbe8bbd7 | |||
de2a250a45 |
30
changelog.md
30
changelog.md
@ -1,5 +1,35 @@
|
||||
# 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.
|
||||
|
||||
- Fixed bug in copy function where files were not being overwritten when they already existed at the destination.
|
||||
- Fixed bug in copySync function to ensure files are overwritten to match the async function's behavior.
|
||||
|
||||
## 2025-01-29 - 11.1.7 - fix(fs)
|
||||
Refactor copy and copySync functions to simplify return type
|
||||
|
||||
- Changed the return type of fs.copy and fs.copySync from boolean to void.
|
||||
- Removed unnecessary promise handling in fs.copy.
|
||||
|
||||
## 2025-01-29 - 11.1.6 - fix(fs)
|
||||
Fix issues with fs file copy functions.
|
||||
|
||||
- Updated dependencies in package.json.
|
||||
- Corrected comments for asynchronous and synchronous file copy functions in fs.ts.
|
||||
|
||||
## 2025-01-07 - 11.1.5 - fix(fs)
|
||||
Improve waitForFileToBeReady function to handle directories and file stabilization
|
||||
|
||||
|
16
package.json
16
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@push.rocks/smartfile",
|
||||
"private": false,
|
||||
"version": "11.1.5",
|
||||
"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",
|
||||
@ -49,22 +49,22 @@
|
||||
"@push.rocks/smartjson": "^5.0.20",
|
||||
"@push.rocks/smartmime": "^2.0.4",
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
"@push.rocks/smartpromise": "^4.1.0",
|
||||
"@push.rocks/smartpromise": "^4.2.2",
|
||||
"@push.rocks/smartrequest": "^2.0.23",
|
||||
"@push.rocks/smartstream": "^3.2.5",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/glob": "^8.1.0",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"fs-extra": "^11.2.0",
|
||||
"glob": "^11.0.0",
|
||||
"fs-extra": "^11.3.0",
|
||||
"glob": "^11.0.1",
|
||||
"js-yaml": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.2.0",
|
||||
"@git.zone/tsbuild": "^2.2.1",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/tapbundle": "^5.5.4",
|
||||
"@types/node": "^22.10.5"
|
||||
"@git.zone/tstest": "^1.0.96",
|
||||
"@push.rocks/tapbundle": "^5.5.6",
|
||||
"@types/node": "^22.12.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
4748
pnpm-lock.yaml
generated
4748
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartfile',
|
||||
version: '11.1.5',
|
||||
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.'
|
||||
}
|
||||
|
26
ts/fs.ts
26
ts/fs.ts
@ -72,25 +72,23 @@ export const isFile = (pathArg): boolean => {
|
||||
===============================================================*/
|
||||
|
||||
/**
|
||||
* copies a file from A to B on the local disk
|
||||
* copies a file or directory from A to B on the local disk
|
||||
*/
|
||||
export const copy = async (fromArg: string, toArg: string): Promise<boolean> => {
|
||||
const done = plugins.smartpromise.defer<boolean>();
|
||||
plugins.fsExtra.copy(fromArg, toArg, {}, (err) => {
|
||||
if (err) {
|
||||
throw new Error(`Could not copy from ${fromArg} to ${toArg}: ${err}`);
|
||||
}
|
||||
done.resolve(true);
|
||||
});
|
||||
return done.promise;
|
||||
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 SYNCHRONOUSLY from A to B on the local disk
|
||||
* copies a file or directory SYNCHRONOUSLY from A to B on the local disk
|
||||
*/
|
||||
export const copySync = (fromArg: string, toArg: string): boolean => {
|
||||
plugins.fsExtra.copySync(fromArg, toArg);
|
||||
return 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