refactor(v2): move source files to be under website/src directory (#1609)

* refactor(v2): move source files to be under website/src directory

* misc: rename src constant
This commit is contained in:
Yangshun Tay 2019-06-15 09:59:23 -07:00 committed by GitHub
parent da3c91373e
commit ffbc7a37f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 56 additions and 37 deletions

View file

@ -11,7 +11,7 @@ const fs = require('fs');
const {encodePath, fileToPath, docuHash} = require('@docusaurus/utils'); const {encodePath, fileToPath, docuHash} = require('@docusaurus/utils');
const DEFAULT_OPTIONS = { const DEFAULT_OPTIONS = {
path: 'pages', // Path to data on filesystem, relative to site dir. path: 'src/pages', // Path to data on filesystem, relative to site dir.
routeBasePath: '', // URL Route. routeBasePath: '', // URL Route.
include: ['**/*.{js,jsx}'], // Extensions to include. include: ['**/*.{js,jsx}'], // Extensions to include.
}; };

View file

@ -3,6 +3,7 @@
## Unreleased ## Unreleased
- Added Google analytics and Google gtag plugins. - Added Google analytics and Google gtag plugins.
- Moved source components to `/src`. Please create a `website/src` directory and move your `/pages` and `/theme` code into it. This is to make it easier to integrate your website with external build/static analysis tooling (you can now just pass in `src/**/*.js` as the path to process).
## 2.0.0-alpha.19 ## 2.0.0-alpha.19

View file

@ -8,7 +8,11 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import shell from 'shelljs'; import shell from 'shelljs';
import {CONFIG_FILE_NAME} from '../constants'; import {
BUILD_DIR_NAME,
CONFIG_FILE_NAME,
GENERATED_FILES_DIR_NAME,
} from '../constants';
import {loadConfig} from '../server/config'; import {loadConfig} from '../server/config';
import {build} from './build'; import {build} from './build';
@ -131,9 +135,9 @@ export async function deploy(siteDir: string): Promise<void> {
shell.cd('../..'); shell.cd('../..');
const fromPath = path.join('build'); const fromPath = path.join(BUILD_DIR_NAME);
const toPath = path.join( const toPath = path.join(
'.docusaurus', GENERATED_FILES_DIR_NAME,
`${projectName}-${deploymentBranch}`, `${projectName}-${deploymentBranch}`,
); );

View file

@ -10,6 +10,8 @@ import fs from 'fs-extra';
import importFresh from 'import-fresh'; import importFresh from 'import-fresh';
import path from 'path'; import path from 'path';
import {THEME_PATH} from '../constants';
export async function swizzle( export async function swizzle(
siteDir: string, siteDir: string,
themeName: string, themeName: string,
@ -20,7 +22,7 @@ export async function swizzle(
let fromPath = pluginInstance.getThemePath(); let fromPath = pluginInstance.getThemePath();
if (fromPath) { if (fromPath) {
let toPath = path.resolve(siteDir, 'theme'); let toPath = path.resolve(siteDir, THEME_PATH);
if (componentName) { if (componentName) {
fromPath = path.join(fromPath, componentName); fromPath = path.join(fromPath, componentName);
toPath = path.join(toPath, componentName); toPath = path.join(toPath, componentName);

View file

@ -5,6 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
export const GENERATED_FILES_DIR_NAME = '.docusaurus'; export const BUILD_DIR_NAME = 'build';
export const STATIC_DIR_NAME = 'static';
export const CONFIG_FILE_NAME = 'docusaurus.config.js'; export const CONFIG_FILE_NAME = 'docusaurus.config.js';
export const GENERATED_FILES_DIR_NAME = '.docusaurus';
export const SRC_DIR_NAME = 'src';
export const STATIC_DIR_NAME = 'static';
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;

View file

@ -18,7 +18,7 @@ module.exports = {
'@docusaurus/plugin-content-docs', '@docusaurus/plugin-content-docs',
{ {
path: '../docs', path: '../docs',
sidebarPath: require.resolve('./sidebars.json'), sidebarPath: require.resolve('./sidebars.js'),
}, },
], ],
'@docusaurus/plugin-content-pages', '@docusaurus/plugin-content-pages',

View file

@ -0,0 +1,13 @@
/**
* 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.
*/
module.exports = {
docs: {
Test: ['foo/bar', 'foo/baz'],
Guides: ['hello'],
},
};

View file

@ -1,11 +0,0 @@
{
"docs": {
"Test": [
"foo/bar",
"foo/baz"
],
"Guides": [
"hello"
]
}
}

View file

@ -18,7 +18,7 @@ module.exports = {
'@docusaurus/plugin-content-docs', '@docusaurus/plugin-content-docs',
{ {
path: '../docs', path: '../docs',
sidebarPath: require.resolve('./sidebars.json'), sidebarPath: require.resolve('./sidebars.js'),
}, },
], ],
'@docusaurus/plugin-content-pages', '@docusaurus/plugin-content-pages',

View file

@ -0,0 +1,13 @@
/**
* 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.
*/
module.exports = {
docs: {
Test: ['foo/bar', 'foo/baz'],
Guides: ['hello'],
},
};

View file

@ -1,11 +0,0 @@
{
"docs": {
"Test": [
"foo/bar",
"foo/baz"
],
"Guides": [
"hello"
]
}
}

View file

@ -8,7 +8,12 @@
import {generate} from '@docusaurus/utils'; import {generate} from '@docusaurus/utils';
import _ from 'lodash'; import _ from 'lodash';
import path from 'path'; import path from 'path';
import {CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME} from '../constants'; import {
BUILD_DIR_NAME,
CONFIG_FILE_NAME,
GENERATED_FILES_DIR_NAME,
THEME_PATH,
} from '../constants';
import {loadClientModules} from './client-modules'; import {loadClientModules} from './client-modules';
import {loadConfig} from './config'; import {loadConfig} from './config';
import {loadPlugins} from './plugins'; import {loadPlugins} from './plugins';
@ -39,7 +44,7 @@ export async function load(
`export default ${JSON.stringify(siteConfig, null, 2)};`, `export default ${JSON.stringify(siteConfig, null, 2)};`,
); );
const outDir = path.resolve(siteDir, 'build'); const outDir = path.resolve(siteDir, BUILD_DIR_NAME);
const {baseUrl} = siteConfig; const {baseUrl} = siteConfig;
const context: LoadContext = { const context: LoadContext = {
@ -72,7 +77,7 @@ export async function load(
const pluginThemes = _.compact( const pluginThemes = _.compact(
plugins.map(plugin => plugin.getThemePath && plugin.getThemePath()), plugins.map(plugin => plugin.getThemePath && plugin.getThemePath()),
); );
const userTheme = path.resolve(siteDir, 'theme'); const userTheme = path.resolve(siteDir, THEME_PATH);
const alias = loadThemeAlias([fallbackTheme, ...pluginThemes, userTheme]); const alias = loadThemeAlias([fallbackTheme, ...pluginThemes, userTheme]);
// Make a fake plugin to resolve aliased theme components. // Make a fake plugin to resolve aliased theme components.
plugins.push({ plugins.push({

View file

@ -74,7 +74,7 @@ module.exports = {
sidebarPath: require.resolve('./sidebars.js'), sidebarPath: require.resolve('./sidebars.js'),
}, },
theme: { theme: {
customCss: require.resolve('./css/custom.css'), customCss: require.resolve('./src/css/custom.css'),
}, },
}, },
], ],

View file

@ -59,7 +59,7 @@ The headers are well-spaced so that the hierarchy is clear.
This will render in the browser as follows: This will render in the browser as follows:
import BrowserWindow from '../components/BrowserWindow'; import BrowserWindow from '../src/components/BrowserWindow';
<BrowserWindow url="http://localhost:3000"> <BrowserWindow url="http://localhost:3000">
<h2>Hello from Docusaurus</h2> <h2>Hello from Docusaurus</h2>

View file

@ -27,7 +27,7 @@ module.exports = {
postsPerPage: 3, postsPerPage: 3,
}, },
theme: { theme: {
customCss: require.resolve('./css/custom.css'), customCss: require.resolve('./src/css/custom.css'),
}, },
}, },
], ],