Merge pull request #91 from equinusocio/feat/in-app-changelog

Feat/in app changelog
This commit is contained in:
Mattia Astorino 2017-09-12 09:24:09 +02:00 committed by GitHub
commit 0a93b3a234
5 changed files with 81 additions and 2 deletions

View file

@ -17,6 +17,9 @@
"Teal": "#80CBC4",
"Yellow": "#FFA000"
},
"changelog": {
"lastversion": "1.0.2"
},
"icons": {
"theme": {
"iconDefinitions": {

View file

@ -0,0 +1,61 @@
import * as path from 'path';
import * as vscode from 'vscode';
import { getDefaultValues, getPackageJSON, writeFile } from "./fs";
import { PATHS } from '../consts/paths';
function previewFile(): void {
let uri = vscode.Uri.parse(path.join('file:///', PATHS.VSIX_DIR, './CHANGELOG.md'));
vscode.commands.executeCommand('markdown.showPreview', uri);
}
function splitVersion(input: string): { major: number, minor: number, patch: number } {
let [ major, minor, patch ] = input.split('.').map(i => parseInt(i));
return { major, minor, patch };
}
export function showChangelog(): void {
let extname: string = 'Microsoft.vscode-markdown';
let md = vscode.extensions.getExtension<any>(extname);
if (md === undefined) {
console.warn(`Ext not found ${ extname }`)
return;
}
if (md.isActive) {
previewFile();
} else {
md.activate().then(() => {
previewFile();
}, reason => {
console.warn(reason);
});
}
}
export function shouldShowChangelog(): boolean {
let defaults = getDefaultValues();
let out: boolean;
let packageJSON = getPackageJSON();
if (defaults.changelog == undefined || (defaults.changelog !== undefined && typeof defaults.changelog.lastversion !== 'string')) {
defaults.changelog = {
lastversion: packageJSON.version
}
out = true;
} else {
let versionCurrent = splitVersion(packageJSON.version);
let versionOld = splitVersion(defaults.changelog.lastversion);
out = versionCurrent.major > versionOld.major || versionCurrent.minor > versionOld.minor || versionCurrent.patch > versionOld.patch;
defaults.changelog.lastversion = packageJSON.version;
}
writeFile(path.join('./extensions/defaults.json'), JSON.stringify(defaults, null, 2));
return out;
}

View file

@ -1,5 +1,6 @@
export interface IDefaults {
accents: IAccents;
changelog: IChangelog;
icons: IDefaultsThemeIcons;
themeVariants: IDefaultsThemeVariant;
themeVariantsColours: IDefaultsThemeVariantColours;
@ -11,6 +12,10 @@ export interface IAccents {
[index: string]: string;
}
export interface IChangelog {
lastversion: string;
}
export interface IDefaultsThemeIcons {
theme: {
iconDefinitions: {

View file

@ -3,15 +3,18 @@ import * as vscode from 'vscode';
import { IGenericObject } from "./interfaces/igeneric-object";
import { THEME_ACCENTS_SETTER } from "./commands/accents-setter/index";
import { THEME_VARIANT } from "./commands/theme-variant/index";
import { shouldShowChangelog, showChangelog } from './helpers/changelog';
enum Commands {
ACCENTS,
CHANGELOG,
COLOUR_VARIANT
}
const OPTIONS: IGenericObject<number> = {
'Change accent color': Commands.ACCENTS,
'Change color variant': Commands.COLOUR_VARIANT
'Change color variant': Commands.COLOUR_VARIANT,
'Read the changelog': Commands.CHANGELOG
}
export function activate(context: vscode.ExtensionContext) {
@ -19,6 +22,10 @@ export function activate(context: vscode.ExtensionContext) {
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.accent', undefined, true);
}
if (shouldShowChangelog()) {
showChangelog();
}
// registering the command
let command = vscode.commands.registerCommand('material.theme.config', () => {
// the user is going to choose what aspect of theme to config
@ -28,6 +35,9 @@ export function activate(context: vscode.ExtensionContext) {
case Commands.ACCENTS:
THEME_ACCENTS_SETTER();
break;
case Commands.CHANGELOG:
showChangelog();
break;
case Commands.COLOUR_VARIANT:
THEME_VARIANT();
break;