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

Function main

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

Source from the content-addressed store, hash-verified

143// ============================================================
144
145async function main() {
146 const { values: args } = parseArgs({
147 options: {
148 cddl: { type: 'string', multiple: true },
149 'override-cddl': { type: 'string', multiple: true },
150 'vendor-cddl': { type: 'string', multiple: true },
151 ast: { type: 'string' },
152 model: { type: 'string' },
153 'dump-ast': { type: 'string' },
154 'dump-model': { type: 'string' },
155 enhancements: { type: 'string' },
156 'output-dir': { type: 'string' },
157 'spec-version': { type: 'string', default: '1.0' },
158 },
159 })
160
161 // One pipeline stage per invocation; the flags select the stage.
162 if (args['dump-ast'] && args.cddl?.length) {
163 // The base spec is several CDDL files (webdriver-bidi + the adjacent specs); each
164 // is parsed independently and their definitions concatenated. Top-level CDDL
165 // productions are position-independent (refs resolve by name later), so this equals
166 // parsing one merged file — without a separate merge step or tool. Spec-shaped Selenium
167 // overrides (e.g. #1140) are applied here; vendor overlays are NOT, so this base AST —
168 // which feeds the model and the browser-neutral TypeScript binding — stays vendor-free.
169 const baseAst = args.cddl.flatMap(parseCddl)
170 writeJson(args['dump-ast'], applyOverrides(baseAst, args['override-cddl'] ?? []), 'ast')
171 } else if (args['dump-ast'] && args.ast && args['vendor-cddl']?.length) {
172 // The base AST plus vendor overlays, consumed ONLY by the schema projector. Applying vendor
173 // on this separate path (rather than into the shared base AST) is what keeps the tagged
174 // vendor fields out of cddl2ts and the model — the schema step segregates them into `vendor`.
175 writeJson(args['dump-ast'], applyVendor(readJson(args.ast, 'AST'), args['vendor-cddl']), 'ast')
176 } else if (args['dump-model'] && args.ast) {
177 writeJson(args['dump-model'], buildModel(readJson(args.ast, 'AST')), 'model', true)
178 } else if (args['output-dir'] && args.ast && args.model) {
179 generateTypeScript(readJson(args.ast, 'AST'), readJson(args.model, 'model'), args)
180 } else {
181 console.error(
182 'Usage (one stage per invocation):\n' +
183 ' generate_bidi.mjs --cddl <file> [--cddl <file>...] --dump-ast <file>\n' +
184 ' generate_bidi.mjs --ast <file> --dump-model <file>\n' +
185 ' generate_bidi.mjs --ast <file> --model <file> --output-dir <dir> [--enhancements <file>] [--spec-version <v>]',
186 )
187 process.exit(1)
188 }
189}
190
191function parseCddl(cddlArg) {
192 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