2018-04-20 20:07:36 +02:00
|
|
|
import * as path from 'path';
|
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
import {IDefaults} from './../interfaces/idefaults';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
import {getDefaultValues, getPackageJSON, writeFile} from './fs';
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
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};
|
|
|
|
};
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
const writeDefaults = (defaults: IDefaults) =>
|
|
|
|
writeFile(path.join('./extensions/defaults.json'), JSON.stringify(defaults, null, 2));
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-18 13:47:22 +02:00
|
|
|
export default (): boolean => {
|
2018-05-03 11:39:51 +02:00
|
|
|
const defaults = getDefaultValues();
|
|
|
|
const packageJSON = getPackageJSON();
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
const defaultsNotPresent = defaults.changelog === undefined ||
|
|
|
|
(defaults.changelog !== undefined && typeof defaults.changelog.lastversion !== 'string');
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
const versionCurrent = splitVersion(packageJSON.version);
|
|
|
|
const versionOld = defaultsNotPresent ? null : splitVersion(defaults.changelog.lastversion);
|
2018-04-20 20:07:36 +02:00
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
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);
|
2018-04-20 20:07:36 +02:00
|
|
|
|
|
|
|
return out;
|
2018-05-03 11:39:51 +02:00
|
|
|
};
|