Skip to content

Commit 505d081

Browse files
committed
Added findPackage method to utils.
1 parent c46ec44 commit 505d081

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

bin/doxdox

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
var fs = require('fs'),
44
path = require('path'),
55
chalk = require('chalk'),
6-
doxdox = require('..');
6+
doxdox = require('..'),
7+
utils = require('../lib/utils');
78

89
var config = {
910
title: '',
@@ -95,35 +96,23 @@ while (args.length) {
9596

9697
}
9798

98-
var stat;
99+
if (!pkg) {
99100

100-
if (!pkg && fs.existsSync(input)) {
101-
102-
stat = fs.statSync(input);
103-
104-
if (stat.isDirectory()) {
105-
106-
pkg = path.normalize(path.resolve(input) + '/package.json');
107-
108-
} else if (stat.isFile()) {
109-
110-
pkg = path.normalize(path.resolve(path.dirname(input)) + '/package.json');
111-
112-
}
101+
pkg = utils.findPackage(input);
113102

114103
}
115104

116105
if (fs.existsSync(pkg)) {
117106

118107
pkg = require(pkg);
119108

120-
if (pkg.name && !config.title) {
109+
if (!config.title && pkg.name) {
121110

122111
config.title = pkg.name;
123112

124113
}
125114

126-
if (pkg.description && !config.description) {
115+
if (!config.description && pkg.description) {
127116

128117
config.description = pkg.description;
129118

lib/utils.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
var fs = require('fs'),
22
path = require('path');
33

4+
module.exports.findPackage = function (input) {
5+
6+
var stat,
7+
pkg;
8+
9+
if (fs.existsSync(input)) {
10+
11+
stat = fs.statSync(input);
12+
13+
if (stat.isDirectory()) {
14+
15+
pkg = path.normalize(path.resolve(input) + '/package.json');
16+
17+
} else if (stat.isFile()) {
18+
19+
pkg = path.normalize(path.resolve(path.dirname(input)) + '/package.json');
20+
21+
}
22+
23+
}
24+
25+
return pkg;
26+
27+
};
28+
429
module.exports.formatStringForUID = function (content) {
530

631
content = String(content).toLowerCase();

0 commit comments

Comments
 (0)