Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
d557e4b4fe | |||
16ded5c3cf | |||
a2bd049ebd | |||
f95c5c9a15 |
11
changelog.md
11
changelog.md
@ -1,5 +1,16 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-01-07 - 11.1.0 - feat(SmartFile)
|
||||||
|
Add rename functionality to SmartFile class
|
||||||
|
|
||||||
|
- Implemented a new method to rename a file within the SmartFile class.
|
||||||
|
- The rename method updates the file path and optionally writes the renamed file to the disk.
|
||||||
|
|
||||||
|
## 2024-12-15 - 11.0.23 - fix(fs)
|
||||||
|
Handle errors in toObjectSync method
|
||||||
|
|
||||||
|
- Added error handling in toObjectSync function to capture and provide more informative error messages.
|
||||||
|
|
||||||
## 2024-06-23 - 11.0.22 - fix(core)
|
## 2024-06-23 - 11.0.22 - fix(core)
|
||||||
Update dependencies and changelog
|
Update dependencies and changelog
|
||||||
|
|
||||||
|
20
package.json
20
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartfile",
|
"name": "@push.rocks/smartfile",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "11.0.22",
|
"version": "11.1.0",
|
||||||
"description": "Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.",
|
"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",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
@ -42,29 +42,29 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/smartfile",
|
"homepage": "https://code.foss.global/push.rocks/smartfile",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/lik": "^6.0.15",
|
"@push.rocks/lik": "^6.1.0",
|
||||||
"@push.rocks/smartdelay": "^3.0.5",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@push.rocks/smartfile-interfaces": "^1.0.7",
|
"@push.rocks/smartfile-interfaces": "^1.0.7",
|
||||||
"@push.rocks/smarthash": "^3.0.4",
|
"@push.rocks/smarthash": "^3.0.4",
|
||||||
"@push.rocks/smartjson": "^5.0.20",
|
"@push.rocks/smartjson": "^5.0.20",
|
||||||
"@push.rocks/smartmime": "^2.0.2",
|
"@push.rocks/smartmime": "^2.0.4",
|
||||||
"@push.rocks/smartpath": "^5.0.18",
|
"@push.rocks/smartpath": "^5.0.18",
|
||||||
"@push.rocks/smartpromise": "^4.0.4",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
"@push.rocks/smartrequest": "^2.0.22",
|
"@push.rocks/smartrequest": "^2.0.23",
|
||||||
"@push.rocks/smartstream": "^3.0.44",
|
"@push.rocks/smartstream": "^3.2.5",
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/glob": "^8.1.0",
|
"@types/glob": "^8.1.0",
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"glob": "^10.4.2",
|
"glob": "^11.0.0",
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.80",
|
"@git.zone/tsbuild": "^2.2.0",
|
||||||
"@git.zone/tsrun": "^1.2.46",
|
"@git.zone/tsrun": "^1.3.3",
|
||||||
"@git.zone/tstest": "^1.0.90",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"@push.rocks/tapbundle": "^5.0.23",
|
"@push.rocks/tapbundle": "^5.5.3",
|
||||||
"@types/node": "^20.14.8"
|
"@types/node": "^22.10.2"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
4337
pnpm-lock.yaml
generated
4337
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartfile',
|
name: '@push.rocks/smartfile',
|
||||||
version: '11.0.22',
|
version: '11.1.0',
|
||||||
description: 'Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.'
|
description: 'Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.'
|
||||||
}
|
}
|
||||||
|
@ -212,6 +212,43 @@ export class SmartFile extends plugins.smartjson.Smartjson {
|
|||||||
await fs.remove(plugins.path.join(this.base, this.path));
|
await fs.remove(plugins.path.join(this.base, this.path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames the file to the specified new name.
|
||||||
|
* - Updates the `path` property with the new name.
|
||||||
|
* - Writes the file to the new location if it exists on disk.
|
||||||
|
* @param newName The new name of the file (including extension if applicable).
|
||||||
|
* @param writeToDisk (optional) If true, also renames the file on the disk.
|
||||||
|
* @returns The updated file path after renaming.
|
||||||
|
*/
|
||||||
|
public async rename(newName: string, writeToDisk: boolean = false): Promise<string> {
|
||||||
|
// Validate the new name
|
||||||
|
if (!newName || typeof newName !== 'string') {
|
||||||
|
throw new Error('Invalid new name provided.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the directory path
|
||||||
|
const oldFilePath = this.path;
|
||||||
|
const dirPath = plugins.path.dirname(this.path);
|
||||||
|
|
||||||
|
// Create the new file path
|
||||||
|
const newFilePath = plugins.path.join(dirPath, newName);
|
||||||
|
|
||||||
|
// Update the `path` property
|
||||||
|
this.path = newFilePath;
|
||||||
|
|
||||||
|
// Optionally write the renamed file to disk
|
||||||
|
if (writeToDisk) {
|
||||||
|
const oldAbsolutePath = plugins.smartpath.transform.makeAbsolute(oldFilePath, this.base);
|
||||||
|
const newAbsolutePath = plugins.smartpath.transform.makeAbsolute(newFilePath, this.base);
|
||||||
|
|
||||||
|
// Rename the file on disk
|
||||||
|
await plugins.fsExtra.rename(oldAbsolutePath, newAbsolutePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the new path
|
||||||
|
return this.path;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
// vinyl compatibility
|
// vinyl compatibility
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
|
5
ts/fs.ts
5
ts/fs.ts
@ -200,7 +200,12 @@ export const toObjectSync = (filePathArg, fileTypeArg?) => {
|
|||||||
const fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
|
const fileString = plugins.fsExtra.readFileSync(filePathArg, 'utf8');
|
||||||
let fileType;
|
let fileType;
|
||||||
fileTypeArg ? (fileType = fileTypeArg) : (fileType = interpreter.filetype(filePathArg));
|
fileTypeArg ? (fileType = fileTypeArg) : (fileType = interpreter.filetype(filePathArg));
|
||||||
|
try {
|
||||||
return interpreter.objectFile(fileString, fileType);
|
return interpreter.objectFile(fileString, fileType);
|
||||||
|
} catch (err) {
|
||||||
|
err.message = `Failed to read file at ${filePathArg}` + err.message;
|
||||||
|
throw err;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user