mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-27 05:28:43 +02:00
chore(v2): rename/ restructure folder (#1351)
* chore(v2): restructure folder * typo * fix test
This commit is contained in:
parent
b6aa6dac89
commit
15bc33df50
49 changed files with 31 additions and 43 deletions
|
@ -11,7 +11,7 @@ import {NavLink} from 'react-router-dom';
|
||||||
|
|
||||||
import DocusaurusContext from '@docusaurus/context';
|
import DocusaurusContext from '@docusaurus/context';
|
||||||
|
|
||||||
import preload from '../core/preload';
|
import preload from '../preload';
|
||||||
|
|
||||||
const externalRegex = /^(https?:|\/\/)/;
|
const externalRegex = /^(https?:|\/\/)/;
|
||||||
|
|
|
@ -13,7 +13,7 @@ const path = require('path');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const globby = require('globby');
|
const globby = require('globby');
|
||||||
const load = require('../load');
|
const load = require('../server/load');
|
||||||
const createServerConfig = require('../webpack/server');
|
const createServerConfig = require('../webpack/server');
|
||||||
const createClientConfig = require('../webpack/client');
|
const createClientConfig = require('../webpack/client');
|
||||||
const {applyConfigureWebpack} = require('../webpack/utils');
|
const {applyConfigureWebpack} = require('../webpack/utils');
|
||||||
|
|
|
@ -9,7 +9,8 @@ const path = require('path');
|
||||||
const shell = require('shelljs');
|
const shell = require('shelljs');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const build = require('./build');
|
const build = require('./build');
|
||||||
const loadConfig = require('../load/config');
|
const loadConfig = require('../server/load/config');
|
||||||
|
const {CONFIG_FILE_NAME} = require('../constants');
|
||||||
|
|
||||||
module.exports = async function deploy(siteDir) {
|
module.exports = async function deploy(siteDir) {
|
||||||
console.log('Deploy command invoked ...');
|
console.log('Deploy command invoked ...');
|
||||||
|
@ -27,16 +28,14 @@ module.exports = async function deploy(siteDir) {
|
||||||
process.env.CURRENT_BRANCH ||
|
process.env.CURRENT_BRANCH ||
|
||||||
shell.exec('git rev-parse --abbrev-ref HEAD').stdout.trim();
|
shell.exec('git rev-parse --abbrev-ref HEAD').stdout.trim();
|
||||||
|
|
||||||
const siteConfig = loadConfig.loadConfig(siteDir);
|
const siteConfig = loadConfig(siteDir);
|
||||||
const organizationName =
|
const organizationName =
|
||||||
process.env.ORGANIZATION_NAME ||
|
process.env.ORGANIZATION_NAME ||
|
||||||
process.env.CIRCLE_PROJECT_USERNAME ||
|
process.env.CIRCLE_PROJECT_USERNAME ||
|
||||||
siteConfig.organizationName;
|
siteConfig.organizationName;
|
||||||
if (!organizationName) {
|
if (!organizationName) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Missing project organization name. Did you forget to define 'organizationName' in ${
|
`Missing project organization name. Did you forget to define 'organizationName' in ${CONFIG_FILE_NAME}? You may also export it via the organizationName environment variable.`,
|
||||||
loadConfig.configFileName
|
|
||||||
}? You may also export it via the organizationName environment variable.`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const projectName =
|
const projectName =
|
||||||
|
@ -45,9 +44,7 @@ module.exports = async function deploy(siteDir) {
|
||||||
siteConfig.projectName;
|
siteConfig.projectName;
|
||||||
if (!projectName) {
|
if (!projectName) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Missing project name. Did you forget to define 'projectName' in ${
|
`Missing project name. Did you forget to define 'projectName' in ${CONFIG_FILE_NAME}? You may also export it via the projectName environment variable.`,
|
||||||
loadConfig.configFileName
|
|
||||||
}? You may also export it via the projectName environment variable.`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ const chalk = require('chalk');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = async function eject(siteDir) {
|
module.exports = async function eject(siteDir) {
|
||||||
const defaultTheme = path.resolve(__dirname, '..', 'theme');
|
const defaultTheme = path.resolve(__dirname, '..', 'default-theme');
|
||||||
const customTheme = path.resolve(siteDir, 'theme');
|
const customTheme = path.resolve(siteDir, 'theme');
|
||||||
await fs.copy(defaultTheme, customTheme);
|
await fs.copy(defaultTheme, customTheme);
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlug
|
||||||
const WebpackDevServer = require('webpack-dev-server');
|
const WebpackDevServer = require('webpack-dev-server');
|
||||||
const merge = require('webpack-merge');
|
const merge = require('webpack-merge');
|
||||||
const {normalizeUrl} = require('@docusaurus/utils');
|
const {normalizeUrl} = require('@docusaurus/utils');
|
||||||
const load = require('../load');
|
const load = require('../server/load');
|
||||||
const loadConfig = require('../load/config');
|
const {CONFIG_FILE_NAME} = require('../constants');
|
||||||
const createClientConfig = require('../webpack/client');
|
const createClientConfig = require('../webpack/client');
|
||||||
const {applyConfigureWebpack} = require('../webpack/utils');
|
const {applyConfigureWebpack} = require('../webpack/utils');
|
||||||
|
|
||||||
|
@ -64,13 +64,10 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).map(normalizeToSiteDir);
|
).map(normalizeToSiteDir);
|
||||||
const fsWatcher = chokidar.watch(
|
const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], {
|
||||||
[...pluginPaths, loadConfig.configFileName],
|
cwd: siteDir,
|
||||||
{
|
ignoreInitial: true,
|
||||||
cwd: siteDir,
|
});
|
||||||
ignoreInitial: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach(event =>
|
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach(event =>
|
||||||
fsWatcher.on(event, reload),
|
fsWatcher.on(event, reload),
|
||||||
);
|
);
|
||||||
|
@ -93,7 +90,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
||||||
hash: true,
|
hash: true,
|
||||||
template: path.resolve(
|
template: path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../core/templates/index.html.template.ejs',
|
'../client/templates/index.html.template.ejs',
|
||||||
),
|
),
|
||||||
filename: 'index.html',
|
filename: 'index.html',
|
||||||
title: siteConfig.title,
|
title: siteConfig.title,
|
||||||
|
|
|
@ -7,4 +7,5 @@
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
GENERATED_FILES_DIR_NAME: '.docusaurus',
|
GENERATED_FILES_DIR_NAME: '.docusaurus',
|
||||||
|
CONFIG_FILE_NAME: 'docusaurus.config.js',
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const {CONFIG_FILE_NAME} = require('../../constants');
|
||||||
const CONFIG_FILE_NAME = 'docusaurus.config.js';
|
|
||||||
|
|
||||||
const REQUIRED_FIELDS = [
|
const REQUIRED_FIELDS = [
|
||||||
'baseUrl',
|
'baseUrl',
|
||||||
|
@ -115,7 +114,4 @@ function loadConfig(siteDir, deleteCache = true) {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = loadConfig;
|
||||||
configFileName: CONFIG_FILE_NAME,
|
|
||||||
loadConfig,
|
|
||||||
};
|
|
|
@ -8,7 +8,7 @@
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {idx} = require('@docusaurus/utils');
|
const {idx} = require('@docusaurus/utils');
|
||||||
const loadConfig = require('./config');
|
const {CONFIG_FILE_NAME} = require('../../constants');
|
||||||
|
|
||||||
module.exports = function loadEnv({siteDir, siteConfig}) {
|
module.exports = function loadEnv({siteDir, siteConfig}) {
|
||||||
// Translation.
|
// Translation.
|
||||||
|
@ -38,9 +38,7 @@ module.exports = function loadEnv({siteDir, siteConfig}) {
|
||||||
|
|
||||||
if (!defaultLanguage) {
|
if (!defaultLanguage) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Please set a default language in ${
|
`Please set a default language in ${CONFIG_FILE_NAME} which is enabled in languages.js`,
|
||||||
loadConfig.configFileName
|
|
||||||
} which is enabled in languages.js`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ const loadEnv = require('./env');
|
||||||
const loadTheme = require('./theme');
|
const loadTheme = require('./theme');
|
||||||
const loadRoutes = require('./routes');
|
const loadRoutes = require('./routes');
|
||||||
const loadPlugins = require('./plugins');
|
const loadPlugins = require('./plugins');
|
||||||
const constants = require('../constants');
|
const constants = require('../../constants');
|
||||||
|
|
||||||
module.exports = async function load(siteDir, cliOptions = {}) {
|
module.exports = async function load(siteDir, cliOptions = {}) {
|
||||||
const generatedFilesDir = path.resolve(
|
const generatedFilesDir = path.resolve(
|
||||||
|
@ -25,10 +25,10 @@ module.exports = async function load(siteDir, cliOptions = {}) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Site Config
|
// Site Config
|
||||||
const siteConfig = loadConfig.loadConfig(siteDir);
|
const siteConfig = loadConfig(siteDir);
|
||||||
await generate(
|
await generate(
|
||||||
generatedFilesDir,
|
generatedFilesDir,
|
||||||
loadConfig.configFileName,
|
constants.CONFIG_FILE_NAME,
|
||||||
`export default ${JSON.stringify(siteConfig, null, 2)};`,
|
`export default ${JSON.stringify(siteConfig, null, 2)};`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ module.exports = async function load(siteDir, cliOptions = {}) {
|
||||||
// Generate contents metadata.
|
// Generate contents metadata.
|
||||||
const metadataTemplateFile = path.resolve(
|
const metadataTemplateFile = path.resolve(
|
||||||
__dirname,
|
__dirname,
|
||||||
'../core/templates/metadata.template.ejs',
|
'../../client/templates/metadata.template.ejs',
|
||||||
);
|
);
|
||||||
const metadataTemplate = fs.readFileSync(metadataTemplateFile).toString();
|
const metadataTemplate = fs.readFileSync(metadataTemplateFile).toString();
|
||||||
const pluginMetadataImports = _.compact(pluginsLoadedContent).map(
|
const pluginMetadataImports = _.compact(pluginsLoadedContent).map(
|
|
@ -12,7 +12,7 @@ module.exports = function loadConfig(siteDir) {
|
||||||
const customThemePath = path.resolve(siteDir, 'theme');
|
const customThemePath = path.resolve(siteDir, 'theme');
|
||||||
const themePath = fs.existsSync(customThemePath)
|
const themePath = fs.existsSync(customThemePath)
|
||||||
? customThemePath
|
? customThemePath
|
||||||
: path.resolve(__dirname, '../theme');
|
: path.resolve(__dirname, '../../default-theme');
|
||||||
|
|
||||||
const themeComponents = [
|
const themeComponents = [
|
||||||
'Doc',
|
'Doc',
|
|
@ -43,8 +43,7 @@ module.exports = function createBaseConfig(props, isServer) {
|
||||||
'@site': siteDir,
|
'@site': siteDir,
|
||||||
'@build': outDir,
|
'@build': outDir,
|
||||||
'@generated': generatedFilesDir,
|
'@generated': generatedFilesDir,
|
||||||
'@core': path.resolve(__dirname, '../core'),
|
'@docusaurus': path.resolve(__dirname, '../client/exports'),
|
||||||
'@docusaurus': path.resolve(__dirname, '../docusaurus'),
|
|
||||||
},
|
},
|
||||||
modules: [
|
modules: [
|
||||||
'node_modules',
|
'node_modules',
|
||||||
|
|
|
@ -18,7 +18,7 @@ module.exports = function createClientConfig(props) {
|
||||||
|
|
||||||
const clientConfig = merge(config, {
|
const clientConfig = merge(config, {
|
||||||
entry: {
|
entry: {
|
||||||
main: path.resolve(__dirname, '../core/clientEntry.js'),
|
main: path.resolve(__dirname, '../client/clientEntry.js'),
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// Generate manifests file
|
// Generate manifests file
|
||||||
|
|
|
@ -19,7 +19,7 @@ module.exports = function createServerConfig(props) {
|
||||||
|
|
||||||
const serverConfig = merge(config, {
|
const serverConfig = merge(config, {
|
||||||
entry: {
|
entry: {
|
||||||
main: path.resolve(__dirname, '../core/serverEntry.js'),
|
main: path.resolve(__dirname, '../client/serverEntry.js'),
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: 'server.bundle.js',
|
filename: 'server.bundle.js',
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {loadConfig} from '@lib/load/config';
|
import loadConfig from '@lib/server/load/config';
|
||||||
import loadSetup from '../loadSetup';
|
import loadSetup from '../loadSetup';
|
||||||
|
|
||||||
describe('loadConfig', () => {
|
describe('loadConfig', () => {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import loadEnv from '@lib/load/env';
|
import loadEnv from '@lib/server/load/env';
|
||||||
import loadSetup from '../loadSetup';
|
import loadSetup from '../loadSetup';
|
||||||
|
|
||||||
describe('loadEnv', () => {
|
describe('loadEnv', () => {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
import '@babel/polyfill';
|
import '@babel/polyfill';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import load from '@lib/load';
|
import load from '@lib/server/load';
|
||||||
|
|
||||||
// Helper methods to setup dummy/fake projects
|
// Helper methods to setup dummy/fake projects
|
||||||
const loadSetup = async name => {
|
const loadSetup = async name => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue