forked from webhook/webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preset-build.js
81 lines (67 loc) · 2.39 KB
/
preset-build.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
var fs = require('fs');
var async = require('async');
require('colors');
console.warn = function() {};
var firebase = require('firebase');
var firebaseRoot = null;
module.exports = function (all, options) {
// Set of basic configuration for this (Defaults)
var config = {
firebaseConfig: '.firebase.conf',
firebaseName: options.firebase || 'webhook',
confData: {},
typeData: {},
realData: {},
settingsData: {},
};
firebaseRoot = new firebase('https://' + config.firebaseName + '.firebaseio.com/');
async.series([
function (step) {
console.log('Reading Config'.green);
if (!fs.existsSync('.firebase.conf')) {
console.log('No webhook configuration found.'.red);
console.log('This command must be run from inside of a webhook site directory'.red);
process.exit(1);
}
var data = fs.readFileSync('.firebase.conf');
config.confData = JSON.parse(data.toString());
step();
},
function (step) {
console.log('Downloading Data'.green);
firebaseRoot.child('buckets/' + config.confData.siteName + '/' + config.confData.secretKey + '/dev/contentType').once('value', function(snap) {
config.typeData = snap.val() || {};
step();
}, function(err) { step(); });
},
function(step) {
if(all) {
firebaseRoot.child('buckets/' + config.confData.siteName + '/' + config.confData.secretKey + '/dev/data').once('value', function(snap) {
config.realData = snap.val() || {};
firebaseRoot.child('buckets/' + config.confData.siteName + '/' + config.confData.secretKey + '/dev/settings').once('value', function(snap) {
config.settingsData = snap.val() || {};
step();
}, function(err) { step(); });
}, function(err) { step(); });
} else {
step();
}
},
], function () {
console.log('Writing File'.green);
if(!all) {
var typeDataString = JSON.stringify(config.typeData, null, 2);
fs.writeFileSync(".preset-data.json", typeDataString, {'flags': 'w+'});
} else {
var dataObj = {
'data' : config.realData,
'settings' : config.settingsData,
'contentType': config.typeData
};
var dataString = JSON.stringify(dataObj, null, 2);
fs.writeFileSync(".preset-data.json", dataString, {'flags': 'w+'});
}
process.exit(0);
});
};