@raisenow/tamaro-cli 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ export type ServeOptions = {
18
18
  export const serve = async (options: ServeOptions): Promise<void> => {
19
19
  assertOptionsValid(options)
20
20
 
21
- const flags = (await prepareFlags([], options)).join(' ')
21
+ const flags = await prepareFlags(options)
22
22
  const {ifCore} = getIfCoreFns()
23
23
  const paths = getPaths(ifCore)
24
24
  const cmd = `
@@ -48,10 +48,8 @@ const assertOptionsValid = (options: ServeOptions) => {
48
48
 
49
49
  ///////////////////////////////////////////////////////////////////////////////
50
50
 
51
- const prepareFlags = async (
52
- flags: string[],
53
- options: ServeOptions,
54
- ): Promise<string[]> => {
51
+ const prepareFlags = async (options: ServeOptions) => {
52
+ const flags: string[] = []
55
53
  const {port: defaultPort, https} = options
56
54
  const port = await getPortPromise({port: Number(defaultPort)})
57
55
 
@@ -67,5 +65,5 @@ const prepareFlags = async (
67
65
  flags.push(`--ssl-key ${keyFile}`)
68
66
  }
69
67
 
70
- return flags
68
+ return flags.join(' ')
71
69
  }
package/src/lib/aws.ts CHANGED
@@ -3,10 +3,6 @@ import {execaCommandSync} from 'execa'
3
3
  import prompts from 'prompts'
4
4
  import stripIndent from 'strip-indent'
5
5
  import {halt} from 'lib/command'
6
- import {
7
- AWS_S3_EMAIL_CONFIG_PROD_BUCKET,
8
- AWS_S3_EMAIL_CONFIG_STAGE_BUCKET,
9
- } from 'lib/constants'
10
6
 
11
7
  ///////////////////////////////////////////////////////////////////////////////
12
8
 
@@ -17,22 +13,13 @@ export type AwsOptions = {
17
13
 
18
14
  ///////////////////////////////////////////////////////////////////////////////
19
15
 
20
- export const withAwsAuthenticate = <Result = any>(
21
- fn: () => Result,
22
- options: AwsOptions,
23
- ): Result => {
24
- awsAuthenticate(options)
25
-
26
- return fn()
27
- }
28
-
29
- ///////////////////////////////////////////////////////////////////////////////
30
-
31
16
  export const awsAuthenticate = (options: AwsOptions) => {
32
17
  if (options.ci) {
33
- // Don't try to authenticate the user.
34
- // This is done when CLI is running within an automated system like pipeline,
35
- // In this case "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" are used instead of "AWS_PROFILE".
18
+ /**
19
+ * Don't try to authenticate the user.
20
+ * This is done when CLI is running within an automated system like pipeline,
21
+ * In this case "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" are used instead of "AWS_PROFILE".
22
+ */
36
23
  return
37
24
  }
38
25
 
@@ -70,20 +57,24 @@ export const getAvailableProfiles = (): string[] => {
70
57
 
71
58
  ///////////////////////////////////////////////////////////////////////////////
72
59
 
73
- // Returns caller identity data (output is ignored here).
74
- // Fails in case of expired SSO session.
60
+ /**
61
+ * Returns caller identity data (output is ignored here).
62
+ * Fails in case of expired SSO session.
63
+ */
75
64
  const checkIdentity = (options: AwsOptions) => {
76
- const flags = prepareFlags([], options).join(' ')
65
+ const flags = prepareFlags(options)
77
66
 
78
67
  execaCommandSync(`aws sts get-caller-identity ${flags}`)
79
68
  }
80
69
 
81
70
  ///////////////////////////////////////////////////////////////////////////////
82
71
 
83
- // Opens SSO authentication page in the browser.
84
- // Fails if user canceled authentication process.
72
+ /**
73
+ * Opens SSO authentication page in the browser.
74
+ * Fails if user canceled authentication process.
75
+ */
85
76
  const login = (options: AwsOptions) => {
86
- const flags = prepareFlags([], options).join(' ')
77
+ const flags = prepareFlags(options)
87
78
 
88
79
  try {
89
80
  execaCommandSync(`aws sso login ${flags}`, {stdio: 'inherit'})
@@ -96,17 +87,30 @@ const login = (options: AwsOptions) => {
96
87
 
97
88
  ///////////////////////////////////////////////////////////////////////////////
98
89
 
99
- export const prepareFlags = (
100
- flags: string[],
101
- options: AwsOptions,
102
- ): string[] => {
90
+ export const prepareFlags = (options: AwsOptions) => {
91
+ const flags: string[] = []
103
92
  const {profile} = options
104
93
 
105
94
  if (profile) {
106
95
  flags.push(`--profile ${profile}`)
107
96
  }
108
97
 
109
- return flags
98
+ return flags.join(' ')
99
+ }
100
+
101
+ ///////////////////////////////////////////////////////////////////////////////
102
+
103
+ export const assertProfileValid = (profile: string) => {
104
+ const profiles = getAvailableProfiles()
105
+
106
+ if (!profiles.includes(profile)) {
107
+ halt(
108
+ stripIndent(`
109
+ AWS profile "${profile}" is not found.
110
+ Available profiles are: ${profiles.map((v) => `"${v}"`).join(', ')}.
111
+ `),
112
+ )
113
+ }
110
114
  }
111
115
 
112
116
  ///////////////////////////////////////////////////////////////////////////////
@@ -126,34 +130,9 @@ export const promptProfile = async (): Promise<string | undefined> => {
126
130
  },
127
131
  ],
128
132
  {
129
- onCancel: () => process.exit(1),
133
+ onCancel: () => halt(),
130
134
  },
131
135
  )
132
136
 
133
137
  return profile
134
138
  }
135
-
136
- ///////////////////////////////////////////////////////////////////////////////
137
-
138
- export const promptBucket = async (): Promise<string> => {
139
- const buckets = [
140
- {title: 'stage', value: AWS_S3_EMAIL_CONFIG_STAGE_BUCKET},
141
- {title: 'prod', value: AWS_S3_EMAIL_CONFIG_PROD_BUCKET},
142
- ]
143
-
144
- const {bucket} = await prompts(
145
- [
146
- {
147
- type: 'select',
148
- name: 'bucket',
149
- message: 'Select environment',
150
- choices: buckets,
151
- },
152
- ],
153
- {
154
- onCancel: () => process.exit(1),
155
- },
156
- )
157
-
158
- return bucket
159
- }
@@ -3,9 +3,9 @@ import {logError} from 'lib/logging'
3
3
 
4
4
  ///////////////////////////////////////////////////////////////////////////////
5
5
 
6
- export const halt = (message?: string, exitCode = 1) => {
6
+ export const halt = (message?: string) => {
7
7
  logError(message)
8
- process.exit(exitCode)
8
+ process.exit(1)
9
9
  }
10
10
 
11
11
  ///////////////////////////////////////////////////////////////////////////////
@@ -1,9 +1,8 @@
1
1
  export const DEFAULT_TAG = 'latest'
2
2
  export const DEFAULT_PORT = 1234
3
- export const DEFAULT_AWS_PROFILE = 'payments-prod-cs-deployer'
4
- export const AWS_S3_EMAIL_CONFIG_PROD_BUCKET = 'rnw-email-service'
5
- export const AWS_S3_EMAIL_CONFIG_STAGE_BUCKET = 'rnw-stage-email-service'
6
- export const AWS_S3_BUCKET = 'tamaro.raisenow.com'
3
+ export const AWS_S3_BUCKET_TAMARO = 'tamaro.raisenow.com'
4
+ export const AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE = 'rnw-stage-email-service'
5
+ export const AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD = 'rnw-email-service'
7
6
  export const CORE_CONFIG_NAME = 'tamaro-core'
8
7
  export const AWS_CLOUDFRONT_DISTRIBUTION_ID = 'EHJ1OM458YQ0I'
9
8
  export const HTTPS_CRT_FILE = 'localhost.crt'
package/src/lib/env.ts CHANGED
@@ -144,8 +144,7 @@ export const assertEnvValid = (env?: string) => {
144
144
 
145
145
  if (envs.length !== 0) {
146
146
  if (!env) {
147
- // There are some ".env.<env>" files, but no "--env" flag is specified,
148
- // so we must require it
147
+ // There are some ".env.<env>" files, but no "--env" flag is specified, so we must require it
149
148
  halt('Flag "--env" is required.')
150
149
  }
151
150
 
@@ -158,8 +158,10 @@ const getWebpackConfig = (env: any): Configuration => {
158
158
 
159
159
  {
160
160
  oneOf: [
161
- // App Javascript and Typescript (Babel)
162
- // and some dependencies distributed in a non-es5 formats
161
+ /**
162
+ * App Javascript and Typescript (Babel)
163
+ * and some dependencies distributed in a non-es5 formats
164
+ */
163
165
  {
164
166
  test: /\.(js|ts)x?$/,
165
167
  include: ifCore(
@@ -268,8 +270,10 @@ const getWebpackConfig = (env: any): Configuration => {
268
270
  },
269
271
  },
270
272
 
271
- // All other files - fallback
272
- // This must be the latest rule!
273
+ /**
274
+ * All other files - fallback
275
+ * This must be the latest rule!
276
+ */
273
277
  {
274
278
  exclude: [/^$/, /\.(js|jsx|ts|tsx|mjs)$/, /\.html$/, /\.json$/],
275
279
  type: 'asset/resource',