diff --git a/.gitignore b/.gitignore index 1781e92..a0dd957 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store **/package-lock.json **/node_modules/ -**/dist/ \ No newline at end of file +**/dist/ diff --git a/TypeScript/10ScopesAndTypes/package.json b/TypeScript/10ScopesAndTypes/package.json index 40e2bff..4db1e0b 100644 --- a/TypeScript/10ScopesAndTypes/package.json +++ b/TypeScript/10ScopesAndTypes/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/10ScopesAndTypes/packageBuild.ts b/TypeScript/10ScopesAndTypes/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/10ScopesAndTypes/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/11BundleLoadingSample/package.json b/TypeScript/11BundleLoadingSample/package.json index a28a985..c7c208b 100644 --- a/TypeScript/11BundleLoadingSample/package.json +++ b/TypeScript/11BundleLoadingSample/package.json @@ -6,21 +6,19 @@ "main": "src/mod.js", "akiVersion": "3.2.2", "isBundleMod": true, - "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "scripts": { + "setup": "npm i", + "build": "node ./packageBuild.ts" }, - "devDependencies": { + "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } -} \ No newline at end of file +} diff --git a/TypeScript/11BundleLoadingSample/packageBuild.ts b/TypeScript/11BundleLoadingSample/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/11BundleLoadingSample/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/12ClassExtensionOverride/package.json b/TypeScript/12ClassExtensionOverride/package.json index b33ef99..bf5d23d 100644 --- a/TypeScript/12ClassExtensionOverride/package.json +++ b/TypeScript/12ClassExtensionOverride/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/12ClassExtensionOverride/packageBuild.ts b/TypeScript/12ClassExtensionOverride/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/12ClassExtensionOverride/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/13AddTrader/package.json b/TypeScript/13AddTrader/package.json index f0d3c57..55ccf95 100644 --- a/TypeScript/13AddTrader/package.json +++ b/TypeScript/13AddTrader/package.json @@ -6,20 +6,18 @@ "author": "Shirito", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" ./**/*.* ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/13AddTrader/packageBuild.ts b/TypeScript/13AddTrader/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/13AddTrader/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/14AfterDBLoadHook/package.json b/TypeScript/14AfterDBLoadHook/package.json index 2650df3..1a75f92 100644 --- a/TypeScript/14AfterDBLoadHook/package.json +++ b/TypeScript/14AfterDBLoadHook/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/14AfterDBLoadHook/packageBuild.ts b/TypeScript/14AfterDBLoadHook/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/14AfterDBLoadHook/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/1LogToConsole/package.json b/TypeScript/1LogToConsole/package.json index 7c52de5..2f6826d 100644 --- a/TypeScript/1LogToConsole/package.json +++ b/TypeScript/1LogToConsole/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./types/**/*.*\" -e \"./%npm_package_name%-%npm_package_version%/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./%npm_package_name%-%npm_package_version%", - "zip:files": "bestzip %npm_package_name%-%npm_package_version%.zip %npm_package_name%-%npm_package_version%", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('%npm_package_name%-%npm_package_version%.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/1LogToConsole/packageBuild.ts b/TypeScript/1LogToConsole/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/1LogToConsole/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/2EditDatabase/package.json b/TypeScript/2EditDatabase/package.json index 79ea9d7..fc98fe3 100644 --- a/TypeScript/2EditDatabase/package.json +++ b/TypeScript/2EditDatabase/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./types/**/*.*\" -e \"./%npm_package_name%-%npm_package_version%/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./%npm_package_name%-%npm_package_version%", - "zip:files": "bestzip %npm_package_name%-%npm_package_version%.zip %npm_package_name%-%npm_package_version%", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('%npm_package_name%-%npm_package_version%.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/2EditDatabase/packageBuild.ts b/TypeScript/2EditDatabase/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/2EditDatabase/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/3GetSptConfigFile/package.json b/TypeScript/3GetSptConfigFile/package.json index b342030..5bb25fe 100644 --- a/TypeScript/3GetSptConfigFile/package.json +++ b/TypeScript/3GetSptConfigFile/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./types/**/*.*\" -e \"./%npm_package_name%-%npm_package_version%/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./%npm_package_name%-%npm_package_version%", - "zip:files": "bestzip %npm_package_name%-%npm_package_version%.zip %npm_package_name%-%npm_package_version%", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('%npm_package_name%-%npm_package_version%.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/3GetSptConfigFile/packageBuild.ts b/TypeScript/3GetSptConfigFile/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/3GetSptConfigFile/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/4UseACustomConfigFile/package.json b/TypeScript/4UseACustomConfigFile/package.json index bd9a0fe..045d631 100644 --- a/TypeScript/4UseACustomConfigFile/package.json +++ b/TypeScript/4UseACustomConfigFile/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/4UseACustomConfigFile/packageBuild.ts b/TypeScript/4UseACustomConfigFile/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/4UseACustomConfigFile/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/5ReplaceMethod/package.json b/TypeScript/5ReplaceMethod/package.json index 6fb51be..f782acb 100644 --- a/TypeScript/5ReplaceMethod/package.json +++ b/TypeScript/5ReplaceMethod/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/5ReplaceMethod/packageBuild.ts b/TypeScript/5ReplaceMethod/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/5ReplaceMethod/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/6ReferenceAnotherClass/package.json b/TypeScript/6ReferenceAnotherClass/package.json index 4041fc4..b05d0d1 100644 --- a/TypeScript/6ReferenceAnotherClass/package.json +++ b/TypeScript/6ReferenceAnotherClass/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"\"./**/*.*\"\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/6ReferenceAnotherClass/packageBuild.ts b/TypeScript/6ReferenceAnotherClass/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/6ReferenceAnotherClass/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/7OnLoadHook/package.json b/TypeScript/7OnLoadHook/package.json index f8a9d7e..a741c83 100644 --- a/TypeScript/7OnLoadHook/package.json +++ b/TypeScript/7OnLoadHook/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/7OnLoadHook/packageBuild.ts b/TypeScript/7OnLoadHook/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/7OnLoadHook/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/8OnUpdateHook/package.json b/TypeScript/8OnUpdateHook/package.json index 9fe2dbd..370d2b5 100644 --- a/TypeScript/8OnUpdateHook/package.json +++ b/TypeScript/8OnUpdateHook/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/8OnUpdateHook/packageBuild.ts b/TypeScript/8OnUpdateHook/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/8OnUpdateHook/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +}); diff --git a/TypeScript/9RouterHooks/package.json b/TypeScript/9RouterHooks/package.json index 1987b20..b83f51f 100644 --- a/TypeScript/9RouterHooks/package.json +++ b/TypeScript/9RouterHooks/package.json @@ -6,20 +6,18 @@ "author": "Chomp", "akiVersion": "3.2.2", "scripts": { - "setup:environment": "npm i", - "build:unzipped": "copyfiles -e \"./node_modules/**/*.*\" -e \"./dist/**/*.*\" -e \"./package-lock.json\" -e \"./tsconfig.json\" -e \"./README.txt\" -e \"./mod.code-workspace\" \"./**/*.*\" ./dist", - "zip:files": "cd dist/ && bestzip ../mod.zip *", - "build:zip": "npm run clean:environment && npm run build:unzipped && npm run zip:files", - "clean:environment": "node -e \"require('fs').rm('mod.zip', ()=>{})\" && node -e \"require('fs').rmdir('./dist/',{recursive:true},()=>{})\"" + "setup": "npm i", + "build": "node ./packageBuild.ts" }, "devDependencies": { "@types/node": "^14.15.3", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", - "copyfiles": "2.4.1", + "bestzip": "2.2.1", "eslint": "7.26.0", + "fs-extra": "^10.1.0", + "glob": "^8.0.3", "tsyringe": "4.6.0", - "typescript": "4.6.4", - "bestzip": "2.2.1" + "typescript": "4.6.4" } } diff --git a/TypeScript/9RouterHooks/packageBuild.ts b/TypeScript/9RouterHooks/packageBuild.ts new file mode 100644 index 0000000..fd0bb4f --- /dev/null +++ b/TypeScript/9RouterHooks/packageBuild.ts @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +// This is a simple script used to build a mod package. The script will copy necessary files to the build directory +// and compress the build directory into a zip file that can be easily shared. + +const fs = require("fs-extra"); +const glob = require("glob"); +const zip = require('bestzip'); +const path = require("path"); + +// Load the package.json file to get some information about the package so we can name things appropriately. This is +// atypical, and you would never do this in a production environment, but this script is only used for development so +// it's fine in this case. Some of these values are stored in environment variables, but those differ between node +// versions; the 'author' value is not available after node v14. +const { author, name:packageName, version } = require("./package.json"); + +// Generate the name of the package, stripping out all non-alphanumeric characters in the 'author' and 'name'. +const modName = `${author.replace(/[^a-z0-9]/gi, "")}-${packageName.replace(/[^a-z0-9]/gi, "")}-${version}`; +console.log(`Generated package name: ${modName}`); + +// Delete the old build directory and compressed package file. +fs.rmSync(`${__dirname}/dist`, { force: true, recursive: true }); +console.log("Previous build files deleted."); + +// Generate a list of files that should not be copied over into the distribution directory. This is a blacklist to ensure +// we always copy over additional files and directories that authors may have added to their project. This may need to be +// expanded upon by the mod author to allow for node modules that are used within the mod; example commented out below. +const ignoreList = [ + "node_modules/", + // "node_modules/!(weighted|glob)", // Instead of excluding the entire node_modules directory, allow two node modules. + "src/**/*.js", + "types/", + ".git/", + ".gitea/", + ".eslintignore", + ".eslintrc.json", + ".gitignore", + ".DS_Store", + "packageBuild.ts", + "mod.code-workspace", + "package-lock.json", + "tsconfig.json" +]; +const exclude = glob.sync(`{${ignoreList.join(",")}}`, { realpath: true, dot: true }); + +// For some reason these basic-bitch functions won't allow us to copy a directory into itself, so we have to resort to +// using a temporary directory, like an idiot. Excuse the normalize spam; some modules cross-platform, some don't... +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter:(filePath) => { + return !exclude.includes(filePath); +}}); +fs.moveSync(path.normalize(`${__dirname}/../~${modName}`), path.normalize(`${__dirname}/${modName}`), { overwrite: true }); +fs.copySync(path.normalize(`${__dirname}/${modName}`), path.normalize(`${__dirname}/dist`)); +console.log("Build files copied."); + +// Compress the files for easy distribution. The compressed file is saved into the dist directory. When uncompressed we +// need to be sure that it includes a directory that the user can easily copy into their game mods directory. +zip({ + source: modName, + destination: `dist/${modName}.zip`, + cwd: __dirname +}).catch(function(err) { + console.error("A bestzip error has occurred: ", err.stack); +}).then(function() { + console.log(`Compressed mod package to: /dist/${modName}.zip`); + + // Now that we're done with the compression we can delete the temporary build directory. + fs.rmSync(`${__dirname}/${modName}`, { force: true, recursive: true }); + console.log("Build successful!"); +});