-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
41 lines (35 loc) · 993 Bytes
/
utils.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
const inquirer = require('inquirer');
const os = require('os');
const path = require('path');
const aws = require('./aws');
async function setup(options) {
const availableRegions = await aws.getRegions();
const homeDir = os.homedir();
if (options.region && !availableRegions.includes(options.region)) {
throw new Error(`Region ${options.region} is not a valid region in this account. Available regions are:\n${availableRegions.join('\n')}`);
}
const accountId = await aws.getAccountId();
const regions = options.region ? [options.region] : availableRegions;
const baseDir = path.join(homeDir, '.stacks');
const stacksFileName = 'stacks.yaml';
return {
accountId,
regions,
baseDir,
stacksFileName,
};
}
async function prompt(message, defaultValue) {
return (
await inquirer.prompt({
type: 'confirm',
name: 'choice',
default: defaultValue || true,
message,
})
).choice;
}
module.exports = {
setup,
prompt,
};