Permalink
Browse files

[bug fix] Compile empty assets

  • Loading branch information...
1 parent df8cb9e commit 2f18926c9cc0abe1ec3d8196c9be7264bbee4103 @ben-lin ben-lin committed Aug 28, 2012
Showing with 49 additions and 45 deletions.
  1. +49 −45 lib/assets/lib.js
View
@@ -56,59 +56,63 @@ module.exports = {
var tmp_path = tmp_dir + group + '.' + type;
var tgt_base_path = config.path.output + '/' + group + '-' + assets[ group ] + '.' + type;
var tgt_path = self.pub_dir + tgt_base_path;
+ var tmp = fs.readFileSync( tmp_path, 'utf8' );
- if( compare ){
- if( fs.existsSync( tgt_path )){
- var tmp = fs.readFileSync( tmp_path, 'utf8' );
- var ori = fs.readFileSync( tgt_path, 'utf8' );
-
- if( tmp !== ori ){
- // delete from s3
- if( config.s3 ){
- s3.destroy({
- tgt_path : tgt_base_path
- }, function (){
- console.log( utils.$alert( 'delete ' ) + tgt_base_path + ' from s3' );
- });
- }
-
- var ori_path = tgt_path;
- var new_tgt_base_path = config.path.output + '/' + group + '-' + uid + '.' + type;
- var new_tgt_path = self.pub_dir + tgt_base_path;
-
- version[ type ][ group ] = uid;
-
- // update version.json
- fs.writeFileSync( version_path, JSON.stringify( version, null, 2 ));
- // write asset file
- fs.writeFileSync( new_tgt_path, tmp );
- console.log( utils.$update( 'replace ' ) + tmp_path + '->' + new_tgt_path );
-
- if( config.s3 ){
- s3.create({
- tgt_path : new_tgt_base_path,
- src_path : tmp_path
- }, function (){
- console.log( utils.$good( 'uploaded ' ) + new_tgt_base_path + ' to s3' );
- });
- }
- }
-
- return;
+ // if the file is empty remove the version and save it
+ if( !tmp ){
+ if( version[ type ][ group ]){
+ delete version[ type ][ group ];
+ return fs.writeFileSync( version_path, JSON.stringify( version, null, 2 ));
}
}
- // does not need to compare files just move it to assets dir
- // ex. assets[ group ] = version.css.common -> 32 rand str
- fs.renameSync( tmp_path, tgt_path );
- console.log( utils.$good( 'moved ' ) + tmp_path + '->' + tgt_path );
+ if( !compare || !fs.existsSync( tgt_path )){
+ // does not need to compare files just move it to assets dir
+ // ex. assets[ group ] = version.css.common -> 32 rand str
+ fs.renameSync( tmp_path, tgt_path );
+ console.log( utils.$good( 'moved ' ) + tmp_path + '->' + tgt_path );
+
+ if( config.s3 ){
+ s3.create({
+ tgt_path : tgt_base_path,
+ src_path : tgt_path
+ }, function (){
+ console.log( utils.$good( 'uploaded ' ) + tgt_base_path + ' to s3' );
+ });
+ }
+ }
+
+ var ori = fs.readFileSync( tgt_path, 'utf8' );
+
+ if( tmp == ori ) return;
+
+ // delete from s3
+ if( config.s3 ){
+ s3.destroy({
+ tgt_path : tgt_base_path
+ }, function (){
+ console.log( utils.$alert( 'delete ' ) + tgt_base_path + ' from s3' );
+ });
+ }
+
+ var ori_path = tgt_path;
+ var new_tgt_base_path = config.path.output + '/' + group + '-' + uid + '.' + type;
+ var new_tgt_path = self.pub_dir + tgt_base_path;
+
+ version[ type ][ group ] = uid;
+
+ // update version.json
+ fs.writeFileSync( version_path, JSON.stringify( version, null, 2 ));
+ // write asset file
+ fs.writeFileSync( new_tgt_path, tmp );
+ console.log( utils.$update( 'replace ' ) + tmp_path + '->' + new_tgt_path );
if( config.s3 ){
s3.create({
- tgt_path : tgt_base_path,
- src_path : tgt_path
+ tgt_path : new_tgt_base_path,
+ src_path : tmp_path
}, function (){
- console.log( utils.$good( 'uploaded ' ) + tgt_base_path + ' to s3' );
+ console.log( utils.$good( 'uploaded ' ) + new_tgt_base_path + ' to s3' );
});
}
});

0 comments on commit 2f18926

Please sign in to comment.