Skip to content

Commit

Permalink
Feat/generator 4 iteration (#400)
Browse files Browse the repository at this point in the history
* chore: move env into src for better build

* chore: removed unused things from webviews

* feat: a better "defaults" - material-theme.config.json

* chore: fix paths for scripts

* feat: new folder "core" with managers

* chore: cleanup all useless things

* chore: update messages to be messages

* refactor: new setAccent command and better material.theme.config entry
  • Loading branch information
LasaleFamine authored and equinusocio committed Dec 26, 2019
1 parent 1ddcebf commit 72a12df
Show file tree
Hide file tree
Showing 38 changed files with 422 additions and 502 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@ node_modules/
/ui/
build
dist
user.material-theme.config.json
5 changes: 0 additions & 5 deletions env.ts

This file was deleted.

109 changes: 109 additions & 0 deletions material-theme.config.json
@@ -0,0 +1,109 @@
{
"accents": {
"Acid Lime": "#C6FF00",
"Blue": "#2979FF",
"Breaking Bad": "#388E3C",
"Bright Teal": "#64FFDA",
"Cyan": "#00BCD4",
"Graphite": "#616161",
"Indigo": "#5C6BC0",
"Lime": "#7CB342",
"Orange": "#FF7042",
"Pink": "#FF4081",
"Purple": "#AB47BC",
"Red": "#E57373",
"Sky": "#84FFFF",
"Tomato": "#F44336",
"Teal": "#80CBC4",
"Yellow": "#FFA000"
},
"accentsProperties": {
"activityBarBadge.background": {
"alpha": 100,
"value": null
},
"list.activeSelectionForeground": {
"alpha": 100,
"value": null
},
"list.inactiveSelectionForeground": {
"alpha": 100,
"value": null
},
"list.highlightForeground": {
"alpha": 100,
"value": null
},
"scrollbarSlider.activeBackground": {
"alpha": 50,
"value": null
},
"editorSuggestWidget.highlightForeground": {
"alpha": 100,
"value": null
},
"textLink.foreground": {
"alpha": 100,
"value": null
},
"progressBar.background": {
"alpha": 100,
"value": null
},
"pickerGroup.foreground": {
"alpha": 100,
"value": null
},
"tab.activeBorder": {
"alpha": 100,
"value": null
},
"notificationLink.foreground": {
"alpha": 100,
"value": null
},
"editorWidget.resizeBorder": {
"alpha": 100,
"value": null
},
"editorWidget.border": {
"alpha": 100,
"value": null
},
"settings.modifiedItemIndicator": {
"alpha": 100,
"value": null
},
"settings.headerForeground": {
"alpha": 100,
"value": null
},
"panelTitle.activeBorder": {
"alpha": 100,
"value": null
},
"breadcrumb.activeSelectionForeground": {
"alpha": 100,
"value": null
},
"menu.selectionForeground": {
"alpha": 100,
"value": null
},
"menubar.selectionForeground": {
"alpha": 100,
"value": null
},
"editor.findMatchBorder": {
"alpha": 100,
"value": null
},
"selection.background": {
"alpha": 40,
"value": null
}
},
"changelog": {
"lastversion": "30.0.0"
}
}
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -21,15 +21,15 @@
},
"engines": {
"node": "<=10",
"vscode": ">=1.39.0"
"vscode": ">=1.1.36"
},
"scripts": {
"build": "yarn cleanup && yarn build:ts && yarn build:generate-themes && yarn build:ui",
"cleanup": "rimraf build && rimraf dist",
"lint": "eslint .",
"build:ui": "node dist/scripts/ui/index.js",
"build:generate-themes": "node dist/scripts/generator/index.js",
"build:ts": "tsc -p ./tsconfig.json && ncp dist/src/ build",
"build:ts": "tsc -p ./tsconfig.json && ncp dist/src/ build && ncp material-theme.config.json build",
"postinstall": "node ./node_modules/vscode/bin/install && opencollective postinstall && tsc -p tsconfig.json"
},
"categories": [
Expand Down
2 changes: 1 addition & 1 deletion scripts/generator/index.ts
Expand Up @@ -4,7 +4,7 @@ import * as path from 'path';
import {generateTheme} from '@moxer/vscode-theme-generator';
import {ThemeSetting} from './types';
import {getColorSet} from './color-set';
import {BUILD_FOLDER_PATH} from '../../env';
import {BUILD_FOLDER_PATH} from '../../src/env';

const THEME_BUILD_PATH = path.join(BUILD_FOLDER_PATH, 'themes');
const themes = ['default', 'darker', 'lighter', 'ocean', 'palenight'];
Expand Down
4 changes: 2 additions & 2 deletions scripts/ui/index.ts
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import browserify from 'browserify';

import {BUILD_FOLDER_PATH, SRC_FOLDER_PATH, TS_BUILD_FOLDER_PATH} from '../../env';
import {BUILD_FOLDER_PATH, SRC_FOLDER_PATH, TS_BUILD_FOLDER_PATH} from '../../src/env';

const UI_FOLDER_PATH = path.join(SRC_FOLDER_PATH, 'webviews', 'ui');
const UI_JS_FOLDER_PATH = path.join(TS_BUILD_FOLDER_PATH, 'src', 'webviews', 'ui');
Expand All @@ -14,7 +14,7 @@ const copyStatics = async (): Promise<void[]> => {
dest: path.join(UI_FOLDER_BUILD_PATH, 'release-notes.html')
}, {
src: path.join(UI_FOLDER_PATH, 'release-notes', 'style.css'),
dest: path.join(UI_FOLDER_BUILD_PATH, 'style.css')
dest: path.join(UI_FOLDER_BUILD_PATH, 'release-notes.css')
}];

