Skip to content

Commit 0f10ced

Browse files
CNCF xRegistry support (#4713)
* add xRegistry API Signed-off-by: Clemens Vasters <[email protected]> * add xRegistry API Signed-off-by: Clemens Vasters <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove instructions Signed-off-by: Clemens Vasters <[email protected]> * omitted type Signed-off-by: Clemens Vasters <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Clemens Vasters <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4a8e5f9 commit 0f10ced

File tree

6 files changed

+688
-2
lines changed

6 files changed

+688
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# This ignore file is shared with Prettier. It seems .git/ must be ignored manually now.
22
.git/
33

4+
# registry API folder
5+
src/api/registry/
6+
47
# Project files
58
temp
69
test.json

cli.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import ora from 'ora'
2121
import chalk from 'chalk'
2222
import minimist from 'minimist'
2323
import fetch, { FetchError } from 'node-fetch'
24+
import { execFile } from 'node:child_process'
25+
import { promisify } from 'node:util'
26+
const execFileAsync = promisify(execFile)
2427

2528
/**
2629
* @import { Ora } from 'ora'
@@ -86,11 +89,11 @@ const SchemaDialects = [
8689
{ draftVersion: 'draft-03', url: 'http://json-schema.org/draft-03/schema#', isActive: false, isTooHigh: false },
8790
]
8891

89-
/** @type {{ _: string[], fix?: boolean, help?: boolean, SchemaName?: string, 'schema-name'?: string, 'unstable-check-with'?: string }} */
92+
/** @type {{ _: string[], fix?: boolean, help?: boolean, SchemaName?: string, 'schema-name'?: string, 'unstable-check-with'?: string, 'build-xregistry'?: boolean, 'verify-xregistry'?: boolean }} */
9093
const argv = /** @type {any} */ (
9194
minimist(process.argv.slice(2), {
9295
string: ['SchemaName', 'schema-name', 'unstable-check-with'],
93-
boolean: ['help'],
96+
boolean: ['help', 'build-xregistry', 'verify-xregistry'],
9497
})
9598
)
9699
if (argv.SchemaName) {
@@ -1773,6 +1776,7 @@ TASKS:
17731776
check-strict: Checks all or the given schema against the strict meta schema
17741777
check-remote: Run all build checks for remote schemas
17751778
maintenance: Run maintenance checks
1779+
build-xregistry: Build the xRegistry from the catalog.json
17761780
17771781
EXAMPLES:
17781782
node ./cli.js check
@@ -1797,6 +1801,53 @@ EXAMPLES:
17971801
console.info(helpMenu)
17981802
process.exit(0)
17991803
}
1804+
/**
1805+
* Executes the xRegistry build process
1806+
*/
1807+
async function buildXRegistry() {
1808+
try {
1809+
console.info('Building xRegistry from catalog.json...')
1810+
const { stdout, stderr } = await execFileAsync('node', [
1811+
'scripts/build-xregistry.js',
1812+
])
1813+
if (stdout) console.log(stdout)
1814+
if (stderr) console.error(stderr)
1815+
1816+
const { stdout: siteStdout, stderr: siteStderr } = await execFileAsync(
1817+
'sh',
1818+
['scripts/build_xregistry_site.sh'],
1819+
)
1820+
if (siteStdout) console.log(siteStdout)
1821+
if (siteStderr) console.error(siteStderr)
1822+
1823+
const { stdout: postStdout, stderr: postStderr } = await execFileAsync(
1824+
'node',
1825+
['scripts/postprocess-xregistry-site.js'],
1826+
)
1827+
if (postStdout) console.log(postStdout)
1828+
if (postStderr) console.error(postStderr)
1829+
1830+
return true
1831+
} catch (error) {
1832+
if (error instanceof Error) {
1833+
console.error('Error executing xRegistry build:', error.message)
1834+
if ('stdout' in error) console.log(error.stdout)
1835+
if ('stderr' in error) console.error(error.stderr)
1836+
} else {
1837+
console.error('Unknown error occurred during xRegistry build:', error)
1838+
}
1839+
return false
1840+
}
1841+
}
1842+
1843+
/**
1844+
* Task to build the xRegistry
1845+
*/
1846+
async function taskBuildXRegistry() {
1847+
if (!(await buildXRegistry())) {
1848+
process.exit(1)
1849+
}
1850+
}
18001851

18011852
/** @type {Record<string, () => Promise<unknown>>} */
18021853
const taskMap = {
@@ -1807,6 +1858,7 @@ EXAMPLES:
18071858
'check-remote': taskCheckRemote,
18081859
report: taskReport,
18091860
maintenance: taskMaintenance,
1861+
'build-xregistry': taskBuildXRegistry,
18101862
build: taskCheck, // Undocumented alias.
18111863
}
18121864
const taskOrFn = argv._[0]

0 commit comments

Comments
 (0)