@raisenow/tamaro-cli 1.1.8 → 1.1.9

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,69 +0,0 @@
1
- import {resolve} from 'path'
2
- import {getPortPromise} from 'portfinder'
3
- import {halt, runCommandSync} from 'lib/command'
4
- import {HTTPS_CRT_FILE, HTTPS_KEY_FILE} from 'lib/constants'
5
- import {assertCrtExists} from 'lib/https'
6
- import {logCommand, logTitle} from 'lib/logging'
7
- import {getIfCoreFns, getPaths} from 'lib/resolve'
8
-
9
- ///////////////////////////////////////////////////////////////////////////////
10
-
11
- export type ServeOptions = {
12
- port: string
13
- https: boolean
14
- }
15
-
16
- ///////////////////////////////////////////////////////////////////////////////
17
-
18
- export const serve = async (options: ServeOptions): Promise<void> => {
19
- assertOptionsValid(options)
20
-
21
- const flags = await prepareFlags(options)
22
- const {ifCore} = getIfCoreFns()
23
- const paths = getPaths(ifCore)
24
- const cmd = `
25
- npx -y serve ${paths.appDist}
26
- --cors
27
- ${flags}
28
- `
29
-
30
- logTitle(`Running web-server for pre-built bundle …`)
31
- logCommand(cmd)
32
- runCommandSync(cmd, {stdio: 'inherit'})
33
- }
34
-
35
- ///////////////////////////////////////////////////////////////////////////////
36
-
37
- const assertOptionsValid = (options: ServeOptions) => {
38
- const {port, https} = options
39
-
40
- if (isNaN(Number(port))) {
41
- halt('Flag "--port" should be a number.')
42
- }
43
-
44
- if (https) {
45
- assertCrtExists()
46
- }
47
- }
48
-
49
- ///////////////////////////////////////////////////////////////////////////////
50
-
51
- const prepareFlags = async (options: ServeOptions) => {
52
- const flags: string[] = []
53
- const {port: defaultPort, https} = options
54
- const port = await getPortPromise({port: Number(defaultPort)})
55
-
56
- flags.push(`-p ${port}`)
57
-
58
- if (https) {
59
- const {ifCore} = getIfCoreFns()
60
- const paths = getPaths(ifCore)
61
- const certFile = resolve(paths.root, HTTPS_CRT_FILE)
62
- const keyFile = resolve(paths.root, HTTPS_KEY_FILE)
63
-
64
- flags.push(`--ssl-cert ${certFile}`)
65
- flags.push(`--ssl-key ${keyFile}`)
66
- }
67
-
68
- return flags.join(' ')
69
- }
@@ -1,47 +0,0 @@
1
- import escapeStringRegexp from 'escape-string-regexp'
2
- import HtmlWebpackPlugin from 'html-webpack-plugin'
3
- import {type Compiler} from 'webpack'
4
-
5
- ///////////////////////////////////////////////////////////////////////////////
6
-
7
- export type Replacements = Record<string, string | undefined>
8
-
9
- ///////////////////////////////////////////////////////////////////////////////
10
-
11
- const PLUGIN_NAME = 'InterpolateHtmlPlugin'
12
-
13
- ///////////////////////////////////////////////////////////////////////////////
14
-
15
- export class InterpolateHtmlPlugin {
16
- replacements: Replacements
17
-
18
- constructor(replacements: Replacements) {
19
- this.replacements = {...replacements}
20
- }
21
-
22
- apply(compiler: Compiler): void {
23
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
24
- const hooks = HtmlWebpackPlugin.getHooks(compilation)
25
-
26
- hooks.alterAssetTagGroups.tap(PLUGIN_NAME, (assets) => {
27
- const publicUrl = this.replacements.PUBLIC_URL ?? ''
28
- const entry = assets.headTags[0].attributes.src as string
29
- this.replacements.ENTRY = `${publicUrl}${entry}`
30
-
31
- return assets
32
- })
33
-
34
- hooks.afterTemplateExecution.tap(PLUGIN_NAME, (data) => {
35
- // Run HTML through a series of user-specified string replacements.
36
- Object.entries(this.replacements).forEach(([key, value]) => {
37
- data.html = data.html.replace(
38
- new RegExp(`%${escapeStringRegexp(key)}%`, 'g'),
39
- value ?? '',
40
- )
41
- })
42
-
43
- return data
44
- })
45
- })
46
- }
47
- }
package/src/lib/aws.ts DELETED
@@ -1,138 +0,0 @@
1
- import {execaCommandSync} from 'execa'
2
- // eslint-disable-next-line import/no-named-as-default
3
- import prompts from 'prompts'
4
- import stripIndent from 'strip-indent'
5
- import {halt} from 'lib/command'
6
-
7
- ///////////////////////////////////////////////////////////////////////////////
8
-
9
- export type AwsOptions = {
10
- profile?: string
11
- ci?: boolean
12
- }
13
-
14
- ///////////////////////////////////////////////////////////////////////////////
15
-
16
- export const awsAuthenticate = (options: AwsOptions) => {
17
- if (options.ci) {
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
- */
23
- return
24
- }
25
-
26
- try {
27
- checkIdentity(options)
28
- } catch (error) {
29
- login(options)
30
- }
31
- }
32
-
33
- ///////////////////////////////////////////////////////////////////////////////
34
-
35
- export const assertProfilesPresent = () => {
36
- const profiles = getAvailableProfiles()
37
-
38
- if (profiles.length === 0) {
39
- halt(
40
- stripIndent(`
41
- No AWS profiles found.
42
- Run "aws configure sso" to set up SSO-enabled profile.
43
- Check the wiki for more information:
44
- https://raisenow.atlassian.net/wiki/x/lIrWvg
45
- `),
46
- )
47
- }
48
- }
49
-
50
- ///////////////////////////////////////////////////////////////////////////////
51
-
52
- export const getAvailableProfiles = (): string[] => {
53
- const {stdout} = execaCommandSync('aws configure list-profiles')
54
-
55
- return stdout.split('\n')
56
- }
57
-
58
- ///////////////////////////////////////////////////////////////////////////////
59
-
60
- /**
61
- * Returns caller identity data (output is ignored here).
62
- * Fails in case of expired SSO session.
63
- */
64
- const checkIdentity = (options: AwsOptions) => {
65
- const flags = prepareFlags(options)
66
-
67
- execaCommandSync(`aws sts get-caller-identity ${flags}`)
68
- }
69
-
70
- ///////////////////////////////////////////////////////////////////////////////
71
-
72
- /**
73
- * Opens SSO authentication page in the browser.
74
- * Fails if user canceled authentication process.
75
- */
76
- const login = (options: AwsOptions) => {
77
- const flags = prepareFlags(options)
78
-
79
- try {
80
- execaCommandSync(`aws sso login ${flags}`, {stdio: 'inherit'})
81
- // eslint-disable-next-line no-console
82
- console.log('')
83
- } catch (error) {
84
- halt('Login failed.')
85
- }
86
- }
87
-
88
- ///////////////////////////////////////////////////////////////////////////////
89
-
90
- export const prepareFlags = (options: AwsOptions) => {
91
- const flags: string[] = []
92
- const {profile} = options
93
-
94
- if (profile) {
95
- flags.push(`--profile ${profile}`)
96
- }
97
-
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
- }
114
- }
115
-
116
- ///////////////////////////////////////////////////////////////////////////////
117
-
118
- export const promptProfile = async (): Promise<string | undefined> => {
119
- const profiles = getAvailableProfiles()
120
- .filter((v) => !!v)
121
- .map((v) => ({title: v, value: v}))
122
-
123
- const {profile} = await prompts(
124
- [
125
- {
126
- type: 'select',
127
- name: 'profile',
128
- message: 'Select AWS profile',
129
- choices: profiles,
130
- },
131
- ],
132
- {
133
- onCancel: () => halt(),
134
- },
135
- )
136
-
137
- return profile
138
- }
@@ -1,27 +0,0 @@
1
- import {execaCommandSync, type SyncOptions, type SyncResult} from 'execa'
2
- import {logError} from 'lib/logging'
3
-
4
- ///////////////////////////////////////////////////////////////////////////////
5
-
6
- export const halt = (message?: string) => {
7
- logError(message)
8
- process.exit(1)
9
- }
10
-
11
- ///////////////////////////////////////////////////////////////////////////////
12
-
13
- export const prepareCommand = (cmd: string): string => {
14
- return cmd
15
- .replace(/\n/gm, ' ')
16
- .replace(/[ \t]{2,}/gm, ' ')
17
- .trim()
18
- }
19
-
20
- ///////////////////////////////////////////////////////////////////////////////
21
-
22
- export const runCommandSync = (
23
- cmd: string,
24
- options?: SyncOptions,
25
- ): SyncResult => {
26
- return execaCommandSync(prepareCommand(cmd), options)
27
- }
@@ -1,9 +0,0 @@
1
- export const DEFAULT_TAG = 'latest'
2
- export const DEFAULT_PORT = 1234
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'
6
- export const CORE_CONFIG_NAME = 'tamaro-core'
7
- export const AWS_CLOUDFRONT_DISTRIBUTION_ID = 'EHJ1OM458YQ0I'
8
- export const HTTPS_CRT_FILE = 'localhost.crt'
9
- export const HTTPS_KEY_FILE = 'localhost.key'
package/src/lib/env.ts DELETED
@@ -1,175 +0,0 @@
1
- import {createRequire} from 'module'
2
- import {basename} from 'path'
3
- import {config as dotenvConfig} from 'dotenv'
4
- import {globSync} from 'glob'
5
- import stripIndent from 'strip-indent'
6
- import type {IfUtilsFn} from 'webpack-config-utils'
7
- import {halt} from 'lib/command'
8
- import {getIfCoreFns, getPaths, getWidgetUuid, resolveApp} from 'lib/resolve'
9
-
10
- ///////////////////////////////////////////////////////////////////////////////
11
-
12
- export type EnvVars = Record<string, string | undefined>
13
-
14
- ///////////////////////////////////////////////////////////////////////////////
15
-
16
- const require = createRequire(import.meta.url)
17
-
18
- ///////////////////////////////////////////////////////////////////////////////
19
-
20
- export const getEnvVars = (
21
- files: string[],
22
- ifMin: IfUtilsFn,
23
- ifCore: IfUtilsFn,
24
- ifLocalCore: IfUtilsFn,
25
- ifHttps: IfUtilsFn,
26
- ) => {
27
- const filePath = files.find((file) => basename(file) === '.env')
28
-
29
- if (filePath) {
30
- dotenvConfig({path: filePath})
31
- }
32
-
33
- process.env.NODE_ENV ??= ifMin('production', 'development')
34
- process.env.BABEL_ENV ??= ifMin('production', 'development')
35
- process.env.EXPOSE_VAR ??= ifCore('rnw.tamaroCore', 'rnw.tamaro')
36
- process.env.ELEMENT_ATTRIBUTE_DATA_WIDGET ??= ifCore(
37
- 'rnw-tamaro-core',
38
- 'rnw-tamaro',
39
- )
40
- process.env.WEBPACK_UNIQUE_NAME ??= ifCore('RnwTamaroCore', 'RnwTamaro')
41
- process.env.BUILD_DATE = new Date().toISOString()
42
- process.env.PUBLIC_URL ??= ''
43
- process.env.HMR_ENABLED ??= ifMin('false', 'true')
44
-
45
- if (ifCore()) {
46
- process.env.PRODUCT_NAME = 'tamaro'
47
-
48
- const corePkgPath = resolveApp('package.json')
49
- // eslint-disable-next-line @typescript-eslint/no-var-requires
50
- const {version} = require(corePkgPath)
51
-
52
- process.env.PRODUCT_VERSION = version
53
- }
54
-
55
- if (!ifCore()) {
56
- process.env.WIDGET_UUID = getWidgetUuid()
57
-
58
- if (ifLocalCore()) {
59
- const protocol = ifHttps() ? 'https' : 'http'
60
- process.env.CORE_URL = `${protocol}://localhost:1234/index.js`
61
- } else {
62
- let version = process.env.CORE_VERSION
63
- version = version ? `@${version}` : ''
64
-
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`
67
- }
68
- }
69
-
70
- // var names which will be exposed along with "PUBLIC_*" var names
71
- const varNames = [
72
- // common
73
- 'NODE_ENV',
74
- 'BABEL_ENV',
75
- 'EXPOSE_VAR',
76
- 'ELEMENT_ATTRIBUTE_DATA_WIDGET',
77
- 'WEBPACK_UNIQUE_NAME',
78
- 'BUILD_DATE',
79
- 'PUBLIC_URL',
80
-
81
- // core
82
- 'PRODUCT_NAME',
83
- 'PRODUCT_VERSION',
84
-
85
- // config
86
- 'WIDGET_UUID',
87
- 'CORE_URL',
88
- 'CORE_VERSION', // should be explicitly specified in each config
89
-
90
- // epik (obsolete since Tamaro v2.5.0)
91
- 'EPP_API_KEY_DEFAULT',
92
- 'EPP_API_URL_STAGE',
93
- 'EPP_API_URL_PROD',
94
- 'EPMS_API_URL_STAGE',
95
- 'EPMS_API_URL_PROD',
96
- 'EPP_PROXY_URL_STAGE',
97
- 'EPP_PROXY_URL_PROD',
98
- 'EPMS_PROXY_URL_STAGE',
99
- 'EPMS_PROXY_URL_PROD',
100
- 'EPMS_TWINT_CHECKOUT_URL_STAGE',
101
- 'EPMS_TWINT_CHECKOUT_URL_PROD',
102
- ]
103
-
104
- // Collect all vars which names start from "PUBLIC_" or present in "varNames" array
105
- const raw = Object.keys(process.env)
106
- .filter((key) => key.startsWith('PUBLIC_') || varNames.includes(key))
107
- .reduce<EnvVars>((env, key) => {
108
- env[key] = process.env[key]
109
-
110
- return env
111
- }, {})
112
-
113
- // Stringify all values so we can feed into webpack DefinePlugin
114
- const stringified = {
115
- 'process.env': Object.keys(raw).reduce<EnvVars>((env, key) => {
116
- env[key] = JSON.stringify(raw[key])
117
-
118
- return env
119
- }, {}),
120
- }
121
-
122
- return {raw, stringified}
123
- }
124
-
125
- ///////////////////////////////////////////////////////////////////////////////
126
-
127
- export const assertEnvValid = (env?: string) => {
128
- const {ifCore} = getIfCoreFns()
129
- const paths = getPaths(ifCore)
130
- const files = globSync(paths.appEnv)
131
- const envs = files
132
- .map((file) => basename(file).replace(/^\.env\./, ''))
133
- .map((file) => basename(file).replace(/^\.env$/, ''))
134
- .filter((v) => !!v)
135
-
136
- if (envs.length === 0) {
137
- if (env) {
138
- // There are no ".env.<env>" files, so we must ignore "--env" flag
139
- // eslint-disable-next-line no-console
140
- console.log('Flag "--env" is ignored.')
141
- }
142
- }
143
-
144
- if (envs.length !== 0) {
145
- if (!env) {
146
- // There are some ".env.<env>" files, but no "--env" flag is specified, so we must require it
147
- halt('Flag "--env" is required.')
148
- }
149
-
150
- if (env && !envs.includes(env)) {
151
- // There are some ".env.<env>" files, but specified "--env" flag is incorrect
152
- halt(
153
- stripIndent(`
154
- Flag "--env" has wrong value.
155
- Available values are: ${envs.map((v) => `"${v}"`).join(', ')}.
156
- `),
157
- )
158
- }
159
- }
160
- }
161
-
162
- export const applyEnv = (env?: string) => {
163
- if (!env) {
164
- return
165
- }
166
-
167
- const {ifCore} = getIfCoreFns()
168
- const paths = getPaths(ifCore)
169
- const files = globSync(paths.appEnv)
170
- const filePath = files.find((file) => basename(file) === `.env.${env}`)
171
-
172
- if (filePath) {
173
- dotenvConfig({path: filePath})
174
- }
175
- }
package/src/lib/https.ts DELETED
@@ -1,27 +0,0 @@
1
- import {existsSync} from 'fs'
2
- import {resolve} from 'path'
3
- import stripIndent from 'strip-indent'
4
- import {halt} from 'lib/command'
5
- import {HTTPS_CRT_FILE, HTTPS_KEY_FILE} from 'lib/constants'
6
- import {getIfCoreFns, getPaths} from 'lib/resolve'
7
-
8
- ///////////////////////////////////////////////////////////////////////////////
9
-
10
- export const assertCrtExists = () => {
11
- const {ifCore} = getIfCoreFns()
12
- const paths = getPaths(ifCore)
13
- const certFile = resolve(paths.root, HTTPS_CRT_FILE)
14
- const keyFile = resolve(paths.root, HTTPS_KEY_FILE)
15
-
16
- if (existsSync(certFile) && existsSync(keyFile)) {
17
- return
18
- }
19
-
20
- halt(
21
- stripIndent(`
22
- Flag "--https" is used, but "${HTTPS_CRT_FILE}" and/or "${HTTPS_KEY_FILE}" files are not found.
23
- You need to generate certificate first.
24
- Check docs: https://unpkg.com/@raisenow/tamaro-cli/readme.html#/?id=use-transport-level-security-https
25
- `),
26
- )
27
- }
@@ -1,37 +0,0 @@
1
- import chalk from 'chalk'
2
- import columnify from 'columnify'
3
- import stripIndent from 'strip-indent'
4
-
5
- ///////////////////////////////////////////////////////////////////////////////
6
-
7
- export const logTitle = (title: string) => {
8
- // eslint-disable-next-line no-console
9
- console.log(chalk.bold(title))
10
- }
11
-
12
- ///////////////////////////////////////////////////////////////////////////////
13
-
14
- export const logError = (message?: string) => {
15
- if (message) {
16
- // eslint-disable-next-line no-console
17
- console.log(chalk.red(message))
18
- }
19
- }
20
-
21
- ///////////////////////////////////////////////////////////////////////////////
22
-
23
- export const logCommand = (cmd: string): void => {
24
- // eslint-disable-next-line no-console
25
- console.log(`\n${chalk.dim(stripIndent(cmd).trim())}\n`)
26
- }
27
-
28
- ///////////////////////////////////////////////////////////////////////////////
29
-
30
- export const logDataTable = (
31
- data: Record<string, string | undefined>,
32
- ): void => {
33
- // eslint-disable-next-line no-console
34
- console.log(columnify(data, {showHeaders: false}))
35
- // eslint-disable-next-line no-console
36
- console.log('')
37
- }
@@ -1,22 +0,0 @@
1
- import notifier from 'node-notifier'
2
- import stripIndent from 'strip-indent'
3
-
4
- ///////////////////////////////////////////////////////////////////////////////
5
-
6
- export type NotifyArgs = {
7
- title: string
8
- message: string
9
- }
10
-
11
- ///////////////////////////////////////////////////////////////////////////////
12
-
13
- export const notify = (args: NotifyArgs) => {
14
- const {title, message = ''} = args
15
-
16
- notifier.notify({
17
- title,
18
- message: stripIndent(message).trim(),
19
- contentImage: 'https://assets.raisenow.io/favicon.png',
20
- sound: 'Funk',
21
- })
22
- }