22
33var pkg = require ( '../package' ) ,
44 fs = require ( 'fs' ) ,
5+ chalk = require ( 'chalk' ) ,
56 dox = require ( 'dox' ) ,
67 hbs = require ( 'handlebars' ) ,
78 helpers = require ( '../lib/helpers' ) ( hbs ) ,
@@ -15,14 +16,15 @@ var templates = {
1516var title = 'Untitled Project' ,
1617 description = '' ,
1718 layout = 'bootstrap' ,
18- filename = '' ;
19+ script = '' ,
20+ output = '' ;
1921
2022var args = process . argv . slice ( 2 ) ,
2123 value ;
2224
2325if ( args . length && ! args [ 0 ] . match ( / ^ \- / ) ) {
2426
25- filename = args . shift ( ) ;
27+ script = args . shift ( ) ;
2628
2729}
2830
@@ -47,6 +49,11 @@ while (args.length) {
4749 layout = args . shift ( ) ;
4850 break ;
4951
52+ case '-o' :
53+ case '--output' :
54+ output = args . shift ( ) ;
55+ break ;
56+
5057 case '-v' :
5158 case '--version' :
5259 process . stdout . write ( pkg . version + '\n' ) ;
@@ -55,17 +62,19 @@ while (args.length) {
5562
5663 default :
5764 process . stdout . write ( '\n' ) ;
58- process . stdout . write ( ' Usage: doxdox <file> [options]' + '\n\n' ) ;
65+ process . stdout . write ( chalk . blue ( ' Usage:' ) + ' doxdox <file> [options]' + '\n\n' ) ;
5966 process . stdout . write ( ' Options:' + '\n\n' ) ;
60- process . stdout . write ( ' -h, --help\t\tDisplay this help message.' + '\n' ) ;
61- process . stdout . write ( ' -v, --version\t\tDisplay the current installed version.' + '\n' ) ;
62- process . stdout . write ( ' -t, --title\t\tSets title.' + '\n' ) ;
63- process . stdout . write ( ' -d, --description\tSets description.' + '\n' ) ;
64- process . stdout . write ( ' -l, --layout\t\tTemplate to render the documentation with.' + '\n' ) ;
67+ process . stdout . write ( chalk . yellow ( ' -h, --help' ) + '\t\tDisplay this help message.' + '\n' ) ;
68+ process . stdout . write ( chalk . yellow ( ' -v, --version' ) + '\t\tDisplay the current installed version.' + '\n' ) ;
69+ process . stdout . write ( chalk . yellow ( ' -t, --title' ) + '\t\tSets title.' + '\n' ) ;
70+ process . stdout . write ( chalk . yellow ( ' -d, --description' ) + '\tSets description.' + '\n' ) ;
71+ process . stdout . write ( chalk . yellow ( ' -l, --layout' ) + '\t\tTemplate to render the documentation with.' + '\n' ) ;
72+ process . stdout . write ( chalk . yellow ( ' -l, --layout' ) + '\t\tTemplate to render the documentation with.' + '\n' ) ;
73+ process . stdout . write ( chalk . yellow ( ' -o, --output' ) + '\t\tFile to save documentation to. Default to stdout.' + '\n' ) ;
6574 process . stdout . write ( '\n' ) ;
6675 process . stdout . write ( ' Available Layouts:' + '\n\n' ) ;
67- process . stdout . write ( ' - Bootstrap (default)\t\t (http://getbootstrap.com/)' + '\n' ) ;
68- process . stdout . write ( ' - Markdown\t\t\t (http://daringfireball.net/projects/markdown/)' + '\n' ) ;
76+ process . stdout . write ( ' - Bootstrap (default)\t (http://getbootstrap.com/)' + '\n' ) ;
77+ process . stdout . write ( ' - Markdown\t\t (http://daringfireball.net/projects/markdown/)' + '\n' ) ;
6978 process . stdout . write ( '\n' ) ;
7079 process . kill ( ) ;
7180 break ;
@@ -74,21 +83,32 @@ while (args.length) {
7483
7584}
7685
77- fs . exists ( filename , function ( exists ) {
86+ fs . exists ( script , function ( exists ) {
7887
79- var data ;
88+ var content ,
89+ data ;
8090
8191 if ( exists ) {
8292
83- data = dox . parseComments ( fs . readFileSync ( filename , 'utf8' ) ) ;
93+ data = dox . parseComments ( fs . readFileSync ( script , 'utf8' ) ) ;
8494
8595 if ( templates [ layout ] ) {
8696
87- process . stdout . write ( templates [ layout ] ( {
97+ content = templates [ layout ] ( {
8898 title : title ,
8999 description : description ,
90100 methods : utils . parseData ( data )
91- } ) ) ;
101+ } ) ;
102+
103+ if ( output ) {
104+
105+ fs . writeFileSync ( output , content , 'utf8' ) ;
106+
107+ } else {
108+
109+ process . stdout . write ( content ) ;
110+
111+ }
92112
93113 } else {
94114
0 commit comments