External Build Script

This update removes the inline build scripts from the `package.json` file and replaces them with an external build script: `packageBuild.ts`. An external script allows for much more flexibility.

Along with the external script change, this PR updates a few other things:
 - Moved from `copyfiles` to `fs-extra` for minor speed improvements.
 - Generates the mod package name by using the `package.json` information. The format used is `Author-PackageName-Version`.
 - Saves the compressed file in the `dist` folder.
 - Saves the compressed file using the new mod package name.
 - Compressed file now includes a root directory named after the mod package for easy copying to the user's `user/mods` game directory.
This commit is contained in:
Dinkadactyl 2022-08-31 22:28:48 -04:00
parent 5ba3a299f8
commit e06fea8398
No known key found for this signature in database
GPG Key ID: DA8524051241DD36
29 changed files with 1055 additions and 116 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
.DS_Store
**/package-lock.json
**/node_modules/
**/dist/
**/dist/

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});

View File

@ -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"
}
}

View File

@ -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!");
});