isaacscript 1.1.74-dev.3 → 1.2.3
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/dist/package.json +5 -5
- package/dist/src/commands/copy/copy.js +13 -12
- package/dist/src/commands/copy/copy.js.map +1 -1
- package/dist/src/commands/init/checkIfProjectPathExists.js +2 -2
- package/dist/src/commands/init/checkIfProjectPathExists.js.map +1 -1
- package/dist/src/commands/init/checkModTargetDirectory.js +2 -2
- package/dist/src/commands/init/checkModTargetDirectory.js.map +1 -1
- package/dist/src/commands/init/createMod.js +55 -34
- package/dist/src/commands/init/createMod.js.map +1 -1
- package/dist/src/commands/init/init.js +10 -8
- package/dist/src/commands/init/init.js.map +1 -1
- package/dist/src/commands/init/installVSCodeExtensions.js +3 -2
- package/dist/src/commands/init/installVSCodeExtensions.js.map +1 -1
- package/dist/src/commands/init/promptVSCode.js +7 -7
- package/dist/src/commands/init/promptVSCode.js.map +1 -1
- package/dist/src/commands/monitor/copyWatcherMod.js +7 -7
- package/dist/src/commands/monitor/copyWatcherMod.js.map +1 -1
- package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js +4 -4
- package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js.map +1 -1
- package/dist/src/commands/monitor/monitor.js +4 -3
- package/dist/src/commands/monitor/monitor.js.map +1 -1
- package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js +1 -1
- package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js.map +1 -1
- package/dist/src/commands/monitor/touchWatcherSaveDatFiles.js +3 -3
- package/dist/src/commands/monitor/touchWatcherSaveDatFiles.js.map +1 -1
- package/dist/src/commands/publish/publish.js +48 -46
- package/dist/src/commands/publish/publish.js.map +1 -1
- package/dist/src/configFile.js +4 -3
- package/dist/src/configFile.js.map +1 -1
- package/dist/src/exec.js +79 -0
- package/dist/src/exec.js.map +1 -0
- package/dist/src/file.js +35 -5
- package/dist/src/file.js.map +1 -1
- package/dist/src/main.js +1 -1
- package/dist/src/main.js.map +1 -1
- package/dist/src/monkeyPatch.js +8 -14
- package/dist/src/monkeyPatch.js.map +1 -1
- package/dist/src/parseArgs.js +20 -1
- package/dist/src/parseArgs.js.map +1 -1
- package/dist/src/util.js +22 -57
- package/dist/src/util.js.map +1 -1
- package/dist/src/validateNodeVersion.js +6 -24
- package/dist/src/validateNodeVersion.js.map +1 -1
- package/package.json +5 -5
- package/publish.sh +1 -1
- package/src/commands/copy/copy.ts +20 -12
- package/src/commands/init/checkIfProjectPathExists.ts +2 -1
- package/src/commands/init/checkModTargetDirectory.ts +2 -1
- package/src/commands/init/createMod.ts +87 -29
- package/src/commands/init/init.ts +15 -7
- package/src/commands/init/installVSCodeExtensions.ts +4 -2
- package/src/commands/init/promptVSCode.ts +12 -7
- package/src/commands/monitor/copyWatcherMod.ts +10 -7
- package/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.ts +3 -3
- package/src/commands/monitor/monitor.ts +5 -3
- package/src/commands/monitor/saveDatWriter/saveDatWriter.ts +1 -1
- package/src/commands/monitor/touchWatcherSaveDatFiles.ts +6 -3
- package/src/commands/publish/publish.ts +65 -55
- package/src/configFile.ts +9 -3
- package/src/exec.ts +102 -0
- package/src/file.ts +48 -5
- package/src/main.ts +1 -1
- package/src/monkeyPatch.ts +8 -13
- package/src/parseArgs.ts +22 -1
- package/src/util.ts +29 -79
- package/src/validateNodeVersion.ts +7 -39
|
@@ -12,15 +12,10 @@ import {
|
|
|
12
12
|
PUBLISH_PRE_COPY_PY_PATH,
|
|
13
13
|
VERSION_TXT_PATH,
|
|
14
14
|
} from "../../constants";
|
|
15
|
+
import { execExe, execShell } from "../../exec";
|
|
15
16
|
import * as file from "../../file";
|
|
16
17
|
import { Config } from "../../types/Config";
|
|
17
|
-
import {
|
|
18
|
-
error,
|
|
19
|
-
execExe,
|
|
20
|
-
execShell,
|
|
21
|
-
getModTargetDirectoryName,
|
|
22
|
-
parseIntSafe,
|
|
23
|
-
} from "../../util";
|
|
18
|
+
import { error, getModTargetDirectoryName, parseIntSafe } from "../../util";
|
|
24
19
|
import { compileAndCopy } from "../copy/copy";
|
|
25
20
|
|
|
26
21
|
const UPDATE_SCRIPT_NAME = "update.sh";
|
|
@@ -30,6 +25,7 @@ export function publish(argv: Record<string, unknown>, config: Config): void {
|
|
|
30
25
|
const setVersion = argv.setVersion as string | undefined;
|
|
31
26
|
const dryRun = argv.dryRun === true;
|
|
32
27
|
const onlyUpload = argv.onlyUpload === true;
|
|
28
|
+
const verbose = argv.verbose === true;
|
|
33
29
|
|
|
34
30
|
const modTargetDirectoryName = getModTargetDirectoryName(config);
|
|
35
31
|
const modTargetPath = path.join(config.modsDirectory, modTargetDirectoryName);
|
|
@@ -43,7 +39,7 @@ export function publish(argv: Record<string, unknown>, config: Config): void {
|
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
if (onlyUpload) {
|
|
46
|
-
uploadMod(modTargetPath, config.steamCmdPath);
|
|
42
|
+
uploadMod(modTargetPath, config.steamCmdPath, verbose);
|
|
47
43
|
return;
|
|
48
44
|
}
|
|
49
45
|
|
|
@@ -54,6 +50,7 @@ export function publish(argv: Record<string, unknown>, config: Config): void {
|
|
|
54
50
|
setVersion,
|
|
55
51
|
config.steamCmdPath,
|
|
56
52
|
dryRun,
|
|
53
|
+
verbose,
|
|
57
54
|
);
|
|
58
55
|
}
|
|
59
56
|
|
|
@@ -64,42 +61,43 @@ function startPublish(
|
|
|
64
61
|
setVersion: string | undefined,
|
|
65
62
|
steamCmdPath: string | undefined,
|
|
66
63
|
dryRun: boolean,
|
|
64
|
+
verbose: boolean,
|
|
67
65
|
) {
|
|
68
|
-
updateDeps();
|
|
66
|
+
updateDeps(verbose);
|
|
69
67
|
|
|
70
68
|
let version =
|
|
71
69
|
setVersion === undefined ? getVersionFromPackageJSON() : setVersion;
|
|
72
70
|
if (!skipVersionIncrement && setVersion === undefined) {
|
|
73
|
-
version = bumpVersionInPackageJSON(version);
|
|
71
|
+
version = bumpVersionInPackageJSON(version, verbose);
|
|
74
72
|
} else if (setVersion !== undefined) {
|
|
75
|
-
writeVersionInPackageJSON(version);
|
|
73
|
+
writeVersionInPackageJSON(version, verbose);
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
writeVersionToConstantsTS(version);
|
|
79
|
-
writeVersionToMetadataXML(version);
|
|
80
|
-
writeVersionToVersionTXT(version);
|
|
81
|
-
runReleaseScriptPreCopy();
|
|
82
|
-
compileAndCopy(modSourcePath, modTargetPath);
|
|
83
|
-
purgeRoomXMLs(modTargetPath);
|
|
84
|
-
runReleaseScriptPostCopy();
|
|
76
|
+
writeVersionToConstantsTS(version, verbose);
|
|
77
|
+
writeVersionToMetadataXML(version, verbose);
|
|
78
|
+
writeVersionToVersionTXT(version, verbose);
|
|
79
|
+
runReleaseScriptPreCopy(verbose);
|
|
80
|
+
compileAndCopy(modSourcePath, modTargetPath, verbose);
|
|
81
|
+
purgeRoomXMLs(modTargetPath, verbose);
|
|
82
|
+
runReleaseScriptPostCopy(verbose);
|
|
85
83
|
|
|
86
84
|
if (!dryRun) {
|
|
87
|
-
gitCommitIfChanges(version);
|
|
88
|
-
uploadMod(modTargetPath, steamCmdPath);
|
|
85
|
+
gitCommitIfChanges(version, verbose);
|
|
86
|
+
uploadMod(modTargetPath, steamCmdPath, verbose);
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
const dryRunSuffix = dryRun ? " (dry run)" : "";
|
|
92
90
|
console.log(`\nPublished version ${version} successfully${dryRunSuffix}.`);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
function updateDeps() {
|
|
93
|
+
function updateDeps(verbose: boolean) {
|
|
96
94
|
if (!file.exists(UPDATE_SCRIPT_NAME)) {
|
|
97
95
|
error(
|
|
98
96
|
`The "${UPDATE_SCRIPT_NAME}" script does not exist in the current working directory.`,
|
|
99
97
|
);
|
|
100
98
|
}
|
|
101
99
|
|
|
102
|
-
execShell("bash", [UPDATE_SCRIPT_NAME]);
|
|
100
|
+
execShell("bash", [UPDATE_SCRIPT_NAME], verbose);
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
function getVersionFromPackageJSON() {
|
|
@@ -138,7 +136,7 @@ function getVersionFromPackageJSON() {
|
|
|
138
136
|
return packageJSON.version;
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
function bumpVersionInPackageJSON(version: string): string {
|
|
139
|
+
function bumpVersionInPackageJSON(version: string, verbose: boolean): string {
|
|
142
140
|
// Get the patch version (i.e. the third number)
|
|
143
141
|
const matches = /(\d+\.\d+\.)(\d+)/.exec(version);
|
|
144
142
|
if (matches === null) {
|
|
@@ -168,7 +166,7 @@ function bumpVersionInPackageJSON(version: string): string {
|
|
|
168
166
|
/"version": ".+",/,
|
|
169
167
|
`"version": "${incrementedVersion}",`,
|
|
170
168
|
);
|
|
171
|
-
file.write(PACKAGE_JSON_PATH, newPackageJSON);
|
|
169
|
+
file.write(PACKAGE_JSON_PATH, newPackageJSON, verbose);
|
|
172
170
|
|
|
173
171
|
console.log(
|
|
174
172
|
`The version of ${incrementedVersion} was written to: ${PACKAGE_JSON_PATH}`,
|
|
@@ -177,18 +175,18 @@ function bumpVersionInPackageJSON(version: string): string {
|
|
|
177
175
|
return incrementedVersion;
|
|
178
176
|
}
|
|
179
177
|
|
|
180
|
-
function writeVersionInPackageJSON(version: string) {
|
|
178
|
+
function writeVersionInPackageJSON(version: string, verbose: boolean) {
|
|
181
179
|
const packageJSON = file.read(PACKAGE_JSON_PATH);
|
|
182
180
|
const newPackageJSON = packageJSON.replace(
|
|
183
181
|
/"version": ".+",/,
|
|
184
182
|
`"version": "${version}",`,
|
|
185
183
|
);
|
|
186
|
-
file.write(PACKAGE_JSON_PATH, newPackageJSON);
|
|
184
|
+
file.write(PACKAGE_JSON_PATH, newPackageJSON, verbose);
|
|
187
185
|
|
|
188
186
|
console.log(`The version of ${version} was written to: ${PACKAGE_JSON_PATH}`);
|
|
189
187
|
}
|
|
190
188
|
|
|
191
|
-
function writeVersionToConstantsTS(version: string) {
|
|
189
|
+
function writeVersionToConstantsTS(version: string, verbose: boolean) {
|
|
192
190
|
if (!file.exists(CONSTANTS_TS_PATH)) {
|
|
193
191
|
console.log(
|
|
194
192
|
'Skipping writing the version to "constants.ts" since it was not found.',
|
|
@@ -201,57 +199,57 @@ function writeVersionToConstantsTS(version: string) {
|
|
|
201
199
|
/const VERSION = ".+"/,
|
|
202
200
|
`const VERSION = "${version}"`,
|
|
203
201
|
);
|
|
204
|
-
file.write(CONSTANTS_TS_PATH, newConstantsTS);
|
|
202
|
+
file.write(CONSTANTS_TS_PATH, newConstantsTS, verbose);
|
|
205
203
|
|
|
206
204
|
console.log(`The version of ${version} was written to: ${CONSTANTS_TS_PATH}`);
|
|
207
205
|
}
|
|
208
206
|
|
|
209
|
-
function writeVersionToMetadataXML(version: string) {
|
|
207
|
+
function writeVersionToMetadataXML(version: string, verbose: boolean) {
|
|
210
208
|
const metadataXML = file.read(METADATA_XML_PATH);
|
|
211
209
|
const newMetadataXML = metadataXML.replace(
|
|
212
210
|
/<version>.+<\/version>/,
|
|
213
211
|
`<version>${version}</version>`,
|
|
214
212
|
);
|
|
215
|
-
file.write(METADATA_XML_PATH, newMetadataXML);
|
|
213
|
+
file.write(METADATA_XML_PATH, newMetadataXML, verbose);
|
|
216
214
|
|
|
217
215
|
console.log(`The version of ${version} was written to: ${METADATA_XML_PATH}`);
|
|
218
216
|
}
|
|
219
217
|
|
|
220
|
-
function writeVersionToVersionTXT(version: string) {
|
|
221
|
-
file.write(VERSION_TXT_PATH, version);
|
|
218
|
+
function writeVersionToVersionTXT(version: string, verbose: boolean) {
|
|
219
|
+
file.write(VERSION_TXT_PATH, version, verbose);
|
|
222
220
|
|
|
223
221
|
console.log(`The version of ${version} was written to: ${VERSION_TXT_PATH}`);
|
|
224
222
|
}
|
|
225
223
|
|
|
226
|
-
function runReleaseScriptPreCopy() {
|
|
224
|
+
function runReleaseScriptPreCopy(verbose: boolean) {
|
|
227
225
|
if (!file.exists(PUBLISH_PRE_COPY_PY_PATH)) {
|
|
228
226
|
return;
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
console.log(`Running the "${PUBLISH_PRE_COPY_PY_PATH}" script.`);
|
|
232
|
-
let [, stdout] = execShell("python", [PUBLISH_PRE_COPY_PY_PATH]);
|
|
230
|
+
let [, stdout] = execShell("python", [PUBLISH_PRE_COPY_PY_PATH], verbose);
|
|
233
231
|
stdout = stdout.trim();
|
|
234
232
|
if (stdout.length > 0) {
|
|
235
233
|
console.log(stdout);
|
|
236
234
|
}
|
|
237
235
|
}
|
|
238
236
|
|
|
239
|
-
function runReleaseScriptPostCopy() {
|
|
237
|
+
function runReleaseScriptPostCopy(verbose: boolean) {
|
|
240
238
|
if (!file.exists(PUBLISH_POST_COPY_PY_PATH)) {
|
|
241
239
|
return;
|
|
242
240
|
}
|
|
243
241
|
|
|
244
242
|
console.log(`Running the "${PUBLISH_POST_COPY_PY_PATH}" script.`);
|
|
245
|
-
let [, stdout] = execShell("python", [PUBLISH_POST_COPY_PY_PATH]);
|
|
243
|
+
let [, stdout] = execShell("python", [PUBLISH_POST_COPY_PY_PATH], verbose);
|
|
246
244
|
stdout = stdout.trim();
|
|
247
245
|
if (stdout.length > 0) {
|
|
248
246
|
console.log(stdout);
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
249
|
|
|
252
|
-
function gitCommitIfChanges(version: string) {
|
|
250
|
+
function gitCommitIfChanges(version: string, verbose: boolean) {
|
|
253
251
|
// Throw an error if this is not a git repository
|
|
254
|
-
execShell("git", ["status"]);
|
|
252
|
+
execShell("git", ["status"], verbose);
|
|
255
253
|
|
|
256
254
|
// Check to see if there are any changes
|
|
257
255
|
// https://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommitted-changes
|
|
@@ -267,16 +265,16 @@ function gitCommitIfChanges(version: string) {
|
|
|
267
265
|
}
|
|
268
266
|
|
|
269
267
|
const commitMessage = `v${version}`;
|
|
270
|
-
execShell("git", ["add", "-A"]);
|
|
271
|
-
execShell("git", ["commit", "-m", commitMessage]);
|
|
272
|
-
execShell("git", ["push"]);
|
|
268
|
+
execShell("git", ["add", "-A"], verbose);
|
|
269
|
+
execShell("git", ["commit", "-m", commitMessage], verbose);
|
|
270
|
+
execShell("git", ["push"], verbose);
|
|
273
271
|
|
|
274
272
|
console.log(
|
|
275
273
|
`Committed and pushed to the git repository with a message of: ${commitMessage}`,
|
|
276
274
|
);
|
|
277
275
|
}
|
|
278
276
|
|
|
279
|
-
function purgeRoomXMLs(modTargetPath: string) {
|
|
277
|
+
function purgeRoomXMLs(modTargetPath: string, verbose: boolean) {
|
|
280
278
|
const roomsPath = path.join(modTargetPath, "resources", "rooms");
|
|
281
279
|
if (!file.exists(roomsPath) || !file.isDir(roomsPath)) {
|
|
282
280
|
return;
|
|
@@ -286,25 +284,33 @@ function purgeRoomXMLs(modTargetPath: string) {
|
|
|
286
284
|
roomFileList.forEach((fileName: string) => {
|
|
287
285
|
if (path.extname(fileName) === ".xml") {
|
|
288
286
|
const roomFilePath = path.join(roomsPath, fileName);
|
|
289
|
-
file.deleteFileOrDirectory(roomFilePath);
|
|
287
|
+
file.deleteFileOrDirectory(roomFilePath, verbose);
|
|
290
288
|
}
|
|
291
289
|
});
|
|
292
290
|
}
|
|
293
291
|
|
|
294
|
-
function uploadMod(
|
|
292
|
+
function uploadMod(
|
|
293
|
+
modTargetPath: string,
|
|
294
|
+
steamCmdPath: string | undefined,
|
|
295
|
+
verbose: boolean,
|
|
296
|
+
) {
|
|
295
297
|
if (steamCmdPath === undefined) {
|
|
296
298
|
console.log(
|
|
297
299
|
`The "steamCmdPath" property was not found in the "${chalk.green(
|
|
298
300
|
CONFIG_FILE_NAME,
|
|
299
301
|
)}" file; assuming that we want to use the ModUploader tool.`,
|
|
300
302
|
);
|
|
301
|
-
execExe(MOD_UPLOADER_PATH, modTargetPath);
|
|
303
|
+
execExe(MOD_UPLOADER_PATH, verbose, modTargetPath);
|
|
302
304
|
} else {
|
|
303
|
-
runSteamCmd(modTargetPath, steamCmdPath);
|
|
305
|
+
runSteamCmd(modTargetPath, steamCmdPath, verbose);
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
|
|
307
|
-
function runSteamCmd(
|
|
309
|
+
function runSteamCmd(
|
|
310
|
+
modTargetPath: string,
|
|
311
|
+
steamCmdPath: string,
|
|
312
|
+
verbose: boolean,
|
|
313
|
+
) {
|
|
308
314
|
if (!file.exists(steamCmdPath)) {
|
|
309
315
|
error(
|
|
310
316
|
chalk.red(
|
|
@@ -347,14 +353,18 @@ function runSteamCmd(modTargetPath: string, steamCmdPath: string) {
|
|
|
347
353
|
|
|
348
354
|
console.log("Uploading the mod to the Steam Workshop...");
|
|
349
355
|
|
|
350
|
-
execShell(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
356
|
+
execShell(
|
|
357
|
+
steamCmdPath,
|
|
358
|
+
[
|
|
359
|
+
"+login",
|
|
360
|
+
username,
|
|
361
|
+
password,
|
|
362
|
+
"+workshop_build_item",
|
|
363
|
+
metadataVDFPath,
|
|
364
|
+
"+quit",
|
|
365
|
+
],
|
|
366
|
+
verbose,
|
|
367
|
+
);
|
|
358
368
|
|
|
359
369
|
console.log("Mod uploaded successfully.");
|
|
360
370
|
}
|
package/src/configFile.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { Config } from "./types/Config";
|
|
|
9
9
|
import { error } from "./util";
|
|
10
10
|
|
|
11
11
|
export async function get(argv: Record<string, unknown>): Promise<Config> {
|
|
12
|
+
const verbose = argv.verbose === true;
|
|
13
|
+
|
|
12
14
|
const existingConfig = readExistingConfig();
|
|
13
15
|
if (existingConfig !== null) {
|
|
14
16
|
return existingConfig;
|
|
@@ -18,7 +20,7 @@ export async function get(argv: Record<string, unknown>): Promise<Config> {
|
|
|
18
20
|
const modsDirectory = await getModsDir(argv);
|
|
19
21
|
const saveSlot = await promptSaveSlot(argv);
|
|
20
22
|
const config = createObject(modsDirectory, saveSlot);
|
|
21
|
-
createFile(CWD, config);
|
|
23
|
+
createFile(CWD, config, verbose);
|
|
22
24
|
|
|
23
25
|
return config;
|
|
24
26
|
}
|
|
@@ -66,8 +68,12 @@ export function createObject(modsDirectory: string, saveSlot: number): Config {
|
|
|
66
68
|
};
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
export function createFile(
|
|
71
|
+
export function createFile(
|
|
72
|
+
projectPath: string,
|
|
73
|
+
config: Config,
|
|
74
|
+
verbose: boolean,
|
|
75
|
+
): void {
|
|
70
76
|
const configFilePath = path.join(projectPath, CONFIG_FILE_NAME);
|
|
71
77
|
const configContents = JSON.stringify(config, null, 2);
|
|
72
|
-
file.write(configFilePath, configContents);
|
|
78
|
+
file.write(configFilePath, configContents, verbose);
|
|
73
79
|
}
|
package/src/exec.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { execSync, spawnSync, SpawnSyncReturns } from "child_process";
|
|
3
|
+
import { CWD } from "./constants";
|
|
4
|
+
import { error } from "./util";
|
|
5
|
+
|
|
6
|
+
export function execExe(path: string, verbose = false, cwd = CWD): string {
|
|
7
|
+
if (verbose) {
|
|
8
|
+
console.log(`Executing binary: ${path}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let stdout: string;
|
|
12
|
+
try {
|
|
13
|
+
const buffer = execSync(`"${path}"`, {
|
|
14
|
+
cwd,
|
|
15
|
+
});
|
|
16
|
+
stdout = buffer.toString().trim();
|
|
17
|
+
} catch (err) {
|
|
18
|
+
error(`Failed to run "${chalk.green(path)}":`, err);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (verbose) {
|
|
22
|
+
console.log(`Executed binary: ${path}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return stdout;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Returns an array of exit status and stdout. */
|
|
29
|
+
export function execShell(
|
|
30
|
+
command: string,
|
|
31
|
+
args: string[] = [],
|
|
32
|
+
verbose = false,
|
|
33
|
+
allowFailure = false,
|
|
34
|
+
cwd = CWD,
|
|
35
|
+
): [number, string] {
|
|
36
|
+
// On Windows, "spawnSync()" will not account for spaces in arguments
|
|
37
|
+
// Thus, wrap everything in a double quote
|
|
38
|
+
// This will cause arguments that naturally have double quotes to fail
|
|
39
|
+
if (command.includes('"')) {
|
|
40
|
+
error(
|
|
41
|
+
"execShell cannot execute commands with double quotes in the command.",
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
for (let i = 0; i < args.length; i++) {
|
|
45
|
+
if (args[i].includes('"')) {
|
|
46
|
+
error(
|
|
47
|
+
"execShell cannot execute commands with double quotes in the arguments.",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
args[i] = `"${args[i]}"`; // eslint-disable-line no-param-reassign
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const commandDescription = `${command} ${args.join(" ")}`.trim();
|
|
55
|
+
|
|
56
|
+
if (verbose) {
|
|
57
|
+
console.log(`Executing command: ${commandDescription}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let spawnSyncReturns: SpawnSyncReturns<Buffer>;
|
|
61
|
+
try {
|
|
62
|
+
spawnSyncReturns = spawnSync(command, args, {
|
|
63
|
+
shell: true,
|
|
64
|
+
cwd,
|
|
65
|
+
});
|
|
66
|
+
} catch (err) {
|
|
67
|
+
error(
|
|
68
|
+
`Failed to run the "${chalk.green(commandDescription)}" command:`,
|
|
69
|
+
err,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (verbose) {
|
|
74
|
+
console.log(`Executed command: ${commandDescription}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const exitStatus = spawnSyncReturns.status;
|
|
78
|
+
if (exitStatus === null) {
|
|
79
|
+
error(
|
|
80
|
+
`Failed to get the return status of th command: ${commandDescription}`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const stdout = spawnSyncReturns.output.join("\n").trim();
|
|
85
|
+
|
|
86
|
+
if (exitStatus !== 0) {
|
|
87
|
+
if (allowFailure) {
|
|
88
|
+
return [exitStatus, stdout];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.error(
|
|
92
|
+
`Failed to run the "${chalk.green(
|
|
93
|
+
commandDescription,
|
|
94
|
+
)}" command with an exit code of ${exitStatus}.`,
|
|
95
|
+
);
|
|
96
|
+
console.error("The output was as follows:");
|
|
97
|
+
console.error(stdout);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return [exitStatus, stdout];
|
|
102
|
+
}
|
package/src/file.ts
CHANGED
|
@@ -3,7 +3,11 @@ import fs from "fs-extra";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { error } from "./util";
|
|
5
5
|
|
|
6
|
-
export function copy(srcPath: string, dstPath: string): void {
|
|
6
|
+
export function copy(srcPath: string, dstPath: string, verbose: boolean): void {
|
|
7
|
+
if (verbose) {
|
|
8
|
+
console.log(`Copying: ${srcPath} --> ${dstPath}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
try {
|
|
8
12
|
// "copySync()" is a "fs-extra" method for copying directories recursively
|
|
9
13
|
fs.copySync(srcPath, dstPath, {
|
|
@@ -17,9 +21,20 @@ export function copy(srcPath: string, dstPath: string): void {
|
|
|
17
21
|
err,
|
|
18
22
|
);
|
|
19
23
|
}
|
|
24
|
+
|
|
25
|
+
if (verbose) {
|
|
26
|
+
console.log(`Copied: ${srcPath} --> ${dstPath}`);
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
export function deleteFileOrDirectory(
|
|
30
|
+
export function deleteFileOrDirectory(
|
|
31
|
+
filePath: string,
|
|
32
|
+
verbose: boolean,
|
|
33
|
+
): void {
|
|
34
|
+
if (verbose) {
|
|
35
|
+
console.log(`Deleting: ${filePath}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
try {
|
|
24
39
|
fs.rmSync(filePath, {
|
|
25
40
|
recursive: true,
|
|
@@ -30,6 +45,10 @@ export function deleteFileOrDirectory(filePath: string): void {
|
|
|
30
45
|
err,
|
|
31
46
|
);
|
|
32
47
|
}
|
|
48
|
+
|
|
49
|
+
if (verbose) {
|
|
50
|
+
console.log(`Deleted: ${filePath}`);
|
|
51
|
+
}
|
|
33
52
|
}
|
|
34
53
|
|
|
35
54
|
export function exists(filePath: string): boolean {
|
|
@@ -80,7 +99,11 @@ export function isSubDirOf(dir: string, parent: string): boolean {
|
|
|
80
99
|
);
|
|
81
100
|
}
|
|
82
101
|
|
|
83
|
-
export function makeDir(dirPath: string): void {
|
|
102
|
+
export function makeDir(dirPath: string, verbose: boolean): void {
|
|
103
|
+
if (verbose) {
|
|
104
|
+
console.log(`Making a directory: ${dirPath}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
84
107
|
try {
|
|
85
108
|
fs.mkdirSync(dirPath, {
|
|
86
109
|
recursive: true,
|
|
@@ -88,6 +111,10 @@ export function makeDir(dirPath: string): void {
|
|
|
88
111
|
} catch (err) {
|
|
89
112
|
error(`Failed to create the "${chalk.green(dirPath)}" directory:`, err);
|
|
90
113
|
}
|
|
114
|
+
|
|
115
|
+
if (verbose) {
|
|
116
|
+
console.log(`Made a directory: ${dirPath}`);
|
|
117
|
+
}
|
|
91
118
|
}
|
|
92
119
|
|
|
93
120
|
export function read(filePath: string): string {
|
|
@@ -101,21 +128,37 @@ export function read(filePath: string): string {
|
|
|
101
128
|
return fileContents;
|
|
102
129
|
}
|
|
103
130
|
|
|
104
|
-
export function touch(filePath: string): void {
|
|
131
|
+
export function touch(filePath: string, verbose: boolean): void {
|
|
132
|
+
if (verbose) {
|
|
133
|
+
console.log(`Touching: ${filePath}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
105
136
|
try {
|
|
106
137
|
const fileHandle = fs.openSync(filePath, "w");
|
|
107
138
|
fs.closeSync(fileHandle);
|
|
108
139
|
} catch (err) {
|
|
109
140
|
error(`Failed to touch the "${chalk.green(filePath)}" file:`, err);
|
|
110
141
|
}
|
|
142
|
+
|
|
143
|
+
if (verbose) {
|
|
144
|
+
console.log(`Touched: ${filePath}`);
|
|
145
|
+
}
|
|
111
146
|
}
|
|
112
147
|
|
|
113
|
-
export function write(filePath: string, data: string): void {
|
|
148
|
+
export function write(filePath: string, data: string, verbose: boolean): void {
|
|
149
|
+
if (verbose) {
|
|
150
|
+
console.log(`Writing data to: ${filePath}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
114
153
|
try {
|
|
115
154
|
fs.writeFileSync(filePath, data);
|
|
116
155
|
} catch (err) {
|
|
117
156
|
error(`Failed to write to the "${chalk.green(filePath)}" file:`, err);
|
|
118
157
|
}
|
|
158
|
+
|
|
159
|
+
if (verbose) {
|
|
160
|
+
console.log(`Wrote data to: ${filePath}`);
|
|
161
|
+
}
|
|
119
162
|
}
|
|
120
163
|
|
|
121
164
|
export function writeTry(filePath: string, data: string): void {
|
package/src/main.ts
CHANGED
package/src/monkeyPatch.ts
CHANGED
|
@@ -20,29 +20,23 @@ see the official website: https://isaacscript.github.io/
|
|
|
20
20
|
`;
|
|
21
21
|
|
|
22
22
|
const MAIN_LUA_REPLACEMENTS = [
|
|
23
|
-
// For TSTL v1.2.X
|
|
23
|
+
// For TSTL v1.2.X-v1.3.3
|
|
24
|
+
// (fixed with GlassBrick's PR)
|
|
24
25
|
["WeakMap = __TS__Class()", "WeakMap = WeakMap or __TS__Class()"],
|
|
25
26
|
["WeakSet = __TS__Class()", "WeakSet = WeakSet or __TS__Class()"],
|
|
26
27
|
["Map = __TS__Class()", "Map = Map or __TS__Class()"],
|
|
27
28
|
["Set = __TS__Class()", "Set = Set or __TS__Class()"],
|
|
28
|
-
|
|
29
|
-
// For TSTL v1.1.1
|
|
30
|
-
/*
|
|
31
|
-
["WeakMap = (function", "WeakMap = WeakMap or (function"],
|
|
32
|
-
["WeakSet = (function", "WeakSet = WeakSet or (function"],
|
|
33
|
-
["Map = (function", "Map = Map or (function"],
|
|
34
|
-
["Set = (function", "Set = Set or (function"],
|
|
35
|
-
*/
|
|
36
29
|
];
|
|
37
30
|
|
|
38
|
-
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32
|
+
function monkeyPatchMainLua(targetModDirectory: string, verbose: boolean) {
|
|
39
33
|
const mainLuaPath = path.join(targetModDirectory, MAIN_LUA);
|
|
40
|
-
|
|
34
|
+
const mainLua = file.read(mainLuaPath);
|
|
41
35
|
|
|
42
36
|
// mainLua = patchInformationalHeader(mainLua);
|
|
43
|
-
mainLua = patchGlobalObjects(mainLua);
|
|
37
|
+
// mainLua = patchGlobalObjects(mainLua);
|
|
44
38
|
|
|
45
|
-
file.write(mainLuaPath, mainLua);
|
|
39
|
+
file.write(mainLuaPath, mainLua, verbose);
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
// Add an informational header for people who happen to be browsing the Lua output
|
|
@@ -56,6 +50,7 @@ function patchInformationalHeader(mainLua: string) {
|
|
|
56
50
|
// Until TSTL has an official fix, monkey patch this
|
|
57
51
|
// We also make sure of this function to compose a stock comment header for curious people looking
|
|
58
52
|
// at the transpiled Lua code
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59
54
|
function patchGlobalObjects(originalMainLua: string) {
|
|
60
55
|
let mainLua = originalMainLua;
|
|
61
56
|
|
package/src/parseArgs.ts
CHANGED
|
@@ -24,6 +24,11 @@ export function parseArgs() {
|
|
|
24
24
|
alias: "c",
|
|
25
25
|
type: "boolean",
|
|
26
26
|
description: "Enable crash debugging",
|
|
27
|
+
})
|
|
28
|
+
.option("verbose", {
|
|
29
|
+
alias: "v",
|
|
30
|
+
type: "boolean",
|
|
31
|
+
description: "Enable verbose output",
|
|
27
32
|
}),
|
|
28
33
|
)
|
|
29
34
|
|
|
@@ -59,10 +64,21 @@ export function parseArgs() {
|
|
|
59
64
|
type: "boolean",
|
|
60
65
|
description:
|
|
61
66
|
'Don\'t automatically run "npm install" after initializing the project',
|
|
67
|
+
})
|
|
68
|
+
.option("verbose", {
|
|
69
|
+
alias: "v",
|
|
70
|
+
type: "boolean",
|
|
71
|
+
description: "Enable verbose output",
|
|
62
72
|
}),
|
|
63
73
|
)
|
|
64
74
|
|
|
65
|
-
.command("copy", "Only compile & copy the mod.")
|
|
75
|
+
.command("copy", "Only compile & copy the mod.", (builder) =>
|
|
76
|
+
builder.option("verbose", {
|
|
77
|
+
alias: "v",
|
|
78
|
+
type: "boolean",
|
|
79
|
+
description: "Enable verbose output",
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
66
82
|
|
|
67
83
|
.command(
|
|
68
84
|
"publish",
|
|
@@ -90,6 +106,11 @@ export function parseArgs() {
|
|
|
90
106
|
type: "boolean",
|
|
91
107
|
description:
|
|
92
108
|
"only upload the mod to the Steam Workshop (without doing anything else)",
|
|
109
|
+
})
|
|
110
|
+
.option("verbose", {
|
|
111
|
+
alias: "v",
|
|
112
|
+
type: "boolean",
|
|
113
|
+
description: "Enable verbose output",
|
|
93
114
|
}),
|
|
94
115
|
)
|
|
95
116
|
|