diff --git a/lib/server/readCategories.js b/lib/server/readCategories.js index 8b19614679..d72d238a5d 100644 --- a/lib/server/readCategories.js +++ b/lib/server/readCategories.js @@ -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; diff --git a/lib/server/versionFallback.js b/lib/server/versionFallback.js index b7f5f4e85f..fdc9fffd31 100644 --- a/lib/server/versionFallback.js +++ b/lib/server/versionFallback.js @@ -20,7 +20,7 @@ const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js"); let versions; if (fs.existsSync(CWD + "/versions.json")) { - versions = require(CWD + "/versions.json"); + versions = require(CWD + "/versions.json"); } else { versions = []; } @@ -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 diff --git a/lib/version.js b/lib/version.js index 7aefd374ee..328262043e 100644 --- a/lib/version.js +++ b/lib/version.js @@ -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")}`);