Created
October 26, 2018 20:47
-
-
Save alexisdiel/d3e08d9b488a653e0ef59c2bc5831a11 to your computer and use it in GitHub Desktop.
Gulp + Azure + CDN
This file contains hidden or 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
| // /** | |
| // * AZURE TASKS | |
| // * Usage? gulp azure --storageKey XXXXXXXXXX --secret XXXXXXXXX | |
| // */ | |
| const gulp = require("gulp"); | |
| const msRestAzure = require("ms-rest-azure"); | |
| const azureCDN = require("azure-arm-cdn"); | |
| const azureStorage = require("gulp-azure-storage"); | |
| let purgeContent = (done) => { | |
| if (!argv.secret) { | |
| log.error("--secret argument missing"); | |
| } | |
| else | |
| msRestAzure.loginWithServicePrincipalSecret( | |
| process.env.AZURE_CLIENT, | |
| argv.secret, | |
| process.env.AZURE_TENANT, | |
| (err, credentials) => { | |
| if (err) return log(err); | |
| var client = new azureCDN(credentials, process.env.AZURE_SUBSCRIPTION); | |
| client.endpoints.purgeContent( | |
| process.env.AZURE_RESOURCEGROUP, | |
| process.env.AZURE_PROFILE, | |
| process.env.AZURE_ENDPOINT, | |
| ["/*"], | |
| (err, result) => { | |
| if (err) return log(err); | |
| if (result) return log(result); | |
| } | |
| ); | |
| } | |
| ); | |
| done(); | |
| }; | |
| let uploadContent = (done) => { | |
| if (!argv.storageKey) | |
| log.error("--storageKey argument missing"); | |
| else | |
| return gulp.src([`bin/${version}/*.js`, `bin/${version}/*.css`]) | |
| .pipe(azureStorage.upload({ account: process.env.AZURE_ACCOUNT, container: "lib", key: argv.storageKey, prefix: `${version}/` })); | |
| done(); | |
| }; | |
| gulp.task("upload", (done) => uploadContent(done)); | |
| gulp.task("purge", (done) => purgeContent(done)); | |
| gulp.task("azure", gulp.series("upload", "purge")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment