Proper version update (#5379)

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2021-01-25 15:35:52 +01:00 committed by GitHub
parent c850c6f2e9
commit 6ba5809679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,7 +93,6 @@ export function writeToFile(filename: string, list: List): void {
// Write out to file, updating version+timestamp if there was change // Write out to file, updating version+timestamp if there was change
export function writeToFileWithUpdate(filename: string, list: List): void { export function writeToFileWithUpdate(filename: string, list: List): void {
let listOld: List = undefined; let listOld: List = undefined;
let oldVersion: Version = new Version(0, 0, 0);
try { try {
listOld = readJsonFile(filename) as List; listOld = readJsonFile(filename) as List;
} catch (err) { } catch (err) {
@ -103,18 +102,16 @@ export function writeToFileWithUpdate(filename: string, list: List): void {
if (listOld === undefined) { if (listOld === undefined) {
changed = true; changed = true;
} else { } else {
oldVersion = listOld.version; list.version = listOld.version; // take over
const diffs = diffTokenlist(list, listOld); const diffs = diffTokenlist(list, listOld);
if (diffs != undefined) { if (diffs != undefined) {
//console.log("List has Changed", JSON.stringify(diffs)); //console.log("List has Changed", JSON.stringify(diffs));
changed = true; changed = true;
list.version = new Version(list.version.major + 1, 0, 0);
} }
} }
if (changed) { if (changed) {
// update version and time // update timestqamp
list.version.major = oldVersion.major + 1;
list.version.minor = 0;
list.version.patch = 0;
list.timestamp = (new Date()).toISOString(); list.timestamp = (new Date()).toISOString();
console.log(`Version and timestamp updated, ${list.version.major}.${list.version.minor}.${list.version.patch} timestamp ${list.timestamp}`); console.log(`Version and timestamp updated, ${list.version.major}.${list.version.minor}.${list.version.patch} timestamp ${list.timestamp}`);
} }