Skip to content

Commit

Permalink
changes to cmd and also don't send events for empty bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
dgbeck committed Aug 7, 2015
1 parent 22825cb commit d5ee6cb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -22,7 +22,7 @@ Many thanks to [James Halliday](https://twitter.com/substack) for his help and g
└── main.js
```

In my-module's `package.json`, the module's style assets just need to be enumerated (glob notation):
In my-module's `package.json`, the module's style assets just need to be enumerated ([glob](https://github.com/isaacs/node-glob#glob-primer) notation):

```
{
Expand Down Expand Up @@ -99,7 +99,7 @@ All transform modules are called on all assets. It is up to the transform module

### Application level transforms

You can apply transforms to all packages within an entire branch of the directory tree (e.g. your entire app directory) using the `appTransforms` and `appTransformDirs` options or their corresponding command line arguments. Packages inside a `node_modules` folder located inside one of the supplied directories are not effected. For example, to transform all sass files inside the current working directory to css,
You can apply transforms to all packages within an entire branch of the directory tree using the `appTransforms` and `appTransformDirs` options or their corresponding command line arguments. (Packages inside a `node_modules` folder located inside one of the supplied directories are not effected.) For example, to transform all sass files inside the current working directory to css,

```
$ browserify main.js -o bundle.js -p [ parcelify -o bundle.css -t sass-css-stream -d . ]
Expand Down
8 changes: 7 additions & 1 deletion bin/cmd.js
Expand Up @@ -15,6 +15,7 @@ var argv = minimist( process.argv.slice(2),
jsBundle : 'j',
cssBundle : 'c',
transform : 't',
transformDirs : 'd',
watch : 'w',
maps : 'm',
help : 'h'
Expand All @@ -34,11 +35,15 @@ var jsBundle = resolvePath( argv.jsBundle ) || path.resolve( tmpdir, 'parcelify-
var cssBundle = resolvePath( argv.cssBundle );
var tmplBundle = resolvePath( argv.tmplBundle );
var mainPath = resolvePath( argv._[0] );
var appTransforms = argv.transform;
var appTransformDirs = argv.transformDirs;
var defaultTransforms = argv.transform;
var logLevel = argv.loglevel;
var watch = argv.watch;
var maps = argv.maps;

if( typeof appTransformDirs === 'string' ) appTransformDirs = [ appTransformDirs ];

if( ! mainPath ) {
console.log( 'No entry point specified' );
process.exit( 1 );
Expand All @@ -53,7 +58,8 @@ var p = parcelify( browserifyInstance, {
style : cssBundle,
template : tmplBundle
},
defaultTransforms : defaultTransforms,
appTransforms : appTransforms,
appTransformDirs : appTransformDirs,
browserifyBundleOptions : {
debug : maps
},
Expand Down
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -166,13 +166,13 @@ Parcelify.prototype.processParcels = function( browserifyInstance, options, call
var thisBundlePath = thisParcelBundles[ thisAssetType ];
if( ! thisBundlePath ) return nextEach();

thisParcel.writeBundle( thisAssetType, thisBundlePath, function( err ) {
thisParcel.writeBundle( thisAssetType, thisBundlePath, function( err, bundleWasWritten ) {
// don't stop writing other bundles if there was an error on this one. errors happen
// frequently with transforms.. like invalid scss, etc. don't stop the show, just
// keep going with our other bundles.

if( err ) _this.emit( 'error', err );
else _this.emit( 'bundleWritten', thisBundlePath, thisAssetType, thisParcel, _this.watching );
else if( bundleWasWritten ) _this.emit( 'bundleWritten', thisBundlePath, thisAssetType, thisParcel, _this.watching );

nextEach();
} );
Expand Down
16 changes: 8 additions & 8 deletions lib/parcel.js
Expand Up @@ -87,10 +87,10 @@ Parcel.prototype.attachWatchListeners = function( bundles ) {
this.calcParcelAssets( [ asset.type ] );

if( bundles[ asset.type ] ) {
_this.writeBundle( asset.type, bundles[ asset.type ], function( err ) {
_this.writeBundle( asset.type, bundles[ asset.type ], function( err, bundleWasWritten ) {
if( err ) return _this.emit( 'error', err );

_this.emit( 'bundleUpdated', bundles[ asset.type ], asset.type );
if( bundleWasWritten ) _this.emit( 'bundleUpdated', bundles[ asset.type ], asset.type );
// ... done!
} );
}
Expand All @@ -104,13 +104,13 @@ Parcel.prototype.attachWatchListeners = function( bundles ) {
var thisBundlePath = bundlesToRewrite[ thisAssetType ];
if( ! thisBundlePath ) return nextEach();

_this.writeBundle( thisAssetType, thisBundlePath, function( err ) {
_this.writeBundle( thisAssetType, thisBundlePath, function( err, bundleWasWritten ) {
// don't stop writing other bundles if there was an error on this one. errors happen
// frequently with transforms.. like invalid scss, etc. don't stop the show, just
// keep going with our other bundles.

if( err ) _this.emit( 'error', err );
else _this.emit( 'bundleWritten', thisBundlePath, thisAssetType, true );
else if( bundleWasWritten ) _this.emit( 'bundleWritten', thisBundlePath, thisAssetType, true );

nextEach();
} );
Expand All @@ -126,7 +126,7 @@ Parcel.prototype.writeBundle = function( assetType, dstPath, callback ) {
var _this = this;

var srcAssets = _this.parcelAssetsByType[ assetType ];
if( ! srcAssets || srcAssets.length === 0 ) return callback(); // we don't want to create an empty bundle just because we have no source files
if( ! srcAssets || srcAssets.length === 0 ) return callback( null, false ); // we don't want to create an empty bundle just because we have no source files

var bundle = through2();
var tempBundlePath = path.join( path.dirname( dstPath ), '.temp_' + path.basename( dstPath ) );
Expand All @@ -138,7 +138,7 @@ Parcel.prototype.writeBundle = function( assetType, dstPath, callback ) {
// so that if the high water mark is reached on one of the readable streams
// it doesn't pause (with no way to resume). See github issue #15.

if( err ) return callback( err );
if( err ) return callback( err, false );

// fs.rename( tempBundlePath, dstPath, function( err ) {
// if( err ) console.log( 'yoyoyoo', fs.existsSync( tempBundlePath ), dstPath, srcAssets );
Expand All @@ -147,7 +147,7 @@ Parcel.prototype.writeBundle = function( assetType, dstPath, callback ) {

//_this.bundlePathsByType[ assetType ] = dstPath; // don't do this. isn't really a property of the parcel so much as an input to parcelify

callback( null );
callback( null, true );
// } );
} );

Expand All @@ -165,7 +165,7 @@ Parcel.prototype.writeBundle = function( assetType, dstPath, callback ) {

thisAssetStream.pipe( bundle, { end : false } );
}, function( err ) {
if( err ) return callback( err );
if( err ) return callback( err, false );

bundle.end();

Expand Down

0 comments on commit d5ee6cb

Please sign in to comment.