@raisenow/tamaro-cli 1.1.6 → 1.1.8

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.
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
@@ -1,7 +1,6 @@
1
1
  import {createRequire} from 'module'
2
2
  import {basename} from 'path'
3
3
  import {config as dotenvConfig} from 'dotenv'
4
- import {expand as dotenvExpand} from 'dotenv-expand'
5
4
  import {globSync} from 'glob'
6
5
  import stripIndent from 'strip-indent'
7
6
  import type {IfUtilsFn} from 'webpack-config-utils'
@@ -28,7 +27,7 @@ export const getEnvVars = (
28
27
  const filePath = files.find((file) => basename(file) === '.env')
29
28
 
30
29
  if (filePath) {
31
- dotenvExpand(dotenvConfig({path: filePath}))
30
+ dotenvConfig({path: filePath})
32
31
  }
33
32
 
34
33
  process.env.NODE_ENV ??= ifMin('production', 'development')
@@ -63,8 +62,8 @@ export const getEnvVars = (
63
62
  let version = process.env.CORE_VERSION
64
63
  version = version ? `@${version}` : ''
65
64
 
66
- // process.env.CORE_URL ??= `https://cdn.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
67
- process.env.CORE_URL ??= `https://fastly.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
65
+ process.env.CORE_URL ??= `https://cdn.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
66
+ // process.env.CORE_URL ??= `https://fastly.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`
68
67
  }
69
68
  }
70
69
 
@@ -144,8 +143,7 @@ export const assertEnvValid = (env?: string) => {
144
143
 
145
144
  if (envs.length !== 0) {
146
145
  if (!env) {
147
- // There are some ".env.<env>" files, but no "--env" flag is specified,
148
- // so we must require it
146
+ // There are some ".env.<env>" files, but no "--env" flag is specified, so we must require it
149
147
  halt('Flag "--env" is required.')
150
148
  }
151
149
 
@@ -172,6 +170,6 @@ export const applyEnv = (env?: string) => {
172
170
  const filePath = files.find((file) => basename(file) === `.env.${env}`)
173
171
 
174
172
  if (filePath) {
175
- dotenvExpand(dotenvConfig({path: filePath}))
173
+ dotenvConfig({path: filePath})
176
174
  }
177
175
  }
@@ -60,17 +60,22 @@ const getWebpackConfig = (env: any): Configuration => {
60
60
  logTitle('Environment variables:')
61
61
  logDataTable(envVars.raw)
62
62
 
63
- const getCssLoaders = (cssOptions: any = {}): RuleSetUseItem[] => {
63
+ const getCssLoaders = ({
64
+ styleLoader = true,
65
+ ...cssOptions
66
+ }: {styleLoader?: boolean} & Record<string, any>): RuleSetUseItem[] => {
64
67
  return removeEmpty([
65
- ifMin({loader: MiniCssExtractPlugin.loader}),
66
- ifNotMin({
67
- loader: require.resolve('style-loader'),
68
- options: {
69
- attributes: {
70
- 'data-widget': process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET,
71
- },
72
- },
73
- }),
68
+ styleLoader ? ifMin({loader: MiniCssExtractPlugin.loader}) : undefined,
69
+ styleLoader
70
+ ? ifNotMin({
71
+ loader: require.resolve('style-loader'),
72
+ options: {
73
+ attributes: {
74
+ 'data-widget': process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET,
75
+ },
76
+ },
77
+ })
78
+ : undefined,
74
79
  {
75
80
  loader: require.resolve('css-loader'),
76
81
  options: {
@@ -158,8 +163,10 @@ const getWebpackConfig = (env: any): Configuration => {
158
163
 
159
164
  {
160
165
  oneOf: [
161
- // App Javascript and Typescript (Babel)
162
- // and some dependencies distributed in a non-es5 formats
166
+ /**
167
+ * App Javascript and Typescript (Babel)
168
+ * and some dependencies distributed in a non-es5 formats
169
+ */
163
170
  {
164
171
  test: /\.(js|ts)x?$/,
165
172
  include: ifCore(
@@ -219,20 +226,23 @@ const getWebpackConfig = (env: any): Configuration => {
219
226
  test: /\.(js|mjs)$/,
220
227
  },
221
228
 
222
- // Styles (not modules)
229
+ // Styles (extracted)
223
230
  {
224
231
  test: /\.s?css$/,
225
- exclude: /\.module\.s?css$/,
232
+ resourceQuery: {not: [/inline/]},
226
233
  use: getCssLoaders({
227
- modules: false,
234
+ styleLoader: true,
228
235
  }),
229
236
  },
230
237
 
231
- // Styles (modules)
238
+ // Styles (as string)
232
239
  {
233
- test: /\.module\.s?css$/,
240
+ test: /\.s?css$/,
241
+ resourceQuery: /inline/,
234
242
  use: getCssLoaders({
235
- modules: {localIdentName: '[local]__[hash:base64]'},
243
+ styleLoader: false,
244
+ exportType: 'string',
245
+ sourceMap: false,
236
246
  }),
237
247
  },
238
248
 
@@ -268,8 +278,10 @@ const getWebpackConfig = (env: any): Configuration => {
268
278
  },
269
279
  },
270
280
 
271
- // All other files - fallback
272
- // This must be the latest rule!
281
+ /**
282
+ * All other files - fallback
283
+ * This must be the latest rule!
284
+ */
273
285
  {
274
286
  exclude: [/^$/, /\.(js|jsx|ts|tsx|mjs)$/, /\.html$/, /\.json$/],
275
287
  type: 'asset/resource',