@@ -15,14 +15,15 @@ var templates = {
1515var title = 'Untitled Project' ,
1616 description = '' ,
1717 layout = 'bootstrap' ,
18- filename = '' ;
18+ script = '' ,
19+ output = '' ;
1920
2021var args = process . argv . slice ( 2 ) ,
2122 value ;
2223
2324if ( args . length && ! args [ 0 ] . match ( / ^ \- / ) ) {
2425
25- filename = args . shift ( ) ;
26+ script = args . shift ( ) ;
2627
2728}
2829
@@ -47,6 +48,11 @@ while (args.length) {
4748 layout = args . shift ( ) ;
4849 break ;
4950
51+ case '-o' :
52+ case '--output' :
53+ output = args . shift ( ) ;
54+ break ;
55+
5056 case '-v' :
5157 case '--version' :
5258 process . stdout . write ( pkg . version + '\n' ) ;
@@ -62,6 +68,7 @@ while (args.length) {
6268 process . stdout . write ( ' -t, --title\t\tSets title.' + '\n' ) ;
6369 process . stdout . write ( ' -d, --description\tSets description.' + '\n' ) ;
6470 process . stdout . write ( ' -l, --layout\t\tTemplate to render the documentation with.' + '\n' ) ;
71+ process . stdout . write ( ' -o, --output\t\tFile to save documentation to. Default to stdout.' + '\n' ) ;
6572 process . stdout . write ( '\n' ) ;
6673 process . stdout . write ( ' Available Layouts:' + '\n\n' ) ;
6774 process . stdout . write ( ' - Bootstrap (default)\t\t(http://getbootstrap.com/)' + '\n' ) ;
@@ -74,21 +81,32 @@ while (args.length) {
7481
7582}
7683
77- fs . exists ( filename , function ( exists ) {
84+ fs . exists ( script , function ( exists ) {
7885
79- var data ;
86+ var content ,
87+ data ;
8088
8189 if ( exists ) {
8290
83- data = dox . parseComments ( fs . readFileSync ( filename , 'utf8' ) ) ;
91+ data = dox . parseComments ( fs . readFileSync ( script , 'utf8' ) ) ;
8492
8593 if ( templates [ layout ] ) {
8694
87- process . stdout . write ( templates [ layout ] ( {
95+ content = templates [ layout ] ( {
8896 title : title ,
8997 description : description ,
9098 methods : utils . parseData ( data )
91- } ) ) ;
99+ } ) ;
100+
101+ if ( output ) {
102+
103+ fs . writeFileSync ( output , content , 'utf8' ) ;
104+
105+ } else {
106+
107+ process . stdout . write ( content ) ;
108+
109+ }
92110
93111 } else {
94112
0 commit comments