Skip to content

Commit

Permalink
add script for auto update schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Apr 8, 2023
1 parent d519571 commit 9eafbfd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# compiled output
*.js
!update-schemas.js
*.d.ts
/dist
/tmp
Expand Down
40 changes: 40 additions & 0 deletions lib/update-schemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require("fs");
const path = require("path");

const BASE_URL =
"https://raw.githubusercontent.com/angular/angular-cli/main/packages/angular_devkit/build_angular/src/builders/";

(async () => {
await updateSchema("browser", "src/browser");
await updateSchema("extract-i18n", "src/extract-i18n");
await updateSchema("karma", "src/karma");
await updateSchema("dev-server", "src/plus-dev-server");
await updateSchema("server", "src/server");
})();

async function updateSchema(builder, targetUrl) {
console.log("- Updating schema for", builder, "in", targetUrl);

const url = path.join(BASE_URL, builder, "schema.json");
const schema = await loadRemoteJson(url);

const extSchemaUrl = `${targetUrl}/schema.ext.json`;
const extSchema = loadLocalJson(extSchemaUrl);

for (const prop in extSchema) {
schema.properties[prop] = extSchema[prop];
}

const fullSchemaText = JSON.stringify(schema, null, 2);
const fullSchemaUrl = `${targetUrl}/schema.json`;

fs.writeFileSync(fullSchemaUrl, fullSchemaText, "utf8");
}

async function loadRemoteJson(url) {
return await fetch(url).then((resp) => resp.json());
}

function loadLocalJson(extSchemaUrl) {
return JSON.parse(fs.readFileSync(extSchemaUrl, { encoding: "utf8" }));
}

0 comments on commit 9eafbfd

Please sign in to comment.