Improved the change list algorithm
parent
f231c5a44d
commit
6a2b592817
|
@ -2,6 +2,7 @@ import {ChangeLog} from "tc-shared/update/ChangeLog";
|
||||||
|
|
||||||
export interface Updater {
|
export interface Updater {
|
||||||
getChangeLog() : ChangeLog;
|
getChangeLog() : ChangeLog;
|
||||||
|
getChangeList(oldVersion: string) : ChangeLog;
|
||||||
|
|
||||||
getLastUsedVersion() : string;
|
getLastUsedVersion() : string;
|
||||||
getCurrentVersion() : string;
|
getCurrentVersion() : string;
|
||||||
|
|
|
@ -3,9 +3,11 @@ import * as loader from "tc-loader";
|
||||||
import {Stage} from "tc-loader";
|
import {Stage} from "tc-loader";
|
||||||
import {setUIUpdater} from "tc-shared/update/index";
|
import {setUIUpdater} from "tc-shared/update/index";
|
||||||
import {Updater} from "tc-shared/update/Updater";
|
import {Updater} from "tc-shared/update/Updater";
|
||||||
|
import {LogCategory, logError, logWarn} from "tc-shared/log";
|
||||||
|
|
||||||
const ChangeLogContents: string = require("../../../ChangeLog.md");
|
const ChangeLogContents: string = require("../../../ChangeLog.md");
|
||||||
const EntryRegex = /^\* \*\*([0-9]{2})\.([0-9]{2})\.([0-9]{2})\*\*$/m;
|
const EntryRegex = /^\* \*\*([0-9]{2})\.([0-9]{2})\.([0-9]{2})\*\*$/m;
|
||||||
|
const TimeStampRegex = /^([0-9]{2})\.([0-9]{2})\.([0-9]{2})$/m;
|
||||||
|
|
||||||
function parseChangeLogEntry(lines: string[], index: number) : { entries: ChangeSetEntry[], index: number } {
|
function parseChangeLogEntry(lines: string[], index: number) : { entries: ChangeSetEntry[], index: number } {
|
||||||
const entryDepth = lines[index].indexOf("-");
|
const entryDepth = lines[index].indexOf("-");
|
||||||
|
@ -108,6 +110,33 @@ class WebUpdater implements Updater {
|
||||||
return this.changeLog;
|
return this.changeLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getChangeList(oldVersion: string): ChangeLog {
|
||||||
|
let changes = {
|
||||||
|
changes: [],
|
||||||
|
currentVersion: this.currentVersion
|
||||||
|
} as ChangeLog;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [ _, oldDay, oldMonth, oldYear ] = oldVersion.match(TimeStampRegex);
|
||||||
|
const oldDate = new Date(parseInt(oldYear), parseInt(oldMonth), parseInt(oldDay));
|
||||||
|
|
||||||
|
for(const change of this.getChangeLog().changes) {
|
||||||
|
const [ _, currentDay, currentMonth, currentYear ] = change.timestamp.match(TimeStampRegex);
|
||||||
|
const currentDate = new Date(parseInt(currentYear), parseInt(currentMonth), parseInt(currentDay));
|
||||||
|
|
||||||
|
if(currentDate.getTime() <= oldDate.getTime())
|
||||||
|
break;
|
||||||
|
|
||||||
|
changes.changes.push(change);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logError(LogCategory.GENERAL, tr("Failed to gather a change list from version %s: %o"), oldVersion, error);
|
||||||
|
return this.getChangeLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
|
|
||||||
getCurrentVersion(): string {
|
getCurrentVersion(): string {
|
||||||
return this.currentVersion;
|
return this.currentVersion;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,19 +23,7 @@ function getChangedChangeLog(updater: Updater) : ChangeLog | undefined {
|
||||||
if(updater.getCurrentVersion() === updater.getLastUsedVersion())
|
if(updater.getCurrentVersion() === updater.getLastUsedVersion())
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
let changes = {
|
const changes = updater.getChangeList(updater.getLastUsedVersion());
|
||||||
changes: [],
|
|
||||||
currentVersion: updater.getCurrentVersion()
|
|
||||||
} as ChangeLog;
|
|
||||||
|
|
||||||
let usedVersion = updater.getLastUsedVersion();
|
|
||||||
for(const change of updater.getChangeLog().changes) {
|
|
||||||
if(change.timestamp === usedVersion)
|
|
||||||
break;
|
|
||||||
|
|
||||||
changes.changes.push(change);
|
|
||||||
}
|
|
||||||
|
|
||||||
return changes.changes.length > 0 ? changes : undefined;
|
return changes.changes.length > 0 ? changes : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue