| 21 | generate('packages/@react-spectrum/s2/spectrum-illustrations/gradient/generic2'); |
| 22 | |
| 23 | function generate(dir) { |
| 24 | let icons = new Map(); |
| 25 | let sizes = { |
| 26 | // illustration sizes |
| 27 | 48: 'S', |
| 28 | 96: 'M', |
| 29 | 160: 'L', |
| 30 | // ui icon sizes |
| 31 | 50: 'XS', |
| 32 | 75: 'S', |
| 33 | 100: 'M', |
| 34 | 200: 'L', |
| 35 | 300: 'XL', |
| 36 | 400: 'XXL', |
| 37 | 500: 'XXXL', |
| 38 | 600: 'XXXXL' |
| 39 | }; |
| 40 | |
| 41 | for (let fileName of fs.readdirSync(dir)) { |
| 42 | let file = path.join(dir, fileName); |
| 43 | let ext = path.extname(file); |
| 44 | if (ext === '.tsx') { |
| 45 | fs.rmSync(file); |
| 46 | } else if (ext === '.svg' && !file.includes('S2_MoveHorizontalTableWidget')) { |
| 47 | let match = |
| 48 | file.match(/S2_(?:lin|fill)_(.+?)_(?:generic\d_)?(\d+)\.svg/) || |
| 49 | file.match(/S2_(.+)Size(\d+)\.svg/); |
| 50 | if (!match) { |
| 51 | throw new Error('Unexpected file ' + file); |
| 52 | } |
| 53 | let [, name, size] = match; |
| 54 | name = name[0].toUpperCase() + name.slice(1).replace(/_/g, ''); |
| 55 | if (!icons.has(name)) { |
| 56 | icons.set(name, {}); |
| 57 | } |
| 58 | let width = '0', |
| 59 | height = '0'; |
| 60 | if (!dir.includes('spectrum-illustrations')) { |
| 61 | let contents = fs.readFileSync(file, 'utf8'); |
| 62 | let dom = new JSDOM(contents); |
| 63 | let svg = dom.window.document.querySelector('svg'); |
| 64 | width = svg.getAttribute('width'); |
| 65 | height = svg.getAttribute('height'); |
| 66 | } |
| 67 | icons.get(name)[sizes[size]] = {fileName, width, height}; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | let relative = process.env.PARCEL_V3 |
| 72 | ? '@react-spectrum/s2/Icon' |
| 73 | : path.relative(dir, 'packages/@react-spectrum/s2/src/Icon'); |
| 74 | let typeImport = dir.includes('ui-icons') |
| 75 | ? "import {ReactNode, SVGProps} from 'react';" |
| 76 | : `import {ReactNode} from 'react'; |
| 77 | import {IconProps, IllustrationContext} from '${relative}';`; |
| 78 | let ctx = dir.includes('spectrum-illustrations') |
| 79 | ? '[props] = useContextProps(props, null, IllustrationContext);\n ' |
| 80 | : ''; |