|
2 | 2 | // SPDX-License-Identifier: Apache-2.0
|
3 | 3 | 'use strict'
|
4 | 4 |
|
5 |
| -const { execute, r, red, green } = require('./utils.js') |
| 5 | +const { red, green } = require('./utils.js') |
6 | 6 |
|
7 | 7 | const deployerConfig = require('./get-deployer-config.js')
|
8 | 8 | const writeConfig = require('./write-config.js')
|
9 |
| - |
10 |
| -const errors = [] |
11 |
| - |
12 |
| -function getRequired (key) { |
13 |
| - const value = deployerConfig[key] |
14 |
| - if (value) return value |
15 |
| - errors.push(key + ' must be defined') |
16 |
| -} |
17 |
| - |
18 |
| -function getOptional (key, orElse) { |
19 |
| - return deployerConfig[key] || orElse |
| 9 | +const deployTemplate = require('./deploy-template.js') |
| 10 | + |
| 11 | +async function main() { |
| 12 | + const missing = deployTemplate(deployerConfig) |
| 13 | + |
| 14 | + if (missing != null) { |
| 15 | + for (const key of missing) console.error(red(key + ' must be defined')) |
| 16 | + } else { |
| 17 | + await writeConfig() |
| 18 | + console.log() |
| 19 | + console.log(green('Process Complete! Run `npm run start` to launch run the dev portal locally.')) |
| 20 | + console.log() |
| 21 | + } |
20 | 22 | }
|
21 | 23 |
|
22 |
| -// required inputs |
23 |
| -const stackName = getRequired('stackName') |
24 |
| -const buildAssetsBucket = getRequired('buildAssetsBucket') |
25 |
| -const siteAssetsBucket = getRequired('siteAssetsBucket') |
26 |
| -const apiAssetsBucket = getRequired('apiAssetsBucket') |
27 |
| -const cognitoDomainName = getRequired('cognitoDomainName') |
28 |
| - |
29 |
| -// required (and defaulted) inputs |
30 |
| -const samTemplate = getOptional('samTemplate', r('../../cloudformation/template.yaml')) |
31 |
| -const packageConfig = getOptional('packageConfig', r('../../cloudformation/packaged.yaml')) |
32 |
| -const customersTableName = getOptional('customersTableName') |
33 |
| -const preLoginAccountsTableName = getOptional('preLoginAccountsTableName') |
34 |
| -const feedbackTableName = getOptional('feedbackTableName') |
35 |
| -const cognitoIdentityPoolName = getOptional('cognitoIdentityPoolName') |
36 |
| - |
37 |
| -// optional inputs |
38 |
| -const staticAssetRebuildMode = getOptional('staticAssetRebuildMode', '') |
39 |
| -const developmentMode = getOptional('developmentMode') |
40 |
| - |
41 |
| -// AWS SAM CLI configuration |
42 |
| -const awsSamCliProfile = getOptional('awsSamCliProfile') |
43 |
| - |
44 |
| -async function main () { |
45 |
| - execute('sam', [ |
46 |
| - 'package', |
47 |
| - '--template-file', samTemplate, |
48 |
| - '--output-template-file', packageConfig, |
49 |
| - '--s3-bucket', buildAssetsBucket, |
50 |
| - ...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : []) |
51 |
| - ]) |
52 |
| - execute('sam', [ |
53 |
| - 'deploy', |
54 |
| - '--template-file', packageConfig, |
55 |
| - '--stack-name', stackName, |
56 |
| - '--capabilities', 'CAPABILITY_NAMED_IAM', |
57 |
| - '--parameter-overrides', |
58 |
| - `StaticAssetRebuildToken=${Date.now()}`, |
59 |
| - ...(staticAssetRebuildMode ? [`StaticAssetRebuildMode=${staticAssetRebuildMode}`] : []), |
60 |
| - `DevPortalSiteS3BucketName=${siteAssetsBucket}`, |
61 |
| - `ArtifactsS3BucketName=${apiAssetsBucket}`, |
62 |
| - ...(customersTableName ? [`DevPortalCustomersTableName=${customersTableName}`] : []), |
63 |
| - ...(preLoginAccountsTableName ? [`DevPortalPreLoginAccountsTableName=${preLoginAccountsTableName}`] : []), |
64 |
| - ...(feedbackTableName ? [`DevPortalFeedbackTableName=${feedbackTableName}`] : []), |
65 |
| - ...(cognitoIdentityPoolName ? [`CognitoIdentityPoolName=${cognitoIdentityPoolName}`] : []), |
66 |
| - ...(developmentMode ? [`LocalDevelopmentMode=${developmentMode}`] : []), |
67 |
| - `CognitoDomainNameOrPrefix=${cognitoDomainName}`, |
68 |
| - '--s3-bucket', buildAssetsBucket, |
69 |
| - ...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : []) |
70 |
| - ]) |
71 |
| - await writeConfig() |
72 |
| - console.log() |
73 |
| - console.log(green('Process Complete! Run `npm run start` to launch run the dev portal locally.')) |
74 |
| - console.log() |
75 |
| -} |
76 |
| - |
77 |
| -if (errors.length) { |
78 |
| - for (const error of errors) console.error(red(error)) |
79 |
| -} else { |
80 |
| - main().catch(err => console.error(red(err))) |
81 |
| -} |
| 24 | +main().catch(err => console.error(red(err))) |
0 commit comments