Skip to content

Commit

Permalink
Merge pull request #66 from cloudfour/fix-dest-paths
Browse files Browse the repository at this point in the history
Fix issue with relative vs. absolute paths in src
  • Loading branch information
lyzadanger committed Apr 13, 2016
2 parents 5b8ae43 + 5601c3d commit c5ca08b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,35 @@ 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
* @param {Object} handlebars Handlebars instance—it can be passed explicitly,
* 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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/write/collections.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*'),
Expand Down
1 change: 1 addition & 0 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,6 @@ describe ('init', () => {
expect(options.parsers.foo).to.contain.keys('pattern');
});
});
it ('should convert relative src paths to absolute');
});
});

0 comments on commit c5ca08b

Please sign in to comment.