Skip to content

Commit cfe1a3f

Browse files
committed
to get typings it creates a PlayerFullsec interface which merges with the hackmud.d.ts PlayerFullsec and is intersected into the other types
1 parent 51fabac commit cfe1a3f

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

index.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,21 @@ export async function generateTypings(srcDir: string, target: string, hackmudPat
365365
let o = ""
366366

367367
for (const script of wildScripts)
368-
o += `import { script as $${script}$ } from "src/${script}"\n`
368+
o += `import { script as $${script}$ } from "./src/${script}"\n`
369369

370370
o += "\n"
371371

372372
for (const user in allScripts) {
373373
const scripts = allScripts[user]
374374

375375
for (const script of scripts)
376-
o += `import { script as $${user}$${script}$ } from "src/${user}/${script}"\n`
376+
o += `import { script as $${user}$${script}$ } from "./src/${user}/${script}"\n`
377377
}
378378

379379
o += `
380380
type Subscript<T extends (...args: any) => any> = Parameters<T>[1] extends undefined
381381
? (args?: Parameters<T>[1]) => ReturnType<T> | ScriptFailure
382-
: (args?: Parameters<T>[1]) => ReturnType<T> | ScriptFailure
382+
: (args: Parameters<T>[1]) => ReturnType<T> | ScriptFailure
383383
384384
type WildFullsec = Record<string, () => ScriptFailure> & {
385385
`
@@ -390,37 +390,30 @@ type WildFullsec = Record<string, () => ScriptFailure> & {
390390
for (const script of wildAnyScripts)
391391
o += `\t${script}: (...args: any) => any\n`
392392

393-
o += "}\n\nexport type PlayerFullsec = {"
393+
o += "}\n\ndeclare global {\n\tinterface PlayerFullsec {"
394394

395395
for (const user of users) {
396396
const scripts = allScripts[user]
397397
const anyScripts = allAnyScripts[user]
398398

399-
o += `\n\t${user}: WildFullsec`
399+
o += `\n\t\t${user}: WildFullsec`
400400

401401
if ((scripts && scripts.length) || (anyScripts && anyScripts.length)) {
402402
o += " & {\n"
403403

404404
for (const script of scripts)
405-
o += `\t\t${script}: Subscript<typeof $${user}$${script}$>\n`
405+
o += `\t\t\t${script}: Subscript<typeof $${user}$${script}$>\n`
406406

407407
for (const script of anyScripts)
408-
o += `\t\t${script}: (...args: any) => any\n`
408+
o += `\t\t\t${script}: (...args: any) => any\n`
409409

410-
o += "\t}"
410+
o += "\t\t}"
411411
}
412412

413-
o += "\n"
413+
o += "\t\n"
414414
}
415415

416-
o += `\
417-
}
418-
419-
export type PlayerHighsec = {}
420-
export type PlayerMidsec = {}
421-
export type PlayerLowsec = {}
422-
export type PlayerNullsec = {}
423-
`
416+
o += "\t}\n}\n"
424417

425418
await writeFile(target, o)
426419
}

0 commit comments

Comments
 (0)