Skip to content

Commit 74f86d7

Browse files
committed
Added ability to load custom parsers.
1 parent 10c3aa7 commit 74f86d7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

DOCUMENTATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Find which node_modules directory to load package from.
118118
Load parser based on user defined choice.
119119

120120
loadParser({'parser': 'dox'}).then(parser => {});
121+
loadParser({'parser': 'parser.js'}).then(parser => {});
121122

122123

123124

lib/loaders.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const findPackagePath = pkg =>
4545
* Load parser based on user defined choice.
4646
*
4747
* loadParser({'parser': 'dox'}).then(parser => {});
48+
* loadParser({'parser': 'parser.js'}).then(parser => {});
4849
*
4950
* @param {Object} config Configuration object.
5051
* @param {String} config.parser String representing the parser to be loaded.
@@ -54,11 +55,27 @@ const findPackagePath = pkg =>
5455

5556
const loadParser = config => new Promise((resolve, reject) => {
5657

57-
findPackagePath(`doxdox-parser-${config.parser}`).then(parser => {
58+
fs.stat(config.parser, (err, stats) => {
5859

59-
if (parser.length) {
60+
if (err) {
61+
62+
findPackagePath(`doxdox-parser-${config.parser}`).then(parser => {
6063

61-
resolve(require(parser[0]));
64+
if (parser.length) {
65+
66+
resolve(require(parser[0]));
67+
68+
} else {
69+
70+
reject('Invalid parser specified.');
71+
72+
}
73+
74+
});
75+
76+
} else if (stats && stats.isFile() && config.parser.match(JAVASCRIPT_PATTERN)) {
77+
78+
resolve(require(path.join(process.cwd(), config.parser)));
6279

6380
} else {
6481

@@ -117,8 +134,6 @@ const loadPlugin = config => new Promise((resolve, reject) => {
117134

118135
}
119136

120-
return false;
121-
122137
});
123138

124139
});

0 commit comments

Comments
 (0)