isaacscript 1.1.53 → 1.1.57

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 (74) hide show
  1. package/.cspell.json +1 -3
  2. package/.eslintrc.js +1 -15
  3. package/.vscode/extensions.json +1 -0
  4. package/.vscode/settings.json +4 -0
  5. package/dist/package.json +8 -6
  6. package/dist/src/checkForWindowsTerminalBugs.js +20 -52
  7. package/dist/src/checkForWindowsTerminalBugs.js.map +1 -1
  8. package/dist/src/commands/init/checkIfProjectPathExists.js +3 -7
  9. package/dist/src/commands/init/checkIfProjectPathExists.js.map +1 -1
  10. package/dist/src/commands/init/checkModTargetDirectory.js +3 -8
  11. package/dist/src/commands/init/checkModTargetDirectory.js.map +1 -1
  12. package/dist/src/commands/init/createMod.js +85 -11
  13. package/dist/src/commands/init/createMod.js.map +1 -1
  14. package/dist/src/commands/init/getModsDir.js +6 -13
  15. package/dist/src/commands/init/getModsDir.js.map +1 -1
  16. package/dist/src/commands/init/getProjectPath.js +4 -17
  17. package/dist/src/commands/init/getProjectPath.js.map +1 -1
  18. package/dist/src/commands/init/init.js +18 -15
  19. package/dist/src/commands/init/init.js.map +1 -1
  20. package/dist/src/commands/init/promptSaveSlot.js +4 -14
  21. package/dist/src/commands/init/promptSaveSlot.js.map +1 -1
  22. package/dist/src/commands/init/promptVSCode.js +3 -8
  23. package/dist/src/commands/init/promptVSCode.js.map +1 -1
  24. package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js +0 -1
  25. package/dist/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.js.map +1 -1
  26. package/dist/src/commands/monitor/monitor.js +10 -4
  27. package/dist/src/commands/monitor/monitor.js.map +1 -1
  28. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js +0 -1
  29. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js.map +1 -1
  30. package/dist/src/commands/publish/publish.js +8 -10
  31. package/dist/src/commands/publish/publish.js.map +1 -1
  32. package/dist/src/constants.js +5 -1
  33. package/dist/src/constants.js.map +1 -1
  34. package/dist/src/main.js +2 -0
  35. package/dist/src/main.js.map +1 -1
  36. package/dist/src/parseArgs.js +62 -58
  37. package/dist/src/parseArgs.js.map +1 -1
  38. package/dist/src/plugins/addCrashDebugStatements.js +31 -0
  39. package/dist/src/plugins/addCrashDebugStatements.js.map +1 -0
  40. package/dist/src/prompt.js +90 -0
  41. package/dist/src/prompt.js.map +1 -0
  42. package/dist/src/types/GitHubCLIHostsYAML.js +3 -0
  43. package/dist/src/types/GitHubCLIHostsYAML.js.map +1 -0
  44. package/dist/src/util.js +12 -23
  45. package/dist/src/util.js.map +1 -1
  46. package/file-templates/dynamic/README.md +2 -2
  47. package/file-templates/dynamic/main.ts +4 -2
  48. package/file-templates/dynamic/metadata.xml +3 -3
  49. package/file-templates/dynamic/package.json +1 -1
  50. package/file-templates/static/.vscode/extensions.json +1 -0
  51. package/file-templates/static/.vscode/settings.json +4 -0
  52. package/file-templates/static/lint.sh +10 -9
  53. package/lint.sh +6 -10
  54. package/package.json +8 -6
  55. package/src/checkForWindowsTerminalBugs.ts +35 -73
  56. package/src/commands/init/checkIfProjectPathExists.ts +4 -7
  57. package/src/commands/init/checkModTargetDirectory.ts +7 -9
  58. package/src/commands/init/createMod.ts +132 -13
  59. package/src/commands/init/getModsDir.ts +8 -14
  60. package/src/commands/init/getProjectPath.ts +7 -19
  61. package/src/commands/init/init.ts +25 -13
  62. package/src/commands/init/promptSaveSlot.ts +6 -13
  63. package/src/commands/init/promptVSCode.ts +5 -9
  64. package/src/commands/monitor/modDirectorySyncer/modDirectorySyncer.ts +0 -2
  65. package/src/commands/monitor/monitor.ts +13 -4
  66. package/src/commands/monitor/saveDatWriter/saveDatWriter.ts +0 -2
  67. package/src/commands/publish/publish.ts +11 -10
  68. package/src/constants.ts +5 -0
  69. package/src/main.ts +2 -0
  70. package/src/parseArgs.ts +34 -28
  71. package/src/plugins/addCrashDebugStatements.ts +29 -0
  72. package/src/prompt.ts +110 -0
  73. package/src/types/GitHubCLIHostsYAML.ts +7 -0
  74. package/src/util.ts +12 -23
