-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prototyping the common types approach
- this isn't as graceful as I'd hoped; the codegen approach employed relies upon processing the actual data, rather than the raw schema. - re: #4
- Loading branch information
1 parent
ff8c5b7
commit 4704461
Showing
31 changed files
with
763 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Data Progress | ||
|
||
0.00% Complete (0 of 2) | ||
|
||
## /Script/CoreUObject.Class'/Script/FactoryGame.FGFauxEntry' | ||
|
||
- [ ] faux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
TypeDefinitionWriter, | ||
} from './lib/TypeDefinitionWriter'; | ||
import { | ||
NoMatchError, | ||
} from './lib/Exceptions'; | ||
import { | ||
writeFile, | ||
} from 'node:fs/promises'; | ||
import { | ||
docs, | ||
} from './lib/helpers'; | ||
|
||
try { | ||
performance.mark('start'); | ||
const bar = new TypeDefinitionWriter( | ||
docs, | ||
'common', | ||
); | ||
performance.measure('bootstrap', 'start'); | ||
performance.mark('bootstrap done'); | ||
await bar.write(`${import.meta.dirname}/generated-types/common/`); | ||
performance.measure('types generated', 'bootstrap done'); | ||
const discovery = await bar.discovery; | ||
const result = await discovery.discover_type_$defs(); | ||
|
||
process.stdout.write( | ||
`${ | ||
JSON.stringify(result.missing_classes, null, '\t') | ||
}\n`, | ||
); | ||
console.table({ | ||
'Found Types': Object.keys(result.found_types).length, | ||
'Missing Types': result.missing_types.length, | ||
'Found Classes': result.found_classes.length, | ||
'Missing Classes': result.missing_classes.length, | ||
}); | ||
/* | ||
await writeFile( | ||
`${import.meta.dirname}/discover-types.common.perf.json`, | ||
`${JSON.stringify(perf(), null, '\t')}`, | ||
); | ||
*/ | ||
} catch (err) { | ||
/* | ||
await writeFile( | ||
`${import.meta.dirname}/discover-types.common.perf.json`, | ||
`${JSON.stringify(perf(), null, '\t')}`, | ||
); | ||
*/ | ||
if (err instanceof NoMatchError) { | ||
console.error('ran into an issue'); | ||
await writeFile( | ||
`./discovery-types.common.failure.json`, | ||
JSON.stringify( | ||
{ | ||
property: err.property as unknown, | ||
message: err.message, | ||
stack: err.stack?.split('\n'), | ||
}, | ||
null, | ||
'\t', | ||
), | ||
); | ||
|
||
console.error(err.message, err.stack); | ||
} else { | ||
throw err; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {faux_1__type, NativeClass__type} from '../../common/unassigned'; | ||
|
||
export type FGFauxEntry__NativeClass = NativeClass__type & { | ||
Classes: [faux_1__type, ...faux_1__type[]]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {UnrealEngineString, StringStartsWith} from '../utils/validators'; | ||
|
||
export type class__type = class__no_description__type & { | ||
mDescription: string; | ||
}; | ||
|
||
export type class__no_description__type = | ||
class__no_description_or_display_name__type & { | ||
mDisplayName: string; | ||
}; | ||
|
||
export type class__no_description_or_display_name__type = { | ||
ClassName: Exclude<string, ''>; | ||
}; | ||
|
||
export type faux_1__type = class__type & { | ||
faux: UnrealEngineString__array__type; | ||
}; | ||
|
||
export type NativeClass__type = { | ||
NativeClass: UnrealEngineString< | ||
'/Script/CoreUObject.Class', | ||
StringStartsWith<'/Script/FactoryGame.FG'> | ||
>; | ||
}; | ||
|
||
export type UnrealEngineString__array__type = [ | ||
UnrealEngineString, | ||
...UnrealEngineString[], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export type StringStartsWith<prefix extends string> = keyof { | ||
[pseudo_key in keyof { | ||
[key: string]: unknown; | ||
} as pseudo_key extends string ? `${prefix}${pseudo_key}` : never]: string; | ||
}; | ||
|
||
export type StringPassedRegExp< | ||
pattern extends string, | ||
T extends string = string, | ||
> = T & { | ||
[pseudo_key in pattern]: never; | ||
}; | ||
|
||
export class UnrealEngineString< | ||
left extends string = string, | ||
right extends string = string, | ||
> { | ||
readonly left: left; | ||
readonly right: right; | ||
protected constructor(left: left, right: right) { | ||
this.left = left; | ||
this.right = right; | ||
} | ||
static fromString< | ||
left extends string = string, | ||
right extends string = string, | ||
>(value: string): UnrealEngineString<left, right> { | ||
const result = /^([^']+)'(?:"([^"]+)"|([^"]+))'$/.exec(value); | ||
if (!result) throw new Error(`Not an UnrealEngineString (${value})`); | ||
return new UnrealEngineString<left, right>( | ||
result[1] as left, | ||
(result[2] || result[3]) as right | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.