forked from Overtorment/Cashier-BTC
-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy-design-docs.js
48 lines (44 loc) · 1.52 KB
/
deploy-design-docs.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
/**
* ==============================================================================
* BTCz-Pay
* ==============================================================================
*
* Version 0.2.1 (production v1.0)
*
* Self-hosted bitcoinZ payment gateway
* https://github.com/MarcelusCH/BTCz-Pay
*
* ------------------------------------------------------------------------------
* deploy-design-docs.js Required by btcz-pay.js
* ------------------------------------------------------------------------------
*
* checks if design docs are deployed
* to Couchdb and deloys them if not
*
* ==============================================================================
*/
let fs = require('fs')
let storage = require('./models/storage')
fs.readdir('./_design_docs', function (err, designDocs) {
if (err) {
console.log('Cant read design documents list')
process.exit()
}
let readFileCallback = function (err, data) {
let json = JSON.parse(data)
if (err) {
return console.log(err)
}
storage.getDocumentPromise(json._id).then(function (doc) {
if (!doc || doc.error === 'not_found') {
console.log(json._id + ' design doc needs to be created')
storage.saveDocumentPromise(json).then(function (response, err) {
console.log('Creating design document resulted in:', JSON.stringify(response || err))
})
}
})
}
for (let i = 0; i < designDocs.length; i++) {
fs.readFile('./_design_docs' + '/' + designDocs[i], 'utf8', readFileCallback)
}
})