forked from ng-doc/ng-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-schema.js
35 lines (28 loc) · 1.03 KB
/
build-schema.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
const {basename, dirname, join} = require('path');
const glob = require('glob');
const yargs = require('yargs/yargs');
const {hideBin} = require('yargs/helpers');
const merge = require('lodash/merge');
const fs = require('fs');
const argv = yargs(hideBin(process.argv)).argv;
function buildSchema(from, to) {
const schemas = glob.sync(from);
schemas.forEach((schemaPath) => {
const builder = basename(dirname(schemaPath));
const schema = loadSchema(schemaPath);
const schemaName = basename(schemaPath);
const originalSchema = loadSchema(
`./node_modules/@angular-devkit/build-angular/src/builders/${builder}/schema.json`,
);
const newSchema = merge(originalSchema, schema);
const newSchemaPath = join(to, builder, schemaName);
fs.writeFileSync(newSchemaPath, JSON.stringify(newSchema, null, 2), 'utf-8');
});
}
function loadSchema(path) {
return JSON.parse(fs.readFileSync(path, {encoding: 'utf-8'}));
}
if (argv.from && argv.to) {
buildSchema(argv.from, argv.to);
}
module.exports = {buildSchema};