Allow overwriting versions of same name

This commit is contained in:
oldmud0 2019-04-03 16:47:16 -05:00
parent 153c458f9e
commit bc92942d29

View File

@ -26,15 +26,15 @@ argParser.addArgument("version", {
}); });
argParser.addArgument([ "-f", "--full" ], { argParser.addArgument([ "-f", "--full" ], {
metavar: "<full zip file>", type: isFile, nargs: 1, metavar: "<full zip file>", type: isFile, nargs: 1,
dest: "fullZipFile" dest: "fullZipFileArgs"
}); });
argParser.addArgument([ "-i", "--incremental" ], { argParser.addArgument([ "-i", "--incremental" ], {
type: isFile, nargs: 2, dest: "incremental", type: isFile, nargs: 2, dest: "incrementalArgs",
metavar: ["<incremental zip file>", "<file containing list of deleted files>"] metavar: ["<incremental zip file>", "<file containing list of deleted files>"]
}); });
argParser.addArgument([ "-e", "--executable" ], { argParser.addArgument([ "-e", "--executable" ], {
metavar: "[executable file]", nargs: 1, metavar: "[executable file]", nargs: 1,
dest: "executable" dest: "executableArgs"
}); });
const { const {
@ -49,6 +49,12 @@ const [incrementalZipFile, deletionsFile] = incrementalArgs || [];
const [fullZipFile] = fullZipFileArgs || []; const [fullZipFile] = fullZipFileArgs || [];
const [executable] = executableArgs || []; const [executable] = executableArgs || [];
// Do one final check
if (!incrementalZipFile && !fullZipFile) {
console.error("No download archive specified! Abort.");
process.exit(1);
}
const manifest = JSON.parse(fs.readFileSync(manifestFile)); const manifest = JSON.parse(fs.readFileSync(manifestFile));
const deleteActions = deletionsFile ? fs.readFileSync(deletionsFile) const deleteActions = deletionsFile ? fs.readFileSync(deletionsFile)
@ -61,7 +67,7 @@ const deleteActions = deletionsFile ? fs.readFileSync(deletionsFile)
const urlBase = "https://s3.wasabisys.com/ao-downloads/"; const urlBase = "https://s3.wasabisys.com/ao-downloads/";
manifest.versions = [{ const versionEntry = {
version, version,
executable, executable,
prev: manifest.versions[0] ? manifest.versions[0].version : undefined, prev: manifest.versions[0] ? manifest.versions[0].version : undefined,
@ -84,6 +90,18 @@ manifest.versions = [{
.digest("hex") .digest("hex")
} }
] : undefined ] : undefined
}, ...manifest.versions]; };
const existingVersion = manifest.versions.filter(v => v.version == version);
if (existingVersion) {
console.warn(`Warning: version ${version} already exists. Adding new values.`);
// Don't overwrite prev - it will cause headaches
delete versionEntry.prev;
Object.assign(existingVersion, versionEntry);
} else {
manifest.versions = [versionEntry, ...manifest.versions];
}
fs.writeFileSync(manifestFile, JSON.stringify(manifest, null, 4)); fs.writeFileSync(manifestFile, JSON.stringify(manifest, null, 4));