vsc-material-theme/extensions/helpers/fs.ts
Mattia Astorino 9907cc8c67
Develop (#185)
* chore: Update meta and readme

* chore. Update README

* Refactor/linting - tslint-xo (#178)

* refactor(deps): added tslint, cleanup, and activationEvents modified

* refactor(lint): linting...

* refactor(changelog): changelo method refactor (should be tested)

* refactor(theme-icons):  linting and small refactor

* refactor(accents-setter): linting and small refactor

* chore(travis): added travis file

* fix(Lighter): Fix folders icon association

* chore: Clean test files

* fix(Icons): Add icon to .spec.ts files

* chore: Update git icon

* Update issue templates (#184)
2018-05-07 16:23:17 +02:00

68 lines
1.9 KiB
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import {IPackageJSON, IPackageJSONThemeIcons} from './../interfaces/ipackage.json';
import {CHARSET} from './../consts/files';
import {IDefaults} from '../interfaces/idefaults';
import {IThemeIcons} from '../interfaces/itheme-icons';
import {PATHS} from '../consts/paths';
export function ensureDir(dirname: string): void {
if (!fs.existsSync(dirname)) {
fs.mkdirSync(dirname);
}
}
export function getDefaultValues(): IDefaults {
const defaults: IDefaults = require(path.join(PATHS.VSIX_DIR, './extensions/defaults.json'));
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 {
const contribute: IPackageJSONThemeIcons = getThemeIconsContribute(ID);
return contribute !== null ? require(path.join(PATHS.VSIX_DIR, contribute.path)) : null;
}
/**
* Gets a theme by name
*/
export function getThemeIconsContribute(ID: string): IPackageJSONThemeIcons {
const contributes = getPackageJSON().contributes.iconThemes.filter(contribute => contribute.id === ID);
return contributes[0] !== undefined ? contributes[0] : null;
}
/**
* Gets package JSON
*/
export function getPackageJSON(): IPackageJSON {
return require(path.join(PATHS.VSIX_DIR, './package.json'));
}
/**
* Writes a file inside the vsix directory
*/
export function writeFile(filename: string, filecontent: string): void {
const filePath = path.join(PATHS.VSIX_DIR, filename);
fs.writeFileSync(filePath, filecontent, {encoding: CHARSET});
}