forked from VATSIM-Radar/vatsim-radar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-icon.mjs
41 lines (32 loc) · 1.37 KB
/
add-icon.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { readFileSync, renameSync, writeFileSync } from 'node:fs';
import { parseArgs } from 'node:util';
const { values: { icon, coefficient } } = parseArgs({
args: process.argv,
allowPositionals: true,
options: {
icon: {
type: 'string',
},
coefficient: {
type: 'string',
},
},
});
const iconsFile = readFileSync('./src/utils/icons.ts', 'utf-8').split('\n');
let invalidIcon;
try {
invalidIcon = readFileSync(`./src/assets/icons/aircraft/${ icon.toUpperCase() }.svg`);
}
catch { /* empty */ }
if (invalidIcon) renameSync(`./src/assets/icons/aircraft/${ icon.toUpperCase() }.svg`, `./src/assets/icons/aircraft/${ icon.toLowerCase() }.svg`);
readFileSync(`./src/assets/icons/aircraft/${ icon.toLowerCase() }.svg`);
const toAddType = iconsFile.findIndex(x => x.includes(`type AircraftIcon =`));
iconsFile.splice(toAddType + 1, 0, ` | '${ icon }'`);
const toAddDefinition = iconsFile.findIndex(x => x.includes(`export const aircraftIcons`));
iconsFile.splice(toAddDefinition + 1, 0, ` ${ icon }: {
icon: '${ icon }',
width: getAircraftSizeByCoef(${ coefficient }),
},`);
const toAddMatching = iconsFile.findIndex(x => x.includes(`return aircraftIcons[faa`));
iconsFile.splice(toAddMatching, 0, ` case '${ icon.toUpperCase() }':`);
writeFileSync('./src/utils/icons.ts', iconsFile.join('\n'));