-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.js
52 lines (48 loc) · 1.25 KB
/
publish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var zipFolder = require('zip-folder');
var path = require('path');
var fs = require('fs');
var request = require('request');
var rootFolder = path.resolve('.');
var zipPath = path.resolve(rootFolder, '../ordercoffeebot.zip');
var kuduApi = 'https://ordercoffeebot.scm.azurewebsites.net/api/zip/site/wwwroot';
var userName = '$ordercoffeebot';
var password = 'Kn7GndSjvbR2P5tv0HnWDnegit9yf66inRiL3eZv7zl0DnAmS5ucsb5G9pfy';
function uploadZip(callback) {
fs.createReadStream(zipPath).pipe(request.put(kuduApi, {
auth: {
username: userName,
password: password,
sendImmediately: true
},
headers: {
"Content-Type": "applicaton/zip"
}
}))
.on('response', function(resp){
if (resp.statusCode >= 200 && resp.statusCode < 300) {
fs.unlink(zipPath);
callback(null);
} else if (resp.statusCode >= 400) {
callback(resp);
}
})
.on('error', function(err) {
callback(err)
});
}
function publish(callback) {
zipFolder(rootFolder, zipPath, function(err) {
if (!err) {
uploadZip(callback);
} else {
callback(err);
}
})
}
publish(function(err) {
if (!err) {
console.log('ordercoffeebot publish');
} else {
console.error('failed to publish ordercoffeebot', err);
}
});