isaacscript 1.2.2 → 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.
Files changed (62) hide show
  1. package/dist/package.json +3 -3
  2. package/dist/src/commands/copy/copy.js +12 -10
  3. package/dist/src/commands/copy/copy.js.map +1 -1
  4. package/dist/src/commands/init/checkIfProjectPathExists.js +2 -2
  5. package/dist/src/commands/init/checkIfProjectPathExists.js.map +1 -1
  6. package/dist/src/commands/init/checkModTargetDirectory.js +2 -2
  7. package/dist/src/commands/init/checkModTargetDirectory.js.map +1 -1
  8. package/dist/src/commands/init/createMod.js +55 -34
  9. package/dist/src/commands/init/createMod.js.map +1 -1
  10. package/dist/src/commands/init/init.js +10 -8
  11. package/dist/src/commands/init/init.js.map +1 -1
  12. package/dist/src/commands/init/installVSCodeExtensions.js +3 -2
  13. package/dist/src/commands/init/installVSCodeExtensions.js.map +1 -1
  14. package/dist/src/commands/init/promptVSCode.js +7 -7
  15. package/dist/src/commands/init/promptVSCode.js.map +1 -1
  16. package/dist/src/commands/monitor/copyWatcherMod.js +7 -7
  17. package/dist/src/commands/monitor/copyWatcherMod.js.map +1 -1
  18. package/dist/src/commands/monitor/monitor.js +4 -3
  19. package/dist/src/commands/monitor/monitor.js.map +1 -1
  20. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js +1 -1
  21. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js.map +1 -1
  22. package/dist/src/commands/monitor/touchWatcherSaveDatFiles.js +3 -3
  23. package/dist/src/commands/monitor/touchWatcherSaveDatFiles.js.map +1 -1
  24. package/dist/src/commands/publish/publish.js +48 -46
  25. package/dist/src/commands/publish/publish.js.map +1 -1
  26. package/dist/src/configFile.js +4 -3
  27. package/dist/src/configFile.js.map +1 -1
  28. package/dist/src/exec.js +79 -0
  29. package/dist/src/exec.js.map +1 -0
  30. package/dist/src/file.js +35 -5
  31. package/dist/src/file.js.map +1 -1
  32. package/dist/src/main.js +1 -1
  33. package/dist/src/main.js.map +1 -1
  34. package/dist/src/monkeyPatch.js +4 -4
  35. package/dist/src/monkeyPatch.js.map +1 -1
  36. package/dist/src/parseArgs.js +20 -1
  37. package/dist/src/parseArgs.js.map +1 -1
  38. package/dist/src/util.js +22 -57
  39. package/dist/src/util.js.map +1 -1
  40. package/dist/src/validateNodeVersion.js +6 -24
  41. package/dist/src/validateNodeVersion.js.map +1 -1
  42. package/package.json +3 -3
  43. package/src/commands/copy/copy.ts +19 -10
  44. package/src/commands/init/checkIfProjectPathExists.ts +2 -1
  45. package/src/commands/init/checkModTargetDirectory.ts +2 -1
  46. package/src/commands/init/createMod.ts +87 -29
  47. package/src/commands/init/init.ts +15 -7
  48. package/src/commands/init/installVSCodeExtensions.ts +4 -2
  49. package/src/commands/init/promptVSCode.ts +12 -7
  50. package/src/commands/monitor/copyWatcherMod.ts +10 -7
  51. package/src/commands/monitor/monitor.ts +5 -3
  52. package/src/commands/monitor/saveDatWriter/saveDatWriter.ts +1 -1
  53. package/src/commands/monitor/touchWatcherSaveDatFiles.ts +6 -3
  54. package/src/commands/publish/publish.ts +65 -55
  55. package/src/configFile.ts +9 -3
  56. package/src/exec.ts +102 -0
  57. package/src/file.ts +48 -5
  58. package/src/main.ts +1 -1
  59. package/src/monkeyPatch.ts +4 -2
  60. package/src/parseArgs.ts +22 -1
  61. package/src/util.ts +29 -79
  62. package/src/validateNodeVersion.ts +7 -39
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(filePath: string): void {
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
@@ -89,7 +89,7 @@ async function handleCommands(argv: Record<string, unknown>) {
89
89
  }
90
90
 
91
91
  case "copy": {
92
- copy(config);
92
+ copy(argv, config);
93
93
  break;
94
94
  }
95
95
 
@@ -28,14 +28,15 @@ const MAIN_LUA_REPLACEMENTS = [
28
28
  ["Set = __TS__Class()", "Set = Set or __TS__Class()"],
29
29
  ];
30
30
 
31
- export function monkeyPatchMainLua(targetModDirectory: string): void {
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ function monkeyPatchMainLua(targetModDirectory: string, verbose: boolean) {
32
33
  const mainLuaPath = path.join(targetModDirectory, MAIN_LUA);
33
34
  const mainLua = file.read(mainLuaPath);
34
35
 
35
36
  // mainLua = patchInformationalHeader(mainLua);
36
37
  // mainLua = patchGlobalObjects(mainLua);
37
38
 
38
- file.write(mainLuaPath, mainLua);
39
+ file.write(mainLuaPath, mainLua, verbose);
39
40
  }
40
41
 
41
42
  // Add an informational header for people who happen to be browsing the Lua output
@@ -49,6 +50,7 @@ function patchInformationalHeader(mainLua: string) {
49
50
  // Until TSTL has an official fix, monkey patch this
50
51
  // We also make sure of this function to compose a stock comment header for curious people looking
51
52
  // at the transpiled Lua code
53
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
52
54
  function patchGlobalObjects(originalMainLua: string) {
53
55
  let mainLua = originalMainLua;
54
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
 
package/src/util.ts CHANGED
@@ -1,7 +1,5 @@
1
- import chalk from "chalk";
2
- import { execSync, spawnSync, SpawnSyncReturns } from "child_process";
3
1
  import moment from "moment";
4
- import { CURRENT_DIRECTORY_NAME, CWD } from "./constants";
2
+ import { CURRENT_DIRECTORY_NAME } from "./constants";
5
3
  import { Config } from "./types/Config";
6
4
 
7
5
  export const ensureAllCases = (obj: never): never => obj;
@@ -11,82 +9,6 @@ export function error(...args: unknown[]): never {
11
9
  process.exit(1);
12
10
  }
13
11
 
14
- export function execExe(path: string, cwd = CWD): string {
15
- let stdout: string;
16
- try {
17
- const buffer = execSync(`"${path}"`, {
18
- cwd,
19
- });
20
- stdout = buffer.toString().trim();
21
- } catch (err) {
22
- console.error(`Failed to run "${chalk.green(path)}":`, err);
23
- process.exit(1);
24
- }
25
-
26
- return stdout;
27
- }
28
-
29
- /** Returns an array of exit status and stdout. */
30
- export function execShell(
31
- command: string,
32
- args: string[] = [],
33
- allowFailure = false,
34
- cwd = CWD,
35
- ): [number | null, 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
- throw new 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
- throw new 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
- let spawnSyncReturns: SpawnSyncReturns<Buffer>;
57
- try {
58
- spawnSyncReturns = spawnSync(command, args, {
59
- shell: true,
60
- cwd,
61
- });
62
- } catch (err) {
63
- error(
64
- `Failed to run the "${chalk.green(commandDescription)}" command:`,
65
- err,
66
- );
67
- }
68
-
69
- const exitStatus = spawnSyncReturns.status;
70
- const stdout = spawnSyncReturns.output.join("\n").trim();
71
-
72
- if (exitStatus !== 0) {
73
- if (allowFailure) {
74
- return [exitStatus, stdout];
75
- }
76
-
77
- console.error(
78
- `Failed to run the "${chalk.green(
79
- commandDescription,
80
- )}" command with an exit code of ${exitStatus}.`,
81
- );
82
- console.error("The output was as follows:");
83
- console.error(stdout);
84
- process.exit(1);
85
- }
86
-
87
- return [exitStatus, stdout];
88
- }
89
-
90
12
  export function getModTargetDirectoryName(config: Config): string {
91
13
  return config.customTargetModDirectoryName === undefined
92
14
  ? CURRENT_DIRECTORY_NAME
@@ -132,3 +54,31 @@ export function parseIntSafe(input: string): number {
132
54
 
133
55
  return parseInt(trimmedInput, 10);
134
56
  }
57
+
58
+ export function parseSemVer(
59
+ versionString: string,
60
+ ): [major: number, minor: number, patch: number] {
61
+ const match = /^v*(\d+)\.(\d+)\.(\d+)/g.exec(versionString);
62
+ if (match === null) {
63
+ error(`Failed to parse the version string of: ${versionString}`);
64
+ }
65
+
66
+ const [, majorVersionString, minorVersionString, patchVersionString] = match;
67
+
68
+ const majorVersion = parseIntSafe(majorVersionString);
69
+ if (Number.isNaN(majorVersion)) {
70
+ error(`Failed to parse the major version number from: ${versionString}`);
71
+ }
72
+
73
+ const minorVersion = parseInt(minorVersionString, 10);
74
+ if (Number.isNaN(minorVersion)) {
75
+ error(`Failed to parse the minor version number from: ${versionString}`);
76
+ }
77
+
78
+ const patchVersion = parseInt(patchVersionString, 10);
79
+ if (Number.isNaN(patchVersion)) {
80
+ error(`Failed to parse the patch version number from: ${versionString}`);
81
+ }
82
+
83
+ return [majorVersion, minorVersion, patchVersion];
84
+ }
@@ -1,56 +1,24 @@
1
1
  import chalk from "chalk";
2
2
  import { PROJECT_NAME } from "./constants";
3
- import { error } from "./util";
3
+ import { parseSemVer } from "./util";
4
4
 
5
- const REQUIRED_MAJOR_VERSION = 16;
5
+ const REQUIRED_NODE_JS_MAJOR_VERSION = 16;
6
6
 
7
7
  // This program requires Node to be at least v16.0.0,
8
8
  // since that is the version that added the "fs.rmSync()" function
9
9
  // (I tested on Node v15.0.0 and it failed)
10
10
  export function validateNodeVersion(): void {
11
- const { version } = process;
11
+ const nodeJSVersionString = process.version;
12
+ const [majorVersion] = parseSemVer(nodeJSVersionString);
12
13
 
13
- const match = /^v(\d+)\.(\d+)\.(\d)+$/g.exec(version);
14
- if (match === null) {
15
- error(`Failed to parse your NodeJS version of: ${version}`);
16
- }
17
-
18
- const majorVersionString = match[1];
19
- const majorVersion = parseInt(majorVersionString, 10);
20
- if (Number.isNaN(majorVersion)) {
21
- error(
22
- `Failed to parse the major version number from: ${majorVersionString}`,
23
- );
24
- }
25
-
26
- const minorVersionString = match[2];
27
- const minorVersion = parseInt(minorVersionString, 10);
28
- if (Number.isNaN(minorVersion)) {
29
- error(
30
- `Failed to parse the minor version number from: ${minorVersionString}`,
31
- );
32
- }
33
-
34
- const patchVersionString = match[3];
35
- const patchVersion = parseInt(patchVersionString, 10);
36
- if (Number.isNaN(patchVersion)) {
37
- error(
38
- `Failed to parse the patch version number from: ${patchVersionString}`,
39
- );
40
- }
41
-
42
- if (majorVersion >= REQUIRED_MAJOR_VERSION) {
14
+ if (majorVersion >= REQUIRED_NODE_JS_MAJOR_VERSION) {
43
15
  return;
44
16
  }
45
17
 
46
- console.error(
47
- `Your Node.js version is: ${chalk.red(
48
- `${majorVersionString}.${minorVersionString}.${patchVersionString}`,
49
- )}`,
50
- );
18
+ console.error(`Your Node.js version is: ${chalk.red(nodeJSVersionString)}`);
51
19
  console.error(
52
20
  `${PROJECT_NAME} requires a Node.js version of ${chalk.red(
53
- "16.0.0",
21
+ `${REQUIRED_NODE_JS_MAJOR_VERSION}.0.0`,
54
22
  )} or greater.`,
55
23
  );
56
24
  console.error(