-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_schemas.ts
48 lines (41 loc) · 1.5 KB
/
build_schemas.ts
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
/**
* build_schemas uses node API to read all schemas from the FS
* at build time and writes them out to a single schemas.js file for
* downstream consumption to avoid FS calls in the browser.
*/
import * as fs from "fs";
import JSONSchemasGenerator from "./src/js/esse/JSONSchemasGenerator";
// JS Modules
const generator = new JSONSchemasGenerator();
const { schemas, wrappedExamples, propertiesManifest, results } = generator;
if (process.env.BUILD_PYTHON_MODULES === "true") {
// PY Modules
fs.writeFileSync(
"./src/py/mat3ra/esse/data/examples.py",
["import json", `EXAMPLES = json.loads(r'''${JSON.stringify(wrappedExamples)}''')`].join(
"\n",
),
"utf8",
);
fs.writeFileSync(
"./src/py/mat3ra/esse/data/schemas.py",
["import json", `SCHEMAS = json.loads(r'''${JSON.stringify(schemas)}''')`].join("\n"),
"utf8",
);
fs.writeFileSync(
"./src/py/mat3ra/esse/data/properties.py",
[
"import json",
`PROPERTIES_MANIFEST = json.loads(r'''${JSON.stringify(propertiesManifest)}''')`,
`RESULTS = json.loads(r'''${JSON.stringify(results)}''')`,
].join("\n"),
"utf8",
);
}
if (process.env.BUILD_ASSETS !== "true") {
process.exit(0);
}
const subfolder = process.env.BUILD_PATH || "./docs/js/";
const skipMergeAllOff = process.env.SKIP_MERGE_ALLOF === "true";
generator.writeResolvedSchemas(subfolder, skipMergeAllOff);
generator.writeResolvedExamples(subfolder);