Comparing version 0.6.6 to 0.6.7
@@ -17,5 +17,5 @@ var fs = require( 'fs' ); | ||
Asset.prototype.addTransform = function( transform, addAtBeginning ) { | ||
if( addAtBeginning ) this.transforms.unshift( transform ); | ||
else this.transforms.push( transform ); | ||
Asset.prototype.addTransform = function( transform, transformOptions ) { | ||
var t = transformOptions ? function( file ) { return transform( file, transformOptions ); } : transform; | ||
this.transforms.push( t ); | ||
}; | ||
@@ -22,0 +22,0 @@ |
@@ -58,4 +58,6 @@ var path = require('path'); | ||
Package.prototype.getAssets = function() { | ||
return _.reduce( this.assetsByType, function( memo, assetsOfThisType ) { | ||
Package.prototype.getAssets = function( types ) { | ||
return _.reduce( this.assetsByType, function( memo, assetsOfThisType, thisAssetType ) { | ||
if( types && ! _.contains( types, thisAssetType ) ) return memo; | ||
return memo.concat( assetsOfThisType ); | ||
@@ -65,2 +67,19 @@ }, [] ); | ||
Package.prototype.addTransform = function( transform, transformOptions, toAssetTypes ) { | ||
var t = transformOptions ? function( file ) { return transform( file, transformOptions ); } : transform; | ||
toAssetTypes = toAssetTypes || Object.keys( this.assetsByType ); | ||
if( ! _.isArray( toAssetTypes ) ) toAssetTypes = [ toAssetTypes ]; | ||
// add transform to existing assets | ||
this.getAssets( toAssetTypes ).forEach( function( thisAsset ) { | ||
thisAsset.addTransform( t ); | ||
} ); | ||
// and also add it to the package itself so it is added to assets created from this point forward | ||
_.each( _.pick( this.assetTransformsByType, toAssetTypes ), function( transformsForThisAssetType ) { | ||
transformsForThisAssetType.push( t ); | ||
} ); | ||
}; | ||
Package.prototype.writeAssetsToDisk = function( assetTypesToWriteToDisk, outputDirectoryPath, callback ) { | ||
@@ -67,0 +86,0 @@ var _this = this; |
{ | ||
"name": "parcelify", | ||
"version": "0.6.6", | ||
"version": "0.6.7", | ||
"description": "Create css bundles from npm packages using the browserify dependency graph.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -144,1 +144,35 @@ var test = require('tape'); | ||
} ); | ||
// test a parcel with no package.json | ||
test( 'page6', function( t ) { | ||
t.plan( 2 ); | ||
var mainPath = __dirname + '/page6/main.js'; | ||
var dstDir = path.resolve( tmpdir, 'parcelify-test-' + Math.random() ); | ||
var options = { | ||
bundles : { | ||
script : path.join( dstDir, 'bundle.js' ), | ||
style : path.join( dstDir, 'bundle.css' ) | ||
} | ||
}; | ||
mkdirp.sync( dstDir ); | ||
p = parcelify( mainPath, options ); | ||
p.on( 'packageCreated', function( thePackage ) { | ||
thePackage.addTransform( require( 'sass-css-stream' ) ); | ||
} ); | ||
p.on( 'done', function() { | ||
t.deepEqual( | ||
fs.readdirSync( dstDir ).sort(), | ||
[ 'bundle.css', 'bundle.js' ] | ||
); | ||
t.deepEqual( fs.readFileSync( options.bundles.style, 'utf8' ), 'div.beep div.boop {\n color: green; }\n' ); | ||
} ); | ||
} ); |
41414
39
796