2
2
3
3
var pkg = require ( '../package' ) ,
4
4
fs = require ( 'fs' ) ,
5
+ dox = require ( 'dox' ) ,
5
6
hbs = require ( 'handlebars' ) ,
6
- helpers = require ( '../lib/helpers' ) ( hbs ) ;
7
+ helpers = require ( '../lib/helpers' ) ( hbs ) ,
8
+ utils = require ( '../lib/utils' ) ;
7
9
8
10
var templates = {
9
11
bootstrap : require ( '../templates/bootstrap.hbs' ) ,
10
12
markdown : require ( '../templates/markdown.hbs' )
11
13
} ;
12
14
13
15
var title = 'Untitled Project' ,
14
- description = '' ;
16
+ description = '' ,
17
+ layout = 'bootstrap' ;
15
18
16
19
var args = process . argv . slice ( 2 ) ,
17
20
value ;
@@ -34,6 +37,11 @@ while (args.length) {
34
37
description = args . shift ( ) ;
35
38
break ;
36
39
40
+ case '-l' :
41
+ case '--layout' :
42
+ layout = args . shift ( ) ;
43
+ break ;
44
+
37
45
case '-v' :
38
46
case '--version' :
39
47
process . stdout . write ( pkg . version + '\n' ) ;
@@ -47,49 +55,20 @@ while (args.length) {
47
55
48
56
}
49
57
50
- if ( filename ) {
51
-
52
- fs . readFile ( filename , 'utf8' , function ( error , data ) {
53
-
54
- if ( ! error ) {
55
-
56
- data = JSON . parse ( data ) ;
57
-
58
- data . forEach ( function ( methods ) {
59
-
60
- if ( methods . tags ) {
61
-
62
- methods . tags . forEach ( function ( tag ) {
63
-
64
- if ( tag . types ) {
58
+ fs . exists ( filename , function ( exists ) {
65
59
66
- tag . types . forEach ( function ( type , index ) {
60
+ var data ;
67
61
68
- if ( type . match ( / \? / g ) ) {
62
+ if ( exists ) {
69
63
70
- tag . optional = true ;
71
- tag . types [ index ] = type . replace ( / \? / g, '' ) ;
64
+ data = dox . parseComments ( fs . readFileSync ( filename , 'utf8' ) ) ;
72
65
73
- }
66
+ process . stdout . write ( templates [ layout ] ( {
67
+ title : title ,
68
+ description : description ,
69
+ methods : utils . parseData ( data )
70
+ } ) ) ;
74
71
75
- } ) ;
76
-
77
- }
78
-
79
- } ) ;
80
-
81
- }
82
-
83
- } ) ;
84
-
85
- process . stdout . write ( templates . bootstrap ( {
86
- title : title ,
87
- description : description ,
88
- methods : data
89
- } ) ) ;
90
-
91
- }
92
-
93
- } ) ;
72
+ }
94
73
95
- }
74
+ } ) ;
0 commit comments