isaacscript 2.0.6 → 2.0.7

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.
Files changed (148) hide show
  1. package/dist/src/commands/init/createMod.js +9 -9
  2. package/dist/src/commands/init/git.js +3 -3
  3. package/dist/src/commands/init/init.js +2 -2
  4. package/dist/src/commands/monitor/monitor.js +9 -9
  5. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js +2 -2
  6. package/dist/src/configFile.js +1 -1
  7. package/dist/src/constants.js +12 -9
  8. package/dist/src/file.js +1 -1
  9. package/dist/src/main.js +3 -3
  10. package/dist/src/utils.js +5 -5
  11. package/dist/src/validateInIsaacScriptProject.js +1 -1
  12. package/package.json +10 -6
  13. package/.cspell.json +0 -25
  14. package/.eslintrc.js +0 -28
  15. package/.gitattributes +0 -9
  16. package/.github/workflows/ci.yml +0 -47
  17. package/.prettierignore +0 -5
  18. package/.prettierrc.js +0 -42
  19. package/.vscode/extensions.json +0 -9
  20. package/.vscode/settings.json +0 -75
  21. package/build.sh +0 -30
  22. package/check-file-updates.sh +0 -67
  23. package/check-file-updates.txt +0 -8
  24. package/check-gitignore.sh +0 -26
  25. package/check-orphaned-words.sh +0 -58
  26. package/dist/package.json +0 -51
  27. package/dist/src/checkForWindowsTerminalBugs.js.map +0 -1
  28. package/dist/src/commands/copy/copy.js.map +0 -1
  29. package/dist/src/commands/init/checkIfProjectPathExists.js.map +0 -1
  30. package/dist/src/commands/init/checkModSubdirectory.js.map +0 -1
  31. package/dist/src/commands/init/checkModTargetDirectory.js.map +0 -1
  32. package/dist/src/commands/init/createMod.js.map +0 -1
  33. package/dist/src/commands/init/getModsDir.js.map +0 -1
  34. package/dist/src/commands/init/getProjectPath.js.map +0 -1
  35. package/dist/src/commands/init/git.js.map +0 -1
  36. package/dist/src/commands/init/init.js.map +0 -1
  37. package/dist/src/commands/init/installVSCodeExtensions.js.map +0 -1
  38. package/dist/src/commands/init/promptSaveSlot.js.map +0 -1
  39. package/dist/src/commands/init/promptVSCode.js.map +0 -1
  40. package/dist/src/commands/monitor/copyWatcherMod.js.map +0 -1
  41. package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js.map +0 -1
  42. package/dist/src/commands/monitor/monitor.js.map +0 -1
  43. package/dist/src/commands/monitor/notifyGame.js.map +0 -1
  44. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js.map +0 -1
  45. package/dist/src/commands/monitor/saveDatWriter/types.js.map +0 -1
  46. package/dist/src/commands/monitor/spawnSaveDatWriter.js.map +0 -1
  47. package/dist/src/commands/monitor/touchWatcherSaveDatFiles.js.map +0 -1
  48. package/dist/src/commands/publish/publish.js.map +0 -1
  49. package/dist/src/configFile.js.map +0 -1
  50. package/dist/src/constants.js.map +0 -1
  51. package/dist/src/exec.js.map +0 -1
  52. package/dist/src/file.js.map +0 -1
  53. package/dist/src/main.js.map +0 -1
  54. package/dist/src/parseArgs.js.map +0 -1
  55. package/dist/src/prompt.js.map +0 -1
  56. package/dist/src/types/Command.js.map +0 -1
  57. package/dist/src/types/Config.js.map +0 -1
  58. package/dist/src/types/GitHubCLIHostsYAML.js.map +0 -1
  59. package/dist/src/utils.js.map +0 -1
  60. package/dist/src/validateInIsaacScriptProject.js.map +0 -1
  61. package/dist/src/validateNodeVersion.js.map +0 -1
  62. package/dist/src/validateOS.js.map +0 -1
  63. package/eslint-debug.sh +0 -11
  64. package/file-templates/dynamic/README.md +0 -3
  65. package/file-templates/dynamic/gitignore +0 -144
  66. package/file-templates/dynamic/main.ts +0 -19
  67. package/file-templates/dynamic/metadata.vdf +0 -6
  68. package/file-templates/dynamic/metadata.xml +0 -8
  69. package/file-templates/dynamic/package.json +0 -20
  70. package/file-templates/static/.cspell.json.template +0 -21
  71. package/file-templates/static/.env_template +0 -2
  72. package/file-templates/static/.eslintrc.js +0 -24
  73. package/file-templates/static/.gitattributes +0 -9
  74. package/file-templates/static/.github/workflows/ci.yml +0 -53
  75. package/file-templates/static/.prettierignore +0 -14
  76. package/file-templates/static/.prettierrc.js +0 -42
  77. package/file-templates/static/.vscode/extensions.json +0 -10
  78. package/file-templates/static/.vscode/settings.json +0 -75
  79. package/file-templates/static/LICENSE +0 -674
  80. package/file-templates/static/build.sh +0 -15
  81. package/file-templates/static/check-orphaned-words.sh +0 -58
  82. package/file-templates/static/lint.sh +0 -39
  83. package/file-templates/static/nuke.sh +0 -18
  84. package/file-templates/static/plugins/addCrashDebugStatements.ts +0 -40
  85. package/file-templates/static/plugins/addIsaacScriptCommentHeader.ts +0 -37
  86. package/file-templates/static/plugins/noExtendedEnums.ts +0 -66
  87. package/file-templates/static/publish.sh +0 -10
  88. package/file-templates/static/run.sh +0 -10
  89. package/file-templates/static/src/bundleEntry.ts +0 -10
  90. package/file-templates/static/tsconfig.eslint.json +0 -11
  91. package/file-templates/static/tsconfig.json +0 -33
  92. package/file-templates/static/update.sh +0 -21
  93. package/file-templates/static-alt/.prettierignore-base +0 -5
  94. package/file-templates/static-alt/.prettierrc-base.js +0 -30
  95. package/file-templates/static-alt/.vscode/extensions-format.json +0 -8
  96. package/file-templates/static-alt/.vscode/extensions-typescript.json +0 -9
  97. package/file-templates/static-alt/.vscode/settings-typescript.json +0 -63
  98. package/file-templates/static-alt/check-file-updates.sh +0 -67
  99. package/isaacscript-watcher/.luacheckrc +0 -96
  100. package/isaacscript-watcher/README.md +0 -8
  101. package/isaacscript-watcher/main.lua +0 -270
  102. package/isaacscript-watcher/metadata.xml +0 -7
  103. package/isaacscript-watcher/resources/gfx/logo.anm2 +0 -27
  104. package/isaacscript-watcher/resources/gfx/logo.png +0 -0
  105. package/lint.sh +0 -38
  106. package/misc/logo.png +0 -0
  107. package/misc/mouseover.png +0 -0
  108. package/nuke.sh +0 -18
  109. package/publish.sh +0 -11
  110. package/src/checkForWindowsTerminalBugs.ts +0 -106
  111. package/src/commands/copy/copy.ts +0 -41
  112. package/src/commands/init/checkIfProjectPathExists.ts +0 -34
  113. package/src/commands/init/checkModSubdirectory.ts +0 -20
  114. package/src/commands/init/checkModTargetDirectory.ts +0 -42
  115. package/src/commands/init/createMod.ts +0 -196
  116. package/src/commands/init/getModsDir.ts +0 -107
  117. package/src/commands/init/getProjectPath.ts +0 -111
  118. package/src/commands/init/git.ts +0 -249
  119. package/src/commands/init/init.ts +0 -93
  120. package/src/commands/init/installVSCodeExtensions.ts +0 -47
  121. package/src/commands/init/promptSaveSlot.ts +0 -27
  122. package/src/commands/init/promptVSCode.ts +0 -33
  123. package/src/commands/monitor/copyWatcherMod.ts +0 -54
  124. package/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.ts +0 -67
  125. package/src/commands/monitor/monitor.ts +0 -180
  126. package/src/commands/monitor/notifyGame.ts +0 -59
  127. package/src/commands/monitor/saveDatWriter/saveDatWriter.ts +0 -145
  128. package/src/commands/monitor/saveDatWriter/types.ts +0 -6
  129. package/src/commands/monitor/spawnSaveDatWriter.ts +0 -36
  130. package/src/commands/monitor/touchWatcherSaveDatFiles.ts +0 -20
  131. package/src/commands/publish/publish.ts +0 -392
  132. package/src/configFile.ts +0 -80
  133. package/src/constants.ts +0 -85
  134. package/src/exec.ts +0 -125
  135. package/src/file.ts +0 -235
  136. package/src/main.ts +0 -131
  137. package/src/parseArgs.ts +0 -127
  138. package/src/prompt.ts +0 -109
  139. package/src/types/Command.ts +0 -3
  140. package/src/types/Config.ts +0 -23
  141. package/src/types/GitHubCLIHostsYAML.ts +0 -7
  142. package/src/utils.ts +0 -92
  143. package/src/validateInIsaacScriptProject.ts +0 -35
  144. package/src/validateNodeVersion.ts +0 -29
  145. package/src/validateOS.ts +0 -20
  146. package/tsconfig.eslint.json +0 -11
  147. package/tsconfig.json +0 -21
  148. package/update.sh +0 -21
