Last active
August 29, 2015 13:57
-
-
Save chrismatheson/9803545 to your computer and use it in GitHub Desktop.
Azure deploy before refactor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp.task('deploy-staging', ['timestamp', 'build'], function(){ | |
'use strict'; | |
var build_sha = process.env.build_sha || '', | |
blobService = azure.createBlobService(), | |
container = 'staging', | |
stagingCssNames = {}, | |
stagingCssLocations = _.map(build.css, function(css){ | |
stagingCssNames[css] = 'static/' + build_sha + css; | |
return 'dist/static/' + css; | |
}), | |
stagingJsNames = {}, | |
stagingJsLocations = _.map(build.js, function(js){ | |
stagingJsNames[js] = 'static/' + build_sha + js; | |
return 'dist/static/' + js; | |
}), | |
stagingCss = _.map(build.css, function(css){ | |
return '/proposal/static/' + build_sha + css; | |
}), | |
stagingJs = _.map(build.js, function(js){ | |
return '/proposal/static/' + build_sha + js; | |
}); | |
gutil.log(build_sha); | |
function deleteBlob(blobName){ | |
if(blobName !== 'index.html' && | |
!stagingCssNames[blobName] && | |
!stagingJsNames[blobName]){ | |
blobService.deleteBlob(container, blobName, function(error){ | |
if(!error){ | |
gutil.log(blobName + ' deleted'); | |
} | |
}); | |
} | |
} | |
return es.concat( | |
//Upload CSS | |
gulp.src(stagingCssLocations) | |
.pipe(gutil.buffer(function(err, files){ | |
if(files && files.length > 0){ | |
files.forEach(function (file){ | |
blobService.createBlockBlobFromFile(container, stagingCssNames[file.relative], file.path, function(error){ | |
if(error){ | |
gutil.log(error); | |
} else { | |
gutil.log(stagingCssNames[file.relative] + ' uploaded'); | |
} | |
}); | |
}); | |
} | |
})), | |
//Upload JS | |
gulp.src(stagingJsLocations) | |
.pipe(gutil.buffer(function(err, files){ | |
if(files && files.length > 0){ | |
files.forEach(function (file){ | |
blobService.createBlockBlobFromFile(container, stagingJsNames[file.relative], file.path, function(error){ | |
if(error){ | |
gutil.log(error); | |
} else { | |
gutil.log(stagingJsNames[file.relative] + ' uploaded'); | |
} | |
}); | |
}); | |
} | |
})), | |
gulp.src(app.index) | |
.pipe(htmlReplace({ | |
'css': stagingCss, | |
'js': stagingJs | |
})) | |
.pipe(gulp.dest('staging')) | |
.pipe(gutil.buffer(function(err, files){ | |
var index = files[0], | |
deleteBlobs = []; | |
blobService.createBlockBlobFromFile(container, index.relative, index.path, function(error){ | |
if(error){ | |
gutil.log(error); | |
} else { | |
gutil.log(index.relative + ' uploaded'); | |
} | |
}); | |
blobService.listBlobs(container, function(error, blobs){ | |
if(!error){ | |
for(var index in blobs){ | |
deleteBlob(blobs[index].name); | |
} | |
} | |
}); | |
})) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment