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.
This commit is contained in:
Hornwitser committed 2020-05-25 20:45:09 +02:00
1 parent 2e24d6c8ae
commit d1b851d890
4 files changed
+25 -15

No files matched your search

+21 -14
View File
@@ -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,
};
File renamed without changes.
File renamed without changes.
@@ -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"]
]
}