Skip to content

Commit

Permalink
添加覆盖率测试
Browse files Browse the repository at this point in the history
  • Loading branch information
kahn1990 committed Jul 19, 2016
1 parent f9dc7fd commit fc1fd22
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.log
node_modules
npm-debug.log
test/doc
coverage
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ TESTS = test/*.js
REPORTER = spec
TIMEOUT = 5000
MOCHA = ./node_modules/mocha/bin/mocha
MOCHA2 = ./node_modules/mocha/bin/_mocha
ISTANBUL = ./node_modules/.bin/istanbul

test:
@npm install
@$(MOCHA) --reporter $(REPORTER) --timeout $(TIMEOUT) $(MOCHA_OPTS) $(TESTS)

istanbul:
@$(ISTANBUL) cover $(MOCHA2) test/jdz.js

.PHONY: test
.PHONY: istanbul
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,13 @@ JSDOC-ZERO 每次生成文档的时候都会清空 `输出目录` 下的所有
1. 增加文件相关信息
1. 增加搜索功能,可以根据相关注释方法名搜索到相应文件
1. 增加返回根目录功能以及生成文件名用 base64 处理


### Coverage summary

| Statements: | 79.1% ( 159/201 ) |
|---|
| Branches: | 51.22% ( 42/82 ) |
| Functions: | 88.24% ( 45/51 ) |
| Lines: | 80.3% ( 159/198 ) |

21 changes: 1 addition & 20 deletions bin/dox → bin/jdz
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ if (!_.isArray(loadConfigFiled.source.suffix)) loadConfigFiled.source.suffix = d

console.log('\n--------------------这里是文档生成工具:--------------------'.rainbow);

command
.version(
console.log(`
name: ${chalk.green(loadConfigFiled.name)}
version: ${chalk.yellow(loadConfigFiled.version)}
`)
)
command.version(console.log('name: '+chalk.green(loadConfigFiled.name)+'\nversion: '+chalk.yellow(loadConfigFiled.version)))
.usage('<keywords>')
.command('build')
.description('开始生成文档')
Expand Down Expand Up @@ -128,16 +122,3 @@ function testBuildCommand(avgs) {
}
}
}
/**
*
源全局路径(不包含文件) sourceGlobalPath
源全局路径文件 sourceGlobalPathFile
源项目路径(不包含文件) sourceProjectPath
源项目路径文件 sourceProjectPathFile
源文件名 sourceFileName
生成全局路径(不包含文件) generateGlobalPath
生成全局路径文件 generateGlobalPathFile
生成项目路径(不包含文件) generateProjectPath
生成项目路径文件 generateProjectPathFile
生成文件名 generateFileName
*/
110 changes: 55 additions & 55 deletions lib/default.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

var fs = require('fs'),
path = require('path'),
swig = require('swig'),
uuid = require('uuid'),
_ = require('underscore'),
mkdirp = require('mkdirp'),
var fs = require('fs'),
path = require('path'),
swig = require('swig'),
uuid = require('uuid'),
_ = require('underscore'),
mkdirp = require('mkdirp'),
underscoreStr = require('underscore.string'),
markdown = require('marked').parse,
colors = require("colors"),
crypto = require('crypto'),
dox = require('dox'),
merge = require('./merge'),
markdown = require('marked').parse,
colors = require("colors"),
crypto = require('crypto'),
dox = require('dox'),
merge = require('./merge'),
child_process = require('child_process');


