Comparing version 0.0.6 to 0.0.7
declare class DirectoryCleaner { | ||
/** | ||
* Recursively deletes all contents of the directory asynchronously. | ||
* Recursively deletes all contents of the directory. | ||
* @param dirPath The path to the directory to clean. | ||
*/ | ||
cleanDirectory(dirPath: string): Promise<void>; | ||
cleanDirectory(dirPath: string): void; | ||
} | ||
export default DirectoryCleaner; |
@@ -20,4 +20,5 @@ "use strict"; | ||
// ============================================================================ | ||
var fs_1 = require("fs"); | ||
// import { promises as fsPromises } from 'fs'; | ||
var path_1 = __importDefault(require("path")); | ||
var fs_1 = __importDefault(require("fs")); | ||
// ============================================================================ | ||
@@ -28,26 +29,44 @@ // Classes | ||
/** | ||
* Recursively deletes all contents of the directory asynchronously. | ||
* Recursively deletes all contents of the directory. | ||
* @param dirPath The path to the directory to clean. | ||
*/ | ||
async cleanDirectory(dirPath) { | ||
try { | ||
const files = await fs_1.promises.readdir(dirPath); | ||
for (const file of files) { | ||
cleanDirectory(dirPath) { | ||
if (fs_1.default.existsSync(dirPath)) { | ||
fs_1.default.readdirSync(dirPath).forEach(file => { | ||
const curPath = path_1.default.join(dirPath, file); | ||
const stat = await fs_1.promises.lstat(curPath); | ||
if (stat.isDirectory()) { | ||
await this.cleanDirectory(curPath); | ||
if (fs_1.default.lstatSync(curPath).isDirectory()) { // Recurse | ||
this.cleanDirectory(curPath); | ||
} | ||
else { | ||
await fs_1.promises.unlink(curPath); | ||
else { // Delete file | ||
fs_1.default.unlinkSync(curPath); | ||
} | ||
} | ||
await fs_1.promises.rmdir(dirPath); | ||
}); | ||
fs_1.default.rmdirSync(dirPath); | ||
} | ||
catch (error) { | ||
console.error(`Error cleaning directory ${dirPath}: ${error}`); | ||
throw error; // Rethrow the error for further handling if necessary | ||
} | ||
} | ||
} | ||
// class DirectoryCleaner { | ||
// /** | ||
// * Recursively deletes all contents of the directory asynchronously. | ||
// * @param dirPath The path to the directory to clean. | ||
// */ | ||
// public async cleanDirectory(dirPath: string): Promise<void> { | ||
// try { | ||
// const files = await fsPromises.readdir(dirPath); | ||
// for (const file of files) { | ||
// const curPath = path.join(dirPath, file); | ||
// const stat = await fsPromises.lstat(curPath); | ||
// if (stat.isDirectory()) { | ||
// await this.cleanDirectory(curPath); | ||
// } else { | ||
// await fsPromises.unlink(curPath); | ||
// } | ||
// } | ||
// await fsPromises.rmdir(dirPath); | ||
// } catch (error) { | ||
// console.error(`Error cleaning directory ${dirPath}: ${error}`); | ||
// throw error; // Rethrow the error for further handling if necessary | ||
// } | ||
// } | ||
// } | ||
// ============================================================================ | ||
@@ -54,0 +73,0 @@ // Export |
import DirectoryCleaner from './class/DirectoryCleaner'; | ||
import DirectoryCopier from './class/DirectoryCopier'; | ||
import DirectoryCreator from './class/DirectoryCreator'; | ||
export { DirectoryCleaner, DirectoryCopier, DirectoryCreator, }; | ||
import FileCopier from './class/FileCopier'; | ||
import FileRenamer from './class/FileRenamer'; | ||
export { DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, }; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DirectoryCreator = exports.DirectoryCopier = exports.DirectoryCleaner = void 0; | ||
exports.FileRenamer = exports.FileCopier = exports.DirectoryCreator = exports.DirectoryCopier = exports.DirectoryCleaner = void 0; | ||
// Copyright 2023 Scape Agency BV | ||
@@ -29,1 +29,5 @@ // Licensed under the Apache License, Version 2.0 (the "License"); | ||
exports.DirectoryCreator = DirectoryCreator_1.default; | ||
var FileCopier_1 = __importDefault(require("./class/FileCopier")); | ||
exports.FileCopier = FileCopier_1.default; | ||
var FileRenamer_1 = __importDefault(require("./class/FileRenamer")); | ||
exports.FileRenamer = FileRenamer_1.default; |
{ | ||
"name": "pack.gl", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Package Builder.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -22,6 +22,6 @@ // class/DirectoryCleaner.ts | ||
import { promises as fsPromises } from 'fs'; | ||
// import { promises as fsPromises } from 'fs'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
// ============================================================================ | ||
@@ -34,30 +34,54 @@ // Classes | ||
/** | ||
* Recursively deletes all contents of the directory asynchronously. | ||
* Recursively deletes all contents of the directory. | ||
* @param dirPath The path to the directory to clean. | ||
*/ | ||
public async cleanDirectory(dirPath: string): Promise<void> { | ||
try { | ||
const files = await fsPromises.readdir(dirPath); | ||
for (const file of files) { | ||
public cleanDirectory(dirPath: string): void { | ||
if (fs.existsSync(dirPath)) { | ||
fs.readdirSync(dirPath).forEach(file => { | ||
const curPath = path.join(dirPath, file); | ||
const stat = await fsPromises.lstat(curPath); | ||
if (stat.isDirectory()) { | ||
await this.cleanDirectory(curPath); | ||
} else { | ||
await fsPromises.unlink(curPath); | ||
if (fs.lstatSync(curPath).isDirectory()) { // Recurse | ||
this.cleanDirectory(curPath); | ||
} else { // Delete file | ||
fs.unlinkSync(curPath); | ||
} | ||
} | ||
}); | ||
await fsPromises.rmdir(dirPath); | ||
} catch (error) { | ||
console.error(`Error cleaning directory ${dirPath}: ${error}`); | ||
throw error; // Rethrow the error for further handling if necessary | ||
fs.rmdirSync(dirPath); | ||
} | ||
} | ||
} | ||
// class DirectoryCleaner { | ||
// /** | ||
// * Recursively deletes all contents of the directory asynchronously. | ||
// * @param dirPath The path to the directory to clean. | ||
// */ | ||
// public async cleanDirectory(dirPath: string): Promise<void> { | ||
// try { | ||
// const files = await fsPromises.readdir(dirPath); | ||
// for (const file of files) { | ||
// const curPath = path.join(dirPath, file); | ||
// const stat = await fsPromises.lstat(curPath); | ||
// if (stat.isDirectory()) { | ||
// await this.cleanDirectory(curPath); | ||
// } else { | ||
// await fsPromises.unlink(curPath); | ||
// } | ||
// } | ||
// await fsPromises.rmdir(dirPath); | ||
// } catch (error) { | ||
// console.error(`Error cleaning directory ${dirPath}: ${error}`); | ||
// throw error; // Rethrow the error for further handling if necessary | ||
// } | ||
// } | ||
// } | ||
// ============================================================================ | ||
@@ -64,0 +88,0 @@ // Export |
@@ -27,4 +27,4 @@ // script/index.ts | ||
import DirectoryCreator from './class/DirectoryCreator'; | ||
// import FileCopier from '../../tmp/FileCopier.js'; | ||
// import FileRenamer from './class/FileRenamer.js'; | ||
import FileCopier from './class/FileCopier'; | ||
import FileRenamer from './class/FileRenamer'; | ||
@@ -59,4 +59,4 @@ // // Import | Internal Classes | ||
DirectoryCreator, | ||
// FileCopier, | ||
// FileRenamer, | ||
FileCopier, | ||
FileRenamer, | ||
@@ -63,0 +63,0 @@ // // Export | Internal Classes |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73905
31
1536
6