-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
merge-schemes.ts
33 lines (29 loc) · 1.14 KB
/
merge-schemes.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
import { writeFileSync } from 'fs';
import { merge } from 'lodash';
import { resolvePackagePath } from './packages/common/src';
interface CustomSchema {
originalSchemaPackage?: string;
originalSchemaPath: string;
schemaExtensionPaths: string[];
newSchemaPath: string;
}
const wd = process.cwd();
const schemesToMerge: CustomSchema[] = require(`${wd}/src/schemes`);
for (const {
originalSchemaPackage,
originalSchemaPath,
schemaExtensionPaths,
newSchemaPath,
} of schemesToMerge) {
const resolvedOriginalSchemaPath = originalSchemaPackage
? // Need it to bypass the Node resolution mechanism which respects only exported paths, currently only for esbuild
resolvePackagePath(originalSchemaPackage, originalSchemaPath)
: originalSchemaPath;
const originalSchema = require(resolvedOriginalSchemaPath);
const schemaExtensions = schemaExtensionPaths.map((path: string) => require(path));
const newSchema = schemaExtensions.reduce(
(extendedSchema: any, currentExtension: any) => merge(extendedSchema, currentExtension),
originalSchema
);
writeFileSync(newSchemaPath, JSON.stringify(newSchema, null, 2), 'utf-8');
}