Skip to content

Commit fda75eb

Browse files
committed
fix(cli): build
1 parent c4a5eae commit fda75eb

File tree

12 files changed

+199
-142
lines changed

12 files changed

+199
-142
lines changed

packages/eslint-plugin-isaacscript/scripts/utils.mts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ export async function getRuleEntries(): Promise<
3131
}
3232

3333
export function getAutoGeneratedComment(): string {
34-
return `/* eslint-disable isaacscript/format-line-comments */
34+
return `
35+
/// THIS FILE IS AUTOMATICALLY GENERATED BY THE "generate.mts" SCRIPT.
36+
/// DO NOT EDIT THIS FILE! YOU CAN REGENERATE IT WITH:
37+
/// npm run generate
3538
36-
// THIS CODE WAS AUTOMATICALLY GENERATED.
37-
// DO NOT EDIT THIS FILE BY HAND.
38-
// YOU CAN REGENERATE IT USING:
39-
// npm run generate
40-
41-
`;
39+
`.trimStart();
4240
}
4341

4442
export function getCamelCaseRuleName(kebabCaseName: string): string {

packages/isaacscript-cli/scripts/build.ts

Lines changed: 139 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import path from "node:path";
1414

1515
const INTERFACE_FILE_NAMES = ["CustomStageTSConfig", "JSONRoomsFile"] as const;
1616
const ENUM_FILE_NAMES = ["DoorSlot", "RoomShape"] as const;
17+
const ENUM_FLAG_FILE_NAMES = ["DoorSlotFlag"] as const;
18+
const OBJECT_FILE_NAMES = [
19+
"doorSlotToDoorSlotFlag",
20+
"roomShapeToDoorSlotCoordinates",
21+
] as const;
1722

1823
const TSCONFIG_SCHEMA_PATH = "schemas/tsconfig-isaacscript-section-schema.json";
1924
const ISAACSCRIPT_SCHEMA_PATH = "schemas/isaacscript-schema.json";
@@ -59,11 +64,94 @@ await buildScript(async ({ packageRoot }) => {
5964
* "isaacscript-common-ts".
6065
*/
6166
function copyIsaacScriptCommonFiles(packageRoot: string) {
62-
copyIsaacScriptCommonInterfaces(packageRoot);
63-
copyIsaacScriptCommonEnums(packageRoot);
67+
copyITDEnums(packageRoot);
68+
copyITDEnumsFlag(packageRoot);
69+
copyISCInterfaces(packageRoot);
70+
copyISCObjects(packageRoot);
6471
}
6572

66-
function copyIsaacScriptCommonInterfaces(packageRoot: string) {
73+
function copyITDEnums(packageRoot: string) {
74+
const sourcePackage = "isaac-typescript-definitions";
75+
const sourceDirectoryPath = path.join(
76+
packageRoot,
77+
"..",
78+
sourcePackage,
79+
"src",
80+
"enums",
81+
);
82+
const destinationDirectoryPath = path.join(
83+
packageRoot,
84+
"src",
85+
"enums",
86+
"copied",
87+
);
88+
mkdir(destinationDirectoryPath);
89+
90+
for (const fileName of ENUM_FILE_NAMES) {
91+
const fullFileName = `${fileName}.ts`;
92+
const sourcePath = path.join(sourceDirectoryPath, fullFileName);
93+
let fileContents = readFile(sourcePath);
94+
95+
if (fileName === "RoomShape") {
96+
fileContents = fileContents.replaceAll(
97+
" // eslint-disable-line @typescript-eslint/naming-convention,isaacscript/enum-member-number-separation",
98+
"",
99+
);
100+
}
101+
102+
const copiedFileHeader = getCopiedFileHeader(sourcePackage);
103+
fileContents = copiedFileHeader + fileContents;
104+
105+
const destinationPath = path.join(destinationDirectoryPath, fullFileName);
106+
writeFile(destinationPath, fileContents);
107+
}
108+
}
109+
110+
function copyITDEnumsFlag(packageRoot: string) {
111+
const sourcePackage = "isaac-typescript-definitions";
112+
const sourceDirectoryPath = path.join(
113+
packageRoot,
114+
"..",
115+
sourcePackage,
116+
"src",
117+
"enums",
118+
"flags",
119+
);
120+
const destinationDirectoryPath = path.join(
121+
packageRoot,
122+
"src",
123+
"enums",
124+
"copied",
125+
);
126+
mkdir(destinationDirectoryPath);
127+
128+
for (const fileName of ENUM_FLAG_FILE_NAMES) {
129+
const fullFileName = `${fileName}.ts`;
130+
const sourcePath = path.join(sourceDirectoryPath, fullFileName);
131+
let fileContents = readFile(sourcePath);
132+
133+
switch (fileName) {
134+
case "DoorSlotFlag": {
135+
fileContents = `/* eslint-disable no-bitwise */\n\n${fileContents}`;
136+
fileContents = fileContents.replace(
137+
'import { DoorSlot } from "../DoorSlot";',
138+
'import { DoorSlot } from "./DoorSlot.js";',
139+
);
140+
fileContents +=
141+
"\ndeclare type BitFlag = number & { readonly __bitFlagBrand: symbol };\n\ndeclare type BitFlags<T extends BitFlag> = T & {\n readonly __bitFlagsBrand: T;\n};\n";
142+
break;
143+
}
144+
}
145+
146+
const copiedFileHeader = getCopiedFileHeader(sourcePackage);
147+
fileContents = copiedFileHeader + fileContents;
148+
149+
const destinationPath = path.join(destinationDirectoryPath, fullFileName);
150+
writeFile(destinationPath, fileContents);
151+
}
152+
}
153+
154+
function copyISCInterfaces(packageRoot: string) {
67155
const sourcePackage = "isaacscript-common";
68156
const sourceDirectoryPath = path.join(
69157
packageRoot,
@@ -84,47 +172,85 @@ function copyIsaacScriptCommonInterfaces(packageRoot: string) {
84172
const fullFileName = `${fileName}.ts`;
85173
const sourcePath = path.join(sourceDirectoryPath, fullFileName);
86174
let fileContents = readFile(sourcePath);
175+
176+
switch (fileName) {
177+
case "CustomStageTSConfig": {
178+
fileContents = fileContents.replace(
179+
'import type { Immutable } from "../types/Immutable";',
180+
'import type { Immutable } from "isaacscript-common-ts";',
181+
);
182+
break;
183+
}
184+
185+
default: {
186+
break;
187+
}
188+
}
189+
87190
const copiedFileHeader = getCopiedFileHeader(sourcePackage);
88191
fileContents = copiedFileHeader + fileContents;
89-
fileContents = fileContents.replaceAll(
90-
'"../types/Immutable"',
91-
'"isaacscript-common-ts"',
92-
);
192+
93193
const destinationPath = path.join(destinationDirectoryPath, fullFileName);
94194
writeFile(destinationPath, fileContents);
95195
}
96196
}
97197

98-
function copyIsaacScriptCommonEnums(packageRoot: string) {
99-
const sourcePackage = "isaac-typescript-definitions";
198+
function copyISCObjects(packageRoot: string) {
199+
const sourcePackage = "isaacscript-common";
100200
const sourceDirectoryPath = path.join(
101201
packageRoot,
102202
"..",
103203
sourcePackage,
104204
"src",
105-
"enums",
205+
"objects",
106206
);
107207
const destinationDirectoryPath = path.join(
108208
packageRoot,
109209
"src",
110-
"enums",
210+
"objects",
111211
"copied",
112212
);
113213
mkdir(destinationDirectoryPath);
114214

115-
for (const fileName of ENUM_FILE_NAMES) {
215+
for (const fileName of OBJECT_FILE_NAMES) {
116216
const fullFileName = `${fileName}.ts`;
117217
const sourcePath = path.join(sourceDirectoryPath, fullFileName);
118218
let fileContents = readFile(sourcePath);
219+
220+
switch (fileName) {
221+
case "doorSlotToDoorSlotFlag": {
222+
fileContents = fileContents.replace(
223+
'import {\n DoorSlot,\n DoorSlotFlag,\n DoorSlotFlagZero,\n} from "isaac-typescript-definitions";',
224+
'import { DoorSlot } from "../../enums/copied/DoorSlot.js";\nimport {\n DoorSlotFlag,\n DoorSlotFlagZero,\n} from "../../enums/copied/DoorSlotFlag.js";',
225+
);
226+
break;
227+
}
228+
229+
case "roomShapeToDoorSlotCoordinates": {
230+
fileContents = fileContents.replace(
231+
'import { DoorSlot, RoomShape } from "isaac-typescript-definitions";',
232+
'import { DoorSlot } from "../../enums/copied/DoorSlot.js";\nimport { RoomShape } from "../../enums/copied/RoomShape.js";',
233+
);
234+
fileContents = fileContents.replaceAll("int", "number");
235+
break;
236+
}
237+
}
238+
119239
const copiedFileHeader = getCopiedFileHeader(sourcePackage);
120240
fileContents = copiedFileHeader + fileContents;
241+
121242
const destinationPath = path.join(destinationDirectoryPath, fullFileName);
122243
writeFile(destinationPath, fileContents);
123244
}
124245
}
125246

126247
function getCopiedFileHeader(packageName: string): string {
127-
return `// THIS FILE IS AUTOMATICALLY GENERATED BY THE "build.ts" SCRIPT.\n// IT IS COPIED FROM THE "${packageName}" package.\n// DO NOT EDIT THIS FILE!\n\n`;
248+
return `
249+
/// THIS FILE IS AUTOMATICALLY GENERATED BY THE "build.ts" SCRIPT.
250+
/// IT IS COPIED FROM THE "${packageName}" package.
251+
/// DO NOT EDIT THIS FILE!
252+
253+
`.trimStart();
128254
}
129255

130256
function renamePluginJSToCJS(pluginsDirPath: string) {

packages/isaacscript-cli/src/common.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import { fatalError } from "isaacscript-common-node";
44
import { parseIntSafe } from "isaacscript-common-ts";
5-
import type { DoorSlot } from "./enums/DoorSlot.js";
6-
import type { DoorSlotFlag } from "./enums/DoorSlotFlag.js";
7-
import type { RoomShape } from "./enums/RoomShape.js";
5+
import type { DoorSlot } from "./enums/copied/DoorSlot.js";
6+
import type { DoorSlotFlag } from "./enums/copied/DoorSlotFlag.js";
7+
import type { RoomShape } from "./enums/copied/RoomShape.js";
88
import type { JSONRoom } from "./interfaces/copied/JSONRoomsFile.js";
9-
import { DOOR_SLOT_TO_DOOR_SLOT_FLAG } from "./objects/doorSlotToDoorSlotFlag.js";
10-
import { ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES } from "./objects/roomShapeDoorToSlotCoordinates.js";
9+
import { DOOR_SLOT_TO_DOOR_SLOT_FLAG } from "./objects/copied/doorSlotToDoorSlotFlag.js";
10+
import { ROOM_SHAPE_TO_DOOR_SLOT_COORDINATES } from "./objects/copied/roomShapeToDoorSlotCoordinates.js";
1111

1212
/** This is copied from `isaacscript-common`. */
1313
export function getJSONRoomDoorSlotFlags(jsonRoom: JSONRoom): number {

packages/isaacscript-cli/src/enums/DoorSlot.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/isaacscript-cli/src/enums/RoomShape.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

packages/isaacscript-cli/src/enums/copied/DoorSlot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// THIS FILE IS AUTOMATICALLY GENERATED BY THE "build.ts" SCRIPT.
2-
// IT IS COPIED FROM THE "isaac-typescript-definitions" package.
3-
// DO NOT EDIT THIS FILE!
1+
/// THIS FILE IS AUTOMATICALLY GENERATED BY THE "build.ts" SCRIPT.
2+
/// IT IS COPIED FROM THE "isaac-typescript-definitions" package.
3+
/// DO NOT EDIT THIS FILE!
44

55
export enum DoorSlot {
66
NO_DOOR_SLOT = -1,

0 commit comments

Comments
 (0)