Skip to content

Commit 6bb3e82

Browse files
committed
handle relative path in options
1 parent 8fffac2 commit 6bb3e82

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/load.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ var Loader = function (data) {
2020
options[key] = _.has(options, key) ? options[key] : defaults[key];
2121
});
2222

23+
// Get absolute path
24+
options.path = path.resolve(process.cwd(), options.path || '');
25+
26+
// Get absolute path of directories
27+
staticFullPaths = _.map(options.directories, function (dir) {
28+
return path.resolve(options.path, dir.directory)
29+
});
30+
2331
logger = new Logger(options.log);
2432

2533
function makeRequest(url) {
@@ -284,15 +292,11 @@ var Loader = function (data) {
284292
fs.ensureDirSync(options.path);
285293
setLoadedFilename(options.url, options.path);
286294

287-
staticFullPaths = _.map(options.directories, function (dir) {
288-
return path.resolve(options.path, dir.directory)
289-
});
290-
291295
return loadCssSources(html, options.url);
292296
})
293297
}
294298

295-
function process() {
299+
function start() {
296300
// Load index page
297301
var p = loadIndexHtml();
298302

@@ -323,14 +327,11 @@ var Loader = function (data) {
323327
scrape: function (callback) {
324328
callback = typeof callback === 'function' ? callback : noop;
325329

326-
if (!options.path) {
327-
return callback(new Error('Path is not defined'), null);
328-
}
329330
if (fs.existsSync(options.path)) {
330331
return callback(new Error('Path ' + options.path + ' exists'), null);
331332
}
332333

333-
process()
334+
start()
334335
.then(function (res) {
335336
return callback(null, res);
336337
})

0 commit comments

Comments
 (0)