@raisenow/tamaro-cli 1.1.5 → 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.
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  assertProfilesPresent,
3
+ assertProfileValid,
4
+ awsAuthenticate,
3
5
  type AwsOptions,
4
6
  prepareFlags,
5
7
  promptProfile,
6
- withAwsAuthenticate,
7
8
  } from 'lib/aws'
8
9
  import {halt, runCommandSync} from 'lib/command'
9
- import {AWS_S3_BUCKET, CORE_CONFIG_NAME} from 'lib/constants'
10
+ import {AWS_S3_BUCKET_TAMARO, CORE_CONFIG_NAME} from 'lib/constants'
10
11
  import {logCommand, logTitle} from 'lib/logging'
11
12
  import {getIfCoreFns, getWidgetUuid} from 'lib/resolve'
12
13
 
@@ -21,14 +22,15 @@ export type ListDeployedOptions = AwsOptions & {
21
22
  export const listDeployed = async (
22
23
  options: ListDeployedOptions,
23
24
  ): Promise<void> => {
24
- assertOptionsValid(options)
25
-
26
- if (!options.ci) {
25
+ if (!options.profile && !options.ci) {
27
26
  assertProfilesPresent()
28
27
  options.profile = await promptProfile()
29
28
  }
30
29
 
31
- const flags = prepareFlags([], options).join(' ')
30
+ assertOptionsValid(options)
31
+ awsAuthenticate(options)
32
+
33
+ const flags = prepareFlags(options)
32
34
  const {config} = options
33
35
  const {ifCore} = getIfCoreFns()
34
36
  const configName = config ?? ifCore(CORE_CONFIG_NAME, getWidgetUuid())
@@ -37,7 +39,7 @@ export const listDeployed = async (
37
39
  ? `Listing deployments of Tamaro Core …`
38
40
  : `Listing deployments of "${configName}" customer configuration …`
39
41
 
40
- const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/`
42
+ const deployUrl = `s3://${AWS_S3_BUCKET_TAMARO}/${configName}/`
41
43
  const cmd = `aws s3 ls ${deployUrl} ${flags}`
42
44
  let out = ''
43
45
 
@@ -47,8 +49,8 @@ export const listDeployed = async (
47
49
  // If customer configuration folder does not exist on AWS S3,
48
50
  // command fails with blank stderr, so we need to handle this case.
49
51
  try {
50
- const result = withAwsAuthenticate(() => runCommandSync(cmd), options)
51
- out = result.stdout
52
+ const result = runCommandSync(cmd)
53
+ out = result.stdout as string
52
54
  } catch (error: any) {
53
55
  out = error.stdout as string
54
56
 
@@ -67,7 +69,7 @@ export const listDeployed = async (
67
69
  text = tags
68
70
  .map((tag, idx) => {
69
71
  // prettier-ignore
70
- return `${idx + 1}. https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`
72
+ return `${idx + 1}. https://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/index.html`
71
73
  })
72
74
  .join('\n')
73
75
  }
@@ -79,9 +81,13 @@ export const listDeployed = async (
79
81
  ///////////////////////////////////////////////////////////////////////////////
80
82
 
81
83
  const assertOptionsValid = (options: ListDeployedOptions) => {
82
- const {config} = options
84
+ const {config, profile} = options
83
85
 
84
86
  assertConfigValid(config)
87
+
88
+ if (profile) {
89
+ assertProfileValid(profile)
90
+ }
85
91
  }
86
92
 
87
93
  ///////////////////////////////////////////////////////////////////////////////
@@ -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
- }
@@ -1,15 +1,11 @@
1
- import {
2
- execaCommandSync,
3
- type ExecaSyncReturnValue,
4
- type SyncOptions,
5
- } from 'execa'
1
+ import {execaCommandSync, type SyncOptions, type SyncResult} from 'execa'
6
2
  import {logError} from 'lib/logging'
7
3
 
8
4
  ///////////////////////////////////////////////////////////////////////////////
9
5
 
10
- export const halt = (message?: string, exitCode = 1) => {
6
+ export const halt = (message?: string) => {
11
7
  logError(message)
12
- process.exit(exitCode)
8
+ process.exit(1)
13
9
  }
14
10
 
15
11
  ///////////////////////////////////////////////////////////////////////////////
@@ -26,6 +22,6 @@ export const prepareCommand = (cmd: string): string => {
26
22
  export const runCommandSync = (
27
23
  cmd: string,
28
24
  options?: SyncOptions,
29
- ): ExecaSyncReturnValue => {
25
+ ): SyncResult => {
30
26
  return execaCommandSync(prepareCommand(cmd), options)
31
27
  }
@@ -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
 
@@ -104,7 +104,7 @@ const getWebpackConfig = (env: any): Configuration => {
104
104
  },
105
105
  {
106
106
  loader: require.resolve('sass-loader'),
107
- options: {sourceMap: true},
107
+ options: {api: 'modern-compiler', sourceMap: true},
108
108
  },
109
109
  ])
110
110
  }
@@ -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',
package/tsconfig.json CHANGED
@@ -1,86 +1,38 @@
1
1
  {
2
+ /* https://aka.ms/tsconfig.json */
2
3
  "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Basic Options */
6
- // "incremental": true, /* Enable incremental compilation */
7
- "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
8
- "module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
9
- // "lib": [], /* Specify library files to be included in the compilation. */
10
- "allowJs": true, /* Allow javascript files to be compiled. */
11
- // "checkJs": true, /* Report errors in .js files. */
12
- "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
- // "declaration": true, /* Generates corresponding '.d.ts' file. */
14
- // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
- // "sourceMap": true, /* Generates corresponding '.map' file. */
16
- // "outFile": "./", /* Concatenate and emit output to single file. */
17
- // "outDir": "./", /* Redirect output structure to the directory. */
18
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
- // "composite": true, /* Enable project compilation */
20
- // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21
- // "removeComments": true, /* Do not emit comments to output. */
22
- "noEmit": true, /* Do not emit outputs. */
23
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24
- // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25
- "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26
-
27
- /* Strict Type-Checking Options */
28
- "strict": true, /* Enable all strict type-checking options. */
29
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30
- // "strictNullChecks": true, /* Enable strict null checks. */
31
- // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32
- // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33
- // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34
- // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35
- // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36
-
37
- /* Additional Checks */
38
- // "noUnusedLocals": true, /* Report errors on unused locals. */
39
- // "noUnusedParameters": true, /* Report errors on unused parameters. */
40
- // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41
- "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42
- // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
43
-
44
- /* Module Resolution Options */
45
- "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
46
- "baseUrl": ".", /* Base directory to resolve non-absolute module names. */
47
- "paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
4
+ "moduleDetection": "force",
5
+ "resolveJsonModule": true,
6
+ "allowJs": true,
7
+ "esModuleInterop": true,
8
+ "isolatedModules": true,
9
+
10
+ "noEmit": true,
11
+ "strict": true,
12
+ "noFallthroughCasesInSwitch": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "skipLibCheck": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+
17
+ "target": "ESNext",
18
+ "module": "ESNext",
19
+ "moduleResolution": "Bundler",
20
+ "jsx": "react",
21
+
22
+ "baseUrl": ".",
23
+ "paths": {
48
24
  "commands/*": ["src/commands/*"],
49
25
  "lib/*": ["src/lib/*"]
50
26
  },
51
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
52
- // "typeRoots": [], /* List of folders to include type definitions from. */
53
- // "types": [], /* Type declaration files to be included in compilation. */
54
- "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
55
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
56
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
57
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
58
-
59
- /* Source Map Options */
60
- // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
61
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
62
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
63
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
64
-
65
- /* Experimental Options */
66
- // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
67
- // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
68
-
69
- /* Advanced Options */
70
- "skipLibCheck": true, /* Skip type checking of declaration files. */
71
- "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
72
-
73
- /* Allow imports from json files */
74
- "resolveJsonModule": true,
75
27
  },
76
28
  "include": [
77
29
  "**/*",
78
30
  ".eslintrc.cjs",
79
31
  ],
80
32
  "exclude": [
81
- ".history/**/*",
82
- ".idea/**/*",
83
- "dist/**/*",
84
- "node_modules/**/*",
33
+ ".history",
34
+ ".idea",
35
+ "dist",
36
+ "node_modules",
85
37
  ]
86
38
  }