1
1
#!/usr/bin/env node
2
2
3
- var chalk = require ( 'chalk' ) ,
3
+ var fs = require ( 'fs' ) ,
4
+ path = require ( 'path' ) ,
5
+ chalk = require ( 'chalk' ) ,
4
6
doxdox = require ( '..' ) ;
5
7
6
8
var config = {
7
- title : 'Untitled Project ' ,
9
+ title : '' ,
8
10
description : '' ,
9
11
layout : 'bootstrap'
10
12
} ;
11
13
12
14
var input = __dirname ,
13
- output ;
15
+ output ,
16
+ pkg ;
14
17
15
18
var args = process . argv . slice ( 2 ) ,
16
19
value ;
@@ -42,6 +45,11 @@ while (args.length) {
42
45
config . layout = args . shift ( ) ;
43
46
break ;
44
47
48
+ case '-p' :
49
+ case '--package' :
50
+ pkg = args . shift ( ) ;
51
+ break ;
52
+
45
53
case '-o' :
46
54
case '--output' :
47
55
output = args . shift ( ) ;
@@ -61,6 +69,7 @@ while (args.length) {
61
69
process . stdout . write ( chalk . yellow ( ' -v, --version' ) + '\t\tDisplay the current installed version.' + '\n' ) ;
62
70
process . stdout . write ( chalk . yellow ( ' -t, --title' ) + '\t\tSets title.' + '\n' ) ;
63
71
process . stdout . write ( chalk . yellow ( ' -d, --description' ) + '\tSets description.' + '\n' ) ;
72
+ process . stdout . write ( chalk . yellow ( ' -p, --package' ) + '\tSets location of package.json file.' + '\n' ) ;
64
73
process . stdout . write ( chalk . yellow ( ' -l, --layout' ) + '\t\tTemplate to render the documentation with.' + '\n' ) ;
65
74
process . stdout . write ( chalk . yellow ( ' -o, --output' ) + '\t\tFile to save documentation to. Default to stdout.' + '\n' ) ;
66
75
process . stdout . write ( '\n' ) ;
@@ -75,4 +84,46 @@ while (args.length) {
75
84
76
85
}
77
86
87
+ var stat ;
88
+
89
+ if ( ! pkg && fs . existsSync ( input ) ) {
90
+
91
+ stat = fs . statSync ( input ) ;
92
+
93
+ if ( stat . isDirectory ( ) ) {
94
+
95
+ pkg = path . normalize ( input + '/package.json' ) ;
96
+
97
+ } else if ( stat . isFile ( ) ) {
98
+
99
+ pkg = path . normalize ( path . dirname ( input ) + '/package.json' ) ;
100
+
101
+ }
102
+
103
+ }
104
+
105
+ if ( fs . existsSync ( pkg ) ) {
106
+
107
+ pkg = require ( pkg ) ;
108
+
109
+ if ( pkg . name && ! config . title ) {
110
+
111
+ config . title = pkg . name ;
112
+
113
+ }
114
+
115
+ if ( pkg . description && ! config . description ) {
116
+
117
+ config . description = pkg . description ;
118
+
119
+ }
120
+
121
+ }
122
+
123
+ if ( ! config . title ) {
124
+
125
+ config . title = 'Untitled Project' ;
126
+
127
+ }
128
+
78
129
doxdox . parseInput ( input , output , config ) ;
0 commit comments