|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +const path = require('path') |
| 7 | +const fs = require('fs') |
| 8 | + |
| 9 | +function buildPropertiesWithMDNData(vscProperties) { |
| 10 | + const propertyMap = {} |
| 11 | + |
| 12 | + const mdnProperties = require('mdn-data/css/properties.json') |
| 13 | + const mdnAtRules = require('mdn-data/css/at-rules.json') |
| 14 | + |
| 15 | + // Flatten at-rule properties and put all properties together |
| 16 | + const allMDNProperties = mdnProperties |
| 17 | + for (const atRuleName of Object.keys(mdnAtRules)) { |
| 18 | + if (mdnAtRules[atRuleName].descriptors) { |
| 19 | + for (const atRulePropertyName of Object.keys(mdnAtRules[atRuleName].descriptors)) { |
| 20 | + allMDNProperties[atRulePropertyName] = mdnAtRules[atRuleName].descriptors[atRulePropertyName] |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * 1. Go through VSC properties. For each entry that has a matching entry in MDN, merge both entry. |
| 27 | + */ |
| 28 | + vscProperties.forEach(p => { |
| 29 | + if (p.name) { |
| 30 | + if (allMDNProperties[p.name]) { |
| 31 | + propertyMap[p.name] = { |
| 32 | + ...p, |
| 33 | + ...allMDNProperties[p.name] |
| 34 | + } |
| 35 | + } else { |
| 36 | + propertyMap[p.name] = p |
| 37 | + } |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + /** |
| 42 | + * 2. Go through MDN properties. For each entry that hasn't been recorded, add it with empty description. |
| 43 | + */ |
| 44 | + for (const pn of Object.keys(allMDNProperties)) { |
| 45 | + if (!propertyMap[pn]) { |
| 46 | + propertyMap[pn] = { |
| 47 | + name: pn, |
| 48 | + description: '', |
| 49 | + ...allMDNProperties[pn] |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + return Object.values(propertyMap) |
| 55 | +} |
| 56 | + |
| 57 | +module.exports = { |
| 58 | + buildPropertiesWithMDNData |
| 59 | +} |
0 commit comments