blob: ca78bc8e969bfc375dbaf597772cd96004f7557f [file] [log] [blame]
Victor Porof1a8a30d2022-06-13 13:07:10 +00001// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// eslint-disable-next-line rulesdir/es_modules_import
6import idl from '@webref/idl';
7import * as fs from 'fs';
8import * as path from 'path';
9import * as url from 'url';
10
11import {SPECS} from './config.js';
12import {addMetadata, getIDLProps, minimize} from './get-props.js';
13import {getMissingTypes} from './util.js';
14
15if (process.argv.length !== 3) {
16 throw new Error('Please provide the path to devtools-frontend');
17}
18
19const files = await idl.listAll();
20const names = Object.keys(SPECS);
21const specs = await Promise.all(names.map(name => files[name].parse().then(idls => ({name, idls}))));
22
23const output = addMetadata(getIDLProps(specs));
24const missing = getMissingTypes(output);
25
26for (const type of missing) {
27 console.warn('Found missing type:', type);
28}
29
30const frontendPath = path.resolve(process.argv[2]);
31const jsMetadataPath = path.join(frontendPath, 'front_end/models/javascript_metadata/');
32const outPath = path.join(jsMetadataPath, 'DOMPinnedProperties.ts');
33const thisPath = path.relative(frontendPath, url.fileURLToPath(import.meta.url));
34
35fs.writeFileSync(outPath, `
36// Copyright 2022 The Chromium Authors. All rights reserved.
37// Use of this source code is governed by a BSD-style license that can be
38// found in the LICENSE file.
39// Generated from ${thisPath}
40
41/**
42 * All the specs used when generating the DOM pinned properties dataset.
43 */
44export const SPECS = ${JSON.stringify(SPECS)};
45
46export interface DOMPinnedWebIDLProp {
47 // A flag specifying whether it's a "global" attribute.
48 global?: boolean;
49 // A bitfield of the specs in which the property is found.
50 // If missing, it implies the default spec: "html".
51 specs?: number;
52}
53
54export interface DOMPinnedWebIDLType {
55 // An inherited Type.
56 inheritance?: string;
57 // A set of Types to also include properties from.
58 includes?: Array<string>;
59 // The properties defined on this Type.
60 props?: {
61 // A property name such as "checked".
62 [PropName: string]: DOMPinnedWebIDLProp,
63 };
64 // The "states" in which only certain properties are "applicable".
65 states?: {
66 // A CSS selector such as "[type=checkbox]".
67 [State: string]: {
68 [PropName: string]: DOMPinnedWebIDLProp,
69 },
70 };
71}
72
73export interface DOMPinnedPropertiesDataset {
74 [TypeName: string]: DOMPinnedWebIDLType;
75}
76
77/**
78 * The DOM pinned properties dataset. Generated from WebIDL data parsed from
79 * the SPECS above.
80 *
81 * This is an object with WebIDL type names as keys and their WebIDL properties
82 * and inheritance/include chains as values.
83 */
84export const DOMPinnedProperties: DOMPinnedPropertiesDataset = ${JSON.stringify(minimize(output))};
85`);