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