@@ -0,0 +1,29 @@
1
+ /*
2
+ import * as crypto from "crypto";
3
+ import { SourceNode } from "source-map";
4
+ import * as ts from "typescript";
5
+ import * as tstl from "typescript-to-lua";
6
+
7
+ class CustomPrinter extends tstl.LuaPrinter {
8
+ printStatement(statement: tstl.Statement): SourceNode {
9
+ const uuid = crypto.randomUUID();
10
+ const debugLineToInsert = `Isaac.DebugString("CRASH DEBUG ${uuid}")\n`;
11
+ const originalResult = super.printStatement(statement);
12
+ return this.createSourceNode(statement, [
13
+ debugLineToInsert,
14
+ originalResult,
15
+ ]);
16
+ }
17
+ }
18
+
19
+ const plugin: tstl.Plugin = {
20
+ printer: (
21
+ program: ts.Program,
22
+ emitHost: tstl.EmitHost,
23
+ fileName: string,
24
+ file: tstl.File,
25
+ ) => new CustomPrinter(emitHost, program, fileName).print(file),
26
+ };
27
+
28
+ export default plugin;
29
+ */
package/src/prompt.ts ADDED
@@ -0,0 +1,110 @@
1
+ // Both the Inquirer.js library and the Prompts library have a bug where text is duplicated in a Git
2
+ // Bash terminal
3
+ // Thus, we revert to using the simpler Prompt library
4
+
5
+ import chalk from "chalk";
6
+ import prompt from "prompt";
7
+ import { error, parseIntSafe } from "./util";
8
+
9
+ const VALID_YES_RESPONSES = new Set(["yes", "ye", "y"]);
10
+ const VALID_NO_RESPONSES = new Set(["no", "n"]);
11
+
12
+ export function promptInit(): void {
13
+ // Override some of the prompt library's default values
14
+ // https://github.com/flatiron/prompt#customizing-your-prompt
15
+ prompt.message = chalk.green("?");
16
+ prompt.delimiter = " ";
17
+ prompt.colors = false;
18
+ }
19
+
20
+ export async function getInputYesNo(
21
+ msg: string,
22
+ defaultValue = true,
23
+ ): Promise<boolean> {
24
+ prompt.start();
25
+
26
+ // Capitalize the letter that represents the default option
27
+ const y = defaultValue ? "Y" : "y";
28
+ const n = defaultValue ? "n" : "N";
29
+
30
+ const questionSuffix = `(${y}\\${n})`;
31
+ const description = `${chalk.bold(msg)} ${chalk.gray(questionSuffix)}`;
32
+
33
+ const { response } = await prompt.get({
34
+ properties: {
35
+ response: {
36
+ type: "string",
37
+ description,
38
+ },
39
+ },
40
+ });
41
+
42
+ if (typeof response !== "string") {
43
+ console.log(typeof response);
44
+ error("Failed to get a proper response from the prompt library.");
45
+ }
46
+
47
+ const cleanedResponse = response.toLowerCase().trim();
48
+
49
+ // Default to true
50
+ if (cleanedResponse === "") {
51
+ return defaultValue;
52
+ }
53
+
54
+ if (VALID_YES_RESPONSES.has(cleanedResponse)) {
55
+ return true;
56
+ }
57
+
58
+ if (VALID_NO_RESPONSES.has(cleanedResponse)) {
59
+ return false;
60
+ }
61
+
62
+ error('Invalid response; must answer "yes" or "no".');
63
+ return false;
64
+ }
65
+
66
+ export async function getInputString(
67
+ msg: string,
68
+ defaultValue?: string,
69
+ ): Promise<string> {
70
+ prompt.start();
71
+
72
+ let description = `${chalk.bold(msg)}`;
73
+ if (defaultValue !== undefined) {
74
+ description += ` ${chalk.gray(`(${defaultValue})`)}`;
75
+ }
76
+
77
+ const { response } = await prompt.get({
78
+ properties: {
79
+ response: {
80
+ type: "string",
81
+ description,
82
+ },
83
+ },
84
+ });
85
+
86
+ if (typeof response !== "string") {
87
+ error("Failed to get a proper response from the prompt library.");
88
+ }
89
+
90
+ if (response === "" && defaultValue !== undefined) {
91
+ return defaultValue;
92
+ }
93
+
94
+ return response.trim();
95
+ }
96
+
97
+ export async function getInputInt(
98
+ msg: string,
99
+ defaultValue = 1,
100
+ ): Promise<number> {
101
+ const defaultValueString = defaultValue.toString();
102
+ const string = await getInputString(msg, defaultValueString);
103
+ const int = parseIntSafe(string);
104
+
105
+ if (Number.isNaN(int)) {
106
+ error("Error: You must enter an integer.");
107
+ }
108
+
109
+ return int;
110
+ }
@@ -0,0 +1,7 @@
1
+ export interface GitHubCLIHostsYAML {
2
+ "github.com": {
3
+ user: string;
4
+ oauth_token: string;
5
+ git_protocol: string;
6
+ };
7
+ }
package/src/util.ts CHANGED
@@ -1,11 +1,9 @@
1
1
  import chalk from "chalk";
