11#!/usr/bin/env node
22
3- var pkg = require ( '../package' ) ,
3+ var fs = require ( 'fs' ) ,
4+ path = require ( 'path' ) ,
45 chalk = require ( 'chalk' ) ,
56 doxdox = require ( '..' ) ;
67
78var config = {
8- title : 'Untitled Project ' ,
9+ title : '' ,
910 description : '' ,
1011 layout : 'bootstrap'
1112} ;
1213
13- var file = '' ,
14- output = '' ;
14+ var input = process . cwd ( ) ,
15+ output ,
16+ pkg ;
1517
16- var args = process . argv . slice ( 2 ) ,
17- value ;
18+ var args = process . argv . slice ( 2 ) ;
1819
1920if ( args . length && ! args [ 0 ] . match ( / ^ \- / ) ) {
2021
21- file = args . shift ( ) ;
22+ input = args . shift ( ) ;
2223
2324}
2425
2526while ( args . length ) {
2627
27- value = args . shift ( ) ;
28-
29- switch ( value ) {
28+ switch ( args . shift ( ) ) {
3029
3130 case '-t' :
3231 case '--title' :
@@ -43,27 +42,33 @@ while (args.length) {
4342 config . layout = args . shift ( ) ;
4443 break ;
4544
45+ case '-p' :
46+ case '--package' :
47+ pkg = args . shift ( ) ;
48+ break ;
49+
4650 case '-o' :
4751 case '--output' :
4852 output = args . shift ( ) ;
4953 break ;
5054
5155 case '-v' :
5256 case '--version' :
53- process . stdout . write ( pkg . version + '\n' ) ;
57+ process . stdout . write ( require ( '../package' ) . version + '\n' ) ;
5458 process . kill ( ) ;
5559 break ;
5660
5761 default :
5862 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' ) ;
6064 process . stdout . write ( ' Options:' + '\n\n' ) ;
6165 process . stdout . write ( chalk . yellow ( ' -h, --help' ) + '\t\tDisplay this help message.' + '\n' ) ;
6266 process . stdout . write ( chalk . yellow ( ' -v, --version' ) + '\t\tDisplay the current installed version.' + '\n' ) ;
6367 process . stdout . write ( chalk . yellow ( ' -t, --title' ) + '\t\tSets title.' + '\n' ) ;
6468 process . stdout . write ( chalk . yellow ( ' -d, --description' ) + '\tSets description.' + '\n' ) ;
6569 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' ) ;
6772 process . stdout . write ( '\n' ) ;
6873 process . stdout . write ( ' Available Layouts:' + '\n\n' ) ;
6974 process . stdout . write ( ' - Bootstrap (default)\t (http://getbootstrap.com/)' + '\n' ) ;
@@ -76,4 +81,46 @@ while (args.length) {
7681
7782}
7883
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