enso/app/gui2/scripts/generateIconMetadata.js
Kaz Wesley 245ec7afe8
Replace execution context controls with record mode controls (#9133)
Closes #8673. Stacked on #9132.

Before:
![image](https://github.com/enso-org/enso/assets/1047859/1b1ca9f4-eda9-45fd-bec1-cd7e255112fa)
![image](https://github.com/enso-org/enso/assets/1047859/b8cf6de1-d75c-48d0-ac0d-9e6e0c659dd4)

After:
![image](https://github.com/enso-org/enso/assets/1047859/91d13862-96e7-4175-a61e-40aecd6d62b0)
![image](https://github.com/enso-org/enso/assets/1047859/ef20511f-00f2-4042-b4d4-97728817500b)

# Important Notes
- The model has been refactored from execution-modes (live/design) to record-mode (on/off) up to the point of the project store, where it's translated (since the backend still uses the live/design concepts).
2024-02-23 20:10:43 +00:00

31 lines
1.0 KiB
JavaScript

import * as fs from 'node:fs/promises'
console.info('Reading icons from "./src/assets/icons.svg"...')
const icons = await fs.readFile('./src/assets/icons.svg', { encoding: 'utf-8' })
const iconNames = icons.match(/(?<=<symbol id=")[^"]+/gm) ?? []
// All generated files MUST follow Prettier formatting.
console.info('Writing icon names to "./src/util/iconList.json"...')
await fs.writeFile('./src/util/iconList.json', JSON.stringify(iconNames, undefined, 2) + '\n')
console.info('Writing icon name type to "./src/util/iconName.ts"...')
await fs.writeFile(
'./src/util/iconName.ts',
`\
// Generated by \`scripts/generateIconMetadata.js\`.
// Please run \`npm run generate-metadata\` to regenerate this file whenever \`icons.svg\` is changed.
import iconNames from '@/util/iconList.json'
export type Icon =
${iconNames?.map((name) => ` | '${name}'`).join('\n')}
export { iconNames }
const iconNamesSet = new Set(iconNames)
export function isIconName(value: string): value is Icon {
return iconNamesSet.has(value)
}
`,
)
console.info('Done.')