UNPKG

754 BJavaScriptView Raw
1#!/usr/bin/env node
2/* eslint-disable no-console */
3
4const fs = require('fs');
5const yargs = require('yargs');
6
7const { argv } = yargs.usage('Usage: $0 [icons...]').help();
8
9const icons = argv._;
10for (let i = 0; i < icons.length; i += 1) {
11 const icon = icons[i];
12 let mapFile = icon;
13 if (mapFile === 'FontAwesome5') {
14 mapFile = 'FontAwesome5Free';
15 }
16
17 const glyphmap = JSON.parse(
18 fs.readFileSync(`glyphmaps/${mapFile}.json`, { encoding: 'utf8' })
19 );
20 const names = Object.keys(glyphmap).join("' | '");
21
22 const iconClass = `/**
23 * @flow strict
24 */
25
26import type { Icon } from './index';
27
28export type ${icon}Glyphs = '${names}';
29
30declare export default Class<Icon<${icon}Glyphs>>;
31`;
32 fs.writeFileSync(`${icon}.js.flow`, iconClass);
33}