Skip to content

Commit

Permalink
v0.0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 3, 2024
1 parent 102f517 commit f50b1f8
Show file tree
Hide file tree
Showing 38 changed files with 1,044 additions and 802 deletions.
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';
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
// ============================================================================
// Classes
// ============================================================================
Expand Down
59 changes: 23 additions & 36 deletions dist/js/class/DirectoryCopier.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
"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 @@ -26,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
const path_1 = __importDefault(require("path"));
const fs_1 = require("fs");
var path_1 = __importDefault(require("path"));
var fs_1 = require("fs");
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -41,37 +32,33 @@ class DirectoryCopier {
* @param destDir The destination directory path.
* @throws Will throw an error if copying fails for any file or directory.
*/
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;
}
});
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;
}
}
/**
* Recursively copies files and directories.
* @param srcDir Source directory.
* @param destDir Destination directory.
*/
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);
}
});
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);
}
}
}
// ============================================================================
Expand Down
37 changes: 13 additions & 24 deletions dist/js/class/DirectoryCreator.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
"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 @@ -26,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
var fs_1 = require("fs");
var path_1 = __importDefault(require("path"));
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -46,20 +37,18 @@ class DirectoryCreator {
* available before performing file operations.
* @throws Will throw an error if directory creation fails.
*/
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;
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}`);
}
});
}
catch (error) {
console.error(`Error creating directories: ${error}`);
throw error;
}
}
}
// ============================================================================
Expand Down
37 changes: 13 additions & 24 deletions dist/js/class/FileCopier.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
"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 @@ -26,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -41,19 +32,17 @@ 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.
*/
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;
}
});
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;
}
}
}
// ============================================================================
Expand Down
31 changes: 10 additions & 21 deletions dist/js/class/FileRenamer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
"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 @@ -26,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
const fs_1 = __importDefault(require("fs"));
var fs_1 = __importDefault(require("fs"));
// ============================================================================
// Classes
// ============================================================================
Expand All @@ -40,17 +31,15 @@ class FileRenamer {
* @param targetPath The new path of the file after renaming.
* @returns Promise<void>
*/
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;
}
});
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;
}
}
}
// ============================================================================
Expand Down
Loading

0 comments on commit f50b1f8

Please sign in to comment.