forked from singularlive/widget-development-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
74 lines (65 loc) · 1.91 KB
/
Copy pathdeploy.js
File metadata and controls
74 lines (65 loc) · 1.91 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
66
67
68
69
70
71
72
73
74
console.log('-----------------------------------------------');
console.log('Singular.Live widget deploy - version 1.0');
try {
var config = require('./singularwidget.json');
if (!config.deploykey) {
console.error('ERROR: Cannot find deploy key in singularwidget.json');
return;
}
}
catch (e) {
console.error('ERROR: Cannot access singularwidget.json: ' + e);
return;
}
var fs = require('fs');
var zipdir = require('zip-dir');
var xhr = require('superagent');
var deployUrl = 'https://staging-enigmatic-ocean-3936.herokuapp.com/widgets/deploywithkey';
console.log('Validating files in directory "source"');
// Check for output.html and icon.png
try {
var stats = fs.lstatSync('./source');
if (stats.isDirectory()) {
try {
var outputHtmlFile = fs.lstatSync('./source/output.html');
} catch(e) {
console.error('ERROR: Cannot find file "source/output.html"');
return;
}
try {
var iconPngFile = fs.lstatSync('./source/icon.png');
} catch(e) {
console.error('ERROR: Cannot find file "source/icon.png"');
return;
}
} else {
console.error('ERROR: "source" is not a directory');
return;
}
} catch(e) {
console.error('ERROR: Cannot find directory "source"');
return;
}
// Zip source folder
console.log('Creating zip file');
zipdir('./source', { saveTo: './SingularWidget.zip' }, function (err, buffer) {
if (err) {
console.error('ERROR: Cannot zip directory "source"');
return;
} else {
console.log('Deploying widget to Singular.Live');
// Upload source folder to Singular.Live
var req = xhr.put(deployUrl);
req.field('key', config.deploykey)
req.attach('zipfile', './SingularWidget.zip');
req.end(function(err, res) {
if(err) {
console.error(err);
} else {
console.log('Widget ID: ' + res.body + ' successfully deployed');
}
// Cleanup
fs.unlink('./SingularWidget.zip');
});
}
});