Skip to content

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 2, 2024
1 parent 556ca1a commit 7aec85d
Show file tree
Hide file tree
Showing 137 changed files with 7,144 additions and 8 deletions.
62 changes: 62 additions & 0 deletions dist/js/class/DirectoryCleaner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";
// class/DirectoryCleaner.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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright 2023 Scape Agency BV
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================
// Import
// ============================================================================
const fs_1 = require("fs");
const path_1 = require("path");
// ============================================================================
// Classes
// ============================================================================
class DirectoryCleaner {
/**
* Recursively deletes all contents of the directory asynchronously.
* @param dirPath The path to the directory to clean.
*/
cleanDirectory(dirPath) {
return __awaiter(this, void 0, void 0, function* () {
try {
const files = yield fs_1.promises.readdir(dirPath);
for (const file of files) {
const curPath = path_1.default.join(dirPath, file);
const stat = yield fs_1.promises.lstat(curPath);
if (stat.isDirectory()) {
yield this.cleanDirectory(curPath);
}
else {
yield fs_1.promises.unlink(curPath);
}
}
yield fs_1.promises.rmdir(dirPath);
}
catch (error) {
console.error(`Error cleaning directory ${dirPath}: ${error}`);
throw error; // Rethrow the error for further handling if necessary
}
});
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = DirectoryCleaner;
64 changes: 64 additions & 0 deletions dist/js/class/DirectoryCopier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const fs_1 = require("fs");
// ============================================================================
// Classes
// ============================================================================
/**
* A class for copying files from one directory to another.
*/
class DirectoryCopier {
/**
* Copies all files and subdirectories from a source directory to a destination directory.
* @param srcDir The source directory path.
* @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;
}
});
}
/**
* 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);
}
});
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = DirectoryCopier;
65 changes: 65 additions & 0 deletions dist/js/class/DirectoryCreator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright 2023 Scape Agency BV
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================
// Import
// ============================================================================
const fs_1 = require("fs");
const path_1 = require("path");
// ============================================================================
// Classes
// ============================================================================
/**
* A class for creating directories.
*/
class DirectoryCreator {
/**
* Creates directories at the specified locations asynchronously.
* @param basePath The base path where directories will be created.
* @param directories An array of directory paths to create.
* @description This method iterates over the provided array of directory paths,
* creating each directory at the specified location within the base path.
* If a directory already exists, it skips creation. This is useful for
* setting up a project structure or ensuring necessary directories are
* 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;
}
});
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = DirectoryCreator;
59 changes: 59 additions & 0 deletions dist/js/class/FileCopier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright 2023 Scape Agency BV
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================
// Import
// ============================================================================
const fs_1 = require("fs");
const path_1 = require("path");
// ============================================================================
// Classes
// ============================================================================
/**
* A class for copying files from one location to another.
*/
class FileCopier {
/**
* Copies a single file to a specified destination directory.
* @param {string} srcFile - The path of the source file to copy.
* @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;
}
});
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = FileCopier;
56 changes: 56 additions & 0 deletions dist/js/class/FileRenamer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright 2023 Scape Agency BV
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================
// Import
// ============================================================================
const fs_1 = require("fs");
// ============================================================================
// Classes
// ============================================================================
/**
* A class for renaming files.
*/
class FileRenamer {
/**
* Renames a file from the source path to the target path.
* @param srcPath The current path of the file.
* @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;
}
});
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = FileRenamer;
Loading

0 comments on commit 7aec85d

Please sign in to comment.