mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
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:
parent
2bd9a148c1
commit
d28b864a59
3 changed files with 24 additions and 7 deletions
|
@ -8,12 +8,14 @@
|
||||||
const CWD = process.cwd();
|
const CWD = process.cwd();
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const chalk = require('chalk');
|
||||||
const siteConfig = require(CWD + '/siteConfig.js');
|
const siteConfig = require(CWD + '/siteConfig.js');
|
||||||
|
|
||||||
const join = path.join;
|
const join = path.join;
|
||||||
|
|
||||||
const languages_js = join(CWD, 'languages.js');
|
const languages_js = join(CWD, 'languages.js');
|
||||||
const versions_json = join(CWD, 'versions.json');
|
const versions_json = join(CWD, 'versions.json');
|
||||||
|
const versions_js = join(CWD, 'pages/en/versions.js');
|
||||||
|
|
||||||
class Translation {
|
class Translation {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -46,10 +48,19 @@ class Versioning {
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
this.defaultVersion = null;
|
this.defaultVersion = null;
|
||||||
this.versions = [];
|
this.versions = [];
|
||||||
|
this.missingVersionsPage = false;
|
||||||
|
|
||||||
this._load();
|
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() {
|
_load() {
|
||||||
if (fs.existsSync(versions_json)) {
|
if (fs.existsSync(versions_json)) {
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
|
@ -58,6 +69,10 @@ class Versioning {
|
||||||
? siteConfig.defaultVersionShown
|
? siteConfig.defaultVersionShown
|
||||||
: this.versions[0]; // otherwise show the latest version (other than next/master)
|
: this.versions[0]; // otherwise show the latest version (other than next/master)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(versions_js)) {
|
||||||
|
this.missingVersionsPage = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ const chalk = require('chalk');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const openBrowser = require('react-dev-utils/openBrowser');
|
const openBrowser = require('react-dev-utils/openBrowser');
|
||||||
const CWD = process.cwd();
|
const CWD = process.cwd();
|
||||||
|
const env = require('./server/env.js');
|
||||||
|
|
||||||
if (!fs.existsSync(CWD + '/siteConfig.js')) {
|
if (!fs.existsSync(CWD + '/siteConfig.js')) {
|
||||||
console.error(
|
console.error(
|
||||||
|
@ -34,6 +35,11 @@ if (!fs.existsSync(CWD + '/siteConfig.js')) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (env.versioning.enabled && env.versioning.missingVersionsPage) {
|
||||||
|
env.versioning.printMissingVersionsPageError();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const program = require('commander');
|
const program = require('commander');
|
||||||
|
|
||||||
program.option('--port <number>', 'Specify port number').parse(process.argv);
|
program.option('--port <number>', 'Specify port number').parse(process.argv);
|
||||||
|
|
|
@ -14,6 +14,7 @@ const mkdirp = require('mkdirp');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const readMetadata = require('./server/readMetadata.js');
|
const readMetadata = require('./server/readMetadata.js');
|
||||||
const versionFallback = require('./server/versionFallback.js');
|
const versionFallback = require('./server/versionFallback.js');
|
||||||
|
const env = require('./server/env.js');
|
||||||
|
|
||||||
const CWD = process.cwd();
|
const CWD = process.cwd();
|
||||||
let versions;
|
let versions;
|
||||||
|
@ -33,13 +34,8 @@ program
|
||||||
})
|
})
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
const hasVersionFile = fs.existsSync(CWD + '/pages/en/versions.js');
|
if (env.versioning.missingVersionsPage) {
|
||||||
if (!hasVersionFile) {
|
env.versioning.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.`
|
|
||||||
);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue