chore: check on installation type now as single module

This commit is contained in:
LasaleFamine 2018-08-12 11:37:25 +02:00
parent c91cc8cc0f
commit 0ecb7ff066
5 changed files with 62 additions and 42 deletions

View file

@ -0,0 +1,34 @@
import {getDefaultValues, getPackageJSON} from './fs';
import {IInstallationType} from '../interfaces/iinstallation-type';
const splitVersion = (input: string): {major: number; minor: number; patch: number} => {
const [major, minor, patch] = input.split('.').map(i => parseInt(i, 10));
return {major, minor, patch};
};
export default (): IInstallationType => {
const out: IInstallationType = {
isUpdate: false,
isFirstInstall: false
};
const defaults = getDefaultValues();
const packageJSON = getPackageJSON();
const isFirstInstall = defaults.changelog === undefined ||
(defaults.changelog !== undefined && typeof defaults.changelog.lastversion !== 'string');
if (isFirstInstall) {
return {...out, isFirstInstall};
}
const versionCurrent = splitVersion(packageJSON.version);
const versionOld = isFirstInstall ? null : splitVersion(defaults.changelog.lastversion);
const isUpdate = !versionOld ||
versionCurrent.major > versionOld.major ||
versionCurrent.minor > versionOld.minor ||
versionCurrent.patch > versionOld.patch;
return {...out, isUpdate};
};

View file

@ -1,35 +0,0 @@
import * as path from 'path';
import {IDefaults} from './../interfaces/idefaults';
import {getDefaultValues, getPackageJSON, writeFile} from './fs';
const splitVersion = (input: string): {major: number; minor: number; patch: number} => {
const [major, minor, patch] = input.split('.').map(i => parseInt(i, 10));
return {major, minor, patch};
};
const writeDefaults = (defaults: IDefaults) =>
writeFile(path.join('./extensions/defaults.json'), JSON.stringify(defaults, null, 2));
export default (): boolean => {
const defaults = getDefaultValues();
const packageJSON = getPackageJSON();
const defaultsNotPresent = defaults.changelog === undefined ||
(defaults.changelog !== undefined && typeof defaults.changelog.lastversion !== 'string');
const versionCurrent = splitVersion(packageJSON.version);
const versionOld = defaultsNotPresent ? null : splitVersion(defaults.changelog.lastversion);
const out = !versionOld ||
versionCurrent.major > versionOld.major ||
versionCurrent.minor > versionOld.minor ||
versionCurrent.patch > versionOld.patch;
const newChangelog = {...defaults.changelog, lastversion: packageJSON.version};
const newDefaults = {...defaults, changelog: newChangelog};
writeDefaults(newDefaults);
return out;
};

View file

@ -0,0 +1,16 @@
import * as path from 'path';
import {getDefaultValues, getPackageJSON, writeFile} from './fs';
import {IDefaults} from './../interfaces/idefaults';
const writeDefaults = (defaults: IDefaults) =>
writeFile(path.join('./extensions/defaults.json'), JSON.stringify(defaults, null, 2));
export default (): void => {
const defaults = getDefaultValues();
const packageJSON = getPackageJSON();
const newChangelog = {...defaults.changelog, lastversion: packageJSON.version};
const newDefaults = {...defaults, changelog: newChangelog};
writeDefaults(newDefaults);
};

View file

@ -0,0 +1,4 @@
export interface IInstallationType {
isUpdate: boolean;
isFirstInstall: boolean;
}

View file

@ -7,10 +7,14 @@ import * as ThemeCommands from './commands';
import {isAutoApplyEnable} from './helpers/settings'; import {isAutoApplyEnable} from './helpers/settings';
import {onChangeConfiguration} from './helpers/configuration-change'; import {onChangeConfiguration} from './helpers/configuration-change';
import {infoMessage, changelogMessage} from './helpers/messages'; import {infoMessage, changelogMessage} from './helpers/messages';
import shouldShowChangelog from './helpers/should-show-changelog'; import checkInstallation from './helpers/check-installation';
import writeChangelog from './helpers/write-changelog';
export async function activate() { export async function activate() {
const config = Workspace.getConfiguration(); const config = Workspace.getConfiguration();
const installationType = checkInstallation();
writeChangelog();
// Listen on set theme: when the theme is Material Theme, just adjust icon and accent. // Listen on set theme: when the theme is Material Theme, just adjust icon and accent.
Workspace.onDidChangeConfiguration(onChangeConfiguration); Workspace.onDidChangeConfiguration(onChangeConfiguration);
@ -20,17 +24,14 @@ export async function activate() {
config.update('materialTheme.cache.workbench', undefined, true); config.update('materialTheme.cache.workbench', undefined, true);
} }
if (shouldShowChangelog()) { const shouldShowChangelog = (installationType.isFirstInstall || installationType.isUpdate) && await changelogMessage();
const show = await changelogMessage(); if (shouldShowChangelog) {
if (show) {
ThemeCommands.showChangelog(); ThemeCommands.showChangelog();
} }
}
// Registering commands // Registering commands
Commands.registerCommand('materialTheme.setAccent', async () => { Commands.registerCommand('materialTheme.setAccent', async () => {
const wasSet = await ThemeCommands.accentsSetter(); const wasSet = await ThemeCommands.accentsSetter();
if (wasSet) { if (wasSet) {
return isAutoApplyEnable() ? ThemeCommands.fixIcons() : infoMessage(); return isAutoApplyEnable() ? ThemeCommands.fixIcons() : infoMessage();
} }