-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from open-rpc/feat/build-and-titles
feat: build and titles
- Loading branch information
Showing
5 changed files
with
189 additions
and
32 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 |
---|---|---|
@@ -1,19 +1,37 @@ | ||
#!/usr/bin/env node | ||
|
||
const schema = require('../schema.json'); | ||
const { compile } = require('json-schema-to-typescript'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { promisify } = require('util'); | ||
const writeFile = promisify(fs.writeFile); | ||
const { ensureDir } = require('fs-extra'); | ||
const {listReleases} = require("@etclabscore/dl-github-releases"); | ||
|
||
// errors if you try to run with $ref to draft 7 json schema | ||
schema.definitions.schema.$ref = undefined; | ||
|
||
const go = async () => { | ||
const generateTypes = async () => { | ||
const ts = await compile(schema, 'OpenRPC'); | ||
const dir = path.resolve(__dirname, '../build/src/'); | ||
await ensureDir(dir); | ||
await writeFile(`${dir}/index.d.ts`, ts, 'utf8'); | ||
|
||
console.log('Generating types complete!'); | ||
}; | ||
go(); | ||
|
||
const setOpenRPCVersionEnum = async (s) => { | ||
s.properties.openrpc.enum = await listReleases("open-rpc", "spec"); | ||
return s; | ||
}; | ||
|
||
const build = async () => { | ||
const withVersionEnum = await setOpenRPCVersionEnum(schema); | ||
await generateTypes(withVersionEnum); | ||
}; | ||
|
||
module.exports = {setOpenRPCVersionEnum}; | ||
if (require.main === module) { | ||
build(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.