mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-25 22:18:01 +02:00
refactor: folder structure & filename
This commit is contained in:
parent
9070fb50ab
commit
dbf78c5c14
10 changed files with 79 additions and 74 deletions
116
bin/blogi.js
116
bin/blogi.js
|
@ -1,58 +1,58 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const chalk = require('chalk');
|
||||
const semver = require('semver');
|
||||
const path = require('path');
|
||||
const program = require('commander');
|
||||
const {dev, build} = require('../lib');
|
||||
const requiredVersion = require('../package.json').engines.node;
|
||||
|
||||
if (!semver.satisfies(process.version, requiredVersion)) {
|
||||
console.log(
|
||||
chalk.red(`\nMinimum node version not met :)`) +
|
||||
chalk.yellow(
|
||||
`\nYou are using Node ${
|
||||
process.version
|
||||
}, but blogi requires Node ${requiredVersion}.\n`
|
||||
)
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function wrapCommand(fn) {
|
||||
return (...args) =>
|
||||
fn(...args).catch(err => {
|
||||
console.error(chalk.red(err.stack));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
|
||||
program
|
||||
.version(require('../package.json').version)
|
||||
.usage('<command> [options]');
|
||||
|
||||
program
|
||||
.command('dev [targetDir]')
|
||||
.description('start development server')
|
||||
.option('-p, --port <port>', 'use specified port (default: 8080)')
|
||||
.action((dir = '.', {port}) => {
|
||||
wrapCommand(dev)(path.resolve(dir), {port});
|
||||
});
|
||||
|
||||
program
|
||||
.command('build [targetDir]')
|
||||
.description('build dir as static site')
|
||||
.option(
|
||||
'-d, --dest <outDir>',
|
||||
'specify build output dir (default: .blogi/dist)'
|
||||
)
|
||||
.action((dir = '.', {dest}) => {
|
||||
const outDir = dest ? path.resolve(dest) : null;
|
||||
wrapCommand(build)(path.resolve(dir), {outDir});
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
if (!process.argv.slice(2).length) {
|
||||
program.outputHelp();
|
||||
}
|
||||
#!/usr/bin/env node
|
||||
|
||||
const chalk = require('chalk');
|
||||
const semver = require('semver');
|
||||
const path = require('path');
|
||||
const program = require('commander');
|
||||
const {dev, build} = require('../lib');
|
||||
const requiredVersion = require('../package.json').engines.node;
|
||||
|
||||
if (!semver.satisfies(process.version, requiredVersion)) {
|
||||
console.log(
|
||||
chalk.red(`\nMinimum node version not met :)`) +
|
||||
chalk.yellow(
|
||||
`\nYou are using Node ${
|
||||
process.version
|
||||
}, but blogi requires Node ${requiredVersion}.\n`
|
||||
)
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function wrapCommand(fn) {
|
||||
return (...args) =>
|
||||
fn(...args).catch(err => {
|
||||
console.error(chalk.red(err.stack));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
|
||||
program
|
||||
.version(require('../package.json').version)
|
||||
.usage('<command> [options]');
|
||||
|
||||
program
|
||||
.command('dev [targetDir]')
|
||||
.description('start development server')
|
||||
.option('-p, --port <port>', 'use specified port (default: 8080)')
|
||||
.action((dir = '.', {port}) => {
|
||||
wrapCommand(dev)(path.resolve(dir), {port});
|
||||
});
|
||||
|
||||
program
|
||||
.command('build [targetDir]')
|
||||
.description('build dir as static site')
|
||||
.option(
|
||||
'-d, --dest <outDir>',
|
||||
'specify build output dir (default: .blogi/dist)'
|
||||
)
|
||||
.action((dir = '.', {dest}) => {
|
||||
const outDir = dest ? path.resolve(dest) : null;
|
||||
wrapCommand(build)(path.resolve(dir), {outDir});
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
if (!process.argv.slice(2).length) {
|
||||
program.outputHelp();
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ const serve = require('webpack-serve');
|
|||
const serveWaitpage = require('webpack-serve-waitpage');
|
||||
const webpackNiceLog = require('webpack-nicelog');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const load = require('./loader');
|
||||
const createDevConfig = require('./webpack/dev');
|
||||
const load = require('../loader');
|
||||
const createDevConfig = require('../webpack/dev');
|
||||
|
||||
async function getPort(port) {
|
||||
portfinder.basePort = parseInt(port, 10) || 8080;
|
||||
|
@ -61,7 +61,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
|
|||
{
|
||||
inject: false,
|
||||
hash: true,
|
||||
template: path.resolve(__dirname, 'core/index.html'),
|
||||
template: path.resolve(__dirname, '../core/index.html'),
|
||||
filename: 'index.html'
|
||||
}
|
||||
]);
|
|
@ -19,7 +19,7 @@ class App extends React.Component {
|
|||
<div key={path}>
|
||||
<Link to={path}>{path}</Link>
|
||||
</div>
|
||||
))}
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</BrowserRouter>
|
|
@ -1,2 +1,7 @@
|
|||
exports.dev = require('./dev');
|
||||
exports.build = require('./build');
|
||||
const dev = require('./commands/dev');
|
||||
const build = require('./commands/build');
|
||||
|
||||
module.exports = {
|
||||
dev,
|
||||
build
|
||||
};
|
||||
|
|
|
@ -25,12 +25,12 @@ module.exports = async function load(sourceDir) {
|
|||
? path.resolve(siteConfig.dest)
|
||||
: path.resolve(sourceDir, '.blogi/dist');
|
||||
|
||||
// resolve the path of our app theme/ layout
|
||||
const themePath =
|
||||
!siteConfig.themePath ||
|
||||
!fs.existsSync(path.resolve(sourceDir, siteConfig.themePath))
|
||||
? path.resolve(__dirname, '../theme')
|
||||
: siteConfig.themePath;
|
||||
// resolve the path of our app user interface layout
|
||||
const uiPath =
|
||||
!siteConfig.uiPath ||
|
||||
!fs.existsSync(path.resolve(sourceDir, siteConfig.uiPath))
|
||||
? path.resolve(__dirname, '../ui')
|
||||
: siteConfig.uiPath;
|
||||
|
||||
const publicPath = siteConfig.base || '/';
|
||||
|
||||
|
@ -39,7 +39,7 @@ module.exports = async function load(sourceDir) {
|
|||
blogDatas,
|
||||
sourceDir,
|
||||
outDir,
|
||||
themePath,
|
||||
uiPath,
|
||||
publicPath
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ const Config = require('webpack-chain');
|
|||
const path = require('path');
|
||||
|
||||
module.exports = function createBaseConfig(props) {
|
||||
const {outDir, themePath, sourceDir, publicPath} = props;
|
||||
const {outDir, uiPath, sourceDir, publicPath} = props;
|
||||
|
||||
const config = new Config();
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
|
@ -17,7 +17,7 @@ module.exports = function createBaseConfig(props) {
|
|||
|
||||
config.resolve
|
||||
.set('symlinks', true)
|
||||
.alias.set('@theme', themePath)
|
||||
.alias.set('@ui', uiPath)
|
||||
.set('@source', sourceDir)
|
||||
.set('@generated', path.resolve(__dirname, '../generated'))
|
||||
.set('@core', path.resolve(__dirname, '../core'))
|
||||
|
|
|
@ -4,7 +4,7 @@ const createBaseConfig = require('./base');
|
|||
module.exports = function createDevConfig(props) {
|
||||
const config = createBaseConfig(props);
|
||||
|
||||
config.entry('main').add(path.resolve(__dirname, '../core/index.js'));
|
||||
config.entry('main').add(path.resolve(__dirname, '../core/devEntry.js'));
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue