-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
137 changed files
with
7,144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.