Skip to content

Commit

Permalink
Merge pull request #132 from open-rpc/feat/build-and-titles
Browse files Browse the repository at this point in the history
feat: build and titles
  • Loading branch information
BelfordZ authored Jun 10, 2019
2 parents ffdace5 + 827e4b6 commit f4ff336
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 32 deletions.
22 changes: 20 additions & 2 deletions bin/generate-types.js → bin/build.js
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();
}
66 changes: 66 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"url": "https://github.com/open-rpc/schema.git"
},
"scripts": {
"build": "tsc && npm run build:generateTypes",
"build:generateTypes": "node bin/generate-types.js",
"publish": "npm run build",
"build": "tsc && node bin/build.js",
"test": "npm run lint && jest src/test.js",
"lint": "tslint -c tslint.json 'src/index.ts' --fix",
"test:watch": "npm run test -- --watch"
Expand All @@ -27,6 +25,7 @@
],
"dependencies": {},
"devDependencies": {
"@etclabscore/dl-github-releases": "^1.1.0",
"ajv": "^6.10.0",
"fs-extra": "^8.0.0",
"jest": "^24.3.1",
Expand Down
Loading

0 comments on commit f4ff336

Please sign in to comment.