mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
Move lua code to slave package and fix paths
Move the export and clusterio mod code to the slave package and fix the path used for them. Refactor tests to use temp/tests/ as the cwd when running integration tests in order to ensure paths to lua code are correctly handled.
This commit is contained in:
1 parent
18e609f3fe
commit
f06d3509e6
15 files changed
+37
-35
No files matched your search
+2
-2
@@ -7,8 +7,8 @@ before_install:
|
||||
- npm install -g codecov
|
||||
script:
|
||||
- npx lerna bootstrap --no-ci
|
||||
- node packages/lib/build_mod --bump-patch --factorio-version 0.18 --output-dir sharedMods
|
||||
- curl -o sharedMods/subspace_storage_1.99.1.zip -L https://github.com/clusterio/factorioClusterioMod/releases/download/1.99.1/subspace_storage_1.99.1.zip
|
||||
- node packages/lib/build_mod --source-dir packages/slave/lua/clusterio_lib --bump-patch --factorio-version 0.18 --output-dir temp/test/sharedMods
|
||||
- curl -o temp/test/sharedMods/subspace_storage_1.99.1.zip -L https://github.com/clusterio/factorioClusterioMod/releases/download/1.99.1/subspace_storage_1.99.1.zip
|
||||
- npm run-script ci-cover
|
||||
- cat temp/test/integration/log.txt
|
||||
- codecov -f coverage/lcov.info
|
||||
|
||||
@@ -8,14 +8,13 @@ const yargs = require("yargs");
|
||||
|
||||
|
||||
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 },
|
||||
"source-dir": { describe: "Path to mod source files", nargs: 1, type: "string", demandOption: true },
|
||||
"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" },
|
||||
@@ -79,7 +78,7 @@ async function build(args) {
|
||||
await events.once(walker, "end");
|
||||
|
||||
for (let pathParts of info.additional_files || []) {
|
||||
let filePath = path.join(...pathParts);
|
||||
let filePath = path.join(args.sourceDir, ...pathParts);
|
||||
zip.file(path.posix.join(modName, path.basename(filePath)), fs.createReadStream(filePath));
|
||||
}
|
||||
delete info.additional_files;
|
||||
|
||||
@@ -33,7 +33,8 @@ async function generateExportMod(server) {
|
||||
clean: false,
|
||||
build: true,
|
||||
pack: true,
|
||||
sourceDir: path.join("lua", "export"),
|
||||
// XXX fix path when moving lib/factorio to slave
|
||||
sourceDir: path.join(__dirname, "..", "..", "slave", "lua", "export"),
|
||||
outputDir: server.writePath("mods"),
|
||||
bumpPatch: false,
|
||||
factorioVersion: server.version.replace(/\.\d+$/, ""),
|
||||
|
||||
File renamed without changes.
File renamed without changes.
@@ -7,6 +7,6 @@
|
||||
"description": "Library for interfacing with Clusterio. Warning: work in progress alpha.",
|
||||
"factorio_version": "0.17",
|
||||
"additional_files": [
|
||||
["modules", "clusterio", "serialize.lua"]
|
||||
["..", "..", "modules", "clusterio", "serialize.lua"]
|
||||
]
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -411,14 +411,14 @@ class Instance extends link.Link{
|
||||
}
|
||||
|
||||
// Find stand alone modules to load
|
||||
// XXX for now it's assumed all available modules should be loaded.
|
||||
for (let entry of await fs.readdir("modules", { withFileTypes: true })) {
|
||||
// XXX for now only the included clusterio module is loaded
|
||||
for (let entry of await fs.readdir(path.join(__dirname, "modules"), { withFileTypes: true })) {
|
||||
if (entry.isDirectory()) {
|
||||
if (modules.has(entry.name)) {
|
||||
throw new Error(`Module with name ${entry.name} already exists in a plugin`);
|
||||
}
|
||||
|
||||
let moduleJsonPath = path.join("modules", entry.name, "module.json");
|
||||
let moduleJsonPath = path.join(__dirname, "modules", entry.name, "module.json");
|
||||
if (!await fs.pathExists(moduleJsonPath)) {
|
||||
throw new Error(`Module ${entry.name} is missing module.json`);
|
||||
}
|
||||
@@ -429,7 +429,7 @@ class Instance extends link.Link{
|
||||
}
|
||||
|
||||
module = {
|
||||
path: path.join("modules", entry.name),
|
||||
path: path.join(__dirname, "modules", entry.name),
|
||||
dependencies: { "clusterio": "*" },
|
||||
load: [],
|
||||
require: [],
|
||||
|
||||
+26
-24
@@ -63,18 +63,20 @@ let control;
|
||||
let url = "https://localhost:4443/";
|
||||
let controlToken = jwt.sign({ aud: "user", user: "test" }, "TestSecretDoNotUse");
|
||||
let instancesDir = path.join("temp", "test", "instances");
|
||||
let databaseDir = path.join("temp", "test", "databse");
|
||||
let masterConfigPath = path.join("temp", "test", "master-integration.json");
|
||||
let slaveConfigPath = path.join("temp", "test", "slave-integration.json");
|
||||
let controlConfigPath = path.join("temp", "test", "control-integration.json");
|
||||
let databaseDir = path.join("temp", "test", "database");
|
||||
let pluginListPath = path.join("temp", "test", "plugin-list.json");
|
||||
let masterConfigPath = path.join("temp", "test", "config-master.json");
|
||||
let slaveConfigPath = path.join("temp", "test", "config-slave.json");
|
||||
let controlConfigPath = path.join("temp", "test", "config-control.json");
|
||||
|
||||
async function exec(...args) {
|
||||
console.log(args[0]);
|
||||
return await util.promisify(child_process.exec)(...args);
|
||||
async function exec(command, options = {}) {
|
||||
console.log(command);
|
||||
options = { cwd: path.join("temp", "test"), ...options };
|
||||
return await util.promisify(child_process.exec)(command, options);
|
||||
}
|
||||
|
||||
async function execCtl(...args) {
|
||||
args[0] = `node packages/ctl --config ${controlConfigPath} ${args[0]}`;
|
||||
args[0] = `node ../../packages/ctl ${args[0]}`;
|
||||
return await exec(...args);
|
||||
}
|
||||
|
||||
@@ -91,7 +93,7 @@ function spawn(name, cmd, waitFor) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(cmd);
|
||||
let parts = cmd.split(" ");
|
||||
let process = child_process.spawn(parts[0], parts.slice(1));
|
||||
let process = child_process.spawn(parts[0], parts.slice(1), { cwd: path.join("temp", "test") });
|
||||
let stdout = new server._LineSplitter((line) => {
|
||||
line = line.toString("utf8");
|
||||
if (line.startsWith(waitFor)) {
|
||||
@@ -113,30 +115,30 @@ before(async function() {
|
||||
await fs.remove(databaseDir);
|
||||
await fs.remove(instancesDir);
|
||||
|
||||
await fs.remove(pluginListPath);
|
||||
await fs.remove(masterConfigPath);
|
||||
await fs.remove(slaveConfigPath);
|
||||
await fs.remove(controlConfigPath);
|
||||
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.database_directory ${databaseDir}`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.auth_secret TestSecretDoNotUse`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.http_port 8880`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.https_port 4443`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.tls_certificate ${path.join(databaseDir, "cert.crt")}`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.tls_private_key ${path.join(databaseDir, "cert.key")}`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.tls_bits 1024`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.heartbeat_interval 0.25`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} config set master.connector_shutdown_timeout 2`);
|
||||
await fs.ensureDir(path.join("temp", "test"));
|
||||
|
||||
await exec(`node packages/master --config ${masterConfigPath} bootstrap create-admin test`);
|
||||
await exec(`node packages/master --config ${masterConfigPath} bootstrap create-ctl-config test --output ${controlConfigPath}`);
|
||||
await exec("node ../../packages/master config set master.auth_secret TestSecretDoNotUse");
|
||||
await exec("node ../../packages/master config set master.http_port 8880");
|
||||
await exec("node ../../packages/master config set master.https_port 4443");
|
||||
await exec("node ../../packages/master config set master.tls_bits 1024");
|
||||
await exec("node ../../packages/master config set master.heartbeat_interval 0.25");
|
||||
await exec("node ../../packages/master config set master.connector_shutdown_timeout 2");
|
||||
|
||||
masterProcess = await spawn("master:", `node packages/master --config ${masterConfigPath} run`, "All plugins loaded");
|
||||
await exec("node ../../packages/master bootstrap create-admin test");
|
||||
await exec("node ../../packages/master bootstrap create-ctl-config test");
|
||||
|
||||
let createArgs = `--id 4 --name slave --generate-token --output ${slaveConfigPath}`;
|
||||
masterProcess = await spawn("master:", "node ../../packages/master run", "All plugins loaded");
|
||||
|
||||
let createArgs = "--id 4 --name slave --generate-token";
|
||||
await execCtl(`slave create-config ${createArgs}`);
|
||||
await exec(`node packages/slave --config ${slaveConfigPath} config set slave.instances_directory ${instancesDir}`);
|
||||
|
||||
slaveProcess = await spawn("slave:", `node packages/slave --config ${slaveConfigPath} run`, "SOCKET | received ready from master");
|
||||
await exec(`node ../../packages/slave config set slave.factorio_directory ${path.join("..", "..", "factorio")}`);
|
||||
slaveProcess = await spawn("slave:", "node ../../packages/slave run", "SOCKET | received ready from master");
|
||||
|
||||
let controlConnector = new TestControlConnector(url, 2);
|
||||
controlConnector.token = controlToken;
|
||||
|
||||
Reference in new issue
Block a user