Don't start server if versions.js is missing but versioning is enabled (#714)

* don't start server if versions.js missing but versioning is enabled

* refactor

* fix nits

* refactor & address review
This commit is contained in:
Endilie Yacop Sucipto 2018-06-03 14:45:36 +08:00 committed by Yangshun Tay
parent 2bd9a148c1
commit d28b864a59
3 changed files with 24 additions and 7 deletions

View file

@ -8,12 +8,14 @@
const CWD = process.cwd();
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const siteConfig = require(CWD + '/siteConfig.js');
const join = path.join;
const languages_js = join(CWD, 'languages.js');
const versions_json = join(CWD, 'versions.json');
const versions_js = join(CWD, 'pages/en/versions.js');
class Translation {
constructor() {
@ -46,10 +48,19 @@ class Versioning {
this.enabled = false;
this.defaultVersion = null;
this.versions = [];
this.missingVersionsPage = false;
this._load();
}
printMissingVersionsPageError() {
console.error(
`${chalk.yellow('No versions.js file found!')}` +
`\nYou should create your versions.js file in pages/en directory.` +
`\nPlease refer to https://docusaurus.io/docs/en/versioning.html.`
);
}
_load() {
if (fs.existsSync(versions_json)) {
this.enabled = true;
@ -58,6 +69,10 @@ class Versioning {
? siteConfig.defaultVersionShown
: this.versions[0]; // otherwise show the latest version (other than next/master)
}
if (!fs.existsSync(versions_js)) {
this.missingVersionsPage = true;
}
}
}