Repository navigation
Expand file tree
/
Copy pathupload.js
More file actions
65 lines (52 loc) · 1.83 KB
/
Copy pathupload.js
File metadata and controls
65 lines (52 loc) · 1.83 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
var r = require('request');
var md5 = require('md5');
var fs = require('fs');
var shell = require('shelljs');
var manifest = require('./manifest.json');
var URL = 'http://platform.joinposter.com/api/application.uploadPOSPlatformBundle?format=json';
var FILENAME = 'bundle.js';
(function () {
if ( ! shell.exec('NODE_ENV=production webpack')) {
console.log('Error while preparing build');
return;
}
fs.readFile(FILENAME, function (err, buf) {
if ( ! err) {
var fileMd5 = md5(buf),
signParts = [
manifest.applicationId,
fileMd5,
manifest.applicationSecret
],
sign = md5(signParts.join(':'));
var formData = {
application_id: manifest.applicationId,
sign: sign,
bundle: fs.createReadStream(__dirname + '/' + FILENAME)
};
r.post({
url: URL,
formData: formData
}, function (err, response, body) {
if ( ! err) {
try {
body = JSON.parse(body);
if (body.error) {
throw new Error(JSON.stringify(body));
}
console.log('Bundle successfully sent to Poster');
} catch (e) {
console.log('Error while send bundle to Poster...');
console.log(e);
}
} else {
console.log('Error while send bundle to Poster...');
console.log(err);
}
});
} else {
console.log('Error while reading ' + fileName);
console.log(err);
}
});
})();