Last active
November 15, 2016 14:21
-
-
Save MartinMuzatko/a3e508ced646f39498df5c80cece7d7e to your computer and use it in GitHub Desktop.
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
// Part of a class | |
apply(compiler) { | |
compiler.plugin('emit', (compilation, callback) => { | |
this.valid = true | |
for (var filename in compilation.assets) { | |
if (this.valid) { | |
this.upload(filename, filename.replace(compilation.options.theme, '')) | |
} | |
} | |
console.log('upload done'); | |
callback() | |
}) | |
compiler.plugin('invalid', () => { | |
this.valid = false | |
}) | |
} | |
upload(from, to) { | |
this.headers = { | |
'Content-Type': 'application/octet-stream', | |
'Content-Length': fs.statSync(from).size, | |
'X-Scroll-Viewport-Resource-Location': to, | |
'Authorization': ('Basic ' + new Buffer(this.username + ':' + this.password).toString('base64')) | |
} | |
fs.createReadStream(from).pipe( | |
request( | |
{ | |
url: this.baseUrl + this.restUrl.update, | |
method: 'POST', | |
headers: this.headers | |
}, | |
function(error, response) { | |
console.log(response.statusCode + ' for ' + to); | |
} | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment