isaacscript 1.1.56 → 1.1.60
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/.cspell.json +1 -3
- package/.eslintrc.js +1 -15
- package/.vscode/extensions.json +1 -0
- package/.vscode/settings.json +4 -0
- package/dist/package.json +8 -6
- package/dist/src/checkForWindowsTerminalBugs.js +20 -52
- package/dist/src/checkForWindowsTerminalBugs.js.map +1 -1
- package/dist/src/commands/init/checkIfProjectPathExists.js +3 -7
- package/dist/src/commands/init/checkIfProjectPathExists.js.map +1 -1
- package/dist/src/commands/init/checkModTargetDirectory.js +3 -8
- package/dist/src/commands/init/checkModTargetDirectory.js.map +1 -1
- package/dist/src/commands/init/createMod.js +85 -11
- package/dist/src/commands/init/createMod.js.map +1 -1
- package/dist/src/commands/init/getModsDir.js +6 -13
- package/dist/src/commands/init/getModsDir.js.map +1 -1
- package/dist/src/commands/init/getProjectPath.js +4 -17
- package/dist/src/commands/init/getProjectPath.js.map +1 -1
- package/dist/src/commands/init/init.js +18 -15
- package/dist/src/commands/init/init.js.map +1 -1
- package/dist/src/commands/init/promptSaveSlot.js +4 -14
- package/dist/src/commands/init/promptSaveSlot.js.map +1 -1
- package/dist/src/commands/init/promptVSCode.js +3 -8
- package/dist/src/commands/init/promptVSCode.js.map +1 -1
- package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js +0 -1
- package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js.map +1 -1
- package/dist/src/commands/monitor/monitor.js +20 -9
- package/dist/src/commands/monitor/monitor.js.map +1 -1
- package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js +0 -1
- package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js.map +1 -1
- package/dist/src/commands/publish/publish.js +3 -3
- package/dist/src/constants.js +5 -1
- package/dist/src/constants.js.map +1 -1
- package/dist/src/main.js +2 -0
- package/dist/src/main.js.map +1 -1
- package/dist/src/monkeyPatch.js +2 -1
- package/dist/src/monkeyPatch.js.map +1 -1
- package/dist/src/parseArgs.js +62 -58
- package/dist/src/parseArgs.js.map +1 -1
- package/dist/src/plugins/addCrashDebugStatements.js +31 -0
- package/dist/src/plugins/addCrashDebugStatements.js.map +1 -0
- package/dist/src/prompt.js +90 -0
- package/dist/src/prompt.js.map +1 -0
- package/dist/src/types/GitHubCLIHostsYAML.js +3 -0
- package/dist/src/types/GitHubCLIHostsYAML.js.map +1 -0
- package/dist/src/util.js +6 -26
- package/dist/src/util.js.map +1 -1
- package/file-templates/dynamic/README.md +2 -2
- package/file-templates/dynamic/main.ts +4 -2
- package/file-templates/dynamic/metadata.xml +3 -3
- package/file-templates/dynamic/package.json +1 -1
- package/file-templates/static/.github/workflows/ci.yml +3 -0
- package/file-templates/static/.vscode/extensions.json +1 -0
- package/file-templates/static/.vscode/settings.json +4 -0
- package/file-templates/static/lint.sh +16 -9
- package/lint.sh +6 -10
- package/package.json +8 -6
- package/src/checkForWindowsTerminalBugs.ts +35 -73
- package/src/commands/init/checkIfProjectPathExists.ts +4 -7
- package/src/commands/init/checkModTargetDirectory.ts +7 -9
- package/src/commands/init/createMod.ts +132 -13
- package/src/commands/init/getModsDir.ts +8 -14
- package/src/commands/init/getProjectPath.ts +7 -19
- package/src/commands/init/init.ts +25 -13
- package/src/commands/init/promptSaveSlot.ts +6 -13
- package/src/commands/init/promptVSCode.ts +5 -9
- package/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.ts +0 -2
- package/src/commands/monitor/monitor.ts +25 -10
- package/src/commands/monitor/saveDatWriter/saveDatWriter.ts +0 -2
- package/src/commands/publish/publish.ts +3 -3
- package/src/constants.ts +5 -0
- package/src/main.ts +2 -0
- package/src/monkeyPatch.ts +2 -1
- package/src/parseArgs.ts +34 -28
- package/src/plugins/addCrashDebugStatements.ts +29 -0
- package/src/prompt.ts +110 -0
- package/src/types/GitHubCLIHostsYAML.ts +7 -0
- package/src/util.ts +6 -28
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import commandExists from "command-exists";
|
|
1
3
|
import path from "path";
|
|
4
|
+
import yaml from "yaml";
|
|
2
5
|
import * as configFile from "../../configFile";
|
|
3
6
|
import {
|
|
4
7
|
GITIGNORE,
|
|
@@ -16,15 +19,18 @@ import {
|
|
|
16
19
|
TEMPLATES_STATIC_DIR,
|
|
17
20
|
} from "../../constants";
|
|
18
21
|
import * as file from "../../file";
|
|
19
|
-
import {
|
|
22
|
+
import { getInputString, getInputYesNo } from "../../prompt";
|
|
23
|
+
import { GitHubCLIHostsYAML } from "../../types/GitHubCLIHostsYAML";
|
|
24
|
+
import { execShell } from "../../util";
|
|
20
25
|
|
|
21
|
-
export function createMod(
|
|
26
|
+
export async function createMod(
|
|
22
27
|
projectName: string,
|
|
23
28
|
projectPath: string,
|
|
24
29
|
createNewDir: boolean,
|
|
25
30
|
modsDirectory: string,
|
|
26
31
|
saveSlot: number,
|
|
27
|
-
|
|
32
|
+
skipNPMInstall: boolean,
|
|
33
|
+
): Promise<void> {
|
|
28
34
|
if (createNewDir) {
|
|
29
35
|
file.makeDir(projectPath);
|
|
30
36
|
}
|
|
@@ -37,7 +43,10 @@ export function createMod(
|
|
|
37
43
|
copyStaticFiles(projectPath);
|
|
38
44
|
copyDynamicFiles(projectName, projectPath, targetModDirectory);
|
|
39
45
|
updateNodeModules(projectPath);
|
|
40
|
-
|
|
46
|
+
await initGitRepository(projectPath, projectName);
|
|
47
|
+
installNodeModules(projectPath, skipNPMInstall);
|
|
48
|
+
|
|
49
|
+
console.log(`Successfully created mod: ${chalk.green(projectName)}`);
|
|
41
50
|
}
|
|
42
51
|
|
|
43
52
|
function makeSubdirectories(projectPath: string) {
|
|
@@ -91,7 +100,7 @@ function copyDynamicFiles(
|
|
|
91
100
|
const fileName = PACKAGE_JSON;
|
|
92
101
|
const templatePath = PACKAGE_JSON_TEMPLATE_PATH;
|
|
93
102
|
const template = file.read(templatePath);
|
|
94
|
-
const packageJSON = template.replace(/
|
|
103
|
+
const packageJSON = template.replace(/MOD_NAME_TO_REPLACE/g, projectName);
|
|
95
104
|
const destinationPath = path.join(projectPath, fileName);
|
|
96
105
|
file.write(destinationPath, packageJSON);
|
|
97
106
|
}
|
|
@@ -101,7 +110,7 @@ function copyDynamicFiles(
|
|
|
101
110
|
const fileName = README_MD;
|
|
102
111
|
const templatePath = README_MD_TEMPLATES_PATH;
|
|
103
112
|
const template = file.read(templatePath);
|
|
104
|
-
const readmeMD = template.replace(/
|
|
113
|
+
const readmeMD = template.replace(/MOD_NAME_TO_REPLACE/g, projectName);
|
|
105
114
|
const destinationPath = path.join(projectPath, fileName);
|
|
106
115
|
file.write(destinationPath, readmeMD);
|
|
107
116
|
}
|
|
@@ -111,7 +120,7 @@ function copyDynamicFiles(
|
|
|
111
120
|
const fileName = METADATA_XML;
|
|
112
121
|
const templatePath = METADATA_XML_TEMPLATE_PATH;
|
|
113
122
|
const template = file.read(templatePath);
|
|
114
|
-
const metadataXML = template.replace(/
|
|
123
|
+
const metadataXML = template.replace(/MOD_NAME_TO_REPLACE/g, projectName);
|
|
115
124
|
const modPath = path.join(projectPath, "mod");
|
|
116
125
|
const destinationPath = path.join(modPath, fileName);
|
|
117
126
|
file.write(destinationPath, metadataXML);
|
|
@@ -133,20 +142,126 @@ function copyDynamicFiles(
|
|
|
133
142
|
// Convert snake_case and kebab-case to camelCase
|
|
134
143
|
// (kebab-case in particular will make the example TypeScript file fail to compile)
|
|
135
144
|
const srcPath = path.join(projectPath, "src");
|
|
136
|
-
const camelCaseProjectName = snakeKebabToCamel(projectName);
|
|
137
145
|
const fileName = MAIN_TS;
|
|
138
146
|
const templatePath = MAIN_TS_TEMPLATE_PATH;
|
|
139
147
|
const template = file.read(templatePath);
|
|
140
|
-
const mainTS = template
|
|
141
|
-
.replace(/MOD_NAME initialized/g, `${projectName} initialized`)
|
|
142
|
-
.replace(/MOD_NAME/g, camelCaseProjectName);
|
|
148
|
+
const mainTS = template.replace(/MOD_NAME_TO_REPLACE/g, projectName);
|
|
143
149
|
const destinationPath = path.join(srcPath, fileName);
|
|
144
150
|
file.write(destinationPath, mainTS);
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
|
|
154
|
+
async function initGitRepository(projectPath: string, projectName: string) {
|
|
155
|
+
if (!commandExists.sync("git")) {
|
|
156
|
+
console.log(
|
|
157
|
+
'Git does not seem to be installed. (The "git" command is not in the path.) Skipping Git-related things.',
|
|
158
|
+
);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const remoteURL = await getGitRemoteURL(projectName);
|
|
163
|
+
if (remoteURL === "") {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
execShell("git", ["init"], false, projectPath);
|
|
168
|
+
execShell("git", ["branch", "-M", "main"], false, projectPath);
|
|
169
|
+
execShell("git", ["remote", "add", "origin", remoteURL], false, projectPath);
|
|
170
|
+
if (isGitNameAndEmailConfigured()) {
|
|
171
|
+
execShell("git", ["add", "--all"], false, projectPath);
|
|
172
|
+
execShell(
|
|
173
|
+
"git",
|
|
174
|
+
["commit", "--message", "IsaacScript template"],
|
|
175
|
+
false,
|
|
176
|
+
projectPath,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function getGitRemoteURL(projectName: string) {
|
|
182
|
+
const guessedRemoteURL = guessRemoteURL(projectName);
|
|
183
|
+
if (guessedRemoteURL !== undefined) {
|
|
184
|
+
const shouldUseGuessedURL = await getInputYesNo(
|
|
185
|
+
`Do you want to use a Git remote URL of: ${chalk.green(
|
|
186
|
+
guessedRemoteURL,
|
|
187
|
+
)}`,
|
|
188
|
+
);
|
|
189
|
+
if (shouldUseGuessedURL) {
|
|
190
|
+
return guessedRemoteURL;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return getInputString(`Paste in the remote Git URL for your project.
|
|
195
|
+
For example, if you have an SSH key, it would be something like:
|
|
196
|
+
${chalk.green("git@github.com:Alice/green-candle.git")}
|
|
197
|
+
If you don't have an SSH key, it would be something like:
|
|
198
|
+
${chalk.green("https://github.com/Alice/green-candle.git")}
|
|
199
|
+
If you don't want to initialize a Git repository for this project, press enter to skip.
|
|
200
|
+
`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function guessRemoteURL(projectName: string) {
|
|
204
|
+
const gitHubUsername = getGitHubUsername();
|
|
205
|
+
if (gitHubUsername === undefined) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return `git@github.com:${gitHubUsername}/${projectName}.git`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function getGitHubUsername() {
|
|
213
|
+
// If the GitHub CLI is installed, we can derive the user's GitHub username
|
|
214
|
+
if (
|
|
215
|
+
!commandExists.sync("gh") ||
|
|
216
|
+
process.env.APPDATA === undefined ||
|
|
217
|
+
process.env.APPDATA === ""
|
|
218
|
+
) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const githubCLIHostsPath = path.join(
|
|
223
|
+
process.env.APPDATA,
|
|
224
|
+
"GitHub CLI",
|
|
225
|
+
"hosts.yml",
|
|
226
|
+
);
|
|
227
|
+
if (!file.exists(githubCLIHostsPath)) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const configYAMLRaw = file.read(githubCLIHostsPath);
|
|
232
|
+
const configYAML = yaml.parse(configYAMLRaw) as GitHubCLIHostsYAML;
|
|
233
|
+
|
|
234
|
+
const githubCom = configYAML["github.com"];
|
|
235
|
+
if (githubCom === undefined) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const { user } = githubCom;
|
|
240
|
+
if (user === "") {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return user;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function isGitNameAndEmailConfigured() {
|
|
248
|
+
const [nameExitStatus] = execShell(
|
|
249
|
+
"git",
|
|
250
|
+
["config", "--global", "user.name"],
|
|
251
|
+
true,
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
const [emailExitStatus] = execShell(
|
|
255
|
+
"git",
|
|
256
|
+
["config", "--global", "user.email"],
|
|
257
|
+
true,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return nameExitStatus === 0 && emailExitStatus === 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
148
263
|
function updateNodeModules(projectPath: string) {
|
|
149
|
-
console.log("
|
|
264
|
+
console.log("Finding out the latest versions of the IsaacScript packages...");
|
|
150
265
|
execShell(
|
|
151
266
|
"npx",
|
|
152
267
|
["npm-check-updates", "--upgrade", "--packageFile", "package.json"],
|
|
@@ -155,7 +270,11 @@ function updateNodeModules(projectPath: string) {
|
|
|
155
270
|
);
|
|
156
271
|
}
|
|
157
272
|
|
|
158
|
-
function installNodeModules(projectPath: string) {
|
|
273
|
+
function installNodeModules(projectPath: string, skipNPMInstall: boolean) {
|
|
274
|
+
if (skipNPMInstall) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
159
278
|
console.log("Installing node modules... (This can take a long time.)");
|
|
160
279
|
execShell("npm", ["install"], false, projectPath);
|
|
161
280
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import os from "os";
|
|
3
2
|
import path from "path";
|
|
4
|
-
import
|
|
3
|
+
import { HOME_DIR } from "../../constants";
|
|
5
4
|
import * as file from "../../file";
|
|
5
|
+
import { getInputString } from "../../prompt";
|
|
6
6
|
import { error } from "../../util";
|
|
7
7
|
|
|
8
|
-
// https://stackoverflow.com/questions/9080085/node-js-find-home-directory-in-platform-agnostic-way
|
|
9
|
-
const homeDir = os.homedir();
|
|
10
|
-
|
|
11
8
|
const MODS = "mods";
|
|
12
9
|
|
|
13
10
|
const DEFAULT_MODS_PATH_WINDOWS = path.join(
|
|
@@ -22,7 +19,7 @@ const DEFAULT_MODS_PATH_WINDOWS = path.join(
|
|
|
22
19
|
|
|
23
20
|
// This is a subdirectory of $HOME
|
|
24
21
|
const DEFAULT_MODS_PATH_LINUX = path.join(
|
|
25
|
-
|
|
22
|
+
HOME_DIR,
|
|
26
23
|
".local",
|
|
27
24
|
"share",
|
|
28
25
|
"Steam",
|
|
@@ -50,16 +47,13 @@ export async function getModsDir(
|
|
|
50
47
|
console.error(
|
|
51
48
|
`Failed to find your mods directory at: ${chalk.green(defaultModsPath)}`,
|
|
52
49
|
);
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
message: `Enter the full path to the "${MODS}" directory on your system, which should be next to your "isaac-ng.exe" program:`,
|
|
57
|
-
});
|
|
50
|
+
const modsDir = await getInputString(
|
|
51
|
+
`Enter the full path to the "${MODS}" directory on your system, which should be next to your "isaac-ng.exe" program:`,
|
|
52
|
+
);
|
|
58
53
|
|
|
59
|
-
if (
|
|
60
|
-
error("Error:
|
|
54
|
+
if (modsDir === "") {
|
|
55
|
+
error("Error: You did not provide a response; exiting.");
|
|
61
56
|
}
|
|
62
|
-
const modsDir = response.modsDir.trim();
|
|
63
57
|
|
|
64
58
|
if (!file.exists(modsDir)) {
|
|
65
59
|
error(
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import prompts from "prompts";
|
|
4
3
|
import { CURRENT_DIRECTORY_NAME, CWD } from "../../constants";
|
|
5
|
-
import {
|
|
4
|
+
import { getInputString, getInputYesNo } from "../../prompt";
|
|
5
|
+
import { hasWhiteSpace } from "../../util";
|
|
6
6
|
|
|
7
7
|
// From: https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3
|
|
8
8
|
const ILLEGAL_CHARACTERS_FOR_WINDOWS_FILENAMES = [
|
|
@@ -54,29 +54,17 @@ function getProjectNameFromCommandLineArgument(
|
|
|
54
54
|
|
|
55
55
|
async function getNewProjectName(): Promise<[string, string, boolean]> {
|
|
56
56
|
console.log("You did not specify a project name as a command-line argument.");
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
name: "useCurrentDir",
|
|
60
|
-
message: `Would you like to create a new project using the current directory "${chalk.green(
|
|
57
|
+
const shouldUseCurrentDir = await getInputYesNo(
|
|
58
|
+
`Would you like to create a new project using the current directory "${chalk.green(
|
|
61
59
|
CURRENT_DIRECTORY_NAME,
|
|
62
60
|
)}" as the root?`,
|
|
63
|
-
|
|
64
|
-
});
|
|
61
|
+
);
|
|
65
62
|
|
|
66
|
-
if (
|
|
63
|
+
if (shouldUseCurrentDir) {
|
|
67
64
|
return [CURRENT_DIRECTORY_NAME, CWD, false];
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
const
|
|
71
|
-
type: "text",
|
|
72
|
-
name: "projectName",
|
|
73
|
-
message: "Enter the name of the project:",
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
if (typeof response2.projectName !== "string") {
|
|
77
|
-
error("Error: The response was not a string.");
|
|
78
|
-
}
|
|
79
|
-
const projectName = response2.projectName.trim();
|
|
67
|
+
const projectName = await getInputString("Enter the name of the project:");
|
|
80
68
|
const projectPath = path.join(CWD, projectName);
|
|
81
69
|
|
|
82
70
|
return [projectName, projectPath, true];
|
|
@@ -21,28 +21,31 @@ export async function init(argv: Record<string, unknown>): Promise<void> {
|
|
|
21
21
|
const projectName = path.basename(projectPath);
|
|
22
22
|
await checkModTargetDirectory(modsDirectory, projectName);
|
|
23
23
|
const saveSlot = await promptSaveSlot(argv);
|
|
24
|
+
const skipNPMInstall = argv.skipNpmInstall === true;
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
await createMod(
|
|
27
|
+
projectName,
|
|
28
|
+
projectPath,
|
|
29
|
+
createNewDir,
|
|
30
|
+
modsDirectory,
|
|
31
|
+
saveSlot,
|
|
32
|
+
skipNPMInstall,
|
|
33
|
+
);
|
|
34
|
+
await openVSCode(projectPath, argv);
|
|
35
|
+
printFinishMessage(projectPath, projectName);
|
|
36
|
+
}
|
|
28
37
|
|
|
38
|
+
async function openVSCode(projectPath: string, argv: Record<string, unknown>) {
|
|
29
39
|
const VSCodeCommand = getVSCodeCommand();
|
|
30
40
|
if (VSCodeCommand === null) {
|
|
31
41
|
console.log(
|
|
32
42
|
'VSCode does not seem to be installed. (The "code" command is not in the path.) Skipping VSCode-related things.',
|
|
33
43
|
);
|
|
34
|
-
|
|
35
|
-
installVSCodeExtensions(projectPath, VSCodeCommand);
|
|
36
|
-
await promptVSCode(projectPath, argv, VSCodeCommand);
|
|
44
|
+
return;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (projectPath !== CWD) {
|
|
42
|
-
commandsToType += `"${chalk.green(`cd ${projectName}`)}" and `;
|
|
43
|
-
}
|
|
44
|
-
commandsToType += `"${chalk.green("npx isaacscript")}"`;
|
|
45
|
-
console.log(`Now, start IsaacScript by typing ${commandsToType}.`);
|
|
47
|
+
installVSCodeExtensions(projectPath, VSCodeCommand);
|
|
48
|
+
await promptVSCode(projectPath, argv, VSCodeCommand);
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
function getVSCodeCommand() {
|
|
@@ -54,3 +57,12 @@ function getVSCodeCommand() {
|
|
|
54
57
|
|
|
55
58
|
return null;
|
|
56
59
|
}
|
|
60
|
+
|
|
61
|
+
function printFinishMessage(projectPath: string, projectName: string) {
|
|
62
|
+
let commandsToType = "";
|
|
63
|
+
if (projectPath !== CWD) {
|
|
64
|
+
commandsToType += `"${chalk.green(`cd ${projectName}`)}" and `;
|
|
65
|
+
}
|
|
66
|
+
commandsToType += `"${chalk.green("npx isaacscript")}"`;
|
|
67
|
+
console.log(`Now, start IsaacScript by typing ${commandsToType}.`);
|
|
68
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getInputInt } from "../../prompt";
|
|
2
2
|
import { error } from "../../util";
|
|
3
3
|
|
|
4
4
|
export async function promptSaveSlot(
|
|
@@ -10,20 +10,13 @@ export async function promptSaveSlot(
|
|
|
10
10
|
return argv.saveSlot as number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
message: "In-game, will you test your mod on save slot 1, 2, or 3?",
|
|
17
|
-
initial: 1,
|
|
18
|
-
});
|
|
13
|
+
const saveSlot = await getInputInt(
|
|
14
|
+
"In-game, will you test your mod on save slot 1, 2, or 3?",
|
|
15
|
+
);
|
|
19
16
|
|
|
20
|
-
if (
|
|
21
|
-
response.saveSlot !== 1 &&
|
|
22
|
-
response.saveSlot !== 2 &&
|
|
23
|
-
response.saveSlot !== 3
|
|
24
|
-
) {
|
|
17
|
+
if (saveSlot !== 1 && saveSlot !== 2 && saveSlot !== 3) {
|
|
25
18
|
error("Error: You must choose a number between 1 and 3.");
|
|
26
19
|
}
|
|
27
20
|
|
|
28
|
-
return
|
|
21
|
+
return saveSlot;
|
|
29
22
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import prompts from "prompts";
|
|
3
2
|
import { MAIN_TS } from "../../constants";
|
|
3
|
+
import { getInputYesNo } from "../../prompt";
|
|
4
4
|
import { execShell } from "../../util";
|
|
5
5
|
|
|
6
6
|
export async function promptVSCode(
|
|
@@ -15,14 +15,10 @@ export async function promptVSCode(
|
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
initial: true,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
if (response.VSCode === true) {
|
|
18
|
+
const shouldOpenVSCode = await getInputYesNo(
|
|
19
|
+
"Do you want to open your new project in VSCode now?",
|
|
20
|
+
);
|
|
21
|
+
if (shouldOpenVSCode) {
|
|
26
22
|
openVSCode(projectPath, VSCodeCommand);
|
|
27
23
|
}
|
|
28
24
|
}
|
|
@@ -26,10 +26,22 @@ export function monitor(argv: Record<string, unknown>, config: Config): void {
|
|
|
26
26
|
config.saveSlot = argv.saveSlot as number; // eslint-disable-line no-param-reassign
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// Read the "tsconfig.json" file
|
|
30
|
+
const tsConfigInclude = getTSConfigInclude();
|
|
31
|
+
const resolvedIncludePath = path.resolve(CWD, tsConfigInclude);
|
|
32
|
+
const modTargetDirectoryName = getModTargetDirectoryName(config);
|
|
33
|
+
const modTargetPath = path.join(config.modsDirectory, modTargetDirectoryName);
|
|
34
|
+
|
|
29
35
|
// Prepare the IsaacScript watcher mod
|
|
30
36
|
copyWatcherMod(config);
|
|
31
37
|
touchWatcherSaveDatFiles(config);
|
|
32
38
|
|
|
39
|
+
// Delete and re-copy the mod every time IsaacScript starts
|
|
40
|
+
// This ensures that it is always the latest version
|
|
41
|
+
if (file.exists(modTargetPath)) {
|
|
42
|
+
file.deleteFileOrDirectory(modTargetPath);
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
// Subprocess #1 - The "save#.dat" file writer
|
|
34
46
|
spawnSaveDatWriter(config);
|
|
35
47
|
|
|
@@ -37,19 +49,13 @@ export function monitor(argv: Record<string, unknown>, config: Config): void {
|
|
|
37
49
|
spawnModDirectorySyncer(config);
|
|
38
50
|
|
|
39
51
|
// Subprocess #3 - tstl --watch (to automatically convert TypeScript to Lua)
|
|
40
|
-
spawnTSTLWatcher();
|
|
52
|
+
spawnTSTLWatcher(argv);
|
|
41
53
|
|
|
42
54
|
// Also, start constantly pinging the watcher mod
|
|
43
55
|
setInterval(() => {
|
|
44
56
|
notifyGame.ping();
|
|
45
57
|
}, 1000); // Every second
|
|
46
58
|
|
|
47
|
-
// Read the "tsconfig.json" file
|
|
48
|
-
const tsConfigInclude = getTSConfigInclude();
|
|
49
|
-
const resolvedIncludePath = path.resolve(CWD, tsConfigInclude);
|
|
50
|
-
const modTargetDirectoryName = getModTargetDirectoryName(config);
|
|
51
|
-
const modTargetPath = path.join(config.modsDirectory, modTargetDirectoryName);
|
|
52
|
-
|
|
53
59
|
console.log("Automatically monitoring the following for changes:");
|
|
54
60
|
console.log(
|
|
55
61
|
`1) your TypeScript code: ${chalk.green(resolvedIncludePath)}`,
|
|
@@ -91,8 +97,17 @@ function spawnModDirectorySyncer(config: Config) {
|
|
|
91
97
|
});
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
function spawnTSTLWatcher() {
|
|
100
|
+
function spawnTSTLWatcher(argv: Record<string, unknown>) {
|
|
95
101
|
const processDescription = "tstl";
|
|
102
|
+
const crashDebug = argv.crashDebug === true;
|
|
103
|
+
|
|
104
|
+
const tstlArgs = ["--watch", "--preserveWatchOutput"];
|
|
105
|
+
if (crashDebug) {
|
|
106
|
+
tstlArgs.push("--luaPlugins");
|
|
107
|
+
tstlArgs.push(
|
|
108
|
+
'\'{ "name": "./node_modules/isaacscript/src/plugins/addCrashDebugStatements.ts" }\'',
|
|
109
|
+
);
|
|
110
|
+
}
|
|
96
111
|
|
|
97
112
|
let tstl: ChildProcessWithoutNullStreams;
|
|
98
113
|
if (runningFromLocalPath()) {
|
|
@@ -105,12 +120,12 @@ function spawnTSTLWatcher() {
|
|
|
105
120
|
"dist",
|
|
106
121
|
"tstl.js",
|
|
107
122
|
);
|
|
108
|
-
tstl = spawn("node", [tstlPath,
|
|
123
|
+
tstl = spawn("node", [tstlPath, ...tstlArgs], {
|
|
109
124
|
shell: true,
|
|
110
125
|
cwd: CWD,
|
|
111
126
|
});
|
|
112
127
|
} else {
|
|
113
|
-
tstl = spawn("npx", ["tstl",
|
|
128
|
+
tstl = spawn("npx", ["tstl", ...tstlArgs], {
|
|
114
129
|
shell: true,
|
|
115
130
|
});
|
|
116
131
|
}
|
|
@@ -24,9 +24,9 @@ const UPDATE_SCRIPT_NAME = "update.sh";
|
|
|
24
24
|
|
|
25
25
|
export function publish(argv: Record<string, unknown>, config: Config): void {
|
|
26
26
|
const skipVersionIncrement = argv.skip === true;
|
|
27
|
-
const setVersion = argv.
|
|
28
|
-
const dryRun = argv.
|
|
29
|
-
const onlyUpload = argv.
|
|
27
|
+
const setVersion = argv.setVersion as string | undefined;
|
|
28
|
+
const dryRun = argv.dryRun === true;
|
|
29
|
+
const onlyUpload = argv.onlyUpload === true;
|
|
30
30
|
|
|
31
31
|
const modTargetDirectoryName = getModTargetDirectoryName(config);
|
|
32
32
|
const modTargetPath = path.join(config.modsDirectory, modTargetDirectoryName);
|
package/src/constants.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import os from "os";
|
|
1
2
|
import path from "path";
|
|
2
3
|
|
|
3
4
|
const cwd = process.cwd();
|
|
4
5
|
|
|
6
|
+
// https://stackoverflow.com/questions/9080085/node-js-find-home-directory-in-platform-agnostic-way
|
|
7
|
+
const homeDir = os.homedir();
|
|
8
|
+
|
|
5
9
|
// Miscellaneous
|
|
6
10
|
export const CURRENT_DIRECTORY_NAME = path.basename(cwd);
|
|
7
11
|
export const CWD = cwd;
|
|
12
|
+
export const HOME_DIR = homeDir;
|
|
8
13
|
export const FILE_SYNCED_MESSAGE = "File synced:";
|
|
9
14
|
|
|
10
15
|
// isaacscript
|
package/src/main.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { publish } from "./commands/publish/publish";
|
|
|
15
15
|
import * as configFile from "./configFile";
|
|
16
16
|
import { CWD } from "./constants";
|
|
17
17
|
import { parseArgs } from "./parseArgs";
|
|
18
|
+
import { promptInit } from "./prompt";
|
|
18
19
|
import { Command, DEFAULT_COMMAND } from "./types/Command";
|
|
19
20
|
import { Config } from "./types/Config";
|
|
20
21
|
import { ensureAllCases, error } from "./util";
|
|
@@ -28,6 +29,7 @@ main().catch((err) => {
|
|
|
28
29
|
|
|
29
30
|
async function main(): Promise<void> {
|
|
30
31
|
sourceMapSupport.install();
|
|
32
|
+
promptInit();
|
|
31
33
|
validateNodeVersion();
|
|
32
34
|
validateOS();
|
|
33
35
|
|
package/src/monkeyPatch.ts
CHANGED
|
@@ -39,13 +39,14 @@ export function monkeyPatchMainLua(targetModDirectory: string): void {
|
|
|
39
39
|
const mainLuaPath = path.join(targetModDirectory, MAIN_LUA);
|
|
40
40
|
let mainLua = file.read(mainLuaPath);
|
|
41
41
|
|
|
42
|
-
mainLua = patchInformationalHeader(mainLua);
|
|
42
|
+
// mainLua = patchInformationalHeader(mainLua);
|
|
43
43
|
mainLua = patchGlobalObjects(mainLua);
|
|
44
44
|
|
|
45
45
|
file.write(mainLuaPath, mainLua);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Add an informational header for people who happen to be browsing the Lua output
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
50
|
function patchInformationalHeader(mainLua: string) {
|
|
50
51
|
return INFORMATIONAL_HEADER + mainLua;
|
|
51
52
|
}
|