@@ -14,6 +14,11 @@ import path from "node:path";
14
14
15
15
const INTERFACE_FILE_NAMES = [ "CustomStageTSConfig" , "JSONRoomsFile" ] as const ;
16
16
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 ;
17
22
18
23
const TSCONFIG_SCHEMA_PATH = "schemas/tsconfig-isaacscript-section-schema.json" ;
19
24
const ISAACSCRIPT_SCHEMA_PATH = "schemas/isaacscript-schema.json" ;
@@ -59,11 +64,94 @@ await buildScript(async ({ packageRoot }) => {
59
64
* "isaacscript-common-ts".
60
65
*/
61
66
function copyIsaacScriptCommonFiles ( packageRoot : string ) {
62
- copyIsaacScriptCommonInterfaces ( packageRoot ) ;
63
- copyIsaacScriptCommonEnums ( packageRoot ) ;
67
+ copyITDEnums ( packageRoot ) ;
68
+ copyITDEnumsFlag ( packageRoot ) ;
69
+ copyISCInterfaces ( packageRoot ) ;
70
+ copyISCObjects ( packageRoot ) ;
64
71
}
65
72
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 ) {
67
155
const sourcePackage = "isaacscript-common" ;
68
156
const sourceDirectoryPath = path . join (
69
157
packageRoot ,
@@ -84,47 +172,85 @@ function copyIsaacScriptCommonInterfaces(packageRoot: string) {
84
172
const fullFileName = `${ fileName } .ts` ;
85
173
const sourcePath = path . join ( sourceDirectoryPath , fullFileName ) ;
86
174
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
+
87
190
const copiedFileHeader = getCopiedFileHeader ( sourcePackage ) ;
88
191
fileContents = copiedFileHeader + fileContents ;
89
- fileContents = fileContents . replaceAll (
90
- '"../types/Immutable"' ,
91
- '"isaacscript-common-ts"' ,
92
- ) ;
192
+
93
193
const destinationPath = path . join ( destinationDirectoryPath , fullFileName ) ;
94
194
writeFile ( destinationPath , fileContents ) ;
95
195
}
96
196
}
97
197
98
- function copyIsaacScriptCommonEnums ( packageRoot : string ) {
99
- const sourcePackage = "isaac-typescript-definitions " ;
198
+ function copyISCObjects ( packageRoot : string ) {
199
+ const sourcePackage = "isaacscript-common " ;
100
200
const sourceDirectoryPath = path . join (
101
201
packageRoot ,
102
202
".." ,
103
203
sourcePackage ,
104
204
"src" ,
105
- "enums " ,
205
+ "objects " ,
106
206
) ;
107
207
const destinationDirectoryPath = path . join (
108
208
packageRoot ,
109
209
"src" ,
110
- "enums " ,
210
+ "objects " ,
111
211
"copied" ,
112
212
) ;
113
213
mkdir ( destinationDirectoryPath ) ;
114
214
115
- for ( const fileName of ENUM_FILE_NAMES ) {
215
+ for ( const fileName of OBJECT_FILE_NAMES ) {
116
216
const fullFileName = `${ fileName } .ts` ;
117
217
const sourcePath = path . join ( sourceDirectoryPath , fullFileName ) ;
118
218
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
+
119
239
const copiedFileHeader = getCopiedFileHeader ( sourcePackage ) ;
120
240
fileContents = copiedFileHeader + fileContents ;
241
+
121
242
const destinationPath = path . join ( destinationDirectoryPath , fullFileName ) ;
122
243
writeFile ( destinationPath , fileContents ) ;
123
244
}
124
245
}
125
246
126
247
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 ( ) ;
128
254
}
129
255
130
256
function renamePluginJSToCJS ( pluginsDirPath : string ) {
0 commit comments