Expand All @@ -21,7 +21,7 @@ merge(_, {str: underscoreStr});
* @returns {{section: *, api: *, doc: *, configuration: *}}
* @api private
*/
var getTemplates = {
var getTemplates = {
'api' : fs.readFileSync(path.join(__dirname, '../templates/api.html'), 'utf8'),
'pageList' : fs.readFileSync(path.join(__dirname, '../templates/pageList.html'), 'utf8'),
'markdown' : fs.readFileSync(path.join(__dirname, '../templates/markdown.html'), 'utf8'),
Expand All @@ -31,7 +31,7 @@ var getTemplates = {
* 生成文件相关的数组收集容器
* @type {Array}
*/
var dirsArrContainer = [];
var dirsArrContainer = [];
/**
* 收集 markdown 文件索引
* @type {Array}
Expand All @@ -41,12 +41,12 @@ var markdownFileListIndexContainer = [];
* 收集 markdown 文件
* @type {Array}
*/
var dirsMarkdownArrContainer = [];
var dirsMarkdownArrContainer = [];
/**
* 收集文件索引对象的参数
* @type {Array}
*/
var dirsFileArrContainer = [];
var dirsFileArrContainer = [];
function dirsArrContainerIterator(waitCreatFileObject, dirs) {
/**
* 收集目录
Expand Down Expand Up @@ -77,10 +77,10 @@ function checkPath(waitForThePathToCheck) {
* @returns {*}
*/
function walk(sourcePathItem, excludePathListObject, callback) {
var generateGlobalPath = sourcePathItem.generateGlobalPath,
generateProjectPath = sourcePathItem.generateProjectPath,
sourceGlobalPath = sourcePathItem.sourceGlobalPath,
sourceProjectPath = sourcePathItem.sourceProjectPath,
var generateGlobalPath = sourcePathItem.generateGlobalPath,
generateProjectPath = sourcePathItem.generateProjectPath,
sourceGlobalPath = sourcePathItem.sourceGlobalPath,
sourceProjectPath = sourcePathItem.sourceProjectPath,
excludeFolderProjectPathList = excludePathListObject[0] ? excludePathListObject[0].folderProjectPathList : [];

if (!fs.existsSync(generateGlobalPath)) {
Expand All @@ -89,7 +89,7 @@ function walk(sourcePathItem, excludePathListObject, callback) {
mkdirp.sync(generateGlobalPath);
console.log('start creat [' + generateGlobalPath + '] folder done');
// 收集空目录下的 index.html 索引文件内容
var generateGlobalPathFile = path.join(generateGlobalPath, 'index.html'),
var generateGlobalPathFile = path.join(generateGlobalPath, 'index.html'),
generateProjectPathFile = path.join(generateProjectPath, 'index.html');

dirsFileArrContainer.push({
Expand Down Expand Up @@ -152,10 +152,10 @@ function walk(sourcePathItem, excludePathListObject, callback) {
*/

function getFileList(sourcePathParam, excludePathListObject, suffixList, callback) {
var sourceGlobalPath = sourcePathParam.sourceGlobalPath,
var sourceGlobalPath = sourcePathParam.sourceGlobalPath,
sourceProjectPath = sourcePathParam.sourceProjectPath,
getFileListInDir = [];
suffixList = suffixList.concat(['.md', '.markdown', '.MARKDOWN', '.MD']);
getFileListInDir = [];
suffixList = suffixList.concat(['.md', '.markdown', '.MARKDOWN', '.MD']);
excludePathListObject = excludePathListObject[0] ? excludePathListObject[0].folderProjectPathList : [];

if (_.indexOf(excludePathListObject, sourceProjectPath) === -1) {
Expand Down Expand Up @@ -197,15 +197,15 @@ var getFileJsonAPIs = function (sourcePathListObject, excludePathListObject, cal
* 从Markdown中提取标题列表
* @return {Array} 返回标题列表
*/
const getIndexs = function (section, level, callback) {
level = level || 0; // 默认从 0 开始
level = level > 6 ? 6 : level; // 最大到6级标题
level = level < 0 ? 0 : level; // 最小到1级标题
callback = callback || function (item, level) {
const getIndexs = function (section, level, callback) {
level = level || 0; // 默认从 0 开始
level = level > 6 ? 6 : level; // 最大到6级标题
level = level < 0 ? 0 : level; // 最小到1级标题
callback = callback || function (item, level) {
return true;
};
var arrayList = [];
var matched = section.match(/.*\r?\n(\=+)|#+\s+(.*)/gm);
var matched = section.match(/.*\r?\n(\=+)|#+\s+(.*)/gm);

if (matched) {
matched.map(function (item) {
Expand Down Expand Up @@ -246,21 +246,21 @@ const getIndexs = function (section, level, callback) {
*/
module.exports = function (options, callback) {

var sourcePathListObject = _.map(options.source.include, function () {
var sourcePathListObject = _.map(options.source.include, function () {
return handlePathList.apply(this, Array.prototype.slice.call(arguments).concat(options.source.output));
}), // 源文件夹队列
excludePathListObject = _.map(options.source.exclude, function () {
return handlePathList.apply(this, Array.prototype.slice.call(arguments).concat(options.source.output));
}), // 过滤文件夹队列
outputGlobalPath = path.join(options.projectHomePath, options.source.output); // 输出文件夹
outputGlobalPath = path.join(options.projectHomePath, options.source.output); // 输出文件夹

verificationOutputGlobalPath(outputGlobalPath);

var generateAllJsFileInfoForJson = getFileJsonAPIs(sourcePathListObject, excludePathListObject, function (sourcePathParam) {
var generateGlobalPath = sourcePathParam.generateGlobalPath,
var generateGlobalPath = sourcePathParam.generateGlobalPath,
generateProjectPath = sourcePathParam.generateProjectPath,
sourceGlobalPath = sourcePathParam.sourceGlobalPath,
sourceProjectPath = sourcePathParam.sourceProjectPath;
sourceGlobalPath = sourcePathParam.sourceGlobalPath,
sourceProjectPath = sourcePathParam.sourceProjectPath;

return {
pathName: sourceGlobalPath, //==>/home/kang/work/kahn1990-object-server/lib
Expand All @@ -269,12 +269,12 @@ module.exports = function (options, callback) {
excludePathListObject,
options.source.suffix,
function (fileNameObject, getFileListInDir) {
var sourceGlobalPathFile = path.join(sourceGlobalPath, fileNameObject.fileHasExtname),
sourceFileContentCache = fs.readFileSync(sourceGlobalPathFile, 'utf8'),
sourceFileNameBuffer = new Buffer(path.join(sourceProjectPath, fileNameObject.fileHasExtname)).toString('base64'),
generateFile = sourceFileNameBuffer + '.html';
var sourceGlobalPathFile = path.join(sourceGlobalPath, fileNameObject.fileHasExtname),
sourceFileContentCache = fs.readFileSync(sourceGlobalPathFile, 'utf8'),
sourceFileNameBuffer = new Buffer(path.join(sourceProjectPath, fileNameObject.fileHasExtname)).toString('base64'),
generateFile = sourceFileNameBuffer + '.html';
fileNameObject.generateFile = generateFile;
var fileObjectCache = {
var fileObjectCache = {
generatePathFile : path.join(generateGlobalPath, generateFile),
generateProjectPath : generateProjectPath,
generateGlobalPath : generateGlobalPath,
Expand All @@ -286,7 +286,7 @@ module.exports = function (options, callback) {

if (_.indexOf(['.md', '.markdown', '.MARKDOWN', '.MD'], fileNameObject.fileExtname) !== -1) {
fileObjectCache.content = markdown(sourceFileContentCache);
fileObjectCache.indexs = getIndexs(sourceFileContentCache, 0, function (item, i) {
fileObjectCache.indexs = getIndexs(sourceFileContentCache, 0, function (item, i) {
return item.level > (i - 1);
});
dirsMarkdownArrContainer.push(fileObjectCache);
Expand Down Expand Up @@ -315,10 +315,10 @@ module.exports = function (options, callback) {
excludePathListObject,
[],
function (fileNameObject) {
var sourceGlobalPathFile = path.join(options.projectHomePath, fileNameObject.fileHasExtname),
sourceFileContentCache = fs.readFileSync(sourceGlobalPathFile, 'utf8'),
sourceFileNameBuffer = new Buffer(path.join(fileNameObject.fileHasExtname)).toString('base64'),
generateFile = sourceFileNameBuffer + '.html';
var sourceGlobalPathFile = path.join(options.projectHomePath, fileNameObject.fileHasExtname),
sourceFileContentCache = fs.readFileSync(sourceGlobalPathFile, 'utf8'),
sourceFileNameBuffer = new Buffer(path.join(fileNameObject.fileHasExtname)).toString('base64'),
generateFile = sourceFileNameBuffer + '.html';
fileNameObject.generateFile = generateFile;
dirsMarkdownArrContainer.push({
generatePathFile : path.join(outputGlobalPath, generateFile),
Expand All @@ -334,12 +334,12 @@ module.exports = function (options, callback) {
});
});
creatFileFuncByMarkdown(options.projectHomePath, outputGlobalPath, dirsMarkdownArrContainer);
creatHtmlIndexFile(options.projectHomePath, outputGlobalPath, sourcePathListObject);
creatHtmlIndexFile(options.projectHomePath, outputGlobalPath, sourcePathListObject, options);
creatincludePathFileFuncByHtml(options.projectHomePath, outputGlobalPath, sourcePathListObject);
creatFileFuncByHtml(options.projectHomePath, outputGlobalPath, dirsArrContainer);
writeJsdocListFile(outputGlobalPath, generateAllJsFileInfoForJson);
child_process.execFileSync('cp', ['-R', path.join(__dirname, '../templates/jsdoc_static'), path.join(outputGlobalPath, 'jsdoc_static')]);
callback();
return true;
};

function writeJsdocListFile(outputGlobalPath, generateAllJsFileInfoForJson) {
Expand Down Expand Up @@ -388,7 +388,7 @@ function writeJsdocListFile(outputGlobalPath, generateAllJsFileInfoForJson) {
*/
function creatFileFuncByMarkdown(projectHomePath, outputGlobalPath, dirsMarkdownArrContainer) {
_.each(dirsMarkdownArrContainer, function (item) {
item.fileNameObject.relativeProjectPathFile = path.relative(outputGlobalPath,item.generatePathFile);
item.fileNameObject.relativeProjectPathFile = path.relative(outputGlobalPath, item.generatePathFile);
markdownFileListIndexContainer.push(item.fileNameObject);

fs.writeFileSync(
Expand Down Expand Up @@ -416,10 +416,10 @@ function creatFileFuncByMarkdown(projectHomePath, outputGlobalPath, dirsMarkdown
function creatFileFuncByHtml(projectHomePath, outputGlobalPath, dirsArrContainer) {
// 处理文件索引
_.each(_.uniq(_.pluck(dirsArrContainer, 'generateProjectPath')), function (value) {
var generateFileGlobalPath = path.join(projectHomePath, value, 'index.html'),
var generateFileGlobalPath = path.join(projectHomePath, value, 'index.html'),
generateFileProjectPath = path.join(value, 'index.html'),
generateProjectPath = path.join(projectHomePath, value),
pageIndexList = _.without(_.map(dirsArrContainer, function (item) {
generateProjectPath = path.join(projectHomePath, value),
pageIndexList = _.without(_.map(dirsArrContainer, function (item) {
if (value === item.generateProjectPath) {
return item.fileNameObject;
} else {
Expand Down Expand Up @@ -494,7 +494,7 @@ function creatincludePathFileFuncByHtml(projectHomePath, outputGlobalPath, sourc
_.without(
_.map(sourcePathListObject, function (item) {
var itemSourceProjectPath = item.sourceProjectPath;
itemSourceProjectPath = itemSourceProjectPath.match(/^\/|\/$/g);
itemSourceProjectPath = itemSourceProjectPath.match(/^\/|\/$/g);
if (!itemSourceProjectPath && _.str.include(itemSourceProjectPath, '/')) return itemSourceProjectPath;
}),
undefined
Expand All @@ -504,7 +504,7 @@ function creatincludePathFileFuncByHtml(projectHomePath, outputGlobalPath, sourc
item.split("/"),
function (memo, num) {
var pathChildrenCache = path.join(outputGlobalPath, _.isNumber(memo) ? '' : memo, num),
generatePathFile = path.join(pathChildrenCache, 'index.html');
generatePathFile = path.join(pathChildrenCache, 'index.html');

fs.writeFileSync(
generatePathFile,
Expand Down Expand Up @@ -538,7 +538,7 @@ function creatincludePathFileFuncByHtml(projectHomePath, outputGlobalPath, sourc
* @param outputGlobalPath
* @param sourcePathListObject
*/
function creatHtmlIndexFile(projectHomePath, outputGlobalPath, sourcePathListObject) {
function creatHtmlIndexFile(projectHomePath, outputGlobalPath, sourcePathListObject, options) {
var generatePathFile = path.join(outputGlobalPath, 'index.html');

fs.writeFileSync(
Expand All @@ -547,7 +547,7 @@ function creatHtmlIndexFile(projectHomePath, outputGlobalPath, sourcePathListObj
getTemplates.indexZero,
{
locals : {
fileName : 'index.html',
fileName : options.name,
staticLoadRelativePath: '.',
content : {
linkList: markdownFileListIndexContainer,
Expand Down Expand Up @@ -630,7 +630,7 @@ function verificationOutputGlobalPath(outputGlobalPath) {
}
}
},
creatOutputGlobalPath = function (outputPathCompletion) {
creatOutputGlobalPath = function (outputPathCompletion) {
mkdirp.sync(outputPathCompletion);
console.log('start creat [' + outputPathCompletion + '] folder done');
};
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
"test": "make test"
},
"bin": {
"jdz": "bin/dox"
"jdz": "bin/jdz"
},
"keywords": [
"documentation",
"jsdoc",
"dox"
],
"dependencies": {
"babel-core": "^6.10.4",
"babel-istanbul": "^0.11.0",
"chai": "^3.5.0",
"chalk": "^1.1.3",
"colors": "^1.1.2",
"commander": "*",
"dox": "*",
"istanbul": "^0.4.4",
"marked": "*",
"mkdirp": "^0.5.0",
"path": "^0.12.7",
Expand Down
Loading

0 comments on commit fc1fd22

Please sign in to comment.