isaacscript 1.2.28 → 1.2.31

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 (77) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/checkForWindowsTerminalBugs.js +7 -7
  3. package/dist/src/checkForWindowsTerminalBugs.js.map +1 -1
  4. package/dist/src/commands/copy/copy.js +1 -1
  5. package/dist/src/commands/copy/copy.js.map +1 -1
  6. package/dist/src/commands/init/checkIfProjectPathExists.js +14 -8
  7. package/dist/src/commands/init/checkIfProjectPathExists.js.map +1 -1
  8. package/dist/src/commands/init/checkModSubdirectory.js +2 -2
  9. package/dist/src/commands/init/checkModSubdirectory.js.map +1 -1
  10. package/dist/src/commands/init/checkModTargetDirectory.js +13 -7
  11. package/dist/src/commands/init/checkModTargetDirectory.js.map +1 -1
  12. package/dist/src/commands/init/createMod.js +27 -24
  13. package/dist/src/commands/init/createMod.js.map +1 -1
  14. package/dist/src/commands/init/getModsDir.js +5 -4
  15. package/dist/src/commands/init/getModsDir.js.map +1 -1
  16. package/dist/src/commands/init/getProjectPath.js +16 -12
  17. package/dist/src/commands/init/getProjectPath.js.map +1 -1
  18. package/dist/src/commands/init/git.js +22 -13
  19. package/dist/src/commands/init/git.js.map +1 -1
  20. package/dist/src/commands/init/init.js +10 -7
  21. package/dist/src/commands/init/init.js.map +1 -1
  22. package/dist/src/commands/init/installVSCodeExtensions.js +4 -4
  23. package/dist/src/commands/init/installVSCodeExtensions.js.map +1 -1
  24. package/dist/src/commands/init/promptSaveSlot.js +4 -1
  25. package/dist/src/commands/init/promptSaveSlot.js.map +1 -1
  26. package/dist/src/commands/monitor/copyWatcherMod.js +3 -3
  27. package/dist/src/commands/monitor/copyWatcherMod.js.map +1 -1
  28. package/dist/src/commands/monitor/getTSConfigInclude.js +2 -2
  29. package/dist/src/commands/monitor/getTSConfigInclude.js.map +1 -1
  30. package/dist/src/commands/monitor/monitor.js +2 -2
  31. package/dist/src/commands/monitor/monitor.js.map +1 -1
  32. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js +13 -12
  33. package/dist/src/commands/monitor/saveDatWriter/saveDatWriter.js.map +1 -1
  34. package/dist/src/commands/monitor/touchWatcherSaveDatFiles.js +2 -2
  35. package/dist/src/commands/monitor/touchWatcherSaveDatFiles.js.map +1 -1
  36. package/dist/src/commands/publish/publish.js +16 -16
  37. package/dist/src/commands/publish/publish.js.map +1 -1
  38. package/dist/src/configFile.js +7 -6
  39. package/dist/src/configFile.js.map +1 -1
  40. package/dist/src/exec.js +2 -2
  41. package/dist/src/exec.js.map +1 -1
  42. package/dist/src/file.js +37 -7
  43. package/dist/src/file.js.map +1 -1
  44. package/dist/src/main.js +5 -4
  45. package/dist/src/main.js.map +1 -1
  46. package/dist/src/parseArgs.js +5 -0
  47. package/dist/src/parseArgs.js.map +1 -1
  48. package/dist/src/utils.js +7 -1
  49. package/dist/src/utils.js.map +1 -1
  50. package/dist/src/validateInIsaacScriptProject.js +3 -2
  51. package/dist/src/validateInIsaacScriptProject.js.map +1 -1
  52. package/package.json +2 -2
  53. package/src/checkForWindowsTerminalBugs.ts +9 -7
  54. package/src/commands/copy/copy.ts +1 -1
  55. package/src/commands/init/checkIfProjectPathExists.ts +19 -12
  56. package/src/commands/init/checkModSubdirectory.ts +2 -2
  57. package/src/commands/init/checkModTargetDirectory.ts +18 -12
  58. package/src/commands/init/createMod.ts +47 -37
  59. package/src/commands/init/getModsDir.ts +7 -3
  60. package/src/commands/init/getProjectPath.ts +19 -12
  61. package/src/commands/init/git.ts +34 -18
  62. package/src/commands/init/init.ts +14 -6
  63. package/src/commands/init/installVSCodeExtensions.ts +4 -4
  64. package/src/commands/init/promptSaveSlot.ts +5 -0
  65. package/src/commands/monitor/copyWatcherMod.ts +3 -3
  66. package/src/commands/monitor/getTSConfigInclude.ts +2 -2
  67. package/src/commands/monitor/monitor.ts +2 -2
  68. package/src/commands/monitor/saveDatWriter/saveDatWriter.ts +14 -12
  69. package/src/commands/monitor/touchWatcherSaveDatFiles.ts +2 -2
  70. package/src/commands/publish/publish.ts +16 -16
  71. package/src/configFile.ts +7 -6
  72. package/src/exec.ts +2 -4
  73. package/src/file.ts +51 -7
  74. package/src/main.ts +5 -4
  75. package/src/parseArgs.ts +6 -0
  76. package/src/utils.ts +8 -0
  77. package/src/validateInIsaacScriptProject.ts +5 -2
