tabs/src/Meta.ts

54 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-05-21 07:38:44 +02:00
import Service from "./Service";
2020-05-22 10:25:19 +02:00
import path from "path";
import fs from "fs";
2020-05-21 07:38:44 +02:00
export default class Meta {
public static readonly title = 'Tabs';
2020-05-22 10:25:19 +02:00
// Paths
public static readonly RESOURCES_PATH = path.resolve(__dirname, '../resources');
public static readonly ICON_PATH = path.resolve(Meta.RESOURCES_PATH, 'images/logo.png');
2020-05-22 10:25:19 +02:00
// Icons
public static readonly BRAND_ICONS = Meta.listIcons('brands');
public static readonly SOLID_ICONS = Meta.listIcons('solid');
public static readonly REGULAR_ICONS = Meta.listIcons('regular');
public static readonly ICON_SETS = [
Meta.BRAND_ICONS,
Meta.SOLID_ICONS,
Meta.REGULAR_ICONS,
];
2020-05-22 10:25:19 +02:00
2020-05-21 07:38:44 +02:00
private static devMode?: boolean;
public static isDevMode() {
if (this.devMode === undefined) {
this.devMode = process.argv.length > 2 && process.argv[2] === '--dev';
console.debug('Dev mode:', this.devMode);
}
return this.devMode;
}
public static getTitleForService(service: Service, viewTitle: string) {
let suffix = '';
if (viewTitle.length > 0) {
suffix = ' - ' + viewTitle;
}
return this.title + ' - ' + service.name + suffix;
}
2020-05-22 10:25:19 +02:00
private static listIcons(set: string) {
console.log('Loading icon set', set);
const directory = path.resolve(Meta.RESOURCES_PATH, `images/icons/${set}`);
const icons: { name: string; faIcon: string; set: string; }[] = [];
const dir = `fa${set[0]}`;
2020-05-22 10:25:19 +02:00
fs.readdirSync(directory).forEach(i => icons.push({
name: i.split('.svg')[0],
faIcon: dir + ' fa-' + i.split('.svg')[0],
set: set,
2020-05-22 10:25:19 +02:00
}));
return icons;
}
}