-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
55 lines (48 loc) · 1.52 KB
/
config.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
'use strict';
const Configstore = require('configstore');
const fsx = require('./fs-additions');
const path = require('path');
const root = require('find-root');
const _ = require('lodash');
// Information about LT itself
const pkg = require('../../package.json');
const conf = new Configstore(pkg.name);
const majorVersion = pkg.version ? pkg.version.split('.')[0] : 'unknown';
const resourceNamePrefix = _.compact([conf.get('ResourcePrefix'), pkg.name, majorVersion, conf.get('ResourceSuffix')]).join('-');
/**
* Helper for loading config file of a project
*/
// Load configuration file from disk (if one exists)
// Default values
let result = {
project: {},
lambda: {
runtime: 'nodejs18.x'
},
aws: {
region: 'us-east-1',
stage: 'dev'
},
tools: {
name: pkg.name,
version: pkg.version,
majorVersion: majorVersion,
resources: {
s3Bucket: [resourceNamePrefix, 'assets'].join('-'),
iamRole: [resourceNamePrefix, 'resource'].join('-'),
apiGateway: [resourceNamePrefix, 'api-gateway'].join('-'),
lambdaVersion: [resourceNamePrefix, 'lambda-version'].join('-')
}
}
};
// Config file is assumed to be at "package root"
try {
const rootPath = root(process.cwd());
const configPath = path.resolve(rootPath, '.lambda-tools-rc.json');
if (fsx.fileExists(configPath)) {
result = _.merge(result, fsx.readJSONFileSync(configPath));
}
} catch (err) {
// Ignore
}
module.exports = result;