@@ -1,145 +0,0 @@
1
- import * as JSONC from "jsonc-parser";
2
- import path from "path";
3
- import { PROJECT_NAME } from "../../../constants";
4
- import * as file from "../../../file";
5
- import { ensureAllCases } from "../../../utils";
6
- import { SaveDatMessage, SaveDatMessageType } from "./types";
7
-
8
- const SUBPROCESS_NAME = "save#.dat writer";
9
- const BASE_ARGV_LENGTH = 2;
10
- const MAX_MESSAGES = 100;
11
- const VERBOSE = false;
12
-
13
- let saveDatPath: string;
14
- let saveDatFileName: string;
15
-
16
- init(VERBOSE);
17
-
18
- function init(verbose: boolean) {
19
- const firstArg = process.argv[BASE_ARGV_LENGTH];
20
- if (firstArg === undefined) {
21
- throw new Error(
22
- `The ${SUBPROCESS_NAME} process did not get a valid first argument.`,
23
- );
24
- }
25
-
26
- saveDatPath = firstArg;
27
- saveDatFileName = path.basename(saveDatPath);
28
-
29
- // Check to see if the data directory exists
30
- const watcherModDataPath = path.dirname(saveDatPath);
31
- if (!file.exists(watcherModDataPath, verbose)) {
32
- file.makeDir(watcherModDataPath, verbose);
33
- }
34
-
35
- // Listen for messages from the parent process
36
- process.on("message", (msg: SaveDatMessage) => {
37
- onMessage(msg.type, msg.data);
38
- });
39
- }
40
-
41
- function onMessage(type: SaveDatMessageType, data: string, numRetries = 0) {
42
- const saveDat = readSaveDatFromDisk(VERBOSE);
43
- if (saveDat.length > MAX_MESSAGES) {
44
- // If IsaacScript is running and:
45
- // - the game is not open
46
- // - or the game is open but the IsaacScript Watcher mod is disabled
47
- //
48
- // Then this process will continue to write to the "save#.dat" file, which can cause it to grow
49
- // arbitrarily large (since there is no-one on the other side removing the messages). If there
50
- // is N messages already in the queue, assume that no-one is listening and stop adding any more
51
- // messages.
52
- return;
53
- }
54
- addMessageToSaveDat(type, saveDat, data); // Mutates saveDat
55
- writeSaveDatToDisk(type, data, saveDat, numRetries, VERBOSE);
56
- }
57
-
58
- function readSaveDatFromDisk(verbose: boolean) {
59
- let saveDat: SaveDatMessage[];
60
- if (file.exists(saveDatPath, verbose)) {
61
- const saveDatRaw = file.read(saveDatPath, verbose);
62
- try {
63
- saveDat = JSONC.parse(saveDatRaw) as SaveDatMessage[];
64
- } catch (err) {
65
- send(`Failed to parse "${saveDatPath}": ${err}`);
66
- process.exit(1);
67
- }
68
- } else {
69
- saveDat = [];
70
- }
71
- if (!Array.isArray(saveDat)) {
72
- saveDat = [];
73
- }
74
-
75
- return saveDat;
76
- }
77
-
78
- function addMessageToSaveDat(
79
- type: SaveDatMessageType,
80
- saveDat: SaveDatMessage[],
81
- data: string,
82
- ) {
83
- switch (type) {
84
- case "command":
85
- case "ping": {
86
- saveDat.push({
87
- type,
88
- data,
89
- });
90
-
91
- break;
92
- }
93
-
94
- case "msg": {
95
- const lines = data.split("\n");
96
- for (const line of lines) {
97
- saveDat.push({
98
- type,
99
- data: line,
100
- });
101
- }
102
-
103
- break;
104
- }
105
-
106
- default: {
107
- ensureAllCases(type);
108
- break;
109
- }
110
- }
111
- }
112
-
113
- function writeSaveDatToDisk(
114
- type: SaveDatMessageType,
115
- data: string,
116
- saveDat: SaveDatMessage[],
117
- numRetries: number,
118
- verbose: boolean,
119
- ) {
120
- const saveDatRaw = JSON.stringify(saveDat, null, 2);
121
- try {
122
- file.writeTry(saveDatPath, saveDatRaw, verbose);
123
- } catch (err) {
124
- if (numRetries > 4) {
125
- send(
126
- `Failed to write to the ${saveDatFileName} for 5 times in a row. Maybe the file got locked somehow. ${PROJECT_NAME} will now exit.`,
127
- );
128
- send(`The writing error is as follows: ${err}`);
129
- process.exit(1);
130
- }
131
-
132
- send(
133
- `Writing to "${saveDatFileName}" failed. (The number of retries so far is ${numRetries}.) Trying again in 0.1 seconds...`,
134
- );
135
- setTimeout(() => {
136
- onMessage(type, data, numRetries + 1);
137
- }, 100);
138
- }
139
- }
140
-
141
- function send(msg: string) {
142
- if (process.send !== undefined) {
143
- process.send(msg);
144
- }
145
- }
@@ -1,6 +0,0 @@
1
- export type SaveDatMessageType = "command" | "msg" | "ping";
2
-
3
- export interface SaveDatMessage {
4
- type: SaveDatMessageType;
5
- data: string;
6
- }
@@ -1,36 +0,0 @@
1
- import { ChildProcess, fork } from "child_process";
2
- import path from "path";
3
- import { WATCHER_MOD_NAME } from "../../constants";
4
- import { Config } from "../../types/Config";
5
- import { error } from "../../utils";
6
- import { SaveDatMessage } from "./saveDatWriter/types";
7
-
8
- let saveDatWriter: ChildProcess | null = null;
9
-
10
- export function spawnSaveDatWriter(config: Config): void {
11
- const processName = "saveDatWriter";
12
- const processDescription = "save#.dat writer";
13
- const processPath = path.join(__dirname, processName, processName);
14
- const modsDataPath = path.join(config.modsDirectory, "..", "data");
15
- const watcherModDataPath = path.join(modsDataPath, WATCHER_MOD_NAME);
16
- const saveDatFileName = `save${config.saveSlot}.dat`;
17
- const saveDatPath = path.join(watcherModDataPath, saveDatFileName);
18
-
19
- saveDatWriter = fork(processPath, [saveDatPath], {
20
- stdio: ["pipe", "pipe", "pipe", "ipc"],
21
- });
22
-
23
- saveDatWriter.on("close", (code: number | null) => {
24
- error(`Error: ${processDescription} subprocess closed with code: ${code}`);
25
- });
26
-
27
- saveDatWriter.on("exit", (code: number | null) => {
28
- error(`Error: ${processDescription} subprocess exited with code: ${code}`);
29
- });
30
- }
31
-
32
- export function sendMsgToSaveDatWriter(msg: SaveDatMessage): void {
33
- if (saveDatWriter !== null) {
34
- saveDatWriter.send(msg);
35
- }
36
- }
@@ -1,20 +0,0 @@
1
- import path from "path";
2
- import { WATCHER_MOD_NAME } from "../../constants";
3
- import * as file from "../../file";
4
- import { Config } from "../../types/Config";
5
-
6
- export function touchWatcherSaveDatFiles(
7
- config: Config,
8
- verbose: boolean,
9
- ): void {
10
- const modsDataPath = path.join(config.modsDirectory, "..", "data");
11
- const watcherModDataPath = path.join(modsDataPath, WATCHER_MOD_NAME);
12
- if (!file.exists(watcherModDataPath, verbose)) {
13
- file.makeDir(watcherModDataPath, verbose);
14
- }
15
- const saveDatFileName = `save${config.saveSlot}.dat`;
16
- const saveDatPath = path.join(watcherModDataPath, saveDatFileName);
17
- if (!file.exists(saveDatPath, verbose)) {
18
- file.touch(saveDatPath, verbose);
19
- }
20
- }
@@ -1,392 +0,0 @@
1
- import chalk from "chalk";
2
- import path from "path";
3
- import {
4
- CONFIG_FILE_NAME,
5
- CONSTANTS_TS_PATH,
6
- METADATA_XML_PATH,
7
- MOD_SOURCE_PATH,
8
- MOD_UPLOADER_PATH,
9
- PACKAGE_JSON_PATH,
10
- PROJECT_NAME,
11
- PUBLISH_POST_COPY_PY_PATH,
12
- PUBLISH_PRE_COPY_PY_PATH,
13
- VERSION_TXT_PATH,
14
- } from "../../constants";
15
- import { execExe, execPowershell, execShell } from "../../exec";
16
- import * as file from "../../file";
17
- import { Config } from "../../types/Config";
18
- import { error, getModTargetDirectoryName, parseIntSafe } from "../../utils";
19
- import { compileAndCopy } from "../copy/copy";
20
- import { gitCommitIfChanges, isGitDirty } from "../init/git";
21
-
22
- const UPDATE_SCRIPT_NAME = "update.sh";
23
-
24
- export function publish(argv: Record<string, unknown>, config: Config): void {
25
- const skipVersionIncrement = argv["skip"] === true;
26
- const setVersion = argv["setVersion"] as string | undefined;
27
- const dryRun = argv["dryRun"] === true;
28
- const onlyUpload = argv["onlyUpload"] === true;
29
- const verbose = argv["verbose"] === true;
30
-
31
- const modTargetDirectoryName = getModTargetDirectoryName(config);
32
- const modTargetPath = path.join(config.modsDirectory, modTargetDirectoryName);
33
-
34
- validateVersion(setVersion);
35
- validateGitNotDirty(verbose);
36
- validateIsaacScriptOtherCopiesNotRunning(verbose);
37
-
38
- if (onlyUpload) {
39
- uploadMod(modTargetPath, config.steamCmdPath, verbose);
40
- return;
41
- }
42
-
43
- startPublish(
44
- MOD_SOURCE_PATH,
45
- modTargetPath,
46
- skipVersionIncrement,
47
- setVersion,
48
- config.steamCmdPath,
49
- dryRun,
50
- verbose,
51
- );
52
- }
53
-
54
- function validateVersion(setVersion: string | undefined) {
55
- if (setVersion !== undefined && /^\d+\.\d+\.\d+$/.exec(setVersion) === null) {
56
- error(
57
- chalk.red(
58
- `The version of "${setVersion}" does not match the semantic versioning format.`,
59
- ),
60
- );
61
- }
62
- }
63
-
64
- function validateGitNotDirty(verbose: boolean) {
65
- if (isGitDirty(verbose)) {
66
- error(
67
- chalk.red(
68
- "Before publishing, you must push your current changes to git. (Version commits should be not contain any code changes.)",
69
- ),
70
- );
71
- }
72
- }
73
-
74
- function validateIsaacScriptOtherCopiesNotRunning(verbose: boolean) {
75
- if (process.platform !== "win32") {
76
- return;
77
- }
78
-
79
- // From: https://securityboulevard.com/2020/01/get-process-list-with-command-line-arguments/
80
- const stdout = execPowershell(
81
- "Get-WmiObject Win32_Process -Filter \"name = 'node.exe'\" | Select-Object -ExpandProperty CommandLine",
82
- verbose,
83
- );
84
- const lines = stdout.split("\r\n");
85
- const otherCopiesOfRunningIsaacScript = lines.filter(
86
- (line) =>
87
- line.includes("node.exe") &&
88
- line.includes("isaacscript") &&
89
- !line.includes("isaacscript publish"),
90
- );
91
- if (otherCopiesOfRunningIsaacScript.length > 0) {
92
- error(
93
- chalk.red(
94
- `Other copies of ${PROJECT_NAME} appear to be running. You must close those copies before publishing.`,
95
- ),
96
- );
97
- }
98
- }
99
-
100
- function startPublish(
101
- modSourcePath: string,
102
- modTargetPath: string,
103
- skipVersionIncrement: boolean,
104
- setVersion: string | undefined,
105
- steamCmdPath: string | undefined,
106
- dryRun: boolean,
107
- verbose: boolean,
108
- ) {
109
- updateDeps(verbose);
110
-
111
- let version =
112
- setVersion === undefined ? getVersionFromPackageJSON(verbose) : setVersion;
113
- if (!skipVersionIncrement && setVersion === undefined) {
114
- version = bumpVersionInPackageJSON(version, verbose);
115
- } else if (setVersion !== undefined) {
116
- writeVersionInPackageJSON(version, verbose);
117
- }
118
-
119
- writeVersionToConstantsTS(version, verbose);
120
- writeVersionToMetadataXML(version, verbose);
121
- writeVersionToVersionTXT(version, verbose);
122
- runReleaseScriptPreCopy(verbose);
123
- compileAndCopy(modSourcePath, modTargetPath, verbose);
124
- purgeRoomXMLs(modTargetPath, verbose);
125
- runReleaseScriptPostCopy(verbose);
126
-
127
- if (!dryRun) {
128
- gitCommitIfChanges(version, verbose);
129
- uploadMod(modTargetPath, steamCmdPath, verbose);
130
- }
131
-
132
- const dryRunSuffix = dryRun ? " (dry run)" : "";
133
- console.log(`\nPublished version ${version} successfully${dryRunSuffix}.`);
134
- }
135
-
136
- function updateDeps(verbose: boolean) {
137
- if (!file.exists(UPDATE_SCRIPT_NAME, verbose)) {
138
- error(
139
- `The "${UPDATE_SCRIPT_NAME}" script does not exist in the current working directory.`,
140
- );
141
- }
142
-
143
- execShell("bash", [UPDATE_SCRIPT_NAME], verbose);
144
- }
145
-
146
- function getVersionFromPackageJSON(verbose: boolean) {
147
- if (!file.exists(PACKAGE_JSON_PATH, verbose)) {
148
- error(
149
- chalk.red(
150
- `A "${PACKAGE_JSON_PATH}" was not found in the current directory.`,
151
- ),
152
- );
153
- }
154
-
155
- const packageJSONRaw = file.read(PACKAGE_JSON_PATH, verbose);
156
- let packageJSON: Record<string, unknown>;
157
- try {
158
- packageJSON = JSON.parse(packageJSONRaw) as Record<string, unknown>;
159
- } catch (err) {
160
- error(`Failed to parse "${chalk.green(PACKAGE_JSON_PATH)}":`, err);
161
- }
162
-
163
- if (!Object.prototype.hasOwnProperty.call(packageJSON, "version")) {
164
- error(
165
- `The "${chalk.green(
166
- PACKAGE_JSON_PATH,
167
- )}" file does not have a "version" field.`,
168
- );
169
- }
170
-
171
- if (typeof packageJSON["version"] !== "string") {
172
- error(
173
- `The "${chalk.green(
174
- PACKAGE_JSON_PATH,
175
- )}" file has a "version" field that is not a string.`,
176
- );
177
- }
178
-
179
- return packageJSON["version"];
180
- }
181
-
182
- function bumpVersionInPackageJSON(version: string, verbose: boolean): string {
183
- // Get the patch version (i.e. the third number)
184
- const matches = /(\d+\.\d+\.)(\d+)/.exec(version);
185
- if (matches === null) {
186
- error(`Failed to parse the version of: ${version}`);
187
- }
188
-
189
- const versionPrefix = matches[1];
190
- if (versionPrefix === undefined) {
191
- error(`Failed to parse the first part of the version: ${version}`);
192
- }
193
-
194
- const patchVersionString = matches[2];
195
- if (patchVersionString === undefined) {
196
- error(`Failed to parse the second part of the version: ${version}`);
197
- }
198
-
199
- const patchVersion = parseIntSafe(patchVersionString);
200
- if (Number.isNaN(patchVersion)) {
201
- error(`Failed to convert "${patchVersionString}" to a number.`);
202
- }
203
-
204
- const incrementedPatchVersion = patchVersion + 1;
205
- const incrementedVersion = `${versionPrefix}${incrementedPatchVersion}`;
206
-
207
- const packageJSON = file.read(PACKAGE_JSON_PATH, verbose);
208
- const newPackageJSON = packageJSON.replace(
209
- /"version": ".+",/,
210
- `"version": "${incrementedVersion}",`,
211
- );
212
- file.write(PACKAGE_JSON_PATH, newPackageJSON, verbose);
213
-
214
- console.log(
215
- `The version of ${incrementedVersion} was written to: ${PACKAGE_JSON_PATH}`,
216
- );
217
-
218
- return incrementedVersion;
219
- }
220
-
221
- function writeVersionInPackageJSON(version: string, verbose: boolean) {
222
- const packageJSON = file.read(PACKAGE_JSON_PATH, verbose);
223
- const newPackageJSON = packageJSON.replace(
224
- /"version": ".+",/,
225
- `"version": "${version}",`,
226
- );
227
- file.write(PACKAGE_JSON_PATH, newPackageJSON, verbose);
228
-
229
- console.log(`The version of ${version} was written to: ${PACKAGE_JSON_PATH}`);
230
- }
231
-
232
- function writeVersionToConstantsTS(version: string, verbose: boolean) {
233
- if (!file.exists(CONSTANTS_TS_PATH, verbose)) {
234
- console.log(
235
- 'Skipping writing the version to "constants.ts" since it was not found.',
236
- );
237
- return;
238
- }
239
-
240
- const constantsTS = file.read(CONSTANTS_TS_PATH, verbose);
241
- const newConstantsTS = constantsTS.replace(
242
- /const VERSION = ".+"/,
243
- `const VERSION = "${version}"`,
244
- );
245
- file.write(CONSTANTS_TS_PATH, newConstantsTS, verbose);
246
-
247
- console.log(`The version of ${version} was written to: ${CONSTANTS_TS_PATH}`);
248
- }
249
-
250
- function writeVersionToMetadataXML(version: string, verbose: boolean) {
251
- const metadataXML = file.read(METADATA_XML_PATH, verbose);
252
- const newMetadataXML = metadataXML.replace(
253
- /<version>.+<\/version>/,
254
- `<version>${version}</version>`,
255
- );
256
- file.write(METADATA_XML_PATH, newMetadataXML, verbose);
257
-
258
- console.log(`The version of ${version} was written to: ${METADATA_XML_PATH}`);
259
- }
260
-
261
- function writeVersionToVersionTXT(version: string, verbose: boolean) {
262
- file.write(VERSION_TXT_PATH, version, verbose);
263
-
264
- console.log(`The version of ${version} was written to: ${VERSION_TXT_PATH}`);
265
- }
266
-
267
- function runReleaseScriptPreCopy(verbose: boolean) {
268
- if (!file.exists(PUBLISH_PRE_COPY_PY_PATH, verbose)) {
269
- return;
270
- }
271
-
272
- console.log(`Running the "${PUBLISH_PRE_COPY_PY_PATH}" script.`);
273
- let [, stdout] = execShell("python", [PUBLISH_PRE_COPY_PY_PATH], verbose);
274
- stdout = stdout.trim();
275
- if (stdout.length > 0) {
276
- console.log(stdout);
277
- }
278
- }
279
-
280
- function runReleaseScriptPostCopy(verbose: boolean) {
281
- if (!file.exists(PUBLISH_POST_COPY_PY_PATH, verbose)) {
282
- return;
283
- }
284
-
285
- console.log(`Running the "${PUBLISH_POST_COPY_PY_PATH}" script.`);
286
- let [, stdout] = execShell("python", [PUBLISH_POST_COPY_PY_PATH], verbose);
287
- stdout = stdout.trim();
288
- if (stdout.length > 0) {
289
- console.log(stdout);
290
- }
291
- }
292
-
293
- function purgeRoomXMLs(modTargetPath: string, verbose: boolean) {
294
- const roomsPath = path.join(modTargetPath, "resources", "rooms");
295
- if (!file.exists(roomsPath, verbose) || !file.isDir(roomsPath, verbose)) {
296
- return;
297
- }
298
-
299
- const roomFileList = file.getDirList(roomsPath, verbose);
300
- roomFileList.forEach((fileName: string) => {
301
- if (path.extname(fileName) === ".xml") {
302
- const roomFilePath = path.join(roomsPath, fileName);
303
- file.deleteFileOrDirectory(roomFilePath, verbose);
304
- }
305
- });
306
- }
307
-
308
- function uploadMod(
309
- modTargetPath: string,
310
- steamCmdPath: string | undefined,
311
- verbose: boolean,
312
- ) {
313
- if (steamCmdPath === undefined) {
314
- console.log(
315
- `The "steamCmdPath" property was not found in the "${chalk.green(
316
- CONFIG_FILE_NAME,
317
- )}" file; assuming that we want to use the ModUploader tool.`,
318
- );
319
- execExe(MOD_UPLOADER_PATH, verbose, modTargetPath);
320
- } else {
321
- runSteamCmd(modTargetPath, steamCmdPath, verbose);
322
- }
323
- }
324
-
325
- function runSteamCmd(
326
- modTargetPath: string,
327
- steamCmdPath: string,
328
- verbose: boolean,
329
- ) {
330
- if (!file.exists(steamCmdPath, verbose)) {
331
- error(
332
- chalk.red(
333
- `The path provided for "steamCmdPath" is "${steamCmdPath}", but that does not exist.`,
334
- ),
335
- );
336
- }
337
-
338
- const metadataVDFPath = path.join(modTargetPath, "metadata.vdf");
339
- if (!file.exists(metadataVDFPath, verbose)) {
340
- console.error(
341
- chalk.red(
342
- `A "metadata.vdf" file was not found in your mod directory. You must create this file in order for "steamcmd.exe" to work. Please see the ${PROJECT_NAME} docs:`,
343
- ),
344
- );
345
- error(getIsaacScriptDocs());
346
- }
347
-
348
- const usernameVar = "STEAM_USERNAME";
349
- const username = process.env[usernameVar];
350
- if (username === undefined || username === "") {
351
- console.error(
352
- chalk.red(
353
- `Failed to read the "${usernameVar}" environment variable from the ".env" file. Please see the ${PROJECT_NAME} docs:`,
354
- ),
355
- );
356
- error(getIsaacScriptDocs());
357
- }
358
-
359
- const passwordVar = "STEAM_PASSWORD";
360
- const password = process.env[passwordVar];
361
- if (password === undefined || password === "") {
362
- console.error(
363
- chalk.red(
364
- `Failed to read the "${passwordVar}" environment variable from the ".env" file. Please see the ${PROJECT_NAME} docs:`,
365
- ),
366
- );
367
- error(getIsaacScriptDocs());
368
- }
369
-
370
- console.log("Uploading the mod to the Steam Workshop...");
371
-
372
- execShell(
373
- steamCmdPath,
374
- [
375
- "+login",
376
- username,
377
- password,
378
- "+workshop_build_item",
379
- metadataVDFPath,
380
- "+quit",
381
- ],
382
- verbose,
383
- );
384
-
385
- console.log("Mod uploaded successfully.");
386
- }
387
-
388
- function getIsaacScriptDocs() {
389
- return chalk.red(
390
- "https://isaacscript.github.io/docs/publishing-to-the-workshop/#metadatavdf",
391
- );
392
- }
package/src/configFile.ts DELETED
@@ -1,80 +0,0 @@
1
- import chalk from "chalk";
2
- import * as JSONC from "jsonc-parser";
3
- import path from "path";
4
- import { getModsDir } from "./commands/init/getModsDir";
5
- import { promptSaveSlot } from "./commands/init/promptSaveSlot";
6
- import { CONFIG_FILE_NAME, CONFIG_FILE_PATH, CWD } from "./constants";
7
- import * as file from "./file";
8
- import { Config } from "./types/Config";
9
- import { error } from "./utils";
10
-
11
- export async function get(argv: Record<string, unknown>): Promise<Config> {
12
- const verbose = argv["verbose"] === true;
13
- const yes = argv["yes"] === true;
14
-
15
- const existingConfig = readExistingConfig(verbose);
16
- if (existingConfig !== undefined) {
17
- return existingConfig;
18
- }
19
-
20
- // No config file exists, so prompt the user for some information and create one
21
- const modsDirectory = await getModsDir(argv, verbose);
22
- const saveSlot = await promptSaveSlot(argv, yes);
23
- const config = createObject(modsDirectory, saveSlot);
24
- createFile(CWD, config, verbose);
25
-
26
- return config;
27
- }
28
-
29
- function readExistingConfig(verbose: boolean): Config | undefined {
30
- if (!file.exists(CONFIG_FILE_PATH, verbose)) {
31
- return undefined;
32
- }
33
-
34
- const configRaw = file.read(CONFIG_FILE_PATH, verbose);
35
- let config: Config;
36
- try {
37
- config = JSONC.parse(configRaw) as Config;
38
- } catch (err) {
39
- error(`Failed to parse the "${chalk.green(CONFIG_FILE_PATH)}" file:`, err);
40
- }
41
-
42
- if (config.modsDirectory === undefined) {
43
- errorMissing(
44
- "modsDirectory",
45
- "This should be equal to the directory where Isaac mods live on your system.",
46
- );
47
- }
48
-
49
- if (config.saveSlot === undefined) {
50
- errorMissing(
51
- "saveSlot",
52
- "This should be equal to the save slot that you test your mods on.",
53
- );
54
- }
55
-
56
- return config;
57
- }
58
-
59
- function errorMissing(field: string, description: string) {
60
- error(
61
- `The "${CONFIG_FILE_NAME}" file is missing a "${field}" value. ${description} Please add it.`,
62
- );
63
- }
64
-
65
- export function createObject(modsDirectory: string, saveSlot: number): Config {
66
- return {
67
- modsDirectory,
68
- saveSlot,
69
- };
70
- }
71
-
72
- export function createFile(
73
- projectPath: string,
74
- config: Config,
75
- verbose: boolean,
76
- ): void {
77
- const configFilePath = path.join(projectPath, CONFIG_FILE_NAME);
78
- const configContents = JSON.stringify(config, null, 2);
79
- file.write(configFilePath, configContents, verbose);
80
- }