diff --git a/TypeScript/10ScopesAndTypes/build.mjs b/TypeScript/10ScopesAndTypes/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/10ScopesAndTypes/build.mjs +++ b/TypeScript/10ScopesAndTypes/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/10ScopesAndTypes/package.json b/TypeScript/10ScopesAndTypes/package.json index e1c22b6..7001124 100644 --- a/TypeScript/10ScopesAndTypes/package.json +++ b/TypeScript/10ScopesAndTypes/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/11BundleLoadingSample/build.mjs b/TypeScript/11BundleLoadingSample/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/11BundleLoadingSample/build.mjs +++ b/TypeScript/11BundleLoadingSample/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/11BundleLoadingSample/package.json b/TypeScript/11BundleLoadingSample/package.json index 768fdac..54e4313 100644 --- a/TypeScript/11BundleLoadingSample/package.json +++ b/TypeScript/11BundleLoadingSample/package.json @@ -17,10 +17,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/12ClassExtensionOverride/build.mjs b/TypeScript/12ClassExtensionOverride/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/12ClassExtensionOverride/build.mjs +++ b/TypeScript/12ClassExtensionOverride/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/12ClassExtensionOverride/package.json b/TypeScript/12ClassExtensionOverride/package.json index ae098c5..5a12315 100644 --- a/TypeScript/12ClassExtensionOverride/package.json +++ b/TypeScript/12ClassExtensionOverride/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/13AddTrader/build.mjs b/TypeScript/13AddTrader/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/13AddTrader/build.mjs +++ b/TypeScript/13AddTrader/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/13AddTrader/package.json b/TypeScript/13AddTrader/package.json index fa4cce4..3ddfb90 100644 --- a/TypeScript/13AddTrader/package.json +++ b/TypeScript/13AddTrader/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/14AfterDBLoadHook/build.mjs b/TypeScript/14AfterDBLoadHook/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/14AfterDBLoadHook/build.mjs +++ b/TypeScript/14AfterDBLoadHook/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/14AfterDBLoadHook/package.json b/TypeScript/14AfterDBLoadHook/package.json index 3ef66ad..31d33d4 100644 --- a/TypeScript/14AfterDBLoadHook/package.json +++ b/TypeScript/14AfterDBLoadHook/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/15HttpListenerExample/build.mjs b/TypeScript/15HttpListenerExample/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/15HttpListenerExample/build.mjs +++ b/TypeScript/15HttpListenerExample/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/15HttpListenerExample/package.json b/TypeScript/15HttpListenerExample/package.json index b822fd2..e7e1b0f 100644 --- a/TypeScript/15HttpListenerExample/package.json +++ b/TypeScript/15HttpListenerExample/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/16ImporterUtil/build.mjs b/TypeScript/16ImporterUtil/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/16ImporterUtil/build.mjs +++ b/TypeScript/16ImporterUtil/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/16ImporterUtil/package.json b/TypeScript/16ImporterUtil/package.json index 389c902..ea78595 100644 --- a/TypeScript/16ImporterUtil/package.json +++ b/TypeScript/16ImporterUtil/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/17AsyncImporterWithDependency1/build.mjs b/TypeScript/17AsyncImporterWithDependency1/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/17AsyncImporterWithDependency1/build.mjs +++ b/TypeScript/17AsyncImporterWithDependency1/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/17AsyncImporterWithDependency1/package.json b/TypeScript/17AsyncImporterWithDependency1/package.json index 353bc78..62af74f 100644 --- a/TypeScript/17AsyncImporterWithDependency1/package.json +++ b/TypeScript/17AsyncImporterWithDependency1/package.json @@ -19,10 +19,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/17AsyncImporterWithDependency2/build.mjs b/TypeScript/17AsyncImporterWithDependency2/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/17AsyncImporterWithDependency2/build.mjs +++ b/TypeScript/17AsyncImporterWithDependency2/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/17AsyncImporterWithDependency2/package.json b/TypeScript/17AsyncImporterWithDependency2/package.json index aaa4843..3ac10f2 100644 --- a/TypeScript/17AsyncImporterWithDependency2/package.json +++ b/TypeScript/17AsyncImporterWithDependency2/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/18CustomItemService/build.mjs b/TypeScript/18CustomItemService/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/18CustomItemService/build.mjs +++ b/TypeScript/18CustomItemService/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/18CustomItemService/package.json b/TypeScript/18CustomItemService/package.json index 3eab599..3d4e038 100644 --- a/TypeScript/18CustomItemService/package.json +++ b/TypeScript/18CustomItemService/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/1LogToConsole/build.mjs b/TypeScript/1LogToConsole/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/1LogToConsole/build.mjs +++ b/TypeScript/1LogToConsole/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/1LogToConsole/package.json b/TypeScript/1LogToConsole/package.json index 2440891..a768e49 100644 --- a/TypeScript/1LogToConsole/package.json +++ b/TypeScript/1LogToConsole/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/2EditDatabase/build.mjs b/TypeScript/2EditDatabase/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/2EditDatabase/build.mjs +++ b/TypeScript/2EditDatabase/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/2EditDatabase/package.json b/TypeScript/2EditDatabase/package.json index e73150f..a03160a 100644 --- a/TypeScript/2EditDatabase/package.json +++ b/TypeScript/2EditDatabase/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/3GetSptConfigFile/build.mjs b/TypeScript/3GetSptConfigFile/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/3GetSptConfigFile/build.mjs +++ b/TypeScript/3GetSptConfigFile/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/3GetSptConfigFile/package.json b/TypeScript/3GetSptConfigFile/package.json index a849791..3e47235 100644 --- a/TypeScript/3GetSptConfigFile/package.json +++ b/TypeScript/3GetSptConfigFile/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/4UseACustomConfigFile/build.mjs b/TypeScript/4UseACustomConfigFile/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/4UseACustomConfigFile/build.mjs +++ b/TypeScript/4UseACustomConfigFile/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/4UseACustomConfigFile/package.json b/TypeScript/4UseACustomConfigFile/package.json index 25f5d5a..f9d0be5 100644 --- a/TypeScript/4UseACustomConfigFile/package.json +++ b/TypeScript/4UseACustomConfigFile/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/5ReplaceMethod/build.mjs b/TypeScript/5ReplaceMethod/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/5ReplaceMethod/build.mjs +++ b/TypeScript/5ReplaceMethod/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/5ReplaceMethod/package.json b/TypeScript/5ReplaceMethod/package.json index 871d1f3..8f6dffc 100644 --- a/TypeScript/5ReplaceMethod/package.json +++ b/TypeScript/5ReplaceMethod/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/6ReferenceAnotherClass/build.mjs b/TypeScript/6ReferenceAnotherClass/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/6ReferenceAnotherClass/build.mjs +++ b/TypeScript/6ReferenceAnotherClass/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/6ReferenceAnotherClass/package.json b/TypeScript/6ReferenceAnotherClass/package.json index 20975be..59e2579 100644 --- a/TypeScript/6ReferenceAnotherClass/package.json +++ b/TypeScript/6ReferenceAnotherClass/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/7OnLoadHook/build.mjs b/TypeScript/7OnLoadHook/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/7OnLoadHook/build.mjs +++ b/TypeScript/7OnLoadHook/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/7OnLoadHook/package.json b/TypeScript/7OnLoadHook/package.json index e4fb8fd..f4f0b05 100644 --- a/TypeScript/7OnLoadHook/package.json +++ b/TypeScript/7OnLoadHook/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/8OnUpdateHook/build.mjs b/TypeScript/8OnUpdateHook/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/8OnUpdateHook/build.mjs +++ b/TypeScript/8OnUpdateHook/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/8OnUpdateHook/package.json b/TypeScript/8OnUpdateHook/package.json index 6962009..032cf4c 100644 --- a/TypeScript/8OnUpdateHook/package.json +++ b/TypeScript/8OnUpdateHook/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +} diff --git a/TypeScript/9RouterHooks/build.mjs b/TypeScript/9RouterHooks/build.mjs index b05c89e..d00117c 100644 --- a/TypeScript/9RouterHooks/build.mjs +++ b/TypeScript/9RouterHooks/build.mjs @@ -29,7 +29,7 @@ * @version v1.0.0 */ -import fs from "fs"; +import fs from "fs-extra"; import os from "os"; import path from "path"; import { fileURLToPath } from "url"; @@ -101,7 +101,7 @@ async function main() { logger.log("success", `Project name created: ${projectName}`); // Remove the old distribution directory and create a fresh one. - const distDir = await cleanAndCreateDistDirectory(currentDir); + const distDir = await removeOldDistDirectory(currentDir); logger.log("info", "Distribution directory successfully cleaned."); // Create a temporary working directory to perform the build operations. @@ -123,12 +123,12 @@ async function main() { // Move the zip file inside of the project directory, within the temporary working directory. const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); - await fs.promises.rename(zipFilePath, zipFileInProjectDir); + await fs.move(zipFilePath, zipFileInProjectDir); logger.log("success", "Archive successfully moved."); logger.log("info", zipFileInProjectDir); // Move the temporary directory into the distribution directory. - await fs.promises.rename(projectDir, path.join(distDir)); + await fs.move(projectDir, distDir); logger.log("success", "Temporary directory successfully moved into project distribution directory."); // Log the success message. Write out the path to the mod package. @@ -232,25 +232,15 @@ function createProjectName(packageJson) { } /** - * Sets up the distribution directory where the final mod package will be stored. The method first deletes any existing - * distribution directory to ensure a clean slate for the build process. It then creates a new distribution directory, - * providing a fresh and clean environment for each build. This approach helps to avoid potential conflicts with files - * from previous builds and ensures that each build is isolated and independent. + * Defines the location of the distribution directory where the final mod package will be stored and deletes any + * existing distribution directory to ensure a clean slate for the build process. * * @param {string} currentDirectory - The absolute path of the current working directory. - * @returns {Promise} A promise that resolves to the absolute path of the newly created distribution directory. + * @returns {Promise} A promise that resolves to the absolute path to the distribution directory. */ -async function cleanAndCreateDistDirectory(projectDir) { +async function removeOldDistDirectory(projectDir) { const distPath = path.join(projectDir, "dist"); - - // Remove the existing distribution directory (if it exists) to ensure a clean slate for the build process. - // The force option allows the operation to proceed without errors if the directory does not exist. - // The recursive option ensures that all subdirectories and files are deleted. - await fs.promises.rm(distPath, { force: true, recursive: true }); - - // Create a new distribution directory to store the final mod package. - await fs.promises.mkdir(distPath); - + await fs.remove(distPath); return distPath; } @@ -271,7 +261,7 @@ async function createTemporaryDirectoryWithProjectName(projectName) { // Create a subdirectory within the temporary directory using the project name for this specific build. const projectDir = path.join(tempDir, projectName); - await fs.promises.mkdir(projectDir); + await fs.ensureDir(projectDir); return projectDir; } @@ -316,13 +306,13 @@ async function copyFiles(srcDir, destDir, ignoreHandler) { if (entry.isDirectory()) { // If the entry is a directory, create the corresponding temporary directory and make a recursive call // to copyFiles to handle copying the contents of the directory. - await fs.promises.mkdir(destPath); + await fs.ensureDir(destPath); copyOperations.push(copyFiles(srcPath, destPath, ignoreHandler)); } else { // If the entry is a file, add a copyFile operation to the copyOperations array and log the event when // the operation is successful. copyOperations.push( - fs.promises.copyFile(srcPath, destPath).then(() => { + fs.copy(srcPath, destPath).then(() => { logger.log("info", `Copied: /${path.relative(process.cwd(), srcPath)}`); }) ); diff --git a/TypeScript/9RouterHooks/package.json b/TypeScript/9RouterHooks/package.json index 27ef6b7..21edea5 100644 --- a/TypeScript/9RouterHooks/package.json +++ b/TypeScript/9RouterHooks/package.json @@ -16,10 +16,11 @@ "@typescript-eslint/parser": "6.2.0", "archiver": "^6.0", "eslint": "8.46.0", + "fs-extra": "^11.1", "ignore": "^5.2", "os": "^0.1", "tsyringe": "4.8.0", "typescript": "5.1.6", "winston": "^3.9" } -} \ No newline at end of file +}