mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-05 19:07:48 +02:00
refactor: use docusaurus structure
This commit is contained in:
parent
44eb7655ca
commit
45cf88e059
24 changed files with 152 additions and 123 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ node_modules
|
||||||
dist
|
dist
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
generated
|
generated
|
||||||
|
website/node_modules
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
# blogi
|
# Munseo
|
||||||
|
📝⚡️ Transform your document (문서) to a website
|
58
bin/blogi.js
58
bin/blogi.js
|
@ -1,58 +0,0 @@
|
||||||
#!/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();
|
|
||||||
}
|
|
65
bin/munseo.js
Normal file
65
bin/munseo.js
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const semver = require('semver');
|
||||||
|
const path = require('path');
|
||||||
|
const program = require('commander');
|
||||||
|
const {build, init, start} = 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
|
||||||
|
}, Requirement: 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('build [siteDir]')
|
||||||
|
.description('Build website')
|
||||||
|
.option(
|
||||||
|
'-sic, --skip-image-compression <skipImageCompression>',
|
||||||
|
'Skip compression of image assets (default: false)'
|
||||||
|
)
|
||||||
|
.action((siteDir = '.', {skipImageCompression}) => {
|
||||||
|
wrapCommand(build)(path.resolve(siteDir), {skipImageCompression});
|
||||||
|
});
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('init [projectDir]')
|
||||||
|
.description('Initialize website')
|
||||||
|
.action((projectDir = '.') => {
|
||||||
|
wrapCommand(init)(path.resolve(projectDir));
|
||||||
|
});
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('start [siteDir]')
|
||||||
|
.description('Start development server')
|
||||||
|
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
||||||
|
.option('-nw, --no-watch <noWatch>', 'disable live reload (default: false)')
|
||||||
|
.action((siteDir = '.', {port, noWatch}) => {
|
||||||
|
wrapCommand(start)(path.resolve(siteDir), {port, noWatch});
|
||||||
|
});
|
||||||
|
|
||||||
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
if (!process.argv.slice(2).length) {
|
||||||
|
program.outputHelp()
|
||||||
|
}
|
6
docs/foo/bar.md
Normal file
6
docs/foo/bar.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
id: bar
|
||||||
|
title: Bar
|
||||||
|
---
|
||||||
|
|
||||||
|
Lorem ipsumsdsdsad
|
6
docs/foo/baz.md
Normal file
6
docs/foo/baz.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
id: baz
|
||||||
|
title: baz
|
||||||
|
---
|
||||||
|
|
||||||
|
Life is so good
|
6
docs/hello.md
Normal file
6
docs/hello.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
id: hello
|
||||||
|
title: Hello, World !
|
||||||
|
---
|
||||||
|
|
||||||
|
Hi, Endilie here :)
|
6
docs/intro.md
Normal file
6
docs/intro.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
id: intro
|
||||||
|
title: Introducing Munseo
|
||||||
|
---
|
||||||
|
|
||||||
|
Introducing Munseo :)
|
|
@ -1,4 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
title: 'Hello World',
|
|
||||||
description: 'Hello World'
|
|
||||||
};
|
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
title: Lorem ipsum
|
|
||||||
date: 2018-06-20
|
|
||||||
---
|
|
||||||
|
|
||||||
Lorem ipsumsdsdsad
|
|
|
@ -1,5 +0,0 @@
|
||||||
---
|
|
||||||
title: Baz
|
|
||||||
date: 2018-05-20
|
|
||||||
---
|
|
||||||
Life is so good
|
|
|
@ -1,12 +0,0 @@
|
||||||
---
|
|
||||||
title: Hello, World !
|
|
||||||
author: Endilie Yacop Sucipto
|
|
||||||
authorURL: http://twitter.com/endiliey
|
|
||||||
authorFBID: 100000251103620
|
|
||||||
---
|
|
||||||
|
|
||||||
Hi, Endilie here.
|
|
||||||
|
|
||||||
<!--truncate-->
|
|
||||||
|
|
||||||
Random tsasshoughts, experiences, write-up of Endilie Yacop Sucipto will be shared here.
|
|
|
@ -1,5 +1,6 @@
|
||||||
module.exports = async function build(sourceDir, cliOptions = {}) {
|
module.exports = async function build(siteDir, cliOptions = {}) {
|
||||||
process.env.NODE_ENV = 'production';
|
process.env.NODE_ENV = 'production';
|
||||||
|
console.log('Build command invoked ...');
|
||||||
|
console.log(siteDir);
|
||||||
console.log(cliOptions);
|
console.log(cliOptions);
|
||||||
console.log('Build');
|
|
||||||
};
|
};
|
||||||
|
|
7
lib/commands/init.js
Normal file
7
lib/commands/init.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module.exports = async function init(projectDir, cliOptions = {}) {
|
||||||
|
console.log('Init command invoked ...');
|
||||||
|
console.log(projectDir);
|
||||||
|
console.log(cliOptions);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
};
|
|
@ -16,22 +16,22 @@ const load = require('../loader');
|
||||||
const createDevConfig = require('../webpack/dev');
|
const createDevConfig = require('../webpack/dev');
|
||||||
|
|
||||||
async function getPort(port) {
|
async function getPort(port) {
|
||||||
portfinder.basePort = parseInt(port, 10) || 8080;
|
portfinder.basePort = parseInt(port, 10) || 3000;
|
||||||
return await portfinder.getPortPromise();
|
return await portfinder.getPortPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = async function dev(sourceDir, cliOptions = {}) {
|
module.exports = async function start(siteDir, cliOptions = {}) {
|
||||||
// load site props from preprocessed files in source directory
|
// load site props from preprocessed files in source directory
|
||||||
const props = await load(sourceDir);
|
const props = await load(siteDir);
|
||||||
|
|
||||||
// Reload for any add/change/remove of file
|
// Reload for any add/change/remove of file
|
||||||
const reload = () => {
|
const reload = () => {
|
||||||
load(sourceDir).catch(err => {
|
load(siteDir).catch(err => {
|
||||||
console.error(chalk.red(err.stack));
|
console.error(chalk.red(err.stack));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const fsWatcher = chokidar.watch(['**/*.md', 'config.js'], {
|
const fsWatcher = chokidar.watch(['**/*.md', 'config.js'], {
|
||||||
cwd: sourceDir,
|
cwd: siteDir,
|
||||||
ignoreInitial: true
|
ignoreInitial: true
|
||||||
});
|
});
|
||||||
fsWatcher.on('add', reload);
|
fsWatcher.on('add', reload);
|
||||||
|
@ -47,7 +47,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
|
||||||
let config = createDevConfig(props);
|
let config = createDevConfig(props);
|
||||||
config.plugin('WebpackNiceLog').use(webpackNiceLog, [
|
config.plugin('WebpackNiceLog').use(webpackNiceLog, [
|
||||||
{
|
{
|
||||||
name: 'Blogi',
|
name: 'Munseo',
|
||||||
onDone: () => {
|
onDone: () => {
|
||||||
console.log(
|
console.log(
|
||||||
`\n${chalk.blue('Development server available at ')}${chalk.cyan(
|
`\n${chalk.blue('Development server available at ')}${chalk.cyan(
|
||||||
|
@ -89,7 +89,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
|
||||||
logLevel: 'error',
|
logLevel: 'error',
|
||||||
port,
|
port,
|
||||||
add: (app, middleware, options) => {
|
add: (app, middleware, options) => {
|
||||||
const staticDir = path.resolve(sourceDir, 'public');
|
const staticDir = path.resolve(siteDir, 'public');
|
||||||
if (fs.existsSync(staticDir)) {
|
if (fs.existsSync(staticDir)) {
|
||||||
app.use(mount(publicPath, serveStatic(staticDir)));
|
app.use(mount(publicPath, serveStatic(staticDir)));
|
||||||
}
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
const dev = require('./commands/dev');
|
|
||||||
const build = require('./commands/build');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dev,
|
build: require('./commands/build'),
|
||||||
build
|
init: require('./commands/init'),
|
||||||
|
start: require('./commands/start')
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,14 +22,14 @@ function parse(fileString) {
|
||||||
return {metadata, content};
|
return {metadata, content};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadBlog(sourceDir) {
|
async function loadBlog(siteDir) {
|
||||||
const blogFiles = await globby(['**/*.md', '!.blogi', '!node_modules'], {
|
const blogFiles = await globby(['**/*.md', '!.munseo', '!node_modules'], {
|
||||||
cwd: sourceDir
|
cwd: siteDir
|
||||||
});
|
});
|
||||||
|
|
||||||
const blogDatas = await Promise.all(
|
const blogDatas = await Promise.all(
|
||||||
blogFiles.map(async file => {
|
blogFiles.map(async file => {
|
||||||
const filepath = path.resolve(sourceDir, file);
|
const filepath = path.resolve(siteDir, file);
|
||||||
const fileString = await fs.readFile(filepath, 'utf-8');
|
const fileString = await fs.readFile(filepath, 'utf-8');
|
||||||
const {metadata, content} = parse(fileString);
|
const {metadata, content} = parse(fileString);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = function loadConfig(sourceDir, deleteCache = true) {
|
module.exports = function loadConfig(siteDir, deleteCache = true) {
|
||||||
const configPath = path.resolve(sourceDir, 'config.js');
|
const configPath = path.resolve(siteDir, 'config.js');
|
||||||
if (deleteCache) {
|
if (deleteCache) {
|
||||||
delete require.cache[configPath];
|
delete require.cache[configPath];
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ const loadConfig = require('./config');
|
||||||
const loadBlog = require('./blog');
|
const loadBlog = require('./blog');
|
||||||
const {generate} = require('../helpers');
|
const {generate} = require('../helpers');
|
||||||
|
|
||||||
module.exports = async function load(sourceDir) {
|
module.exports = async function load(siteDir) {
|
||||||
// load siteConfig
|
// load siteConfig
|
||||||
const siteConfig = loadConfig(sourceDir);
|
const siteConfig = loadConfig(siteDir);
|
||||||
|
|
||||||
// extract data from all blog files
|
// extract data from all blog files
|
||||||
const blogDatas = await loadBlog(sourceDir);
|
const blogDatas = await loadBlog(siteDir);
|
||||||
|
|
||||||
await generate(
|
await generate(
|
||||||
'blogDatas.js',
|
'blogDatas.js',
|
||||||
|
@ -23,12 +23,12 @@ module.exports = async function load(sourceDir) {
|
||||||
// resolve outDir
|
// resolve outDir
|
||||||
const outDir = siteConfig.dest
|
const outDir = siteConfig.dest
|
||||||
? path.resolve(siteConfig.dest)
|
? path.resolve(siteConfig.dest)
|
||||||
: path.resolve(sourceDir, '.blogi/dist');
|
: path.resolve(siteDir, '.munseo/dist');
|
||||||
|
|
||||||
// resolve the path of our app user interface layout
|
// resolve the path of our app user interface layout
|
||||||
const uiPath =
|
const uiPath =
|
||||||
!siteConfig.uiPath ||
|
!siteConfig.uiPath ||
|
||||||
!fs.existsSync(path.resolve(sourceDir, siteConfig.uiPath))
|
!fs.existsSync(path.resolve(siteDir, siteConfig.uiPath))
|
||||||
? path.resolve(__dirname, '../ui')
|
? path.resolve(__dirname, '../ui')
|
||||||
: siteConfig.uiPath;
|
: siteConfig.uiPath;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ module.exports = async function load(sourceDir) {
|
||||||
return {
|
return {
|
||||||
siteConfig,
|
siteConfig,
|
||||||
blogDatas,
|
blogDatas,
|
||||||
sourceDir,
|
siteDir,
|
||||||
outDir,
|
outDir,
|
||||||
uiPath,
|
uiPath,
|
||||||
publicPath
|
publicPath
|
||||||
|
|
|
@ -2,7 +2,7 @@ const Config = require('webpack-chain');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = function createBaseConfig(props) {
|
module.exports = function createBaseConfig(props) {
|
||||||
const {outDir, uiPath, sourceDir, publicPath} = props;
|
const {outDir, uiPath, siteDir, publicPath} = props;
|
||||||
|
|
||||||
const config = new Config();
|
const config = new Config();
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
const isProd = process.env.NODE_ENV === 'production';
|
||||||
|
@ -18,7 +18,7 @@ module.exports = function createBaseConfig(props) {
|
||||||
config.resolve
|
config.resolve
|
||||||
.set('symlinks', true)
|
.set('symlinks', true)
|
||||||
.alias.set('@ui', uiPath)
|
.alias.set('@ui', uiPath)
|
||||||
.set('@source', sourceDir)
|
.set('@source', siteDir)
|
||||||
.set('@generated', path.resolve(__dirname, '../generated'))
|
.set('@generated', path.resolve(__dirname, '../generated'))
|
||||||
.set('@core', path.resolve(__dirname, '../core'))
|
.set('@core', path.resolve(__dirname, '../core'))
|
||||||
.end();
|
.end();
|
||||||
|
|
19
package.json
19
package.json
|
@ -1,21 +1,22 @@
|
||||||
{
|
{
|
||||||
"name": "blogi",
|
"name": "munseo",
|
||||||
"version": "1.0.0",
|
"version": "0.0.1",
|
||||||
"description": "Blog instantly",
|
"description": "📝⚡️ Transform your document (문서) to a website",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"blogi": "bin/blogi.js"
|
"munseo": "bin/munseo.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node bin/blogi dev examples",
|
"munseo": "node bin/munseo",
|
||||||
"build": "node bin/blogi build examples",
|
"start": "yarn munseo start website",
|
||||||
|
"build": "yarn munseo build website",
|
||||||
"prettier": "prettier --config .prettierrc --write \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
|
"prettier": "prettier --config .prettierrc --write \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
|
||||||
"lint": "eslint --cache \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
|
"lint": "eslint --cache \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/endiliey/blogi.git"
|
"url": "git+https://github.com/endiliey/munseo.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"blog",
|
"blog",
|
||||||
|
@ -25,9 +26,9 @@
|
||||||
"author": "endiliey",
|
"author": "endiliey",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/endiliey/blogi/issues"
|
"url": "https://github.com/endiliey/munseo/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/endiliey/blogi#readme",
|
"homepage": "https://github.com/endiliey/munseo#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^4.19.1",
|
"eslint": "^4.19.1",
|
||||||
"eslint-config-airbnb": "17.0.0",
|
"eslint-config-airbnb": "17.0.0",
|
||||||
|
|
9
website/package.json
Normal file
9
website/package.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"start": "node ../bin/munseo start",
|
||||||
|
"build": "node ../bin/munseo build"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"munseo": "../../munseo/"
|
||||||
|
}
|
||||||
|
}
|
7
website/siteConfig.js
Normal file
7
website/siteConfig.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module.exports = {
|
||||||
|
title: 'Munseo',
|
||||||
|
tagline: '📝⚡️ Transform your document (문서) to a website',
|
||||||
|
organizationName: 'endiliey',
|
||||||
|
projectName: 'munseo',
|
||||||
|
baseUrl: '/'
|
||||||
|
};
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
Loading…
Add table
Add a link
Reference in a new issue