-
Notifications
You must be signed in to change notification settings - Fork 10
/
deploy-design-docs.js
43 lines (38 loc) · 1.05 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
/**
* Cashier-BTC
* -----------
* Self-hosted bitcoin payment gateway
*
* https://github.com/Overtorment/Cashier-BTC
*
**/
/**
* 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)
}
})