set proper id and label

This commit is contained in:
Sandeep Somavarapu 2019-02-06 19:53:01 +01:00
parent 59de5bcc22
commit b74557cf54
3 changed files with 14 additions and 9 deletions

View file

@ -787,9 +787,9 @@ class ThemeFilesCollector implements IFilesCollector {
}
private collectColorThemesFile(colorThemes: ColorTheme[]): Promise<IFile> {
return Promise.all(colorThemes.map(theme => readFile(path.join(this.options.cwd, theme.path), 'utf8').then(contents => ({ ...theme, contents }))))
return Promise.all(colorThemes.map(theme => readFile(path.join(this.options.cwd, theme.path), 'utf8').then(contents => ({ theme, contents }))))
.then(result => {
const themes = result.map(({ id, label, uiTheme, contents }) => ({ id, label, uiTheme, contents }));
const themes = result.map(({ theme, contents }) => ({ id: this.getId(theme), label: this.getLabel(theme), uiTheme: theme.uiTheme, contents }));
return {
contents: JSON.stringify(themes),
path: ThemeFilesCollector.COLOR_THEME_PATH
@ -798,9 +798,9 @@ class ThemeFilesCollector implements IFilesCollector {
}
private collectIconThemesFile(iconThemes: Theme[]): Promise<IFile> {
return Promise.all(iconThemes.map(theme => readFile(path.join(this.options.cwd, theme.path), 'utf8').then(contents => ({ ...theme, contents }))))
return Promise.all(iconThemes.map(theme => readFile(path.join(this.options.cwd, theme.path), 'utf8').then(contents => ({ theme, contents }))))
.then(result => {
const themes = result.map(({ id, label, contents }) => ({ id, label, contents }));
const themes = result.map(({theme, contents}) => ({ id: this.getId(theme), label: this.getLabel(theme), contents }));
return {
contents: JSON.stringify(themes),
path: ThemeFilesCollector.ICON_THEME_PATH
@ -808,6 +808,14 @@ class ThemeFilesCollector implements IFilesCollector {
});
}
private getId(theme: Theme): string {
return theme.id || this.getLabel(theme);
}
private getLabel(theme: Theme): string {
return theme.label || path.basename(theme.path);
}
}
export class ThemeProcessor extends BaseProcessor {

View file

@ -12,7 +12,6 @@
"uiTheme": "vs"
},
{
"id": "monokai-dark",
"label": "Monokai Dark",
"path": "./themes/monokai-dark.json",
"uiTheme": "vs-dark"
@ -20,8 +19,6 @@
],
"iconThemes": [
{
"id": "fakeicons",
"label": "fakeicons",
"path": "./themes/fakeicons.json"
}
]

View file

@ -230,11 +230,11 @@ describe('collect', function () {
const colorThemesFile = files.filter(f => f.path === 'colorThemes.json')[0];
assert.deepEqual(JSON.parse(colorThemesFile.contents.toString()), [
{ id: 'monokai', label: 'Monokai', uiTheme: 'vs', contents: '{ "theme": "monokai" }' },
{ id: 'monokai-dark', label: 'Monokai Dark', uiTheme: 'vs-dark', contents: '{ "theme": "monokai-dark" }' }
{ id: 'Monokai Dark', label: 'Monokai Dark', uiTheme: 'vs-dark', contents: '{ "theme": "monokai-dark" }' }
]);
const iconThemesFile = files.filter(f => f.path === 'iconThemes.json')[0];
assert.deepEqual(JSON.parse(iconThemesFile.contents.toString()), [
{ id: 'fakeicons', label: 'fakeicons', contents: '{ "theme": "fakeicons" }' }
{ id: 'fakeicons.json', label: 'fakeicons.json', contents: '{ "theme": "fakeicons" }' }
]);
});
});