refactor: use docusaurus structure

This commit is contained in:
endiliey 2018-08-05 14:54:20 +08:00
parent 44eb7655ca
commit 45cf88e059
24 changed files with 152 additions and 123 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ node_modules
dist
yarn-error.log
generated
website/node_modules

View file

@ -1 +1,2 @@
# blogi
# Munseo
📝⚡️ Transform your document (문서) to a website

View file

@ -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
View 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
View file

@ -0,0 +1,6 @@
---
id: bar
title: Bar
---
Lorem ipsumsdsdsad

6
docs/foo/baz.md Normal file
View file

@ -0,0 +1,6 @@
---
id: baz
title: baz
---
Life is so good

6
docs/hello.md Normal file
View file

@ -0,0 +1,6 @@
---
id: hello
title: Hello, World !
---
Hi, Endilie here :)

6
docs/intro.md Normal file
View file

@ -0,0 +1,6 @@
---
id: intro
title: Introducing Munseo
---
Introducing Munseo :)

View file

@ -1,4 +0,0 @@
module.exports = {
title: 'Hello World',
description: 'Hello World'
};

View file

@ -1,6 +0,0 @@
---
title: Lorem ipsum
date: 2018-06-20
---
Lorem ipsumsdsdsad

View file

@ -1,5 +0,0 @@
---
title: Baz
date: 2018-05-20
---
Life is so good

View file

@ -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.

View file

@ -1,5 +1,6 @@
module.exports = async function build(sourceDir, cliOptions = {}) {
module.exports = async function build(siteDir, cliOptions = {}) {
process.env.NODE_ENV = 'production';
console.log('Build command invoked ...');
console.log(siteDir);
console.log(cliOptions);
console.log('Build');
};

7
lib/commands/init.js Normal file
View file

@ -0,0 +1,7 @@
module.exports = async function init(projectDir, cliOptions = {}) {
console.log('Init command invoked ...');
console.log(projectDir);
console.log(cliOptions);
// TODO
};

View file

@ -16,22 +16,22 @@ const load = require('../loader');
const createDevConfig = require('../webpack/dev');
async function getPort(port) {
portfinder.basePort = parseInt(port, 10) || 8080;
portfinder.basePort = parseInt(port, 10) || 3000;
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
const props = await load(sourceDir);
const props = await load(siteDir);
// Reload for any add/change/remove of file
const reload = () => {
load(sourceDir).catch(err => {
load(siteDir).catch(err => {
console.error(chalk.red(err.stack));
});
};
const fsWatcher = chokidar.watch(['**/*.md', 'config.js'], {
cwd: sourceDir,
cwd: siteDir,
ignoreInitial: true
});
fsWatcher.on('add', reload);
@ -47,7 +47,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
let config = createDevConfig(props);
config.plugin('WebpackNiceLog').use(webpackNiceLog, [
{
name: 'Blogi',
name: 'Munseo',
onDone: () => {
console.log(
`\n${chalk.blue('Development server available at ')}${chalk.cyan(
@ -89,7 +89,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
logLevel: 'error',
port,
add: (app, middleware, options) => {
const staticDir = path.resolve(sourceDir, 'public');
const staticDir = path.resolve(siteDir, 'public');
if (fs.existsSync(staticDir)) {
app.use(mount(publicPath, serveStatic(staticDir)));
}

View file

@ -1,7 +1,5 @@
const dev = require('./commands/dev');
const build = require('./commands/build');
module.exports = {
dev,
build
build: require('./commands/build'),
init: require('./commands/init'),
start: require('./commands/start')
};

View file

@ -22,14 +22,14 @@ function parse(fileString) {
return {metadata, content};
}
async function loadBlog(sourceDir) {
const blogFiles = await globby(['**/*.md', '!.blogi', '!node_modules'], {
cwd: sourceDir
async function loadBlog(siteDir) {
const blogFiles = await globby(['**/*.md', '!.munseo', '!node_modules'], {
cwd: siteDir
});
const blogDatas = await Promise.all(
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 {metadata, content} = parse(fileString);

View file

@ -1,8 +1,8 @@
const fs = require('fs-extra');
const path = require('path');
module.exports = function loadConfig(sourceDir, deleteCache = true) {
const configPath = path.resolve(sourceDir, 'config.js');
module.exports = function loadConfig(siteDir, deleteCache = true) {
const configPath = path.resolve(siteDir, 'config.js');
if (deleteCache) {
delete require.cache[configPath];
}

View file

@ -4,12 +4,12 @@ const loadConfig = require('./config');
const loadBlog = require('./blog');
const {generate} = require('../helpers');
module.exports = async function load(sourceDir) {
module.exports = async function load(siteDir) {
// load siteConfig
const siteConfig = loadConfig(sourceDir);
const siteConfig = loadConfig(siteDir);
// extract data from all blog files
const blogDatas = await loadBlog(sourceDir);
const blogDatas = await loadBlog(siteDir);
await generate(
'blogDatas.js',
@ -23,12 +23,12 @@ module.exports = async function load(sourceDir) {
// resolve outDir
const outDir = 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
const uiPath =
!siteConfig.uiPath ||
!fs.existsSync(path.resolve(sourceDir, siteConfig.uiPath))
!fs.existsSync(path.resolve(siteDir, siteConfig.uiPath))
? path.resolve(__dirname, '../ui')
: siteConfig.uiPath;
@ -37,7 +37,7 @@ module.exports = async function load(sourceDir) {
return {
siteConfig,
blogDatas,
sourceDir,
siteDir,
outDir,
uiPath,
publicPath

View file

@ -2,7 +2,7 @@ const Config = require('webpack-chain');
const path = require('path');
module.exports = function createBaseConfig(props) {
const {outDir, uiPath, sourceDir, publicPath} = props;
const {outDir, uiPath, siteDir, publicPath} = props;
const config = new Config();
const isProd = process.env.NODE_ENV === 'production';
@ -18,7 +18,7 @@ module.exports = function createBaseConfig(props) {
config.resolve
.set('symlinks', true)
.alias.set('@ui', uiPath)
.set('@source', sourceDir)
.set('@source', siteDir)
.set('@generated', path.resolve(__dirname, '../generated'))
.set('@core', path.resolve(__dirname, '../core'))
.end();

View file

@ -1,21 +1,22 @@
{
"name": "blogi",
"version": "1.0.0",
"description": "Blog instantly",
"name": "munseo",
"version": "0.0.1",
"description": "📝⚡️ Transform your document (문서) to a website",
"main": "lib/index.js",
"bin": {
"blogi": "bin/blogi.js"
"munseo": "bin/munseo.js"
},
"scripts": {
"dev": "node bin/blogi dev examples",
"build": "node bin/blogi build examples",
"munseo": "node bin/munseo",
"start": "yarn munseo start website",
"build": "yarn munseo build website",
"prettier": "prettier --config .prettierrc --write \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
"lint": "eslint --cache \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/endiliey/blogi.git"
"url": "git+https://github.com/endiliey/munseo.git"
},
"keywords": [
"blog",
@ -25,9 +26,9 @@
"author": "endiliey",
"license": "MIT",
"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": {
"eslint": "^4.19.1",
"eslint-config-airbnb": "17.0.0",

9
website/package.json Normal file
View 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
View file

@ -0,0 +1,7 @@
module.exports = {
title: 'Munseo',
tagline: '📝⚡️ Transform your document (문서) to a website',
organizationName: 'endiliey',
projectName: 'munseo',
baseUrl: '/'
};

View file

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Before After
Before After