11#!/usr/bin/env node
22
33var pkg = require ( '../package' ) ,
4- fs = require ( 'fs' ) ,
54 chalk = require ( 'chalk' ) ,
6- dox = require ( 'dox' ) ,
7- hbs = require ( 'handlebars' ) ,
8- helpers = require ( '../lib/helpers' ) ( hbs ) ,
9- utils = require ( '../lib/utils' ) ;
10-
11- var templates = {
12- bootstrap : require ( '../templates/bootstrap.hbs' ) ,
13- markdown : require ( '../templates/markdown.hbs' )
5+ doxdox = require ( '..' ) ;
6+
7+ var config = {
8+ title : 'Untitled Project' ,
9+ description : '' ,
10+ layout : 'bootstrap'
1411} ;
1512
16- var title = 'Untitled Project' ,
17- description = '' ,
18- layout = 'bootstrap' ,
19- script = '' ,
13+ var script = '' ,
2014 output = '' ;
2115
2216var args = process . argv . slice ( 2 ) ,
@@ -36,17 +30,17 @@ while (args.length) {
3630
3731 case '-t' :
3832 case '--title' :
39- title = args . shift ( ) ;
33+ config . title = args . shift ( ) ;
4034 break ;
4135
4236 case '-d' :
4337 case '--description' :
44- description = args . shift ( ) ;
38+ config . description = args . shift ( ) ;
4539 break ;
4640
4741 case '-l' :
4842 case '--layout' :
49- layout = args . shift ( ) ;
43+ config . layout = args . shift ( ) ;
5044 break ;
5145
5246 case '-o' :
@@ -69,7 +63,6 @@ while (args.length) {
6963 process . stdout . write ( chalk . yellow ( ' -t, --title' ) + '\t\tSets title.' + '\n' ) ;
7064 process . stdout . write ( chalk . yellow ( ' -d, --description' ) + '\tSets description.' + '\n' ) ;
7165 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' ) ;
7366 process . stdout . write ( chalk . yellow ( ' -o, --output' ) + '\t\tFile to save documentation to. Default to stdout.' + '\n' ) ;
7467 process . stdout . write ( '\n' ) ;
7568 process . stdout . write ( ' Available Layouts:' + '\n\n' ) ;
@@ -83,43 +76,4 @@ while (args.length) {
8376
8477}
8578
86- fs . exists ( script , function ( exists ) {
87-
88- var content ,
89- data ;
90-
91- if ( exists ) {
92-
93- data = dox . parseComments ( fs . readFileSync ( script , 'utf8' ) ) ;
94-
95- if ( templates [ layout ] ) {
96-
97- content = templates [ layout ] ( {
98- title : title ,
99- description : description ,
100- methods : utils . parseData ( data )
101- } ) ;
102-
103- if ( output ) {
104-
105- fs . writeFileSync ( output , content , 'utf8' ) ;
106-
107- } else {
108-
109- process . stdout . write ( content ) ;
110-
111- }
112-
113- } else {
114-
115- process . stdout . write ( 'Invalid layout specified.' + '\n' ) ;
116-
117- }
118-
119- } else {
120-
121- process . stdout . write ( 'File not found.' + '\n' ) ;
122-
123- }
124-
125- } ) ;
79+ doxdox . parseScript ( script , output , config ) ;
0 commit comments