|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const DOMProperty = require('react-dom/lib/DOMProperty'); |
| 4 | +const SVGDOMPropertyConfig = require('react-dom/lib/SVGDOMPropertyConfig'); |
| 5 | +const { LIB_DIR, SVG_DIR } = require('./constants'); |
| 6 | + |
| 7 | +/** |
| 8 | + * Creates the DOM property map via injection. |
| 9 | + * |
| 10 | + * @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L57 |
| 11 | + */ |
| 12 | +DOMProperty.injection.injectDOMPropertyConfig(SVGDOMPropertyConfig); |
| 13 | + |
| 14 | +// `autofocus` is removed since it's not an applicable attribute for SVG elements |
| 15 | +delete DOMProperty.getPossibleStandardName.autofocus; |
| 16 | + |
| 17 | +/** |
| 18 | + * Create output directories (if it does not exist). |
| 19 | + */ |
| 20 | +try { |
| 21 | + fs.mkdirSync(LIB_DIR); |
| 22 | +} catch (error) { |
| 23 | + // throw error; |
| 24 | +} |
| 25 | + |
| 26 | +try { |
| 27 | + fs.mkdirSync(SVG_DIR); |
| 28 | +} catch (error) { |
| 29 | + // throw error; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * SVG DOM property config. |
| 34 | + */ |
| 35 | +const attributeToProperty = {}; |
| 36 | + |
| 37 | +/** |
| 38 | + * List of SVG DOM attributes. |
| 39 | + */ |
| 40 | +const attributes = []; |
| 41 | + |
| 42 | +Object.keys(DOMProperty.getPossibleStandardName).forEach(attributeName => { |
| 43 | + const propertyName = DOMProperty.getPossibleStandardName[attributeName]; |
| 44 | + |
| 45 | + if (attributeName !== propertyName) { |
| 46 | + attributeToProperty[attributeName] = propertyName; |
| 47 | + } |
| 48 | + |
| 49 | + attributes.push(attributeName); |
| 50 | +}); |
| 51 | + |
| 52 | +fs.writeFileSync( |
| 53 | + path.resolve(SVG_DIR, 'attributes.json'), |
| 54 | + JSON.stringify(attributes) |
| 55 | +); |
| 56 | + |
| 57 | +fs.writeFileSync( |
| 58 | + path.resolve(SVG_DIR, 'attribute-to-property.json'), |
| 59 | + JSON.stringify(attributeToProperty) |
| 60 | +); |
0 commit comments