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

Function main

javascript/selenium-webdriver/generate_bidi.mjs:109–155  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

107// ============================================================
108
109async function main() {
110 const { values: args } = parseArgs({
111 options: {
112 cddl: { type: 'string', multiple: true },
113 'override-cddl': { type: 'string', multiple: true },
114 'vendor-cddl': { type: 'string', multiple: true },
115 ast: { type: 'string' },
116 model: { type: 'string' },
117 'vendor-model': { type: 'string' },
118 'dump-ast': { type: 'string' },
119 'dump-model': { type: 'string' },
120 'output-dir': { type: 'string' },
121 'spec-version': { type: 'string', default: '1.0' },
122 },
123 })
124
125 // One pipeline stage per invocation; the flags select the stage.
126 if (args['dump-ast'] && args.cddl?.length) {
127 // The base spec is several CDDL files (webdriver-bidi + the adjacent specs); each
128 // is parsed independently and their definitions concatenated. Top-level CDDL
129 // productions are position-independent (refs resolve by name later), so this equals
130 // parsing one merged file — without a separate merge step or tool. Spec-shaped Selenium
131 // overrides are applied here; vendor overlays are NOT, so this base AST —
132 // which feeds the model and the browser-neutral TypeScript binding — stays vendor-free.
133 const baseAst = args.cddl.flatMap(parseCddl)
134 writeJson(args['dump-ast'], applyOverrides(baseAst, args['override-cddl'] ?? []), 'ast')
135 } else if (args['dump-ast'] && args.ast && args['vendor-cddl']?.length) {
136 // The base AST plus vendor overlays, consumed ONLY by the schema projector. Applying vendor
137 // on this separate path (rather than into the shared base AST) is what keeps the tagged
138 // vendor fields out of cddl2ts and the model — the schema step segregates them into `vendor`.
139 writeJson(args['dump-ast'], applyVendor(readJson(args.ast, 'AST'), args['vendor-cddl']), 'ast')
140 } else if (args['dump-model'] && args.ast) {
141 writeJson(args['dump-model'], buildModel(readJson(args.ast, 'AST')), 'model', true)
142 } else if (args['output-dir'] && args.ast && args.model) {
143 const vendorModel = args['vendor-model'] ? readJson(args['vendor-model'], 'vendor model') : null
144 generateTypeScript(readJson(args.ast, 'AST'), readJson(args.model, 'model'), vendorModel, args)
145 } else {
146 console.error(
147 'Usage (one stage per invocation):\n' +
148 ' generate_bidi.mjs --cddl <file> [--cddl <file>...] [--override-cddl <file>...] --dump-ast <file>\n' +
149 ' generate_bidi.mjs --ast <file> --vendor-cddl <namespace>=<file> [...] --dump-ast <file>\n' +
150 ' generate_bidi.mjs --ast <file> --dump-model <file>\n' +
151 ' generate_bidi.mjs --ast <file> --model <file> [--vendor-model <file>] --output-dir <dir> [--spec-version <v>]',
152 )
153 process.exit(1)
154 }
155}
156
157function parseCddl(cddlArg) {
158 const cddlPath = resolveInputPath(cddlArg)

Callers 1

generate_bidi.mjsFile · 0.70

Calls 7

writeJsonFunction · 0.85
applyOverridesFunction · 0.85
applyVendorFunction · 0.85
readJsonFunction · 0.85
buildModelFunction · 0.85
generateTypeScriptFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected