forked from ethereum/execution-apis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
117 lines (103 loc) · 2.72 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import fs from "fs";
import yaml from "js-yaml";
import mergeAllOf from "json-schema-merge-allof";
import { dereferenceDocument } from "@open-rpc/schema-utils-js";
function sortByMethodName(methods) {
return methods.slice().sort((a, b) => {
if (a['name'] > b['name']) {
return 1;
} else if (a['name'] < b['name']) {
return -1;
} else {
return 0;
}
})
}
console.log("Loading files...\n");
let methods = [];
let methodsBase = "src/eth/";
let methodFiles = fs.readdirSync(methodsBase);
methodFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(methodsBase + file);
let parsed = yaml.load(raw);
methods = [
...methods,
...parsed,
];
});
methodsBase = "src/debug/";
methodFiles = fs.readdirSync(methodsBase);
methodFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(methodsBase + file);
let parsed = yaml.load(raw);
methods = [
...methods,
...parsed,
];
});
methodsBase = "src/engine/openrpc/methods/";
methodFiles = fs.readdirSync(methodsBase);
methodFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(methodsBase + file);
let parsed = yaml.load(raw);
methods = [
...methods,
...parsed,
];
});
let schemas = {};
let schemasBase = "src/schemas/"
let schemaFiles = fs.readdirSync(schemasBase);
schemaFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(schemasBase + file);
let parsed = yaml.load(raw);
schemas = {
...schemas,
...parsed,
};
});
schemasBase = "src/engine/openrpc/schemas/"
schemaFiles = fs.readdirSync(schemasBase);
schemaFiles.forEach(file => {
console.log(file);
let raw = fs.readFileSync(schemasBase + file);
let parsed = yaml.load(raw);
schemas = {
...schemas,
...parsed,
};
});
const doc = {
openrpc: "1.2.4",
info: {
title: "Ethereum JSON-RPC Specification",
description: "A specification of the standard interface for Ethereum clients.",
license: {
name: "CC0-1.0",
url: "https://creativecommons.org/publicdomain/zero/1.0/legalcode"
},
version: "0.0.0"
},
methods: sortByMethodName(methods),
components: {
schemas: schemas
}
}
fs.writeFileSync('refs-openrpc.json', JSON.stringify(doc, null, '\t'));
let spec = await dereferenceDocument(doc);
spec.components = {};
// Merge instances of `allOf` in methods.
for (var i=0; i < spec.methods.length; i++) {
for (var j=0; j < spec.methods[i].params.length; j++) {
spec.methods[i].params[j].schema = mergeAllOf(spec.methods[i].params[j].schema);
}
spec.methods[i].result.schema = mergeAllOf(spec.methods[i].result.schema);
}
let data = JSON.stringify(spec, null, '\t');
fs.writeFileSync('openrpc.json', data);
console.log();
console.log("Build successful.");