From b2348014eacdad5c6d2c76bc519493a9e34a5cc2 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 2 Aug 2023 09:52:36 +0100 Subject: [PATCH] Fixed issue with example mods building zip containing types + other unnecessary files (Thanks to TorturedChunk for fix) --- TypeScript/10ScopesAndTypes/packageBuild.ts | 13 ++-- .../11BundleLoadingSample/packageBuild.ts | 13 ++-- .../12ClassExtensionOverride/packageBuild.ts | 13 ++-- TypeScript/13AddTrader/packageBuild.ts | 13 ++-- TypeScript/14AfterDBLoadHook/packageBuild.ts | 13 ++-- .../15HttpListenerExample/packageBuild.ts | 75 +++++++++++++++++++ TypeScript/16ImporterUtil/packageBuild.ts | 13 ++-- .../packageBuild.ts | 13 ++-- .../packageBuild.ts | 13 ++-- .../18CustomItemService/packageBuild.ts | 13 ++-- TypeScript/1LogToConsole/packageBuild.ts | 13 ++-- TypeScript/2EditDatabase/packageBuild.ts | 13 ++-- TypeScript/3GetSptConfigFile/packageBuild.ts | 13 ++-- .../4UseACustomConfigFile/packageBuild.ts | 13 ++-- TypeScript/5ReplaceMethod/packageBuild.ts | 13 ++-- .../6ReferenceAnotherClass/packageBuild.ts | 13 ++-- TypeScript/7OnLoadHook/packageBuild.ts | 13 ++-- TypeScript/8OnUpdateHook/packageBuild.ts | 13 ++-- TypeScript/9RouterHooks/packageBuild.ts | 13 ++-- 19 files changed, 219 insertions(+), 90 deletions(-) create mode 100644 TypeScript/15HttpListenerExample/packageBuild.ts diff --git a/TypeScript/10ScopesAndTypes/packageBuild.ts b/TypeScript/10ScopesAndTypes/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/10ScopesAndTypes/packageBuild.ts +++ b/TypeScript/10ScopesAndTypes/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/11BundleLoadingSample/packageBuild.ts b/TypeScript/11BundleLoadingSample/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/11BundleLoadingSample/packageBuild.ts +++ b/TypeScript/11BundleLoadingSample/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/12ClassExtensionOverride/packageBuild.ts b/TypeScript/12ClassExtensionOverride/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/12ClassExtensionOverride/packageBuild.ts +++ b/TypeScript/12ClassExtensionOverride/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/13AddTrader/packageBuild.ts b/TypeScript/13AddTrader/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/13AddTrader/packageBuild.ts +++ b/TypeScript/13AddTrader/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/14AfterDBLoadHook/packageBuild.ts b/TypeScript/14AfterDBLoadHook/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/14AfterDBLoadHook/packageBuild.ts +++ b/TypeScript/14AfterDBLoadHook/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/15HttpListenerExample/packageBuild.ts b/TypeScript/15HttpListenerExample/packageBuild.ts new file mode 100644 index 0000000..d76ddd8 --- /dev/null +++ b/TypeScript/15HttpListenerExample/packageBuild.ts @@ -0,0 +1,75 @@ +#!/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"); +const minimatch = require('minimatch'); + +// 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 }); + +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => +{ + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + +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! your zip file has been created and is ready to be uploaded to hub.sp-tarkov.com/files/"); +}); \ No newline at end of file diff --git a/TypeScript/16ImporterUtil/packageBuild.ts b/TypeScript/16ImporterUtil/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/16ImporterUtil/packageBuild.ts +++ b/TypeScript/16ImporterUtil/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/17AsyncImporterWithDependency1/packageBuild.ts b/TypeScript/17AsyncImporterWithDependency1/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/17AsyncImporterWithDependency1/packageBuild.ts +++ b/TypeScript/17AsyncImporterWithDependency1/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/17AsyncImporterWithDependency2/packageBuild.ts b/TypeScript/17AsyncImporterWithDependency2/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/17AsyncImporterWithDependency2/packageBuild.ts +++ b/TypeScript/17AsyncImporterWithDependency2/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/18CustomItemService/packageBuild.ts b/TypeScript/18CustomItemService/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/18CustomItemService/packageBuild.ts +++ b/TypeScript/18CustomItemService/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/1LogToConsole/packageBuild.ts b/TypeScript/1LogToConsole/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/1LogToConsole/packageBuild.ts +++ b/TypeScript/1LogToConsole/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/2EditDatabase/packageBuild.ts b/TypeScript/2EditDatabase/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/2EditDatabase/packageBuild.ts +++ b/TypeScript/2EditDatabase/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/3GetSptConfigFile/packageBuild.ts b/TypeScript/3GetSptConfigFile/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/3GetSptConfigFile/packageBuild.ts +++ b/TypeScript/3GetSptConfigFile/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/4UseACustomConfigFile/packageBuild.ts b/TypeScript/4UseACustomConfigFile/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/4UseACustomConfigFile/packageBuild.ts +++ b/TypeScript/4UseACustomConfigFile/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/5ReplaceMethod/packageBuild.ts b/TypeScript/5ReplaceMethod/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/5ReplaceMethod/packageBuild.ts +++ b/TypeScript/5ReplaceMethod/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/6ReferenceAnotherClass/packageBuild.ts b/TypeScript/6ReferenceAnotherClass/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/6ReferenceAnotherClass/packageBuild.ts +++ b/TypeScript/6ReferenceAnotherClass/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/7OnLoadHook/packageBuild.ts b/TypeScript/7OnLoadHook/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/7OnLoadHook/packageBuild.ts +++ b/TypeScript/7OnLoadHook/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/8OnUpdateHook/packageBuild.ts b/TypeScript/8OnUpdateHook/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/8OnUpdateHook/packageBuild.ts +++ b/TypeScript/8OnUpdateHook/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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."); diff --git a/TypeScript/9RouterHooks/packageBuild.ts b/TypeScript/9RouterHooks/packageBuild.ts index c829979..d76ddd8 100644 --- a/TypeScript/9RouterHooks/packageBuild.ts +++ b/TypeScript/9RouterHooks/packageBuild.ts @@ -7,6 +7,7 @@ const fs = require("fs-extra"); const glob = require("glob"); const zip = require('bestzip'); const path = require("path"); +const minimatch = require('minimatch'); // 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 @@ -43,12 +44,14 @@ const ignoreList = [ ]; 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) => +fs.copySync(__dirname, path.normalize(`${__dirname}/../~${modName}`), {filter: (src) => { - return !exclude.includes(filePath); -}}); + const relativePath = path.relative(__dirname, src); + const shouldExclude = exclude.some((pattern) => minimatch(relativePath, pattern)); + console.log(`${relativePath} - Excluded: ${shouldExclude}`); + return !shouldExclude; +},}); + 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.");