Skip to content

Commit

Permalink
v0.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 3, 2024
1 parent 33425ec commit 102f517
Show file tree
Hide file tree
Showing 40 changed files with 1,016 additions and 340 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.10
0.0.11
4 changes: 2 additions & 2 deletions dist/js/class/DirectoryCleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
// Import
// ============================================================================
// import { promises as fsPromises } from 'fs';
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
// ============================================================================
// Classes
// ============================================================================
Expand Down
59 changes: 36 additions & 23 deletions dist/js/class/DirectoryCopier.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
"use strict";
// class/DirectoryCopier.ts
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Expand All @@ -17,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
var path_1 = __importDefault(require("path"));
var fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const fs_1 = require("fs");
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -32,33 +41,37 @@ class DirectoryCopier {
* @param destDir The destination directory path.
* @throws Will throw an error if copying fails for any file or directory.
*/
async copyFiles(srcDir, destDir) {
try {
const resolvedSrcDir = path_1.default.resolve(srcDir);
const resolvedDestDir = path_1.default.resolve(destDir);
await this.recursiveCopy(resolvedSrcDir, resolvedDestDir);
console.log(`Files copied from ${resolvedSrcDir} to ${resolvedDestDir}`);
}
catch (error) {
console.error('Error copying files:', error);
throw error;
}
copyFiles(srcDir, destDir) {
return __awaiter(this, void 0, void 0, function* () {
try {
const resolvedSrcDir = path_1.default.resolve(srcDir);
const resolvedDestDir = path_1.default.resolve(destDir);
yield this.recursiveCopy(resolvedSrcDir, resolvedDestDir);
console.log(`Files copied from ${resolvedSrcDir} to ${resolvedDestDir}`);
}
catch (error) {
console.error('Error copying files:', error);
throw error;
}
});
}
/**
* Recursively copies files and directories.
* @param srcDir Source directory.
* @param destDir Destination directory.
*/
async recursiveCopy(srcDir, destDir) {
await fs_1.promises.mkdir(destDir, { recursive: true });
const entries = await fs_1.promises.readdir(srcDir, { withFileTypes: true });
for (let entry of entries) {
const srcPath = path_1.default.join(srcDir, entry.name);
const destPath = path_1.default.join(destDir, entry.name);
entry.isDirectory() ?
await this.recursiveCopy(srcPath, destPath) :
await fs_1.promises.copyFile(srcPath, destPath);
}
recursiveCopy(srcDir, destDir) {
return __awaiter(this, void 0, void 0, function* () {
yield fs_1.promises.mkdir(destDir, { recursive: true });
const entries = yield fs_1.promises.readdir(srcDir, { withFileTypes: true });
for (let entry of entries) {
const srcPath = path_1.default.join(srcDir, entry.name);
const destPath = path_1.default.join(destDir, entry.name);
entry.isDirectory() ?
yield this.recursiveCopy(srcPath, destPath) :
yield fs_1.promises.copyFile(srcPath, destPath);
}
});
}
}
// ============================================================================
Expand Down
37 changes: 24 additions & 13 deletions dist/js/class/DirectoryCreator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
"use strict";
// class/DirectoryGenerator.ts
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Expand All @@ -17,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
var fs_1 = require("fs");
var path_1 = __importDefault(require("path"));
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -37,18 +46,20 @@ class DirectoryCreator {
* available before performing file operations.
* @throws Will throw an error if directory creation fails.
*/
async createDirectories(basePath, directories) {
try {
for (const dir of directories) {
const dirPath = path_1.default.join(basePath, dir);
await fs_1.promises.mkdir(dirPath, { recursive: true });
console.log(`Directory created or already exists: ${dirPath}`);
createDirectories(basePath, directories) {
return __awaiter(this, void 0, void 0, function* () {
try {
for (const dir of directories) {
const dirPath = path_1.default.join(basePath, dir);
yield fs_1.promises.mkdir(dirPath, { recursive: true });
console.log(`Directory created or already exists: ${dirPath}`);
}
}
catch (error) {
console.error(`Error creating directories: ${error}`);
throw error;
}
}
catch (error) {
console.error(`Error creating directories: ${error}`);
throw error;
}
});
}
}
// ============================================================================
Expand Down
37 changes: 24 additions & 13 deletions dist/js/class/FileCopier.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
"use strict";
// class/FileCopier.ts
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Expand All @@ -17,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -32,17 +41,19 @@ class FileCopier {
* @param {string} destDir - The destination directory where the file should be copied.
* @throws Will throw an error if the file copy operation fails.
*/
async copyFileToDirectory(srcFile, destDir) {
try {
const fileName = path_1.default.basename(srcFile);
const destFilePath = path_1.default.join(destDir, fileName);
await fs_1.default.promises.copyFile(srcFile, destFilePath);
console.log(`File copied from ${srcFile} to ${destFilePath}`);
}
catch (error) {
console.error('Error copying file:', error);
throw error;
}
copyFileToDirectory(srcFile, destDir) {
return __awaiter(this, void 0, void 0, function* () {
try {
const fileName = path_1.default.basename(srcFile);
const destFilePath = path_1.default.join(destDir, fileName);
yield fs_1.default.promises.copyFile(srcFile, destFilePath);
console.log(`File copied from ${srcFile} to ${destFilePath}`);
}
catch (error) {
console.error('Error copying file:', error);
throw error;
}
});
}
}
// ============================================================================
Expand Down
31 changes: 21 additions & 10 deletions dist/js/class/FileRenamer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
"use strict";
// class/FileRenamer.ts
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Expand All @@ -17,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
var fs_1 = __importDefault(require("fs"));
const fs_1 = __importDefault(require("fs"));
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -31,15 +40,17 @@ class FileRenamer {
* @param targetPath The new path of the file after renaming.
* @returns Promise<void>
*/
async renameFile(srcPath, targetPath) {
try {
await fs_1.default.promises.rename(srcPath, targetPath);
console.log(`File renamed from ${srcPath} to ${targetPath}`);
}
catch (error) {
console.error('Error renaming file:', error);
throw error;
}
renameFile(srcPath, targetPath) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield fs_1.default.promises.rename(srcPath, targetPath);
console.log(`File renamed from ${srcPath} to ${targetPath}`);
}
catch (error) {
console.error('Error renaming file:', error);
throw error;
}
});
}
}
// ============================================================================
Expand Down
Loading

0 comments on commit 102f517

Please sign in to comment.