Update messages for versioning

This commit is contained in:
Frank Li 2017-08-09 16:17:39 -07:00
parent cdea25eceb
commit 88359ea845
3 changed files with 16 additions and 7 deletions

View file

@ -56,7 +56,9 @@ function readCategories(sidebar) {
if (metadata.next) {
if (!articles[metadata.next]) {
throw new Error(
"Improper sidebars.json file. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated."
metadata.version
? `Improper sidebars file for version ${metadata.version}. Make sure that all documents with ids specified in this version's sidebar file exist and that no ids are repeated.`
: `Improper sidebars.json file. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated.`
);
}
previous[articles[metadata.next].id] = metadata.id;

View file

@ -124,7 +124,9 @@ function docVersion(id, req_version) {
return versions[i];
}
}
return null;
throw new Error(
`No document available to use for version ${req_version} of document with id ${id}. Verify that all version files are correct.`
);
}
// returns whether a given file has content that differ from the
@ -226,7 +228,7 @@ function docData() {
// return the version of the sidebar to use given a requested version
function sidebarVersion(req_version) {
// iterate through versions until a version less than or equal to the requested
// is found, then check if that verison has an available file to use
// is found, then check if that version has an available file to use
let requestedFound = false;
for (let i = 0; i < versions.length; i++) {
if (versions[i] === req_version) {
@ -243,7 +245,9 @@ function sidebarVersion(req_version) {
return versions[i];
}
}
return null;
throw new Error(
`No sidebar file available to use for version ${req_version}. Verify that all version files are correct.`
);
}
// return whether or not the current sidebars.json file differs from the

View file

@ -13,6 +13,7 @@ const glob = require("glob");
const fs = require("fs-extra");
const path = require("path");
const mkdirp = require("mkdirp");
const chalk = require("chalk");
const readMetadata = require("./server/readMetadata.js");
const versionFallback = require("./server/versionFallback.js");
@ -36,14 +37,14 @@ program
if (typeof version === "undefined") {
console.error(
"No version number specified!\nPass the version you wish to create as an argument.\nEx: 1.0.0"
`${chalk.yellow("No version number specified!")}\nPass the version you wish to create as an argument.\nEx: 1.0.0`
);
process.exit(1);
}
if (versions.includes(version)) {
console.error(
"This verison already exists!\nSpecify a new version to create that does not already exist."
`${chalk.yellow("This version already exists!")}\nSpecify a new version to create that does not already exist.`
);
process.exit(1);
}
@ -120,3 +121,5 @@ if (versionFallback.diffLatestSidebar()) {
// update versions.json file
versions.unshift(version);
fs.writeFileSync(CWD + "/versions.json", JSON.stringify(versions, null, 2));
console.log(`${chalk.green("Version " + version + " created!\n")}`);