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