@@ -15,14 +15,15 @@ var templates = {
15
15
var title = 'Untitled Project' ,
16
16
description = '' ,
17
17
layout = 'bootstrap' ,
18
- filename = '' ;
18
+ script = '' ,
19
+ output = '' ;
19
20
20
21
var args = process . argv . slice ( 2 ) ,
21
22
value ;
22
23
23
24
if ( args . length && ! args [ 0 ] . match ( / ^ \- / ) ) {
24
25
25
- filename = args . shift ( ) ;
26
+ script = args . shift ( ) ;
26
27
27
28
}
28
29
@@ -47,6 +48,11 @@ while (args.length) {
47
48
layout = args . shift ( ) ;
48
49
break ;
49
50
51
+ case '-o' :
52
+ case '--output' :
53
+ output = args . shift ( ) ;
54
+ break ;
55
+
50
56
case '-v' :
51
57
case '--version' :
52
58
process . stdout . write ( pkg . version + '\n' ) ;
@@ -62,6 +68,7 @@ while (args.length) {
62
68
process . stdout . write ( ' -t, --title\t\tSets title.' + '\n' ) ;
63
69
process . stdout . write ( ' -d, --description\tSets description.' + '\n' ) ;
64
70
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' ) ;
65
72
process . stdout . write ( '\n' ) ;
66
73
process . stdout . write ( ' Available Layouts:' + '\n\n' ) ;
67
74
process . stdout . write ( ' - Bootstrap (default)\t\t(http://getbootstrap.com/)' + '\n' ) ;
@@ -74,21 +81,32 @@ while (args.length) {
74
81
75
82
}
76
83
77
- fs . exists ( filename , function ( exists ) {
84
+ fs . exists ( script , function ( exists ) {
78
85
79
- var data ;
86
+ var content ,
87
+ data ;
80
88
81
89
if ( exists ) {
82
90
83
- data = dox . parseComments ( fs . readFileSync ( filename , 'utf8' ) ) ;
91
+ data = dox . parseComments ( fs . readFileSync ( script , 'utf8' ) ) ;
84
92
85
93
if ( templates [ layout ] ) {
86
94
87
- process . stdout . write ( templates [ layout ] ( {
95
+ content = templates [ layout ] ( {
88
96
title : title ,
89
97
description : description ,
90
98
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
+ }
92
110
93
111
} else {
94
112
0 commit comments