UNPKG

gulp-logify-alert

Version:

Gulp plugin for uploading source map files to Logify Alert

50 lines (44 loc) 1.53 kB
var through = require('through2'); var rest = require('restler'); var path = require('path'); function gulpLogifyAlert(privateApiKey) { var streamFiles = []; return through.obj(function(file, enc, callback) { if (file.isNull() || file.isDirectory()) { this.push(file); return callback(); } if (file.isStream()) { this.emit('error', new PluginError({ plugin: 'gulp-logify-alert', message: 'Streams are not supported.' })); return callback(); } if (file.isBuffer()) { streamFiles.push(file); this.push(file); return callback(); } }, function () { sendFiles(streamFiles, privateApiKey); }); } function sendFiles(files, privateApiKey) { var data = {}; for(var filesCounter = 0; filesCounter < files.length; filesCounter++) { var currentFile = files[filesCounter]; if(currentFile.history.length > 0) { var fileName = path.parse(currentFile.history[0]).base; data["file" + filesCounter.toString()] = rest.data(fileName, "multipart/form-data", currentFile.contents); } } rest.post('http://logifyview.cloudapp.net:54979/api/jsmap/uploadfiles', { multipart: true, data: data, headers: { 'Authorization': 'amx ' + privateApiKey } }); } module.exports = gulpLogifyAlert;