chore: check on installation type now as single module
This commit is contained in:
parent
c91cc8cc0f
commit
0ecb7ff066
5 changed files with 62 additions and 42 deletions
34
extensions/helpers/check-installation.ts
Normal file
34
extensions/helpers/check-installation.ts
Normal 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};
|
||||
};
|
|
@ -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;
|
||||
};
|
16
extensions/helpers/write-changelog.ts
Normal file
16
extensions/helpers/write-changelog.ts
Normal 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);
|
||||
};
|
4
extensions/interfaces/iinstallation-type.ts
Normal file
4
extensions/interfaces/iinstallation-type.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export interface IInstallationType {
|
||||
isUpdate: boolean;
|
||||
isFirstInstall: boolean;
|
||||
}
|
|
@ -7,10 +7,14 @@ import * as ThemeCommands from './commands';
|
|||
import {isAutoApplyEnable} from './helpers/settings';
|
||||
import {onChangeConfiguration} from './helpers/configuration-change';
|
||||
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() {
|
||||
const config = Workspace.getConfiguration();
|
||||
const installationType = checkInstallation();
|
||||
|
||||
writeChangelog();
|
||||
|
||||
// Listen on set theme: when the theme is Material Theme, just adjust icon and accent.
|
||||
Workspace.onDidChangeConfiguration(onChangeConfiguration);
|
||||
|
@ -20,17 +24,14 @@ export async function activate() {
|
|||
config.update('materialTheme.cache.workbench', undefined, true);
|
||||
}
|
||||
|
||||
if (shouldShowChangelog()) {
|
||||
const show = await changelogMessage();
|
||||
if (show) {
|
||||
ThemeCommands.showChangelog();
|
||||
}
|
||||
const shouldShowChangelog = (installationType.isFirstInstall || installationType.isUpdate) && await changelogMessage();
|
||||
if (shouldShowChangelog) {
|
||||
ThemeCommands.showChangelog();
|
||||
}
|
||||
|
||||
// Registering commands
|
||||
Commands.registerCommand('materialTheme.setAccent', async () => {
|
||||
const wasSet = await ThemeCommands.accentsSetter();
|
||||
|
||||
if (wasSet) {
|
||||
return isAutoApplyEnable() ? ThemeCommands.fixIcons() : infoMessage();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue