forked from architect/deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (45 loc) · 1.29 KB
/
index.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
let _inventory = require('@architect/inventory')
let { updater } = require('@architect/utils')
let cleanup = require('./src/utils/cleanup')
let direct = require('./src/direct')
let sam = require('./src/sam')
let _static = require('./src/static')
function run (mod) {
return function (options, callback) {
let promise
if (!callback) {
promise = new Promise(function ugh (res, rej) {
callback = function errback (err, result) {
if (err) rej(err)
else res(result)
}
})
}
// Always attempt to clean up after ourselves before exiting
function clean (err, result) {
cleanup()
if (err) callback(err)
else callback(null, result)
}
// Entered via CLI (or something that supplied inventory)
if (options.inventory) mod(options, clean)
else {
// Get inventory, but don't fetch env vars if it's a dry-run
_inventory({ env: true }, function (err, inv) {
if (err) callback(err)
else {
options.update = updater('Deploy')
options.region = options.region || inv.inv.aws.region
options.inventory = inv
mod(options, clean)
}
})
}
return promise
}
}
module.exports = {
direct: run(direct),
sam: run(sam),
static: run(_static)
}