diff --git a/src/init.js b/src/init.js index 3b3e40c..8c5d583 100644 --- a/src/init.js +++ b/src/init.js @@ -2,6 +2,24 @@ import deepExtend from 'deep-extend'; import defaults from './defaults'; import Promise from 'bluebird'; +import path from 'path'; + +/** + * For relative pathing to work, let's convert all paths in src options to + * absolute paths, if they are not already. + * @param {Object} opts Mutated in place. + */ +function normalizePaths (opts) { + for (var srcKey in opts.src) { + if (!path.isAbsolute(opts.src[srcKey].glob)) { + opts.src[srcKey].glob = path.resolve(opts.src[srcKey].glob); + } + if (!path.isAbsolute(opts.src[srcKey].basedir)) { + opts.src[srcKey].basedir = path.resolve(opts.src[srcKey].basedir); + } + } +} + /** * Merge defaults into passed options. * @param {Object} options @@ -9,8 +27,10 @@ import Promise from 'bluebird'; * primarily for testing purposes. * @return {Promise} resolving to merged options */ + function init (options = {}, handlebars) { const opts = deepExtend({}, defaults, options); + normalizePaths(opts); opts.handlebars = handlebars || require('handlebars'); return Promise.resolve(opts); } diff --git a/src/write/collections.js b/src/write/collections.js index 29c8dd5..03d9b6e 100644 --- a/src/write/collections.js +++ b/src/write/collections.js @@ -1,5 +1,6 @@ import { writeResource } from '../utils/write'; import DrizzleError from '../utils/error'; +import path from 'path'; const hasCollection = patterns => patterns.hasOwnProperty('collection'); const isCollection = patterns => patterns.hasOwnProperty('items'); @@ -41,7 +42,7 @@ function writeCollections (drizzleData) { return Promise.all(walkCollections( drizzleData.patterns, drizzleData, - [drizzleData.options.src.patterns.basedir]) + [path.basename(drizzleData.options.src.patterns.basedir)]) ).then(writePromises => drizzleData, error => DrizzleError.error(error, drizzleData.options.debug)); } diff --git a/test/config.js b/test/config.js index 99fd889..fb583f9 100644 --- a/test/config.js +++ b/test/config.js @@ -73,8 +73,8 @@ var config = { basedir: fixturePath('pages') }, patterns: { - glob: fixturePath('patterns/**/*.html'), - basedir: fixturePath('patterns') + glob: './test/fixtures/patterns/**/*.html', + basedir: './test/fixtures/patterns' }, templates: { glob: fixturePath('templates/**/*'), diff --git a/test/init.js b/test/init.js index 181aa90..8cdeec9 100644 --- a/test/init.js +++ b/test/init.js @@ -140,5 +140,6 @@ describe ('init', () => { expect(options.parsers.foo).to.contain.keys('pattern'); }); }); + it ('should convert relative src paths to absolute'); }); });