-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow performing of specific actions
- Loading branch information
Showing
12 changed files
with
109 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
#!/usr/bin/env node | ||
|
||
const usage = require('../src/cli/usage'); | ||
const supportedActions = require('../src/cli/supported-actions'); | ||
|
||
if(process.argv.length < 4) { | ||
usage(); | ||
process.exit(1); | ||
} | ||
switch(process.argv.length) { | ||
case 4: { | ||
const project = process.argv[2]; | ||
const instanceUrl = process.argv[3]; | ||
const couchUrl = `${instanceUrl}/medic`; | ||
|
||
return require('../src/cli/all.js')(project, couchUrl); | ||
} | ||
|
||
case 5: { | ||
const project = process.argv[3]; | ||
const instanceUrl = process.argv[4]; | ||
const couchUrl = `${instanceUrl}/medic`; | ||
|
||
const project = process.argv[2]; | ||
const instanceUrl = process.argv[3]; | ||
const couchUrl = `${instanceUrl}/medic`; | ||
const action = process.argv[2]; | ||
|
||
if(supportedActions.includes(action)) { | ||
const log = require('../src/lib/log'); | ||
|
||
require('../src/cli/all.js')(project, couchUrl); | ||
log('##', `Performing ${action} on ${instanceUrl}...`); | ||
return require(`../src/fn/${action}`)(project, couchUrl) | ||
.then(() => log('##', action, 'complete.')); | ||
} | ||
} | ||
|
||
/* falls through */ | ||
default: | ||
usage(); | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = [ | ||
'backup-app-settings', | ||
'backup-forms', | ||
'compile-app-settings', | ||
'delete-forms', | ||
'upload-app-settings', | ||
'upload-forms', | ||
'upload-resources', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
const fs = require('../lib/sync-fs'); | ||
const request = require('request-promise-native'); | ||
|
||
const log = require('../lib/log'); | ||
const backupFileFor = require('../lib/backup-file-for'); | ||
|
||
module.exports = (project, couchUrl) => { | ||
const backupLocation = backupFileFor(project, 'app_settings.json'); | ||
|
||
return request({ | ||
url: `${couchUrl}/_design/medic/_rewrite/app_settings/medic`, | ||
json: true, | ||
}) | ||
.then(body => fs.writeJson(backupFileFor(project, 'app_settings.json'), body.settings)); | ||
.then(body => fs.writeJson(backupLocation, body.settings)) | ||
.then(() => log('Backed up to:', backupLocation)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
const fs = require('../lib/sync-fs'); | ||
const attachmentsFromDir = require('../lib/attachments-from-dir'); | ||
|
||
const PouchDB = require('pouchdb'); | ||
|
||
const attachmentsFromDir = require('../lib/attachments-from-dir'); | ||
const insertOrUpdate = require('../lib/insert-or-update'); | ||
|
||
module.exports = (project, couchUrl) => { | ||
const db = new PouchDB(couchUrl); | ||
|
||
return db.get('resources') | ||
.catch(e => { | ||
if(e.status === 404) return { _id:'resources' }; | ||
else throw e; | ||
}) | ||
.then(doc => { | ||
doc.resources = fs.readJson(`${project}/resources.json`); | ||
doc._attachments = attachmentsFromDir(`${project}/resources`); | ||
return db.put(doc); | ||
}); | ||
return insertOrUpdate(db, { | ||
_id: 'resources', | ||
resources: fs.readJson(`${project}/resources.json`), | ||
_attachments: attachmentsFromDir(`${project}/resources`), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = (db, doc) => | ||
db.get(doc._id) | ||
.then(existingDoc => doc._rev = existingDoc._rev) | ||
.catch(e => { | ||
if(e.status === 404) return; | ||
else throw e; | ||
}) | ||
.then(() => db.put(doc)); |