1
1
#!/usr/bin/env node
2
2
3
3
var pkg = require ( '../package' ) ,
4
- fs = require ( 'fs' ) ,
5
4
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'
14
11
} ;
15
12
16
- var title = 'Untitled Project' ,
17
- description = '' ,
18
- layout = 'bootstrap' ,
19
- script = '' ,
13
+ var script = '' ,
20
14
output = '' ;
21
15
22
16
var args = process . argv . slice ( 2 ) ,
@@ -36,17 +30,17 @@ while (args.length) {
36
30
37
31
case '-t' :
38
32
case '--title' :
39
- title = args . shift ( ) ;
33
+ config . title = args . shift ( ) ;
40
34
break ;
41
35
42
36
case '-d' :
43
37
case '--description' :
44
- description = args . shift ( ) ;
38
+ config . description = args . shift ( ) ;
45
39
break ;
46
40
47
41
case '-l' :
48
42
case '--layout' :
49
- layout = args . shift ( ) ;
43
+ config . layout = args . shift ( ) ;
50
44
break ;
51
45
52
46
case '-o' :
@@ -69,7 +63,6 @@ while (args.length) {
69
63
process . stdout . write ( chalk . yellow ( ' -t, --title' ) + '\t\tSets title.' + '\n' ) ;
70
64
process . stdout . write ( chalk . yellow ( ' -d, --description' ) + '\tSets description.' + '\n' ) ;
71
65
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
66
process . stdout . write ( chalk . yellow ( ' -o, --output' ) + '\t\tFile to save documentation to. Default to stdout.' + '\n' ) ;
74
67
process . stdout . write ( '\n' ) ;
75
68
process . stdout . write ( ' Available Layouts:' + '\n\n' ) ;
@@ -83,43 +76,4 @@ while (args.length) {
83
76
84
77
}
85
78
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