Skip to content

Instantly share code, notes, and snippets.

@MartinMuzatko
Last active November 15, 2016 14:21
Show Gist options
  • Save MartinMuzatko/a3e508ced646f39498df5c80cece7d7e to your computer and use it in GitHub Desktop.
Save MartinMuzatko/a3e508ced646f39498df5c80cece7d7e to your computer and use it in GitHub Desktop.
// 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