forked from mr-doc/mr-doc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
383 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ lib-cov | |
*.out | ||
*.pid | ||
*.gz | ||
/node_modules/ | ||
|
||
|
||
pids | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env node | ||
|
||
var program = require('commander'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
_ = require('lodash'), | ||
|
||
dir = require('../lib/dir'), | ||
parse = require('../lib/parser'), | ||
compile = require('../lib/compile'), | ||
symbols = require('../lib/symbols'), | ||
|
||
version = require('../package').version; | ||
|
||
/** | ||
* Options & Defaults | ||
*/ | ||
var ignoredDirs = 'test,public,static,views,templates'; | ||
|
||
program | ||
.version(version) | ||
// .option('-r, --raw', 'output \'raw\' comments, leaving the markdown intact') | ||
.option('-d, --debug', 'output parsed comments for debugging') | ||
.option('-t, --title <string>', 'The title for the page produced') | ||
.option('-s, --source <source>', 'The folder which should get parsed') | ||
.option('-i, --ignore <directories>', 'Comma seperated list of directories to ignore. Default: ' + ignoredDirs) | ||
.option('-T, --target <target>', 'The folder which will contain the results. Default: <process.cwd()>/docs') | ||
.option('--template <jade template>', 'The jade template file to use'); | ||
|
||
function showHelp(){ | ||
console.log(' Examples:\n'); | ||
console.log(' # parse a whole folder'); | ||
console.log(' $ doxx --source ./lib --target ./docs'); | ||
} | ||
|
||
// examples | ||
program.on('--help', showHelp); | ||
|
||
// parse argv | ||
program.parse(process.argv); | ||
|
||
if(program.template){ | ||
compile.tpl = fs.readFileSync(program.template).toString(); | ||
} | ||
|
||
if (!program.source) { | ||
console.error(" Error you must define a source\n"); | ||
return showHelp(); | ||
} | ||
|
||
var target = path.resolve(process.cwd(), program.target) || process.cwd() + '/docs', | ||
source = path.resolve(process.cwd(), program.source), | ||
ignore = program.ignore || ignoredDirs; | ||
|
||
// Cleanup and turn into an array the ignoredDirs | ||
ignore = ignore.trim().replace(' ','').split(','); | ||
|
||
// Find, cleanup and validate all potential files | ||
var files = dir.collectFiles(source, ignore); | ||
|
||
dir.createTargetFolders(target, files); | ||
|
||
// Parse each file | ||
files = files.map(function(file) { | ||
var dox = parse(path.join(source, file), {}); | ||
return { | ||
name: file, | ||
dox: dox, | ||
symbols: symbols(dox) | ||
}; | ||
}); | ||
|
||
// Compute all symboles | ||
var allSymbols = files.reduce(function(m, a, b){ | ||
m = (a.symbols || []).concat(b.symbols || []); | ||
return m; | ||
}, []); | ||
|
||
// Render and write each file | ||
files.forEach(function(file){ | ||
|
||
var options = _.extend({}, file, { | ||
title: program.title || require(process.cwd() + '/package').name, | ||
allSymbols: allSymbols | ||
}); | ||
|
||
var compiled = compile(options); | ||
fs.writeFileSync(path.join(target, file.name+".html"), compiled); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,5 +32,4 @@ module.exports = function(grunt) { | |
|
||
// Default task. | ||
grunt.registerTask('default', 'lint'); | ||
|
||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var jade = require('jade'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
_ = require('lodash'); | ||
|
||
/** | ||
* Compile | ||
* @param {Object} options | ||
* @return {String} | ||
*/ | ||
function compile(options){ | ||
return jade.compile(compile.tpl,{})(options); | ||
} | ||
|
||
/** | ||
* Template used to produce the documentation | ||
*/ | ||
compile.tpl = fs.readFileSync(path.resolve(__dirname,'../views/template.jade')).toString(); | ||
|
||
module.exports = compile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var fs = require('fs'), | ||
path = require('path'), | ||
path = require('path'), | ||
mkdirp = require('mkdirp'), | ||
findit = require('findit'), | ||
_ = require('lodash'); | ||
|
||
/* | ||
* Create an array of all the right files in the source dir | ||
*/ | ||
exports.collectFiles = function(source, options, callback) { | ||
var dirtyFiles = findit.findSync(source), // tee hee! | ||
ignore = options.ignore || [], | ||
files = []; | ||
|
||
dirtyFiles.forEach(function(file){ | ||
file = path.relative(source, file); | ||
|
||
var doNotIgnore = _.all(ignore, function(d){ | ||
// return true if no part of the path is in the ignore list | ||
return (file.indexOf(d) === -1); | ||
}); | ||
|
||
if ((file.substr(-2) === 'js') && doNotIgnore) { | ||
files.push(file); | ||
} | ||
}); | ||
|
||
return files; | ||
}; | ||
|
||
/* | ||
* Make sure the folder structure in target mirrors source | ||
*/ | ||
exports.createTargetFolders = function(target, files) { | ||
var folders = []; | ||
|
||
files.forEach(function(file){ | ||
var folder = file.substr(0, file.lastIndexOf('/')); | ||
|
||
if ((folder !== '') && (folders.indexOf(folder) === -1)) { | ||
folders.push(folder); | ||
mkdirp.sync(target + '/' + folder); | ||
} | ||
}); | ||
}; |
Oops, something went wrong.