vsc-material-theme/extensions/helpers/changelog.ts

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-09-07 21:02:45 +02:00
import * as path from 'path';
2017-09-08 10:16:16 +02:00
import * as vscode from 'vscode';
2017-09-07 21:02:45 +02:00
import { getDefaultValues, getPackageJSON, writeFile } from "./fs";
2017-09-08 10:16:16 +02:00
import { PATHS } from '../consts/paths';
2017-09-07 21:02:45 +02:00
2017-09-08 10:16:16 +02:00
function previewFile(): void {
let uri = vscode.Uri.parse(path.join('file:///', PATHS.VSIX_DIR, './CHANGELOG.md'));
vscode.commands.executeCommand('markdown.showPreview', uri);
}
2017-09-07 21:02:45 +02:00
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 {
2017-09-08 10:16:16 +02:00
let extname: string = 'Microsoft.vscode-markdown';
let md = vscode.extensions.getExtension<any>(extname);
2017-09-07 21:02:45 +02:00
2017-09-08 10:16:16 +02:00
if (md === undefined) {
console.warn(`Ext not found ${ extname }`)
return;
}
if (md.isActive) {
previewFile();
} else {
md.activate().then(() => {
previewFile();
}, reason => {
console.warn(reason);
});
}
2017-09-07 21:02:45 +02:00
}
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 = {
2017-09-08 10:16:16 +02:00
lastversion: packageJSON.version
2017-09-07 21:02:45 +02:00
}
out = true;
} else {
let versionCurrent = splitVersion(packageJSON.version);
let versionOld = splitVersion(defaults.changelog.lastversion);
2017-09-08 10:16:16 +02:00
out = versionCurrent.major > versionOld.major || versionCurrent.minor > versionOld.minor || versionCurrent.patch > versionOld.patch;
2017-09-07 21:02:45 +02:00
defaults.changelog.lastversion = packageJSON.version;
}
2017-09-08 10:16:16 +02:00
writeFile(path.join('./extensions/defaults.json'), JSON.stringify(defaults, null, 2));
2017-09-07 21:02:45 +02:00
return out;
}