package/src/file.ts CHANGED
@@ -51,7 +51,11 @@ export function deleteFileOrDirectory(
51
51
  }
52
52
  }
53
53
 
54
- export function exists(filePath: string): boolean {
54
+ export function exists(filePath: string, verbose: boolean): boolean {
55
+ if (verbose) {
56
+ console.log(`Checking to see if the following path exists: ${filePath}`);
57
+ }
58
+
55
59
  let pathExists: boolean;
56
60
  try {
57
61
  pathExists = fs.existsSync(filePath);
@@ -59,10 +63,18 @@ export function exists(filePath: string): boolean {
59
63
  error(`Failed to check to see if "${chalk.green(filePath)}" exists:`, err);
60
64
  }
61
65
 
66
+ if (verbose) {
67
+ console.log(`Path exists: ${pathExists}`);
68
+ }
69
+
62
70
  return pathExists;
63
71
  }
64
72
 
65
- export function getDirList(dirPath: string): string[] {
73
+ export function getDirList(dirPath: string, verbose: boolean): string[] {
74
+ if (verbose) {
75
+ console.log(`Getting a directory list from: ${dirPath}`);
76
+ }
77
+
66
78
  let fileList: string[];
67
79
  try {
68
80
  fileList = fs.readdirSync(dirPath);
@@ -73,10 +85,18 @@ export function getDirList(dirPath: string): string[] {
73
85
  );
74
86
  }
75
87
 
88
+ if (verbose) {
89
+ console.log(`Got a directory list from: ${dirPath}`);
90
+ }
91
+
76
92
  return fileList;
77
93
  }
78
94
 
79
- function getFileStats(filePath: string): fs.Stats {
95
+ function getFileStats(filePath: string, verbose: boolean): fs.Stats {
96
+ if (verbose) {
97
+ console.log(`Getting file stats from: ${filePath}`);
98
+ }
99
+
80
100
  let fileStats: fs.Stats;
81
101
  try {
82
102
  fileStats = fs.statSync(filePath);
@@ -84,11 +104,15 @@ function getFileStats(filePath: string): fs.Stats {
84
104
  error(`Failed to get the file stats for "${chalk.green(filePath)}":`, err);
85
105
  }
86
106
 
107
+ if (verbose) {
108
+ console.log(`Got file stats from: ${filePath}`);
109
+ }
110
+
87
111
  return fileStats;
88
112
  }
89
113
 
90
- export function isDir(filePath: string): boolean {
91
- const fileStats = getFileStats(filePath);
114
+ export function isDir(filePath: string, verbose: boolean): boolean {
115
+ const fileStats = getFileStats(filePath, verbose);
92
116
  return fileStats.isDirectory();
93
117
  }
94
118
 
@@ -117,7 +141,11 @@ export function makeDir(dirPath: string, verbose: boolean): void {
117
141
  }
118
142
  }
119
143
 
120
- export function read(filePath: string): string {
144
+ export function read(filePath: string, verbose: boolean): string {
145
+ if (verbose) {
146
+ console.log(`Reading a file: ${filePath}`);
147
+ }
148
+
121
149
  let fileContents: string;
122
150
  try {
123
151
  fileContents = fs.readFileSync(filePath, "utf8");
@@ -125,6 +153,10 @@ export function read(filePath: string): string {
125
153
  error(`Failed to read the "${chalk.green(filePath)}" file:`, err);
126
154
  }
127
155
 
156
+ if (verbose) {
157
+ console.log(`Read a file: ${filePath}`);
158
+ }
159
+
128
160
  return fileContents;
129
161
  }
130
162
 
@@ -161,6 +193,18 @@ export function write(filePath: string, data: string, verbose: boolean): void {
161
193
  }
162
194
  }
163
195
 
164
- export function writeTry(filePath: string, data: string): void {
196
+ export function writeTry(
197
+ filePath: string,
198
+ data: string,
199
+ verbose: boolean,
200
+ ): void {
201
+ if (verbose) {
202
+ console.log(`Writing data to: ${filePath}`);
203
+ }
204
+
165
205
  fs.writeFileSync(filePath, data);
206
+
207
+ if (verbose) {
208
+ console.log(`Wrote data to: ${filePath}`);
209
+ }
166
210
  }
package/src/main.ts CHANGED
@@ -36,6 +36,7 @@ async function main(): Promise<void> {
36
36
 
37
37
  // Get command line arguments
38
38
  const argv = parseArgs();
39
+ const verbose = argv.verbose === true;
39
40
 
40
41
  printBanner();
41
42
 
@@ -43,9 +44,9 @@ async function main(): Promise<void> {
43
44
  updateNotifier({ pkg }).notify();
44
45
 
45
46
  // Pre-flight checks
46
- await checkForWindowsTerminalBugs();
47
+ await checkForWindowsTerminalBugs(verbose);
47
48
 
48
- await handleCommands(argv);
49
+ await handleCommands(argv, verbose);
49
50
  }
50
51
 
51
52
  function loadEnvironmentVariables() {
@@ -62,7 +63,7 @@ function printBanner() {
62
63
  console.log();
63
64
  }
64
65
 
65
- async function handleCommands(argv: Record<string, unknown>) {
66
+ async function handleCommands(argv: Record<string, unknown>, verbose: boolean) {
66
67
  const positionalArgs = argv._ as string[];
67
68
  let command: Command;
68
69
  if (positionalArgs.length > 0) {
@@ -73,7 +74,7 @@ async function handleCommands(argv: Record<string, unknown>) {
73
74
 
74
75
  let config = new Config();
75
76
  if (command !== "init") {
76
- validateInIsaacScriptProject();
77
+ validateInIsaacScriptProject(verbose);
77
78
  config = await configFile.get(argv);
78
79
  }
79
80
 
package/src/parseArgs.ts CHANGED
@@ -32,6 +32,12 @@ export function parseArgs(): Record<string, unknown> {
32
32
  `Initialize a new ${PROJECT_NAME} mod.`,
33
33
  (builder) =>
34
34
  builder
35
+ .option("yes", {
36
+ alias: "y",
37
+ type: "boolean",
38
+ description:
39
+ 'Answer yes to every dialog option, similar to how "npm init --yes" works.',
40
+ })
35
41
  .option("use-current-dir", {
36
42
  alias: "u",
37
43
  type: "boolean",
package/src/utils.ts CHANGED
@@ -2,6 +2,10 @@ import moment from "moment";
2
2
  import { CURRENT_DIRECTORY_NAME } from "./constants";
3
3
  import { Config } from "./types/Config";
4
4
 
5
+ /** From: https://github.com/expandjs/expandjs/blob/master/lib/kebabCaseRegex.js */
6
+ const KEBAB_CASE_REGEX =
7
+ /^([a-z](?![\d])|[\d](?![a-z]))+(-?([a-z](?![\d])|[\d](?![a-z])))*$|^$/;
8
+
5
9
  export const ensureAllCases = (obj: never): never => obj;
6
10
 
7
11
  export function error(...args: unknown[]): never {
@@ -24,6 +28,10 @@ export function hasWhiteSpace(s: string): boolean {
24
28
  return /\s/g.test(s);
25
29
  }
26
30
 
31
+ export function isKebabCase(s: string): boolean {
32
+ return KEBAB_CASE_REGEX.test(s);
33
+ }
34
+
27
35
  /**
28
36
  * parseIntSafe is a more reliable version of parseInt. By default, "parseInt('1a')" will return
29
37
  * "1", which is unexpected. This returns either an integer or NaN.
@@ -4,11 +4,14 @@ import { CWD, PROJECT_NAME } from "./constants";
4
4
  import * as file from "./file";
5
5
 
6
6
  // Validate that we are in a directory that looks like an IsaacScript project
7
- export function validateInIsaacScriptProject(): void {
7
+ export function validateInIsaacScriptProject(verbose: boolean): void {
8
8
  const subdirectoriesToCheck = ["src", "mod", "node_modules"];
9
9
  for (const subdirectoryName of subdirectoriesToCheck) {
10
10
  const subdirectoryPath = path.join(CWD, subdirectoryName);
11
- if (!file.exists(subdirectoryPath) || !file.isDir(subdirectoryPath)) {
11
+ if (
12
+ !file.exists(subdirectoryPath, verbose) ||
13
+ !file.isDir(subdirectoryPath, verbose)
14
+ ) {
12
15
  errorNotExists(subdirectoryPath);
13
16
  }
14
17
  }