factorio-test-cli 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/buffer-line-splitter.js +1 -1
- package/package.json +1 -1
- package/run.js +14 -9
package/buffer-line-splitter.js
CHANGED
|
@@ -17,7 +17,7 @@ export default class BufferLineSplitter extends EventEmitter {
|
|
|
17
17
|
instream.on("data", (chunk) => {
|
|
18
18
|
this.buf += chunk.toString();
|
|
19
19
|
while (this.buf.length > 0) {
|
|
20
|
-
const index = this.buf.
|
|
20
|
+
const index = this.buf.search(/\r?\n/);
|
|
21
21
|
if (index === -1)
|
|
22
22
|
break;
|
|
23
23
|
this.emit("line", this.buf.slice(0, index));
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { program
|
|
1
|
+
import { program } from "commander";
|
|
2
2
|
import * as os from "os";
|
|
3
3
|
import * as fsp from "fs/promises";
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
|
-
import { spawn } from "child_process";
|
|
6
|
+
import { spawn, spawnSync } from "child_process";
|
|
7
7
|
import BufferLineSplitter from "./buffer-line-splitter.js";
|
|
8
8
|
import chalk from "chalk";
|
|
9
|
-
const program = theProgram;
|
|
10
9
|
const thisCommand = program
|
|
11
10
|
.command("run")
|
|
12
11
|
.summary("Runs tests with Factorio test.")
|
|
13
12
|
.description("Runs tests for the specified mod with Factorio test. Exits with code 0 only if all tests pass.\n")
|
|
14
|
-
.argument("[mod-path]", "The path to the mod to test (containing info.json). A symlink will be created in the
|
|
13
|
+
.argument("[mod-path]", "The path to the mod to test (containing info.json). A symlink will be created in the mods folder to this folder. Alternatively, you can specify --mod-name for manual setup.")
|
|
15
14
|
.option("--mod-name <name>", "The name of the mod to test. If specified, the mod must already be present in the mods directory (sse --data-directory below). One of [mod-path] or --mod-name must be specified.")
|
|
16
15
|
.option("--factorio-path <path>", "The path to the factorio binary. If not specified, tries to auto-detect the factorio installation.")
|
|
17
16
|
.option("-d --data-directory <path>", 'The path to the data directory. The "config.ini" file and the "mods" folder will be in this directory.', "./factorio-test-data")
|
|
@@ -109,12 +108,11 @@ async function checkModExists(modsDir, modName) {
|
|
|
109
108
|
}
|
|
110
109
|
async function installFactorioTest(modsDir) {
|
|
111
110
|
await fsp.mkdir(modsDir, { recursive: true });
|
|
112
|
-
// const testModName = "testorio"
|
|
113
111
|
const testModName = "factorio-test";
|
|
114
112
|
// if not found, install it
|
|
115
113
|
const alreadyExists = await checkModExists(modsDir, testModName);
|
|
116
114
|
if (!alreadyExists) {
|
|
117
|
-
console.log(`Downloading ${testModName} from mod portal
|
|
115
|
+
console.log(`Downloading ${testModName} from mod portal using fmtk. This may ask for factorio login credentials.`);
|
|
118
116
|
await runScript("fmtk mods install", "--modsPath", modsDir, testModName);
|
|
119
117
|
}
|
|
120
118
|
}
|
|
@@ -142,7 +140,7 @@ async function setSettingsForAutorun(factorioPath, dataDir, modsDir, modToTest)
|
|
|
142
140
|
console.log("Creating mod-settings.dat file by running factorio");
|
|
143
141
|
// run factorio once to create it
|
|
144
142
|
const dummySaveFile = path.join(dataDir, "____dummy_save_file.zip");
|
|
145
|
-
await runProcess(false, factorioPath
|
|
143
|
+
await runProcess(false, `"${factorioPath}"`, "--create", dummySaveFile, "--mod-directory", modsDir, "-c", path.join(dataDir, "config.ini"));
|
|
146
144
|
if (fs.existsSync(dummySaveFile)) {
|
|
147
145
|
await fsp.rm(dummySaveFile);
|
|
148
146
|
}
|
|
@@ -226,22 +224,29 @@ function runProcess(inheritStdio, command, ...args) {
|
|
|
226
224
|
shell: true,
|
|
227
225
|
});
|
|
228
226
|
return new Promise((resolve, reject) => {
|
|
227
|
+
process.on("error", reject);
|
|
229
228
|
process.on("exit", (code) => {
|
|
230
229
|
if (code === 0) {
|
|
231
230
|
resolve();
|
|
232
231
|
}
|
|
233
232
|
else {
|
|
234
|
-
reject(new Error(`Command exited with code ${code}`));
|
|
233
|
+
reject(new Error(`Command exited with code ${code}: ${command} ${args.join(" ")}`));
|
|
235
234
|
}
|
|
236
235
|
});
|
|
237
236
|
});
|
|
238
237
|
}
|
|
238
|
+
function factorioIsInPath() {
|
|
239
|
+
const result = spawnSync("factorio", ["--version"], { stdio: "ignore" });
|
|
240
|
+
return result.status === 0;
|
|
241
|
+
}
|
|
239
242
|
function autoDetectFactorioPath() {
|
|
243
|
+
if (factorioIsInPath()) {
|
|
244
|
+
return "factorio";
|
|
245
|
+
}
|
|
240
246
|
let pathsToTry;
|
|
241
247
|
// check if is linux
|
|
242
248
|
if (os.platform() === "linux" || os.platform() === "darwin") {
|
|
243
249
|
pathsToTry = [
|
|
244
|
-
"factorio",
|
|
245
250
|
"~/.local/share/Steam/steamapps/common/Factorio/bin/x64/factorio",
|
|
246
251
|
"~/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents/MacOS/factorio",
|
|
247
252
|
"~/.factorio/bin/x64/factorio",
|