mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +02:00
chore: move to monorepo (#1297)
* chore: move to monorepo * lint all js file * simplify circleCI * fix failing tests * fix tests due to folder rename * fix test since v1 website is renamed
This commit is contained in:
parent
6b1d2e8c9c
commit
1f91d19a8c
619 changed files with 12713 additions and 26817 deletions
85
packages/docusaurus-1.x/lib/server/env.js
Normal file
85
packages/docusaurus-1.x/lib/server/env.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
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 languagesFile = join(CWD, 'languages.js');
|
||||
const versionsJSONFile = join(CWD, 'versions.json');
|
||||
const versionsFile = join(CWD, 'pages/en/versions.js');
|
||||
|
||||
class Translation {
|
||||
constructor() {
|
||||
this.enabled = false;
|
||||
this.languages = [
|
||||
{
|
||||
enabled: true,
|
||||
name: 'English',
|
||||
tag: 'en',
|
||||
},
|
||||
];
|
||||
|
||||
this.load();
|
||||
}
|
||||
|
||||
enabledLanguages = () => this.languages.filter(lang => lang.enabled);
|
||||
|
||||
load() {
|
||||
if (fs.existsSync(languagesFile)) {
|
||||
this.enabled = true;
|
||||
this.languages = require(languagesFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Versioning {
|
||||
constructor() {
|
||||
this.enabled = false;
|
||||
this.latestVersion = null;
|
||||
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(versionsJSONFile)) {
|
||||
this.enabled = true;
|
||||
this.versions = JSON.parse(fs.readFileSync(versionsJSONFile, 'utf8'));
|
||||
this.latestVersion = this.versions[0];
|
||||
this.defaultVersion = siteConfig.defaultVersionShown
|
||||
? siteConfig.defaultVersionShown
|
||||
: this.latestVersion; // otherwise show the latest version (other than next/master)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(versionsFile)) {
|
||||
this.missingVersionsPage = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const env = {
|
||||
translation: new Translation(),
|
||||
versioning: new Versioning(),
|
||||
};
|
||||
|
||||
module.exports = env;
|
Loading…
Add table
Add a link
Reference in a new issue