2
- import { execSync, spawnSync, SpawnSyncReturns } from "child_process";
2
+ import { spawnSync, SpawnSyncReturns } from "child_process";
3
3
  import moment from "moment";
4
4
  import { CURRENT_DIRECTORY_NAME, CWD } from "./constants";
5
5
  import { Config } from "./types/Config";
6
6
 
7
- // Use this on a switch statement's default case to get
8
- // the linter to complain if a case was not predicted
9
7
  export const ensureAllCases = (obj: never): never => obj;
10
8
 
11
9
  export function error(...args: unknown[]): never {
@@ -13,23 +11,10 @@ export function error(...args: unknown[]): never {
13
11
  process.exit(1);
14
12
  }
15
13
 
16
- export function execExe(path: string, cwd = CWD): string {
17
- let stdout: string;
18
- try {
19
- const buffer = execSync(`"${path}"`, {
20
- cwd,
21
- });
22
- stdout = buffer.toString().trim();
23
- } catch (err) {
24
- error(`Failed to run "${chalk.green(path)}":`, err);
25
- }
26
-
27
- return stdout;
28
- }
29
-
14
+ /** Returns an array of exit status and stdout. */
30
15
  export function execShell(
31
16
  command: string,
32
- args: string[],
17
+ args: string[] = [],
33
18
  allowFailure = false,
34
19
  cwd = CWD,
35
20
  ): [number | null, string] {
@@ -97,9 +82,10 @@ export function hasWhiteSpace(s: string): boolean {
97
82
  return /\s/g.test(s);
98
83
  }
99
84
 
100
- // parseIntSafe is a more reliable version of parseInt
101
- // By default, "parseInt('1a')" will return "1", which is unexpected
102
- // This returns either an integer or NaN
85
+ /**
86
+ * parseIntSafe is a more reliable version of parseInt. By default, "parseInt('1a')" will return
87
+ * "1", which is unexpected. This returns either an integer or NaN.
88
+ */
103
89
  export function parseIntSafe(input: string): number {
104
90
  if (typeof input !== "string") {
105
91
  return NaN;
@@ -127,8 +113,11 @@ export function parseIntSafe(input: string): number {
127
113
  return parseInt(trimmedInput, 10);
128
114
  }
129
115
 
130
- // Convert snake_case and kebab-case to camelCase
131
- // From: https://hisk.io/javascript-snake-to-camel/
116
+ /**
117
+ * Converts snake_case and kebab-case to camelCase.
118
+ *
119
+ * From: https://hisk.io/javascript-snake-to-camel/
120
+ */
132
121
  export function snakeKebabToCamel(str: string): string {
133
122
  return str.replace(/([-_][a-z])/g, (group) =>
134
123
  group.toUpperCase().replace("-", "").replace("_", ""),