1
1
#!/usr/bin/env node
2
2
3
- var pkg = require ( '../package' ) ,
3
+ var fs = require ( 'fs' ) ,
4
+ path = require ( 'path' ) ,
4
5
chalk = require ( 'chalk' ) ,
5
6
doxdox = require ( '..' ) ;
6
7
7
8
var config = {
8
- title : 'Untitled Project ' ,
9
+ title : '' ,
9
10
description : '' ,
10
11
layout : 'bootstrap'
11
12
} ;
12
13
13
- var file = '' ,
14
- output = '' ;
14
+ var input = process . cwd ( ) ,
15
+ output ,
16
+ pkg ;
15
17
16
- var args = process . argv . slice ( 2 ) ,
17
- value ;
18
+ var args = process . argv . slice ( 2 ) ;
18
19
19
20
if ( args . length && ! args [ 0 ] . match ( / ^ \- / ) ) {
20
21
21
- file = args . shift ( ) ;
22
+ input = args . shift ( ) ;
22
23
23
24
}
24
25
25
26
while ( args . length ) {
26
27
27
- value = args . shift ( ) ;
28
-
29
- switch ( value ) {
28
+ switch ( args . shift ( ) ) {
30
29
31
30
case '-t' :
32
31
case '--title' :
@@ -43,27 +42,33 @@ while (args.length) {
43
42
config . layout = args . shift ( ) ;
44
43
break ;
45
44
45
+ case '-p' :
46
+ case '--package' :
47
+ pkg = args . shift ( ) ;
48
+ break ;
49
+
46
50
case '-o' :
47
51
case '--output' :
48
52
output = args . shift ( ) ;
49
53
break ;
50
54
51
55
case '-v' :
52
56
case '--version' :
53
- process . stdout . write ( pkg . version + '\n' ) ;
57
+ process . stdout . write ( require ( '../package' ) . version + '\n' ) ;
54
58
process . kill ( ) ;
55
59
break ;
56
60
57
61
default :
58
62
process . stdout . write ( '\n' ) ;
59
- process . stdout . write ( chalk . blue ( ' Usage:' ) + ' doxdox <file > [options]' + '\n\n' ) ;
63
+ process . stdout . write ( chalk . blue ( ' Usage:' ) + ' doxdox <path > [options]' + '\n\n' ) ;
60
64
process . stdout . write ( ' Options:' + '\n\n' ) ;
61
65
process . stdout . write ( chalk . yellow ( ' -h, --help' ) + '\t\tDisplay this help message.' + '\n' ) ;
62
66
process . stdout . write ( chalk . yellow ( ' -v, --version' ) + '\t\tDisplay the current installed version.' + '\n' ) ;
63
67
process . stdout . write ( chalk . yellow ( ' -t, --title' ) + '\t\tSets title.' + '\n' ) ;
64
68
process . stdout . write ( chalk . yellow ( ' -d, --description' ) + '\tSets description.' + '\n' ) ;
65
69
process . stdout . write ( chalk . yellow ( ' -l, --layout' ) + '\t\tTemplate to render the documentation with.' + '\n' ) ;
66
- process . stdout . write ( chalk . yellow ( ' -o, --output' ) + '\t\tFile to save documentation to. Default to stdout.' + '\n' ) ;
70
+ process . stdout . write ( chalk . yellow ( ' -p, --package' ) + '\tSets location of package.json file.' + '\n' ) ;
71
+ process . stdout . write ( chalk . yellow ( ' -o, --output' ) + '\t\tFile to save documentation to. Defaults to stdout.' + '\n' ) ;
67
72
process . stdout . write ( '\n' ) ;
68
73
process . stdout . write ( ' Available Layouts:' + '\n\n' ) ;
69
74
process . stdout . write ( ' - Bootstrap (default)\t (http://getbootstrap.com/)' + '\n' ) ;
@@ -76,4 +81,46 @@ while (args.length) {
76
81
77
82
}
78
83
79
- doxdox . parseFile ( file , output , config ) ;
84
+ var stat ;
85
+
86
+ if ( ! pkg && fs . existsSync ( input ) ) {
87
+
88
+ stat = fs . statSync ( input ) ;
89
+
90
+ if ( stat . isDirectory ( ) ) {
91
+
92
+ pkg = path . normalize ( input + '/package.json' ) ;
93
+
94
+ } else if ( stat . isFile ( ) ) {
95
+
96
+ pkg = path . normalize ( path . dirname ( input ) + '/package.json' ) ;
97
+
98
+ }
99
+
100
+ }
101
+
102
+ if ( fs . existsSync ( pkg ) ) {
103
+
104
+ pkg = require ( pkg ) ;
105
+
106
+ if ( pkg . name && ! config . title ) {
107
+
108
+ config . title = pkg . name ;
109
+
110
+ }
111
+
112
+ if ( pkg . description && ! config . description ) {
113
+
114
+ config . description = pkg . description ;
115
+
116
+ }
117
+
118
+ }
119
+
120
+ if ( ! config . title ) {
121
+
122
+ config . title = 'Untitled Project' ;
123
+
124
+ }
125
+
126
+ doxdox . parseInput ( input , output , config ) ;
0 commit comments