-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
64 lines (57 loc) · 1.46 KB
/
cli.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
#!/usr/bin/env node
var path = require('path');
var nconf = require('nconf');
var sftploy = require('./sftploy');
var leprechaun = require('leprechaun');
var inquirer = require('inquirer');
var merge = require('lodash.merge');
var snakeCase = require('lodash.snakecase');
var Promise = require('bluebird');
var options = {};
nconf.argv().env({
match: /^sftploy/i
}).file({
file: path.resolve(process.cwd(), 'sftploy.json')
});
[
'username',
'password',
'privateKey',
'host',
'port',
'files',
'localRoot',
'remoteRoot',
'exclude'
].forEach(function (key) {
var env = snakeCase(key);
options[key] = nconf.get(key) || nconf.get('sftploy_' + env.toLowerCase()) || nconf.get('SFTPLOY_' + env.toUpperCase());
});
function ensurePassword (opts) {
return new Promise(function (resolve) {
if (opts.password || opts.privateKey) {
resolve(opts);
} else {
inquirer.prompt([{
type: 'password',
message: 'Enter your password',
name: 'password',
validate: function (value) {
return !!value || 'Please enter a password.';
}
}]).then(function (answers) {
resolve(merge(opts, answers));
});
}
});
}
function deploy (opts) {
sftploy(opts).then(function () {
leprechaun.success('SFTPloyment successful.');
}).catch(function (error) {
leprechaun.error('SFTPloyment failed.');
console.error(error);
process.exit(1);
});
}
ensurePassword(options).then(deploy);