2018-05-03 11:39:51 +02:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as path from 'path';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
import {IPackageJSON, IPackageJSONThemeIcons} from './../interfaces/ipackage.json';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
import {CHARSET} from './../consts/files';
|
|
|
|
import {IDefaults} from '../interfaces/idefaults';
|
|
|
|
import {IThemeIcons} from '../interfaces/itheme-icons';
|
|
|
|
import {PATHS} from '../consts/paths';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
|
|
|
export function ensureDir(dirname: string): void {
|
|
|
|
if (!fs.existsSync(dirname)) {
|
|
|
|
fs.mkdirSync(dirname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getDefaultValues(): IDefaults {
|
2018-05-03 11:39:51 +02:00
|
|
|
const defaults: IDefaults = require(path.join(PATHS.VSIX_DIR, './extensions/defaults.json'));
|
2018-04-20 20:07:36 +02:00
|
|
|
|
|
|
|
if (defaults === undefined || defaults === null) {
|
|
|
|
throw new Error('Cannot find defaults params');
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getAbsolutePath(input: string): string {
|
|
|
|
return path.join(PATHS.VSIX_DIR, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getAccentableIcons(): string[] {
|
|
|
|
return getDefaultValues().accentableIcons;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getVariantIcons(): string[] {
|
|
|
|
return getDefaultValues().variantsIcons;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a theme content by a given contribute ID
|
|
|
|
*/
|
|
|
|
export function getThemeIconsByContributeID(ID: string): IThemeIcons | null {
|
2018-05-03 11:39:51 +02:00
|
|
|
const contribute: IPackageJSONThemeIcons = getThemeIconsContribute(ID);
|
2018-04-20 20:07:36 +02:00
|
|
|
return contribute !== null ? require(path.join(PATHS.VSIX_DIR, contribute.path)) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a theme by name
|
|
|
|
*/
|
|
|
|
export function getThemeIconsContribute(ID: string): IPackageJSONThemeIcons {
|
2018-05-03 11:39:51 +02:00
|
|
|
const contributes = getPackageJSON().contributes.iconThemes.filter(contribute => contribute.id === ID);
|
2018-04-20 20:07:36 +02:00
|
|
|
return contributes[0] !== undefined ? contributes[0] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets package JSON
|
|
|
|
*/
|
|
|
|
export function getPackageJSON(): IPackageJSON {
|
2018-05-03 11:39:51 +02:00
|
|
|
return require(path.join(PATHS.VSIX_DIR, './package.json'));
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a file inside the vsix directory
|
|
|
|
*/
|
|
|
|
export function writeFile(filename: string, filecontent: string): void {
|
2018-05-03 11:39:51 +02:00
|
|
|
const filePath = path.join(PATHS.VSIX_DIR, filename);
|
|
|
|
fs.writeFileSync(filePath, filecontent, {encoding: CHARSET});
|
|
|
|
}
|