Skip to content

Commit 15a74f5

Browse files
committed
Added support for package.json file based config.
Updated README.
1 parent 5bff94f commit 15a74f5

File tree

2 files changed

+63
-11
lines changed

2 files changed

+63
-11
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ $ npm install doxdox -g
1919

2020
Options:
2121

22-
-h, --help Display this help message.
23-
-v, --version Display the current installed version.
24-
-t, --title Sets title.
25-
-d, --description Sets description.
26-
-l, --layout Template to render the documentation with.
27-
-o, --output File to save documentation to. Default to stdout.
22+
-h, --help Display this help message.
23+
-v, --version Display the current installed version.
24+
-t, --title Sets title.
25+
-d, --description Sets description.
26+
-p, --package Sets location of package.json file.
27+
-l, --layout Template to render the documentation with.
28+
-o, --output File to save documentation to. Default to stdout.
2829

2930
Available Layouts:
3031

31-
- Bootstrap (default) (http://getbootstrap.com/)
32-
- Markdown (http://daringfireball.net/projects/markdown/)
32+
- Bootstrap (default) (http://getbootstrap.com/)
33+
- Markdown (http://daringfireball.net/projects/markdown/)
3334
```
3435

3536
##Examples:

bin/doxdox

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/usr/bin/env node
22

3-
var chalk = require('chalk'),
3+
var fs = require('fs'),
4+
path = require('path'),
5+
chalk = require('chalk'),
46
doxdox = require('..');
57

68
var config = {
7-
title: 'Untitled Project',
9+
title: '',
810
description: '',
911
layout: 'bootstrap'
1012
};
1113

1214
var input = __dirname,
13-
output;
15+
output,
16+
pkg;
1417

1518
var args = process.argv.slice(2),
1619
value;
@@ -42,6 +45,11 @@ while (args.length) {
4245
config.layout = args.shift();
4346
break;
4447

48+
case '-p':
49+
case '--package':
50+
pkg = args.shift();
51+
break;
52+
4553
case '-o':
4654
case '--output':
4755
output = args.shift();
@@ -61,6 +69,7 @@ while (args.length) {
6169
process.stdout.write(chalk.yellow(' -v, --version') + '\t\tDisplay the current installed version.' + '\n');
6270
process.stdout.write(chalk.yellow(' -t, --title') + '\t\tSets title.' + '\n');
6371
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');
6473
process.stdout.write(chalk.yellow(' -l, --layout') + '\t\tTemplate to render the documentation with.' + '\n');
6574
process.stdout.write(chalk.yellow(' -o, --output') + '\t\tFile to save documentation to. Default to stdout.' + '\n');
6675
process.stdout.write('\n');
@@ -75,4 +84,46 @@ while (args.length) {
7584

7685
}
7786

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+
78129
doxdox.parseInput(input, output, config);

0 commit comments

Comments
 (0)