diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60e3cd99ac57..64cbac178b0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: run: pnpm install --frozen-lockfile - name: Generate JSON schema types # Schema types are required to correctly lint the TypeScript code - run: pnpm admin build-schema + run: pnpm run build-schema - name: Run ESLint run: pnpm lint --cache-strategy content - name: Validate NgBot Configuration diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index aab59a7bc029..3709678d22bc 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -46,7 +46,7 @@ jobs: run: pnpm install --frozen-lockfile - name: Generate JSON schema types # Schema types are required to correctly lint the TypeScript code - run: pnpm admin build-schema + run: pnpm run build-schema - name: Run ESLint run: pnpm lint --cache-strategy content - name: Validate NgBot Configuration diff --git a/package.json b/package.json index 19b580831ba2..1559dd9b8324 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "bazel": "bazelisk", "test": "bazel test //packages/...", "build": "pnpm -s admin build", + "build-schema": "bazel build //... --build_tag_filters schema --symlink_prefix dist-schema/", "lint": "eslint --cache --max-warnings=0 \"**/*.@(ts|mts|cts)\"", "templates": "pnpm -s admin templates", "validate": "pnpm -s admin validate", diff --git a/scripts/build-schema.mts b/scripts/build-schema.mts deleted file mode 100644 index ffc042af9630..000000000000 --- a/scripts/build-schema.mts +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.dev/license - */ - -import { spawn } from 'node:child_process'; -import { rm } from 'node:fs/promises'; -import { join, resolve } from 'node:path'; - -const __dirname = import.meta.dirname; -const baseDir = resolve(`${__dirname}/..`); -const bazelCmd = process.env.BAZEL ?? `pnpm -s bazel`; -const distRoot = join(baseDir, '/dist-schema/'); - -function _clean() { - console.info('Cleaning...'); - console.info(' Removing dist-schema/...'); - - return rm(join(__dirname, '../dist-schema'), { force: true, recursive: true, maxRetries: 3 }); -} - -function _exec(cmd: string, captureStdout: boolean): Promise { - return new Promise((resolve, reject) => { - const proc = spawn(cmd, { - stdio: 'pipe', - shell: true, - env: { - HOME: process.env.HOME, - PATH: process.env.PATH, - }, - }); - - let output = ''; - proc.stdout.on('data', (data) => { - console.info(data.toString().trim()); - if (captureStdout) { - output += data.toString(); - } - }); - proc.stderr.on('data', (data) => console.info(data.toString().trim())); - - proc.on('error', (error) => { - console.error(error.message); - }); - - proc.on('exit', (status) => { - if (status !== 0) { - reject(`Command failed: ${cmd}`); - } else { - resolve(output); - } - }); - }); -} - -async function _buildSchemas(): Promise { - console.info(`Building schemas...`); - - const queryTargetsCmd = `${bazelCmd} query --output=label "attr(name, .*_schema, //packages/...)"`; - const targets = (await _exec(queryTargetsCmd, true)).split(/\r?\n/); - - await _exec(`${bazelCmd} build ${targets.join(' ')} --symlink_prefix=${distRoot}`, false); -} - -export default async function (argv: {}): Promise { - await _clean(); - - await _buildSchemas(); -} diff --git a/tools/ng_cli_schema_generator.bzl b/tools/ng_cli_schema_generator.bzl index 9bcc4d287a6a..86d9552dd70c 100644 --- a/tools/ng_cli_schema_generator.bzl +++ b/tools/ng_cli_schema_generator.bzl @@ -4,6 +4,7 @@ def cli_json_schema(name, src, out, data = []): js_run_binary( name = name, outs = [out], + tags = ["schema"], srcs = [src] + data, tool = "//tools:ng_cli_schema", progress_message = "Generating CLI interface from %s" % src, diff --git a/tools/ts_json_schema.bzl b/tools/ts_json_schema.bzl index deb34c0af597..dab651d0d7e0 100644 --- a/tools/ts_json_schema.bzl +++ b/tools/ts_json_schema.bzl @@ -12,6 +12,7 @@ def ts_json_schema(name, src, data = []): name = name + ".interface", outs = [out], srcs = [src] + data, + tags = ["schema"], tool = "//tools:quicktype_runner", progress_message = "Generating TS interface for %s" % src, mnemonic = "TsJsonSchema",