isaacscript 2.0.14-dev.8 → 2.0.15-dev.0
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/LICENSE +674 -0
- package/README.md +4 -6
- package/file-templates/dynamic/gitignore +3 -0
- package/file-templates/static/{.eslintrc.js → .eslintrc.js.template} +0 -0
- package/file-templates/static/.github/workflows/ci.yml +4 -3
- package/file-templates/static/.prettierignore +1 -1
- package/file-templates/static/check-orphaned-words.sh +3 -3
- package/file-templates/static/{.cspell.json.template → cspell.json.template} +1 -1
- package/file-templates/static-alt/.prettierignore-base +1 -1
- package/package.json +7 -2
- package/src/checkForWindowsTerminalBugs.js +75 -79
- package/src/checkForWindowsTerminalBugs.js.map +1 -1
- package/src/commands/copy/copy.js +32 -32
- package/src/commands/init/checkIfProjectPathExists.js +27 -29
- package/src/commands/init/checkIfProjectPathExists.js.map +1 -1
- package/src/commands/init/checkModSubdirectory.js +15 -15
- package/src/commands/init/checkModTargetDirectory.js +30 -32
- package/src/commands/init/checkModTargetDirectory.js.map +1 -1
- package/src/commands/init/createMod.js +142 -137
- package/src/commands/init/createMod.js.map +1 -1
- package/src/commands/init/getModsDir.js +55 -57
- package/src/commands/init/getModsDir.js.map +1 -1
- package/src/commands/init/getProjectPath.js +88 -92
- package/src/commands/init/getProjectPath.js.map +1 -1
- package/src/commands/init/git.js +150 -152
- package/src/commands/init/git.js.map +1 -1
- package/src/commands/init/init.js +65 -69
- package/src/commands/init/init.js.map +1 -1
- package/src/commands/init/installVSCodeExtensions.js +32 -32
- package/src/commands/init/promptSaveSlot.js +21 -24
- package/src/commands/init/promptSaveSlot.js.map +1 -1
- package/src/commands/init/promptVSCode.js +24 -26
- package/src/commands/init/promptVSCode.js.map +1 -1
- package/src/commands/monitor/constants.js +4 -4
- package/src/commands/monitor/copyWatcherMod.js +38 -38
- package/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js +49 -49
- package/src/commands/monitor/monitor.js +146 -146
- package/src/commands/monitor/notifyGame.js +57 -57
- package/src/commands/monitor/saveDatWriter/saveDatWriter.js +116 -116
- package/src/commands/monitor/saveDatWriter/types.js +2 -2
- package/src/commands/monitor/spawnSaveDatWriter.js +34 -34
- package/src/commands/monitor/touchWatcherSaveDatFiles.js +20 -20
- package/src/commands/publish/publish.js +220 -220
- package/src/configFile.js +63 -65
- package/src/configFile.js.map +1 -1
- package/src/constants.js +59 -59
- package/src/exec.js +95 -95
- package/src/file.js +193 -193
- package/src/main.js +117 -121
- package/src/main.js.map +1 -1
- package/src/parseArgs.js +106 -106
- package/src/prompt.js +86 -92
- package/src/prompt.js.map +1 -1
- package/src/types/Command.js +4 -4
- package/src/types/Config.js +12 -12
- package/src/types/GitHubCLIHostsYAML.js +2 -2
- package/src/utils.js +81 -81
- package/src/validateInIsaacScriptProject.js +26 -26
- package/src/validateNodeVersion.js +24 -24
- package/src/validateOS.js +16 -16
- package/file-templates/static/.gitattributes +0 -9
- package/file-templates/static/nuke.sh +0 -18
- package/file-templates/static/publish.sh +0 -10
- package/src/checkForWindowsTerminalBugs.d.ts +0 -5
- package/src/commands/copy/copy.d.ts +0 -3
- package/src/commands/init/checkIfProjectPathExists.d.ts +0 -1
- package/src/commands/init/checkModSubdirectory.d.ts +0 -1
- package/src/commands/init/checkModTargetDirectory.d.ts +0 -1
- package/src/commands/init/createMod.d.ts +0 -1
- package/src/commands/init/getModsDir.d.ts +0 -1
- package/src/commands/init/getProjectPath.d.ts +0 -1
- package/src/commands/init/git.d.ts +0 -4
- package/src/commands/init/init.d.ts +0 -1
- package/src/commands/init/installVSCodeExtensions.d.ts +0 -1
- package/src/commands/init/promptSaveSlot.d.ts +0 -1
- package/src/commands/init/promptVSCode.d.ts +0 -1
- package/src/commands/monitor/constants.d.ts +0 -1
- package/src/commands/monitor/copyWatcherMod.d.ts +0 -2
- package/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.d.ts +0 -1
- package/src/commands/monitor/monitor.d.ts +0 -2
- package/src/commands/monitor/notifyGame.d.ts +0 -3
- package/src/commands/monitor/saveDatWriter/saveDatWriter.d.ts +0 -1
- package/src/commands/monitor/saveDatWriter/types.d.ts +0 -5
- package/src/commands/monitor/spawnSaveDatWriter.d.ts +0 -4
- package/src/commands/monitor/touchWatcherSaveDatFiles.d.ts +0 -2
- package/src/commands/publish/publish.d.ts +0 -2
- package/src/configFile.d.ts +0 -4
- package/src/constants.d.ts +0 -34
- package/src/exec.d.ts +0 -4
- package/src/file.d.ts +0 -12
- package/src/main.d.ts +0 -2
- package/src/parseArgs.d.ts +0 -1
- package/src/prompt.d.ts +0 -5
- package/src/types/Command.d.ts +0 -2
- package/src/types/Config.d.ts +0 -18
- package/src/types/GitHubCLIHostsYAML.d.ts +0 -7
- package/src/utils.d.ts +0 -13
- package/src/validateInIsaacScriptProject.d.ts +0 -1
- package/src/validateNodeVersion.d.ts +0 -5
- package/src/validateOS.d.ts +0 -1
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.monitor = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
-
const child_process_1 = require("child_process");
|
|
7
|
-
const JSONC = tslib_1.__importStar(require("jsonc-parser"));
|
|
8
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
-
const constants_1 = require("../../constants");
|
|
10
|
-
const file = tslib_1.__importStar(require("../../file"));
|
|
11
|
-
const utils_1 = require("../../utils");
|
|
12
|
-
const constants_2 = require("./constants");
|
|
13
|
-
const copyWatcherMod_1 = require("./copyWatcherMod");
|
|
14
|
-
const notifyGame = tslib_1.__importStar(require("./notifyGame"));
|
|
15
|
-
const spawnSaveDatWriter_1 = require("./spawnSaveDatWriter");
|
|
16
|
-
const touchWatcherSaveDatFiles_1 = require("./touchWatcherSaveDatFiles");
|
|
17
|
-
let compilationStartTime = new Date();
|
|
18
|
-
function monitor(argv, config) {
|
|
19
|
-
const verbose = argv["verbose"] === true;
|
|
20
|
-
// If they specified some command-line flags, override the values found in the config file.
|
|
21
|
-
if (argv["modsDirectory"] !== undefined) {
|
|
22
|
-
config.modsDirectory = argv["modsDirectory"]; // eslint-disable-line no-param-reassign
|
|
23
|
-
}
|
|
24
|
-
if (argv["saveSlot"] !== undefined) {
|
|
25
|
-
config.saveSlot = argv["saveSlot"]; // eslint-disable-line no-param-reassign
|
|
26
|
-
}
|
|
27
|
-
// Read the "tsconfig.json" file.
|
|
28
|
-
const tsConfigInclude = getFirstTSConfigIncludePath(verbose);
|
|
29
|
-
const resolvedIncludePath = path_1.default.resolve(constants_1.CWD, tsConfigInclude);
|
|
30
|
-
const modTargetDirectoryName = (0, utils_1.getModTargetDirectoryName)(config);
|
|
31
|
-
const modTargetPath = path_1.default.join(config.modsDirectory, modTargetDirectoryName);
|
|
32
|
-
// Prepare the IsaacScript watcher mod.
|
|
33
|
-
(0, copyWatcherMod_1.copyWatcherMod)(config, verbose);
|
|
34
|
-
(0, touchWatcherSaveDatFiles_1.touchWatcherSaveDatFiles)(config, verbose);
|
|
35
|
-
// Delete and re-copy the mod every time IsaacScript starts. This ensures that it is always the
|
|
36
|
-
// latest version.
|
|
37
|
-
if (file.exists(modTargetPath, verbose)) {
|
|
38
|
-
file.deleteFileOrDirectory(modTargetPath, true);
|
|
39
|
-
}
|
|
40
|
-
// Subprocess #1 - The "save#.dat" file writer.
|
|
41
|
-
(0, spawnSaveDatWriter_1.spawnSaveDatWriter)(config);
|
|
42
|
-
// Subprocess #2 - The mod directory syncer.
|
|
43
|
-
spawnModDirectorySyncer(config);
|
|
44
|
-
// Subprocess #3 - tstl --watch (to automatically convert TypeScript to Lua).
|
|
45
|
-
spawnTSTLWatcher();
|
|
46
|
-
// Also, start constantly pinging the watcher mod.
|
|
47
|
-
setInterval(() => {
|
|
48
|
-
notifyGame.ping();
|
|
49
|
-
}, 1000); // Every second
|
|
50
|
-
console.log("Automatically monitoring the following for changes:");
|
|
51
|
-
console.log(`1) your TypeScript code: ${chalk_1.default.green(resolvedIncludePath)}`);
|
|
52
|
-
console.log(`2) the source mod directory: ${chalk_1.default.green(constants_1.MOD_SOURCE_PATH)}`);
|
|
53
|
-
console.log("");
|
|
54
|
-
console.log(`Copying files to: ${chalk_1.default.green(modTargetPath)}`);
|
|
55
|
-
console.log("");
|
|
56
|
-
// (The process will now continue indefinitely for as long as the subprocesses exist.)
|
|
57
|
-
}
|
|
58
|
-
exports.monitor = monitor;
|
|
59
|
-
function spawnModDirectorySyncer(config) {
|
|
60
|
-
const processName = "modDirectorySyncer";
|
|
61
|
-
const processDescription = "Directory syncer";
|
|
62
|
-
const processPath = path_1.default.join(__dirname, processName, processName);
|
|
63
|
-
const modTargetName = (0, utils_1.getModTargetDirectoryName)(config);
|
|
64
|
-
const modTargetPath = path_1.default.join(config.modsDirectory, modTargetName);
|
|
65
|
-
const directorySyncer = (0, child_process_1.fork)(processPath, [constants_1.MOD_SOURCE_PATH, modTargetPath]);
|
|
66
|
-
directorySyncer.on("message", (msg) => {
|
|
67
|
-
notifyGame.msg(msg);
|
|
68
|
-
// If the "main.lua" file was successfully copied over, we also have to tell isaacscript-watcher
|
|
69
|
-
// to reload the mod. Look for something like: "File synced: \main.lua"
|
|
70
|
-
if (msg === `${constants_1.FILE_SYNCED_MESSAGE} ${path_1.default.sep}${constants_1.MAIN_LUA}`) {
|
|
71
|
-
notifyGame.command(`luamod ${modTargetName}`);
|
|
72
|
-
notifyGame.command("restart");
|
|
73
|
-
notifyGame.msg("Reloaded the mod.");
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
directorySyncer.on("close", (code) => {
|
|
77
|
-
(0, utils_1.error)(`Error: ${processDescription} subprocess closed with code: ${code}`);
|
|
78
|
-
});
|
|
79
|
-
directorySyncer.on("exit", (code) => {
|
|
80
|
-
(0, utils_1.error)(`Error: ${processDescription} subprocess exited with code: ${code}`);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function spawnTSTLWatcher() {
|
|
84
|
-
const processDescription = "tstl";
|
|
85
|
-
const tstl = (0, child_process_1.spawn)("npx", ["tstl", "--watch", "--preserveWatchOutput"], {
|
|
86
|
-
shell: true,
|
|
87
|
-
});
|
|
88
|
-
tstl.stdout.on("data", (data) => {
|
|
89
|
-
const msg = data.toString().trim();
|
|
90
|
-
if (msg.includes("Starting compilation in watch mode...")) {
|
|
91
|
-
const newMsg = `${constants_1.PROJECT_NAME} is now watching for changes.`;
|
|
92
|
-
notifyGame.msg(newMsg);
|
|
93
|
-
}
|
|
94
|
-
else if (msg.includes("File change detected. Starting incremental compilation...")) {
|
|
95
|
-
compilationStartTime = new Date();
|
|
96
|
-
const newMsg = "TypeScript change detected. Compiling...";
|
|
97
|
-
notifyGame.msg(newMsg);
|
|
98
|
-
}
|
|
99
|
-
else if (msg.includes("Found 0 errors. Watching for file changes.")) {
|
|
100
|
-
const compilationFinishTime = new Date();
|
|
101
|
-
const elapsedTimeMilliseconds = compilationFinishTime.getTime() - compilationStartTime.getTime();
|
|
102
|
-
const elapsedTimeSeconds = elapsedTimeMilliseconds / 1000;
|
|
103
|
-
const newMsg = `${constants_2.COMPILATION_SUCCESSFUL} (in ${elapsedTimeSeconds} seconds)`;
|
|
104
|
-
notifyGame.msg(newMsg);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
notifyGame.msg(msg);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
tstl.stderr.on("data", (data) => {
|
|
111
|
-
const msg = data.toString().trim();
|
|
112
|
-
if (msg === "^C") {
|
|
113
|
-
// Hide the line that appears when you cancel the program with `Ctrl + c`.
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
notifyGame.msg(`Error: ${msg}`);
|
|
117
|
-
});
|
|
118
|
-
tstl.on("close", (code) => {
|
|
119
|
-
(0, utils_1.error)(`Error: ${processDescription} subprocess exited with code: ${code}`);
|
|
120
|
-
});
|
|
121
|
-
tstl.on("exit", (code) => {
|
|
122
|
-
(0, utils_1.error)(`Error: ${processDescription} subprocess exited with code: ${code}`);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
function getFirstTSConfigIncludePath(verbose) {
|
|
126
|
-
const tsConfigRaw = file.read(constants_1.TSCONFIG_PATH, verbose);
|
|
127
|
-
let tsConfig;
|
|
128
|
-
try {
|
|
129
|
-
tsConfig = JSONC.parse(tsConfigRaw);
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
(0, utils_1.error)(`Failed to parse "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}":`, err);
|
|
133
|
-
}
|
|
134
|
-
const include = tsConfig["include"];
|
|
135
|
-
if (include === undefined) {
|
|
136
|
-
(0, utils_1.error)(`Your "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}" file does not have an "include" property, which is surely a mistake. Delete the file and re-run ${constants_1.PROJECT_NAME}.`);
|
|
137
|
-
}
|
|
138
|
-
if (!Array.isArray(include)) {
|
|
139
|
-
(0, utils_1.error)(`Your "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}" file has an "include" property that is not an array, which is surely a mistake. Delete the file and re-run ${constants_1.PROJECT_NAME}.`);
|
|
140
|
-
}
|
|
141
|
-
const firstInclude = include[0];
|
|
142
|
-
if (firstInclude === undefined) {
|
|
143
|
-
(0, utils_1.error)(`Your "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}" file has an empty "include" property, which is surely a mistake. Delete the file and re-run ${constants_1.PROJECT_NAME}.`);
|
|
144
|
-
}
|
|
145
|
-
return firstInclude;
|
|
146
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.monitor = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const JSONC = tslib_1.__importStar(require("jsonc-parser"));
|
|
8
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
+
const constants_1 = require("../../constants");
|
|
10
|
+
const file = tslib_1.__importStar(require("../../file"));
|
|
11
|
+
const utils_1 = require("../../utils");
|
|
12
|
+
const constants_2 = require("./constants");
|
|
13
|
+
const copyWatcherMod_1 = require("./copyWatcherMod");
|
|
14
|
+
const notifyGame = tslib_1.__importStar(require("./notifyGame"));
|
|
15
|
+
const spawnSaveDatWriter_1 = require("./spawnSaveDatWriter");
|
|
16
|
+
const touchWatcherSaveDatFiles_1 = require("./touchWatcherSaveDatFiles");
|
|
17
|
+
let compilationStartTime = new Date();
|
|
18
|
+
function monitor(argv, config) {
|
|
19
|
+
const verbose = argv["verbose"] === true;
|
|
20
|
+
// If they specified some command-line flags, override the values found in the config file.
|
|
21
|
+
if (argv["modsDirectory"] !== undefined) {
|
|
22
|
+
config.modsDirectory = argv["modsDirectory"]; // eslint-disable-line no-param-reassign
|
|
23
|
+
}
|
|
24
|
+
if (argv["saveSlot"] !== undefined) {
|
|
25
|
+
config.saveSlot = argv["saveSlot"]; // eslint-disable-line no-param-reassign
|
|
26
|
+
}
|
|
27
|
+
// Read the "tsconfig.json" file.
|
|
28
|
+
const tsConfigInclude = getFirstTSConfigIncludePath(verbose);
|
|
29
|
+
const resolvedIncludePath = path_1.default.resolve(constants_1.CWD, tsConfigInclude);
|
|
30
|
+
const modTargetDirectoryName = (0, utils_1.getModTargetDirectoryName)(config);
|
|
31
|
+
const modTargetPath = path_1.default.join(config.modsDirectory, modTargetDirectoryName);
|
|
32
|
+
// Prepare the IsaacScript watcher mod.
|
|
33
|
+
(0, copyWatcherMod_1.copyWatcherMod)(config, verbose);
|
|
34
|
+
(0, touchWatcherSaveDatFiles_1.touchWatcherSaveDatFiles)(config, verbose);
|
|
35
|
+
// Delete and re-copy the mod every time IsaacScript starts. This ensures that it is always the
|
|
36
|
+
// latest version.
|
|
37
|
+
if (file.exists(modTargetPath, verbose)) {
|
|
38
|
+
file.deleteFileOrDirectory(modTargetPath, true);
|
|
39
|
+
}
|
|
40
|
+
// Subprocess #1 - The "save#.dat" file writer.
|
|
41
|
+
(0, spawnSaveDatWriter_1.spawnSaveDatWriter)(config);
|
|
42
|
+
// Subprocess #2 - The mod directory syncer.
|
|
43
|
+
spawnModDirectorySyncer(config);
|
|
44
|
+
// Subprocess #3 - tstl --watch (to automatically convert TypeScript to Lua).
|
|
45
|
+
spawnTSTLWatcher();
|
|
46
|
+
// Also, start constantly pinging the watcher mod.
|
|
47
|
+
setInterval(() => {
|
|
48
|
+
notifyGame.ping();
|
|
49
|
+
}, 1000); // Every second
|
|
50
|
+
console.log("Automatically monitoring the following for changes:");
|
|
51
|
+
console.log(`1) your TypeScript code: ${chalk_1.default.green(resolvedIncludePath)}`);
|
|
52
|
+
console.log(`2) the source mod directory: ${chalk_1.default.green(constants_1.MOD_SOURCE_PATH)}`);
|
|
53
|
+
console.log("");
|
|
54
|
+
console.log(`Copying files to: ${chalk_1.default.green(modTargetPath)}`);
|
|
55
|
+
console.log("");
|
|
56
|
+
// (The process will now continue indefinitely for as long as the subprocesses exist.)
|
|
57
|
+
}
|
|
58
|
+
exports.monitor = monitor;
|
|
59
|
+
function spawnModDirectorySyncer(config) {
|
|
60
|
+
const processName = "modDirectorySyncer";
|
|
61
|
+
const processDescription = "Directory syncer";
|
|
62
|
+
const processPath = path_1.default.join(__dirname, processName, processName);
|
|
63
|
+
const modTargetName = (0, utils_1.getModTargetDirectoryName)(config);
|
|
64
|
+
const modTargetPath = path_1.default.join(config.modsDirectory, modTargetName);
|
|
65
|
+
const directorySyncer = (0, child_process_1.fork)(processPath, [constants_1.MOD_SOURCE_PATH, modTargetPath]);
|
|
66
|
+
directorySyncer.on("message", (msg) => {
|
|
67
|
+
notifyGame.msg(msg);
|
|
68
|
+
// If the "main.lua" file was successfully copied over, we also have to tell isaacscript-watcher
|
|
69
|
+
// to reload the mod. Look for something like: "File synced: \main.lua"
|
|
70
|
+
if (msg === `${constants_1.FILE_SYNCED_MESSAGE} ${path_1.default.sep}${constants_1.MAIN_LUA}`) {
|
|
71
|
+
notifyGame.command(`luamod ${modTargetName}`);
|
|
72
|
+
notifyGame.command("restart");
|
|
73
|
+
notifyGame.msg("Reloaded the mod.");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
directorySyncer.on("close", (code) => {
|
|
77
|
+
(0, utils_1.error)(`Error: ${processDescription} subprocess closed with code: ${code}`);
|
|
78
|
+
});
|
|
79
|
+
directorySyncer.on("exit", (code) => {
|
|
80
|
+
(0, utils_1.error)(`Error: ${processDescription} subprocess exited with code: ${code}`);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function spawnTSTLWatcher() {
|
|
84
|
+
const processDescription = "tstl";
|
|
85
|
+
const tstl = (0, child_process_1.spawn)("npx", ["tstl", "--watch", "--preserveWatchOutput"], {
|
|
86
|
+
shell: true,
|
|
87
|
+
});
|
|
88
|
+
tstl.stdout.on("data", (data) => {
|
|
89
|
+
const msg = data.toString().trim();
|
|
90
|
+
if (msg.includes("Starting compilation in watch mode...")) {
|
|
91
|
+
const newMsg = `${constants_1.PROJECT_NAME} is now watching for changes.`;
|
|
92
|
+
notifyGame.msg(newMsg);
|
|
93
|
+
}
|
|
94
|
+
else if (msg.includes("File change detected. Starting incremental compilation...")) {
|
|
95
|
+
compilationStartTime = new Date();
|
|
96
|
+
const newMsg = "TypeScript change detected. Compiling...";
|
|
97
|
+
notifyGame.msg(newMsg);
|
|
98
|
+
}
|
|
99
|
+
else if (msg.includes("Found 0 errors. Watching for file changes.")) {
|
|
100
|
+
const compilationFinishTime = new Date();
|
|
101
|
+
const elapsedTimeMilliseconds = compilationFinishTime.getTime() - compilationStartTime.getTime();
|
|
102
|
+
const elapsedTimeSeconds = elapsedTimeMilliseconds / 1000;
|
|
103
|
+
const newMsg = `${constants_2.COMPILATION_SUCCESSFUL} (in ${elapsedTimeSeconds} seconds)`;
|
|
104
|
+
notifyGame.msg(newMsg);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
notifyGame.msg(msg);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
tstl.stderr.on("data", (data) => {
|
|
111
|
+
const msg = data.toString().trim();
|
|
112
|
+
if (msg === "^C") {
|
|
113
|
+
// Hide the line that appears when you cancel the program with `Ctrl + c`.
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
notifyGame.msg(`Error: ${msg}`);
|
|
117
|
+
});
|
|
118
|
+
tstl.on("close", (code) => {
|
|
119
|
+
(0, utils_1.error)(`Error: ${processDescription} subprocess exited with code: ${code}`);
|
|
120
|
+
});
|
|
121
|
+
tstl.on("exit", (code) => {
|
|
122
|
+
(0, utils_1.error)(`Error: ${processDescription} subprocess exited with code: ${code}`);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function getFirstTSConfigIncludePath(verbose) {
|
|
126
|
+
const tsConfigRaw = file.read(constants_1.TSCONFIG_PATH, verbose);
|
|
127
|
+
let tsConfig;
|
|
128
|
+
try {
|
|
129
|
+
tsConfig = JSONC.parse(tsConfigRaw);
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
(0, utils_1.error)(`Failed to parse "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}":`, err);
|
|
133
|
+
}
|
|
134
|
+
const include = tsConfig["include"];
|
|
135
|
+
if (include === undefined) {
|
|
136
|
+
(0, utils_1.error)(`Your "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}" file does not have an "include" property, which is surely a mistake. Delete the file and re-run ${constants_1.PROJECT_NAME}.`);
|
|
137
|
+
}
|
|
138
|
+
if (!Array.isArray(include)) {
|
|
139
|
+
(0, utils_1.error)(`Your "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}" file has an "include" property that is not an array, which is surely a mistake. Delete the file and re-run ${constants_1.PROJECT_NAME}.`);
|
|
140
|
+
}
|
|
141
|
+
const firstInclude = include[0];
|
|
142
|
+
if (firstInclude === undefined) {
|
|
143
|
+
(0, utils_1.error)(`Your "${chalk_1.default.green(constants_1.TSCONFIG_PATH)}" file has an empty "include" property, which is surely a mistake. Delete the file and re-run ${constants_1.PROJECT_NAME}.`);
|
|
144
|
+
}
|
|
145
|
+
return firstInclude;
|
|
146
|
+
}
|
|
147
147
|
//# sourceMappingURL=monitor.js.map
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ping = exports.command = exports.msg = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
8
|
-
const spawnSaveDatWriter_1 = require("./spawnSaveDatWriter");
|
|
9
|
-
function msg(data) {
|
|
10
|
-
const formattedData = data
|
|
11
|
-
.replace(/\r\n/g, "\n") // Replace Windows newlines with Unix newlines
|
|
12
|
-
.trim(); // Trim whitespace
|
|
13
|
-
for (const line of formattedData.split("\n")) {
|
|
14
|
-
const trimmedLine = line.trim();
|
|
15
|
-
if (trimmedLine === "") {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
// Ignore the final message from tstl upon exiting the program.
|
|
19
|
-
if (trimmedLine === "Terminate batch job (Y/N)?") {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
// Add a time prefix.
|
|
23
|
-
const formattedLine = `[${(0, utils_1.getTime)()}] ${trimmedLine}`;
|
|
24
|
-
(0, spawnSaveDatWriter_1.sendMsgToSaveDatWriter)({
|
|
25
|
-
type: "msg",
|
|
26
|
-
data: formattedLine,
|
|
27
|
-
});
|
|
28
|
-
// We also print the message to standard out so that the end-user can choose between reading
|
|
29
|
-
// tstl errors from the IsaacScript terminal window or from looking at the in-game output.
|
|
30
|
-
printMsgToStandardOut(formattedLine);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.msg = msg;
|
|
34
|
-
function printMsgToStandardOut(data) {
|
|
35
|
-
let coloredData = data;
|
|
36
|
-
if (data.includes(constants_1.COMPILATION_SUCCESSFUL)) {
|
|
37
|
-
coloredData = chalk_1.default.green(data);
|
|
38
|
-
}
|
|
39
|
-
else if (data.match(/error/g) !== null) {
|
|
40
|
-
coloredData = chalk_1.default.red(data);
|
|
41
|
-
}
|
|
42
|
-
console.log(coloredData);
|
|
43
|
-
}
|
|
44
|
-
function command(data) {
|
|
45
|
-
(0, spawnSaveDatWriter_1.sendMsgToSaveDatWriter)({
|
|
46
|
-
type: "command",
|
|
47
|
-
data,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
exports.command = command;
|
|
51
|
-
function ping() {
|
|
52
|
-
(0, spawnSaveDatWriter_1.sendMsgToSaveDatWriter)({
|
|
53
|
-
type: "ping",
|
|
54
|
-
data: "",
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
exports.ping = ping;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ping = exports.command = exports.msg = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const spawnSaveDatWriter_1 = require("./spawnSaveDatWriter");
|
|
9
|
+
function msg(data) {
|
|
10
|
+
const formattedData = data
|
|
11
|
+
.replace(/\r\n/g, "\n") // Replace Windows newlines with Unix newlines
|
|
12
|
+
.trim(); // Trim whitespace
|
|
13
|
+
for (const line of formattedData.split("\n")) {
|
|
14
|
+
const trimmedLine = line.trim();
|
|
15
|
+
if (trimmedLine === "") {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
// Ignore the final message from tstl upon exiting the program.
|
|
19
|
+
if (trimmedLine === "Terminate batch job (Y/N)?") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Add a time prefix.
|
|
23
|
+
const formattedLine = `[${(0, utils_1.getTime)()}] ${trimmedLine}`;
|
|
24
|
+
(0, spawnSaveDatWriter_1.sendMsgToSaveDatWriter)({
|
|
25
|
+
type: "msg",
|
|
26
|
+
data: formattedLine,
|
|
27
|
+
});
|
|
28
|
+
// We also print the message to standard out so that the end-user can choose between reading
|
|
29
|
+
// tstl errors from the IsaacScript terminal window or from looking at the in-game output.
|
|
30
|
+
printMsgToStandardOut(formattedLine);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.msg = msg;
|
|
34
|
+
function printMsgToStandardOut(data) {
|
|
35
|
+
let coloredData = data;
|
|
36
|
+
if (data.includes(constants_1.COMPILATION_SUCCESSFUL)) {
|
|
37
|
+
coloredData = chalk_1.default.green(data);
|
|
38
|
+
}
|
|
39
|
+
else if (data.match(/error/g) !== null) {
|
|
40
|
+
coloredData = chalk_1.default.red(data);
|
|
41
|
+
}
|
|
42
|
+
console.log(coloredData);
|
|
43
|
+
}
|
|
44
|
+
function command(data) {
|
|
45
|
+
(0, spawnSaveDatWriter_1.sendMsgToSaveDatWriter)({
|
|
46
|
+
type: "command",
|
|
47
|
+
data,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.command = command;
|
|
51
|
+
function ping() {
|
|
52
|
+
(0, spawnSaveDatWriter_1.sendMsgToSaveDatWriter)({
|
|
53
|
+
type: "ping",
|
|
54
|
+
data: "",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.ping = ping;
|
|
58
58
|
//# sourceMappingURL=notifyGame.js.map
|
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const JSONC = tslib_1.__importStar(require("jsonc-parser"));
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
-
const constants_1 = require("../../../constants");
|
|
7
|
-
const file = tslib_1.__importStar(require("../../../file"));
|
|
8
|
-
const utils_1 = require("../../../utils");
|
|
9
|
-
const SUBPROCESS_NAME = "save#.dat writer";
|
|
10
|
-
const BASE_ARGV_LENGTH = 2;
|
|
11
|
-
const MAX_MESSAGES = 100;
|
|
12
|
-
const VERBOSE = false;
|
|
13
|
-
let saveDatPath;
|
|
14
|
-
let saveDatFileName;
|
|
15
|
-
init(VERBOSE);
|
|
16
|
-
function init(verbose) {
|
|
17
|
-
const firstArg = process.argv[BASE_ARGV_LENGTH];
|
|
18
|
-
if (firstArg === undefined) {
|
|
19
|
-
throw new Error(`The ${SUBPROCESS_NAME} process did not get a valid first argument.`);
|
|
20
|
-
}
|
|
21
|
-
saveDatPath = firstArg;
|
|
22
|
-
saveDatFileName = path_1.default.basename(saveDatPath);
|
|
23
|
-
// Check to see if the data directory exists.
|
|
24
|
-
const watcherModDataPath = path_1.default.dirname(saveDatPath);
|
|
25
|
-
if (!file.exists(watcherModDataPath, verbose)) {
|
|
26
|
-
file.makeDir(watcherModDataPath, verbose);
|
|
27
|
-
}
|
|
28
|
-
// Listen for messages from the parent process.
|
|
29
|
-
process.on("message", (msg) => {
|
|
30
|
-
onMessage(msg.type, msg.data);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function onMessage(type, data, numRetries = 0) {
|
|
34
|
-
const saveDat = readSaveDatFromDisk(VERBOSE);
|
|
35
|
-
if (saveDat.length > MAX_MESSAGES) {
|
|
36
|
-
// If IsaacScript is running and:
|
|
37
|
-
// - the game is not open
|
|
38
|
-
// - or the game is open but the IsaacScript Watcher mod is disabled
|
|
39
|
-
//
|
|
40
|
-
// Then this process will continue to write to the "save#.dat" file, which can cause it to grow
|
|
41
|
-
// arbitrarily large (since there is no-one on the other side removing the messages). If there
|
|
42
|
-
// is N messages already in the queue, assume that no-one is listening and stop adding any more
|
|
43
|
-
// messages.
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
addMessageToSaveDat(type, saveDat, data); // Mutates saveDat
|
|
47
|
-
writeSaveDatToDisk(type, data, saveDat, numRetries, VERBOSE);
|
|
48
|
-
}
|
|
49
|
-
function readSaveDatFromDisk(verbose) {
|
|
50
|
-
let saveDat;
|
|
51
|
-
if (file.exists(saveDatPath, verbose)) {
|
|
52
|
-
const saveDatRaw = file.read(saveDatPath, verbose);
|
|
53
|
-
try {
|
|
54
|
-
saveDat = JSONC.parse(saveDatRaw);
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
send(`Failed to parse "${saveDatPath}": ${err}`);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
saveDat = [];
|
|
63
|
-
}
|
|
64
|
-
if (!Array.isArray(saveDat)) {
|
|
65
|
-
saveDat = [];
|
|
66
|
-
}
|
|
67
|
-
return saveDat;
|
|
68
|
-
}
|
|
69
|
-
function addMessageToSaveDat(type, saveDat, data) {
|
|
70
|
-
switch (type) {
|
|
71
|
-
case "command":
|
|
72
|
-
case "ping": {
|
|
73
|
-
saveDat.push({
|
|
74
|
-
type,
|
|
75
|
-
data,
|
|
76
|
-
});
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case "msg": {
|
|
80
|
-
const lines = data.split("\n");
|
|
81
|
-
for (const line of lines) {
|
|
82
|
-
saveDat.push({
|
|
83
|
-
type,
|
|
84
|
-
data: line,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
default: {
|
|
90
|
-
(0, utils_1.ensureAllCases)(type);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function writeSaveDatToDisk(type, data, saveDat, numRetries, verbose) {
|
|
96
|
-
const saveDatRaw = JSON.stringify(saveDat, null, 2);
|
|
97
|
-
try {
|
|
98
|
-
file.writeTry(saveDatPath, saveDatRaw, verbose);
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
if (numRetries > 4) {
|
|
102
|
-
send(`Failed to write to the ${saveDatFileName} for 5 times in a row. Maybe the file got locked somehow. ${constants_1.PROJECT_NAME} will now exit.`);
|
|
103
|
-
send(`The writing error is as follows: ${err}`);
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
send(`Writing to "${saveDatFileName}" failed. (The number of retries so far is ${numRetries}.) Trying again in 0.1 seconds...`);
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
onMessage(type, data, numRetries + 1);
|
|
109
|
-
}, 100);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function send(msg) {
|
|
113
|
-
if (process.send !== undefined) {
|
|
114
|
-
process.send(msg);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const JSONC = tslib_1.__importStar(require("jsonc-parser"));
|
|
5
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
+
const constants_1 = require("../../../constants");
|
|
7
|
+
const file = tslib_1.__importStar(require("../../../file"));
|
|
8
|
+
const utils_1 = require("../../../utils");
|
|
9
|
+
const SUBPROCESS_NAME = "save#.dat writer";
|
|
10
|
+
const BASE_ARGV_LENGTH = 2;
|
|
11
|
+
const MAX_MESSAGES = 100;
|
|
12
|
+
const VERBOSE = false;
|
|
13
|
+
let saveDatPath;
|
|
14
|
+
let saveDatFileName;
|
|
15
|
+
init(VERBOSE);
|
|
16
|
+
function init(verbose) {
|
|
17
|
+
const firstArg = process.argv[BASE_ARGV_LENGTH];
|
|
18
|
+
if (firstArg === undefined) {
|
|
19
|
+
throw new Error(`The ${SUBPROCESS_NAME} process did not get a valid first argument.`);
|
|
20
|
+
}
|
|
21
|
+
saveDatPath = firstArg;
|
|
22
|
+
saveDatFileName = path_1.default.basename(saveDatPath);
|
|
23
|
+
// Check to see if the data directory exists.
|
|
24
|
+
const watcherModDataPath = path_1.default.dirname(saveDatPath);
|
|
25
|
+
if (!file.exists(watcherModDataPath, verbose)) {
|
|
26
|
+
file.makeDir(watcherModDataPath, verbose);
|
|
27
|
+
}
|
|
28
|
+
// Listen for messages from the parent process.
|
|
29
|
+
process.on("message", (msg) => {
|
|
30
|
+
onMessage(msg.type, msg.data);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function onMessage(type, data, numRetries = 0) {
|
|
34
|
+
const saveDat = readSaveDatFromDisk(VERBOSE);
|
|
35
|
+
if (saveDat.length > MAX_MESSAGES) {
|
|
36
|
+
// If IsaacScript is running and:
|
|
37
|
+
// - the game is not open
|
|
38
|
+
// - or the game is open but the IsaacScript Watcher mod is disabled
|
|
39
|
+
//
|
|
40
|
+
// Then this process will continue to write to the "save#.dat" file, which can cause it to grow
|
|
41
|
+
// arbitrarily large (since there is no-one on the other side removing the messages). If there
|
|
42
|
+
// is N messages already in the queue, assume that no-one is listening and stop adding any more
|
|
43
|
+
// messages.
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
addMessageToSaveDat(type, saveDat, data); // Mutates saveDat
|
|
47
|
+
writeSaveDatToDisk(type, data, saveDat, numRetries, VERBOSE);
|
|
48
|
+
}
|
|
49
|
+
function readSaveDatFromDisk(verbose) {
|
|
50
|
+
let saveDat;
|
|
51
|
+
if (file.exists(saveDatPath, verbose)) {
|
|
52
|
+
const saveDatRaw = file.read(saveDatPath, verbose);
|
|
53
|
+
try {
|
|
54
|
+
saveDat = JSONC.parse(saveDatRaw);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
send(`Failed to parse "${saveDatPath}": ${err}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
saveDat = [];
|
|
63
|
+
}
|
|
64
|
+
if (!Array.isArray(saveDat)) {
|
|
65
|
+
saveDat = [];
|
|
66
|
+
}
|
|
67
|
+
return saveDat;
|
|
68
|
+
}
|
|
69
|
+
function addMessageToSaveDat(type, saveDat, data) {
|
|
70
|
+
switch (type) {
|
|
71
|
+
case "command":
|
|
72
|
+
case "ping": {
|
|
73
|
+
saveDat.push({
|
|
74
|
+
type,
|
|
75
|
+
data,
|
|
76
|
+
});
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "msg": {
|
|
80
|
+
const lines = data.split("\n");
|
|
81
|
+
for (const line of lines) {
|
|
82
|
+
saveDat.push({
|
|
83
|
+
type,
|
|
84
|
+
data: line,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
default: {
|
|
90
|
+
(0, utils_1.ensureAllCases)(type);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function writeSaveDatToDisk(type, data, saveDat, numRetries, verbose) {
|
|
96
|
+
const saveDatRaw = JSON.stringify(saveDat, null, 2);
|
|
97
|
+
try {
|
|
98
|
+
file.writeTry(saveDatPath, saveDatRaw, verbose);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (numRetries > 4) {
|
|
102
|
+
send(`Failed to write to the ${saveDatFileName} for 5 times in a row. Maybe the file got locked somehow. ${constants_1.PROJECT_NAME} will now exit.`);
|
|
103
|
+
send(`The writing error is as follows: ${err}`);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
send(`Writing to "${saveDatFileName}" failed. (The number of retries so far is ${numRetries}.) Trying again in 0.1 seconds...`);
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
onMessage(type, data, numRetries + 1);
|
|
109
|
+
}, 100);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function send(msg) {
|
|
113
|
+
if (process.send !== undefined) {
|
|
114
|
+
process.send(msg);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
117
|
//# sourceMappingURL=saveDatWriter.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=types.js.map
|