Skip to content

Commit

Permalink
Merge pull request #139 from open-rpc/feat/quicktype
Browse files Browse the repository at this point in the history
feat: switch to using quicktype to generate types
  • Loading branch information
BelfordZ authored Jul 8, 2019
2 parents 37a957e + 5c4b1cc commit 2a3c196
Show file tree
Hide file tree
Showing 3 changed files with 1,171 additions and 4 deletions.
19 changes: 17 additions & 2 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
#!/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");
const { quicktype } = require("quicktype");

// errors if you try to run with $ref to draft 7 json schema
schema.definitions.schema.$ref = undefined;

const getQuickTypeSources = (s) => {
return [{
kind: "schema",
name: "OpenRPC",
schema: JSON.stringify(s),
}];
};

const generateTypes = async (s) => {
const ts = await compile(s, "OpenRPC");
const sources = getQuickTypeSources(s);
const result = await quicktype({
lang: "typescript",
leadingComments: undefined,
rendererOptions: { "just-types": true },
sources,
});
const ts = result.lines.join("\n");
const dir = path.resolve(__dirname, "../build/src/");
await ensureDir(dir);
await writeFile(`${dir}/index.d.ts`, ts, "utf8");
Expand Down
Loading

0 comments on commit 2a3c196

Please sign in to comment.