-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
medic-conf.js
executable file
·65 lines (57 loc) · 1.68 KB
/
medic-conf.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
#!/usr/bin/env node
const error = require('../src/lib/log').error;
const info = require('../src/lib/log').info;
const path = require('path');
const usage = require('../src/cli/usage');
const supportedActions = require('../src/cli/supported-actions');
const args = process.argv.slice(2);
if(args.length === 1) {
switch(args[0]) {
case '--help': usage(); return process.exit(0);
case '--version':
console.log(require('../package.json').version);
process.exit(0);
}
}
if(args.length < 2) {
usage();
process.exit(1);
}
const project = path.normalize(args[0]).replace(/\/$/, '');
const instanceUrl = args[1];
const couchUrl = `${instanceUrl}/medic`;
let actions;
if(args.length === 2) {
actions = [
'compile-app-settings',
'backup-app-settings',
'upload-app-settings',
'convert-app-forms',
'convert-contact-forms',
'backup-forms',
'delete-forms',
'upload-app-forms',
'upload-contact-forms',
'upload-resources',
'upload-custom-translations',
];
} else {
actions = args.slice(2);
}
const unsupported = actions.filter(a => !supportedActions.includes(a));
if(unsupported.length) {
error(`Unsupported action(s): ${unsupported.join(' ')}`);
process.exit(1);
}
info(`Processing config in ${project} for ${instanceUrl}. Actions: ${actions}`);
return actions.reduce((promiseChain, action) =>
promiseChain
.then(() => info(`Starting action: ${action}…`))
.then(() => require(`../src/fn/${action}`)(project, couchUrl))
.then(() => info(`${action} complete.`)),
Promise.resolve())
.then(() => { if(actions.length > 1) info('All actions completed.'); })
.catch(e => {
error(e);
process.exit(1);
});