return Promise.all(paths.map(async path => fs.copyFile(path.src, path.dest)));
Expand Down
3 changes: 0 additions & 3 deletions src/commands/accents-setter/consts.ts

This file was deleted.

67 changes: 0 additions & 67 deletions src/commands/accents-setter/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/commands/accents-setter/quick-pick.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/commands/index.ts
@@ -1,2 +1 @@
export {default as accentsSetter} from './accents-setter';
export {default as accentsQuickPick} from './accents-setter/quick-pick';
export {command as setAccent} from './set-accent';
55 changes: 55 additions & 0 deletions src/commands/set-accent.ts
@@ -0,0 +1,55 @@
import {workspace, window} from 'vscode';
import {extensionManager} from '../core/extension-manager';
import {settingsManager} from '../core/settings-manager';

const PURGE_KEY = 'Remove accents';

const isValidColor = (color: string | null | undefined): boolean =>
color && /^#([0-9A-F]{6}|[0-9A-F]{8})$/i.test(color);

const getThemeColorCustomizationsConfig = (accentColor?: string): Record<string, unknown> => {
const {accentsProperties} = extensionManager.getConfig();
const color = isValidColor(accentColor) ? accentColor : undefined;

const themeColorCustomConfig = Object.keys(accentsProperties).reduce((acc: any, propName) => {
const currentProp = accentsProperties[propName];
const shouldModify = color && currentProp.alpha < 100;
const colorProp = shouldModify ? `${color}${currentProp.alpha > 10 ? currentProp.alpha : `0${currentProp.alpha}`}` : color;
acc[propName] = colorProp;
return acc;
}, {});

return themeColorCustomConfig;
};

const updateColorCustomizationsConfig = async (config: any): Promise<boolean> => {
try {
workspace.getConfiguration().update('workbench.colorCustomizations', config, true);
return true;
} catch (error) {
window.showErrorMessage(error);
}
};

const quickPick = async (): Promise<string> => {
const themeConfig = extensionManager.getConfig();
const options: string[] = Object.keys(themeConfig.accents).concat(PURGE_KEY);
return window.showQuickPick(options);
};

export const command = async (): Promise<void> => {
const themeConfig = extensionManager.getConfig();
const currentColorCustomizationsConfig: any = workspace.getConfiguration().get('workbench.colorCustomizations');
const accent = await quickPick();

const config = accent === PURGE_KEY ? {
...currentColorCustomizationsConfig,
...getThemeColorCustomizationsConfig()
} : {
...currentColorCustomizationsConfig,
...getThemeColorCustomizationsConfig(themeConfig.accents[accent])
};

await updateColorCustomizationsConfig(config);
await settingsManager.updateSetting('accent', accent);
};
4 changes: 0 additions & 4 deletions src/consts/files.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/consts/paths.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/core/changelog-manager.ts
@@ -0,0 +1,28 @@
import {window} from 'vscode';
import {MESSAGES} from '../helpers/messages';

type AskMessage = {
message: string;
options: {
ok: string;
cancel: string;
};
};

class ChangelogManager {
private readonly askMessage: AskMessage;

constructor(message: AskMessage) {
this.askMessage = message;
}

async askShowChangelog(): Promise<boolean> {
return await window.showInformationMessage(
this.askMessage.message,
this.askMessage.options.ok,
this.askMessage.options.cancel
) === this.askMessage.options.ok;
}
}

export const changelogManager = new ChangelogManager(MESSAGES.CHANGELOG);

0 comments on commit 72a12df

Please sign in to comment.