-
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.
✨💚 added automatic fetching of udr schema
- Loading branch information
1 parent
48a3b8a
commit f848433
Showing
6 changed files
with
315 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,4 +130,5 @@ dist | |
.pnp.* | ||
|
||
# generated files | ||
/public | ||
/public | ||
/src/libraries/udr.d.ts |
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 @@ | ||
export function Try<T>(fn: () => T, err: (e: Error) => any): T { | ||
try { | ||
return fn(); | ||
} catch (e) { | ||
return err(e as Error); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./libraries/udr"; | ||
export { IProps } from "./interfaces/IProps"; | ||
export { handleBars } from "./libraries/handleBars"; | ||
export { MyClass } from "./modules/MyClass"; |
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,43 @@ | ||
import { promises as fs } from "fs"; | ||
import { JSONSchema, compile } from "json-schema-to-typescript"; | ||
import { Try } from "../src/libraries/helpers"; | ||
import { format } from "prettier"; | ||
|
||
async function main(): Promise<void> { | ||
let udrJsonSchema = await fetch( | ||
"https://oshifty.gitlab.io/e173/udr-document.json", | ||
).then((res) => res.text()); | ||
|
||
const schema = Try<JSONSchema>( | ||
() => JSON.parse(udrJsonSchema), | ||
() => { | ||
throw new TypeError(`Error parsing JSON`); | ||
}, | ||
); | ||
|
||
let typeDefinitions = await compile(schema, "udr"); | ||
|
||
let currentTimestamp = new Date().toUTCString(); | ||
|
||
let dtsFile = `/** | ||
* E1.73 (Uniform Device Representation) | ||
* | ||
* This file is generated by \`tools/fetchUDR.ts\` | ||
* @see https://oshifty.gitlab.io/e173/udr-document.json | ||
* @updated ${currentTimestamp} | ||
*/ | ||
export namespace UDR { | ||
${typeDefinitions} | ||
} | ||
`; | ||
|
||
let options = await fs | ||
.readFile(".prettierrc", "utf8") | ||
.then((res) => JSON.parse(res)); | ||
options.parser = "typescript"; | ||
dtsFile = await format(dtsFile, options); | ||
|
||
await fs.writeFile("src/libraries/udr.d.ts", dtsFile); | ||
} | ||
|
||
main(); |
Oops, something went wrong.