mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-22 20:47:53 +02:00
feat: add siteConfig loader
This commit is contained in:
parent
06faff3474
commit
94c45e36cb
11 changed files with 4726 additions and 51 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,4 +4,4 @@
|
||||||
.eslintcache
|
.eslintcache
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
|
yarn-error.log
|
||||||
|
|
0
lib/loader/blog.js
Normal file
0
lib/loader/blog.js
Normal file
14
lib/loader/config.js
Normal file
14
lib/loader/config.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = function loadConfig(sourceDir, deleteCache = true) {
|
||||||
|
const configPath = path.resolve(sourceDir, '.blogi', 'config.js');
|
||||||
|
if (deleteCache) {
|
||||||
|
delete require.cache[configPath];
|
||||||
|
}
|
||||||
|
let config = {};
|
||||||
|
if (fs.existsSync(configPath)) {
|
||||||
|
config = require(configPath);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
};
|
12
lib/loader/index.js
Normal file
12
lib/loader/index.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
const path = require('path');
|
||||||
|
const loadConfig = require('./config');
|
||||||
|
|
||||||
|
module.exports = async function load(sourceDir) {
|
||||||
|
// 1. load siteConfig
|
||||||
|
const siteConfig = loadConfig(sourceDir);
|
||||||
|
|
||||||
|
// 2. extract metadata from markdown files
|
||||||
|
const metadatas = [];
|
||||||
|
|
||||||
|
return null; // todo
|
||||||
|
};
|
25
package.json
25
package.json
|
@ -9,9 +9,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node bin/blogi dev blog",
|
"dev": "node bin/blogi dev blog",
|
||||||
"build": "node bin/blogi build blog",
|
"build": "node bin/blogi build blog",
|
||||||
"prettier": "prettier --config .prettierrc --write \"lib/**/*.js\" \"bin/**/*.js\"",
|
"prettier": "prettier --config .prettierrc --write \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
|
||||||
"lint": "eslint --cache \"lib/**/*.js\" \"bin/**/*.js\"",
|
"lint": "eslint --cache \"lib/**/*.js\" \"bin/**/*.js\" \"test/**/*.js\"",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -35,14 +35,31 @@
|
||||||
"eslint-plugin-import": "^2.12.0",
|
"eslint-plugin-import": "^2.12.0",
|
||||||
"eslint-plugin-jsx-a11y": "^6.0.3",
|
"eslint-plugin-jsx-a11y": "^6.0.3",
|
||||||
"eslint-plugin-react": "^7.9.1",
|
"eslint-plugin-react": "^7.9.1",
|
||||||
|
"jest": "^23.4.2",
|
||||||
"prettier": "^1.13.7"
|
"prettier": "^1.13.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^2.4.1",
|
"chalk": "^2.4.1",
|
||||||
|
"chokidar": "^2.0.4",
|
||||||
"commander": "^2.16.0",
|
"commander": "^2.16.0",
|
||||||
"semver": "^5.5.0"
|
"connect-history-api-fallback": "^1.5.0",
|
||||||
|
"fs-extra": "^7.0.0",
|
||||||
|
"koa-connect": "^2.0.1",
|
||||||
|
"koa-convert": "^1.2.0",
|
||||||
|
"koa-mount": "^3.0.0",
|
||||||
|
"koa-range": "^0.3.0",
|
||||||
|
"koa-static": "^5.0.0",
|
||||||
|
"ora": "^3.0.0",
|
||||||
|
"semver": "^5.5.0",
|
||||||
|
"webpack": "^4.16.3",
|
||||||
|
"webpack-chain": "^4.8.0",
|
||||||
|
"webpack-serve": "^2.0.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testPathIgnorePatterns": ["/node_modules/", "__fixtures__"],
|
||||||
|
"testEnvironment": "node"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
test/loader/__fixtures__/custom/.blogi/config.js
Normal file
6
test/loader/__fixtures__/custom/.blogi/config.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = {
|
||||||
|
title: 'Hello World',
|
||||||
|
description: 'Hello World',
|
||||||
|
dest: 'blogi',
|
||||||
|
base: 'blogi'
|
||||||
|
};
|
5
test/loader/__fixtures__/custom/hello.md
Normal file
5
test/loader/__fixtures__/custom/hello.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Hello, World !
|
||||||
|
---
|
||||||
|
|
||||||
|
Hello World
|
4
test/loader/__fixtures__/simple/.blogi/config.js
Normal file
4
test/loader/__fixtures__/simple/.blogi/config.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = {
|
||||||
|
title: 'Hello World',
|
||||||
|
description: 'Hello World'
|
||||||
|
};
|
5
test/loader/__fixtures__/simple/hello.md
Normal file
5
test/loader/__fixtures__/simple/hello.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Hello, World !
|
||||||
|
---
|
||||||
|
|
||||||
|
Hello World
|
28
test/loader/config.test.js
Normal file
28
test/loader/config.test.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const loadConfig = require('../../lib/loader/config');
|
||||||
|
|
||||||
|
describe('loadConfig', () => {
|
||||||
|
const simpleDir = path.join(__dirname, '__fixtures__', 'simple');
|
||||||
|
const customDir = path.join(__dirname, '__fixtures__', 'custom');
|
||||||
|
|
||||||
|
test('simple', () => {
|
||||||
|
expect(loadConfig(simpleDir)).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"description": "Hello World",
|
||||||
|
"title": "Hello World",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('custom', () => {
|
||||||
|
expect(loadConfig(customDir)).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
|
"base": "blogi",
|
||||||
|
"description": "Hello World",
|
||||||
|
"dest": "blogi",
|
||||||
|
"title": "Hello World",
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue