Skip to content

Commit

Permalink
feat: add summary test case and 重构 ydoc.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hellosean1025 committed Jan 3, 2018
1 parent e771b83 commit 5376b98
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 28 deletions.
119 changes: 119 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "ydoc",
"version": "3.2.5",
"description": "Yummy Doc 文档生成工具",
"scripts": {
"test": "export TESTING=true; mocha --reporter spec --bail --recursive"
},
"keywords": [
"doc",
"document"
Expand All @@ -11,11 +14,6 @@
"bin": {
"ydoc": "bin/ydoc"
},
"author": {
"name": "edwon.lin",
"email": "[email protected]",
"url": "https://ymfe.org/"
},
"repository": {
"type": "git",
"url": "[email protected]:YMFE/ydoc.git"
Expand All @@ -41,8 +39,14 @@
},
"devDependencies": {
"ghooks": "^2.0.0",
"mocha": "^4.1.0",
"validate-commit-msg": "^2.12.2"
},
"ava": {
"files": [
"test/**/*.js"
]
},
"config": {
"ghooks": {
"commit-msg": "validate-commit-msg"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const logger = require('../logger');

const config = utils.fileExist(configFilepath) ? require(configFilepath) : require(path.resolve(projectPath, 'ydoc.js'));
const ydoc = require('../ydoc.js');
utils.extend(ydoc, config);
utils.extend(ydoc.config, config);

module.exports = {
setOptions: function (yargs) {
Expand All @@ -21,7 +21,7 @@ module.exports = {
})
},
run: function (argv) {
const root = path.resolve(process.cwd(), ydoc.root);
const root = path.resolve(process.cwd(), ydoc.config.root);
const dist = path.resolve(process.cwd(), defaultBuildPath);
utils.log = new logger( argv.verbose ? 'debug' : 'info' );
fs.removeSync(dist);
Expand Down
22 changes: 11 additions & 11 deletions src/parse/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const fs = require('fs-extra');
const utils = require('../utils.js');
const dom = require('./dom');
const ydoc = require('../ydoc.js');
const ydocConfig = require('../ydoc.js').config;
const defaultIndexPage = 'index';
const defaultSummaryPage = 'summary.md';
const defaultNavPage = 'nav.md';
Expand Down Expand Up @@ -46,7 +46,7 @@ function getNav(filepath){
function getBookContext(book, page){
const context = utils.extend({}, book);
context.page = page;
context.config = ydoc;
context.config = ydocConfig;
return context;
}

Expand All @@ -64,7 +64,7 @@ function handleMdPathToHtml(filepath){
base: fileObj.base
})
}
let errpath = filepath.substr(ydoc.buildPath.length);
let errpath = filepath.substr(ydocConfig.buildPath.length);

utils.log.warn(`The file ${errpath} type isn't .md or .html .`)

Expand All @@ -75,25 +75,25 @@ function handleMdPathToHtml(filepath){

exports.parseSite =async function(dist){
try{
ydoc.buildPath = dist;
ydocConfig.buildPath = dist;
await emitHook('init');
await emitHook('markdown', utils.md);
let indexPath = await getIndexPath(dist);
if(!indexPath){
return utils.log.error(`The root directory of documents didn't find index.html or index.md`)
}

ydoc.nav = getNav(dist);
ydocConfig.nav = getNav(dist);
const generateSitePage = generate(dist);
generateSitePage({
title: ydoc.title,
title: ydocConfig.title,
page: {
srcPath: indexPath,
distPath: './index.html'
},
config: ydoc
config: ydocConfig
})
runBatch();
await runBatch();
let rootFiles = fs.readdirSync(dist);
for(let index in rootFiles){
let item = rootFiles[index];
Expand All @@ -119,7 +119,7 @@ function getBookInfo(filepath){
}
page = parsePage(page);
return {
title: page.title || ydoc.title,
title: page.title || ydocConfig.title,
description: page.description
}
}
Expand All @@ -138,7 +138,7 @@ const bookSchema = {
srcPath: 'string',
distPath: 'string'
},
config: {} //ydoc 配置
config: {} //ydocConfig 配置
}

async function parseBook(bookpath){
Expand Down Expand Up @@ -167,7 +167,7 @@ async function parseBook(bookpath){
await parseDocuments(summary);
};

runBatch();
await runBatch();

utils.log.ok(`Generate ${book.title} book "${bookpath}/index.html"`);
async function parseDocuments(summary){
Expand Down
7 changes: 5 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ydoc = require('./ydoc.js');
const ydoc = require('./ydoc.js').config;
const path = require('path');
const utils = require('./utils.js');

Expand All @@ -22,6 +22,9 @@ const hooks = {
},
"page": {
listener: []
},
"markdown": {
listener: []
}
}

Expand Down Expand Up @@ -65,7 +68,7 @@ exports.loadPlugins = function loadPlugins(){
let pluginName = plugins[i].name;
try{
let pluginModule = require(path.resolve(modules, './ydoc-plugin-' + pluginName));
utils.log.info(`Load plugin ${pluginName} success.`)
utils.log.info(`Load plugin "${pluginName}" success.`)
for(let key in pluginModule){
if(hooks[key]){
bindHook(key, pluginModule[key])
Expand Down
15 changes: 7 additions & 8 deletions src/ydoc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const utils = require('./utils.js');
const ydoc = {
version: require('../package.json').version
version: require('../package.json').version,
config: {
root: "./docs",
title: "ydoc",
description: "ydoc description",
author: "ymfe"
}
}

const defaultConfig = {
root: "./docs",
title: "ydoc",
description: "ydoc description",
author: "ymfe"
}
utils.extend(ydoc, defaultConfig);
module.exports=ydoc;


Loading

0 comments on commit 5376b98

Please sign in to comment.