MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / main

Function main

javascript/selenium-webdriver/project_bidi_schema.mjs:1034–1101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1032// ============================================================
1033
1034async function main() {
1035 const { parseArgs } = await import('node:util')
1036 const { readFileSync, writeFileSync } = await import('node:fs')
1037 const { resolve } = await import('node:path')
1038
1039 // Under Bazel the js_binary wrapper chdir's to BAZEL_BINDIR, but $(location)
1040 // inputs are execroot-relative and already carry that prefix — strip it so the
1041 // path is not doubled. Mirrors resolveInputPath() in generate_bidi.mjs.
1042 const resolveInput = (p) => {
1043 if (!process.env.BAZEL_BINDIR) return resolve(p)
1044 const prefix = process.env.BAZEL_BINDIR.replaceAll('\\', '/') + '/'
1045 const norm = p.replaceAll('\\', '/')
1046 return resolve(norm.startsWith(prefix) ? norm.slice(prefix.length) : norm)
1047 }
1048
1049 const { values: args } = parseArgs({
1050 options: {
1051 ast: { type: 'string' },
1052 model: { type: 'string' },
1053 'dump-schema': { type: 'string' },
1054 // Repeatable: one webref dfns index per merged spec. Optional — omitting them
1055 // (and --anchors) yields a schema with no specHref links (fully backward compatible).
1056 dfns: { type: 'string', multiple: true },
1057 // The core spec's prose-anchor index (see extract_bidi_anchors.mjs). Optional;
1058 // upgrades type links to prose sections and adds command/event/domain links.
1059 anchors: { type: 'string' },
1060 // The model built from the vendor-overlaid AST; its vendor-tagged messages are filed
1061 // under `vendor.<namespace>`. Optional.
1062 'vendor-model': { type: 'string' },
1063 },
1064 })
1065 if (!args.ast || !args.model || !args['dump-schema']) {
1066 console.error(
1067 'Usage: project_bidi_schema.mjs --ast <ast.json> --model <model.json> --dump-schema <out.json>' +
1068 ' [--dfns <dfns.json> ...] [--anchors <anchors.json>] [--vendor-model <model.json>]',
1069 )
1070 process.exit(1)
1071 }
1072
1073 const ast = JSON.parse(readFileSync(resolveInput(args.ast), 'utf8'))
1074 const model = JSON.parse(readFileSync(resolveInput(args.model), 'utf8'))
1075 const dfnsDocs = (args.dfns ?? []).map((p) => JSON.parse(readFileSync(resolveInput(p), 'utf8')))
1076 const anchors = args.anchors ? JSON.parse(readFileSync(resolveInput(args.anchors), 'utf8')) : {}
1077 const vendorModel = args['vendor-model'] ? JSON.parse(readFileSync(resolveInput(args['vendor-model']), 'utf8')) : null
1078 const schema = projectSchema(ast, model, buildSpecLinks(dfnsDocs, anchors), vendorModel)
1079
1080 // Generation is the gate: a broken or incomplete schema fails the build.
1081 const errors = [...checkSchema(schema), ...checkCompleteness(ast, schema)]
1082 if (errors.length) {
1083 console.error('BiDi schema validation failed:')
1084 errors.forEach((e) => console.error(` ${e}`))
1085 process.exit(1)
1086 }
1087
1088 writeFileSync(resolve(args['dump-schema']), JSON.stringify(schema, null, 2) + '\n', 'utf8')
1089 const prose = (u) => (u && !u.includes('#cddl-') ? 1 : 0)
1090 const linkedTypes = Object.values(schema.types).filter((t) => t.specHref)
1091 const proseTypes = linkedTypes.filter((t) => prose(t.specHref)).length

Callers 1

Calls 15

projectSchemaFunction · 0.85
buildSpecLinksFunction · 0.85
checkSchemaFunction · 0.85
checkCompletenessFunction · 0.85
proseFunction · 0.85
filterMethod · 0.80
valuesMethod · 0.80
entriesMethod · 0.80
resolveInputFunction · 0.70
logMethod · 0.65
resolveFunction · 0.50
errorMethod · 0.45

Tested by

no test coverage detected