From d1b851d8902eee41c1558ca7a3f7be53af6c2e3d Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 25 May 2020 20:45:09 +0200 Subject: [PATCH] Move clusterio_lib to lua/clusterio_lib Move the library mod to lua/clusterio_lib and restructure build_mod.js to handle additonal files as a property to info.js instead of being hard coded. --- build-mod.js | 35 ++++++++++++++---------- {mod => lua/clusterio_lib}/api.lua | 0 {mod => lua/clusterio_lib}/changelog.txt | 0 {mod => lua/clusterio_lib}/info.json | 5 +++- 4 files changed, 25 insertions(+), 15 deletions(-) rename {mod => lua/clusterio_lib}/api.lua (100%) rename {mod => lua/clusterio_lib}/changelog.txt (100%) rename {mod => lua/clusterio_lib}/info.json (71%) diff --git a/build-mod.js b/build-mod.js index 2d1cb81d..db9a6140 100644 --- a/build-mod.js +++ b/build-mod.js @@ -7,29 +7,28 @@ const path = require("path"); const yargs = require("yargs"); -// Location of mod source files -const sourceDir = "mod"; - -// Paths to additional files to put into the mod's folder. -const additionalFiles = [ - path.join("modules", "clusterio", "serialize.lua"), -]; - async function main() { + const libPath = path.join("lua", "clusterio_lib"); const args = yargs .scriptName("build") .options({ 'clean': { describe: "Remove previous builds", type: 'boolean', default: false }, 'build': { describe: "Build mod", type: 'boolean', default: true }, 'pack': { describe: "Pack into zip file", type: 'boolean', default: true }, + "source-dir": { describe: "Path to mod source files", nargs: 1, type: "string", default: libPath }, 'output-dir': { describe: "Path to output built mod", nargs: 1, type: 'string', default: "dist" }, "bump-patch": { describe: "Increment patch number of build", type: "boolean", default: false }, "factorio-version": { describe: "Override factorio_version", type: "string" }, }) + .strict() .argv ; - let info = JSON.parse(await fs.readFile(path.join(sourceDir, "info.json"))); + await build(args); +} + +async function build(args) { + let info = JSON.parse(await fs.readFile(path.join(args.sourceDir, "info.json"))); if (args.bumpPatch) { let [major, minor, patch] = info.version.split("."); @@ -62,22 +61,24 @@ async function main() { if (args.pack) { let zip = new JSZip(); - let walker = klaw(sourceDir) + let walker = klaw(args.sourceDir) .on('data', item => { if (item.stats.isFile()) { // On Windows the path created uses backslashes as the directory sepparator // but the zip file needs to use forward slashes. We can't use the posix // version of relative here as it doesn't work with Windows style paths. - let basePath = path.relative(sourceDir, item.path).replace(/\\/g, "/"); + let basePath = path.relative(args.sourceDir, item.path).replace(/\\/g, "/"); zip.file(path.posix.join(modName, basePath), fs.createReadStream(item.path)); } }) ; await events.once(walker, 'end'); - for (let filePath of additionalFiles) { + for (let pathParts of info.additional_files || []) { + let filePath = path.join(...pathParts); zip.file(path.posix.join(modName, path.basename(filePath)), fs.createReadStream(filePath)); } + delete info.additional_files; zip.file(path.posix.join(modName, "info.json"), JSON.stringify(info, null, 4)); @@ -93,10 +94,12 @@ async function main() { await fs.remove(modDir); } console.log(`Building ${modDir}`); - await fs.copy(sourceDir, modDir); - for (let filePath of additionalFiles) { + await fs.copy(args.sourceDir, modDir); + for (let pathParts of info.additional_files || []) { + let filePath = path.join(...pathParts); await fs.copy(filePath, path.join(modDir, path.basename(filePath))); } + delete info.additional_files; await fs.writeFile(path.join(modDir, "info.json"), JSON.stringify(info, null, 4)); } @@ -106,3 +109,7 @@ async function main() { if (module === require.main) { main().catch(err => { console.log(err) }); } + +module.exports = { + build, +}; diff --git a/mod/api.lua b/lua/clusterio_lib/api.lua similarity index 100% rename from mod/api.lua rename to lua/clusterio_lib/api.lua diff --git a/mod/changelog.txt b/lua/clusterio_lib/changelog.txt similarity index 100% rename from mod/changelog.txt rename to lua/clusterio_lib/changelog.txt diff --git a/mod/info.json b/lua/clusterio_lib/info.json similarity index 71% rename from mod/info.json rename to lua/clusterio_lib/info.json index dd75e41f..43177950 100644 --- a/mod/info.json +++ b/lua/clusterio_lib/info.json @@ -5,5 +5,8 @@ "author": "Clusterio Team", "homepage": "https://github.com/clusterio/factorioClusterio", "description": "Library for interfacing with Clusterio. Warning: work in progress alpha.", - "factorio_version": "0.17" + "factorio_version": "0.17", + "additional_files": [ + ["modules", "clusterio", "serialize.lua"] + ] }