@raisenow/tamaro-cli 1.1.7 → 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.
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/runConfigurations/build_watch.xml +13 -0
- package/.idea/runConfigurations/lint_fix.xml +13 -0
- package/.idea/runConfigurations/tscheck.xml +12 -0
- package/.idea/tamaro-cli.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.nvmrc +1 -1
- package/README.md +35 -13
- package/bitbucket-pipelines.yml +43 -0
- package/dist/{chunk-NJVU7WR2.js → chunk-KVWFHWZD.js} +4 -5
- package/dist/cli.js +48 -10
- package/dist/webpack.config.js +17 -11
- package/package.json +10 -9
- package/src/cli.ts +0 -178
- package/src/commands/build.ts +0 -131
- package/src/commands/deploy-email-config.ts +0 -159
- package/src/commands/deploy.ts +0 -164
- package/src/commands/dev.ts +0 -88
- package/src/commands/list-deployed.ts +0 -117
- package/src/commands/serve.ts +0 -69
- package/src/lib/InterpolateHtmlPlugin.ts +0 -47
- package/src/lib/aws.ts +0 -138
- package/src/lib/command.ts +0 -27
- package/src/lib/constants.ts +0 -9
- package/src/lib/env.ts +0 -176
- package/src/lib/https.ts +0 -27
- package/src/lib/logging.ts +0 -37
- package/src/lib/notifier.ts +0 -22
- package/src/lib/resolve.ts +0 -143
- package/src/webpack.config.ts +0 -429
- package/tsconfig.json +0 -38
package/src/cli.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {createCommand} from 'commander'
|
|
4
|
-
import {build, type BuildOptions} from 'commands/build'
|
|
5
|
-
import {deploy, type DeployOptions} from 'commands/deploy'
|
|
6
|
-
import {
|
|
7
|
-
deployEmailConfig,
|
|
8
|
-
type DeployEmailConfigOptions,
|
|
9
|
-
} from 'commands/deploy-email-config'
|
|
10
|
-
import {dev, type DevOptions} from 'commands/dev'
|
|
11
|
-
import {listDeployed, type ListDeployedOptions} from 'commands/list-deployed'
|
|
12
|
-
import {serve, type ServeOptions} from 'commands/serve'
|
|
13
|
-
import {halt} from 'lib/command'
|
|
14
|
-
import {DEFAULT_PORT, DEFAULT_TAG} from 'lib/constants'
|
|
15
|
-
import {logError, logTitle} from 'lib/logging'
|
|
16
|
-
import pkg from '../package.json'
|
|
17
|
-
|
|
18
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Makes the script crash on unhandled rejections instead of silently
|
|
22
|
-
* ignoring them. In the future, promise rejections that are not handled will
|
|
23
|
-
* terminate the Node.js process with a non-zero exit code.
|
|
24
|
-
*/
|
|
25
|
-
process.on('unhandledRejection', (error) => {
|
|
26
|
-
throw error
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
// Exit on ctrl+c
|
|
30
|
-
process.on('SIGINT', () => {
|
|
31
|
-
halt()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
35
|
-
|
|
36
|
-
const cli = createCommand().name(pkg.name).version(pkg.version, '-v, --version')
|
|
37
|
-
|
|
38
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
39
|
-
|
|
40
|
-
cli
|
|
41
|
-
.command('dev')
|
|
42
|
-
.description(
|
|
43
|
-
'Run the local development server for Tamaro Core or a particular customer configuration',
|
|
44
|
-
)
|
|
45
|
-
.option(
|
|
46
|
-
'--local-core',
|
|
47
|
-
'Load Tamaro Core from localhost:1234 instead of the CDN',
|
|
48
|
-
false,
|
|
49
|
-
)
|
|
50
|
-
.option(
|
|
51
|
-
'--https',
|
|
52
|
-
'Let local web server serve Tamaro with SSL encryption',
|
|
53
|
-
false,
|
|
54
|
-
)
|
|
55
|
-
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
56
|
-
.option('--env <env>', 'Environment (dev, stage, prod)')
|
|
57
|
-
.option('--nolint', 'Disable ESLint', false)
|
|
58
|
-
.action(async (options: DevOptions) => {
|
|
59
|
-
await dev(options)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
cli
|
|
63
|
-
.command('build')
|
|
64
|
-
.description(
|
|
65
|
-
'Build an optimised (minified) bundle of Tamaro Core or a customer configuration',
|
|
66
|
-
)
|
|
67
|
-
.option(
|
|
68
|
-
'--local-core',
|
|
69
|
-
'Load Tamaro Core from localhost:1234 instead of the CDN',
|
|
70
|
-
false,
|
|
71
|
-
)
|
|
72
|
-
.option('--analyze', 'Generate bundle statistics to "reports" folder', false)
|
|
73
|
-
.option('--serve', 'Run the generated bundle with a local web server', false)
|
|
74
|
-
.option(
|
|
75
|
-
'--https',
|
|
76
|
-
'Let local web server serve Tamaro with SSL encryption',
|
|
77
|
-
false,
|
|
78
|
-
)
|
|
79
|
-
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
80
|
-
.option('--env <env>', 'Environment (dev, stage, prod)')
|
|
81
|
-
.option('--profile <profile>', 'AWS profile')
|
|
82
|
-
.option('--ci', 'CI environment', false)
|
|
83
|
-
.option(
|
|
84
|
-
'--deploy',
|
|
85
|
-
'Deploy Tamaro Core or a customer configuration bundle to AWS S3',
|
|
86
|
-
false,
|
|
87
|
-
)
|
|
88
|
-
.option(
|
|
89
|
-
'--tag <tag>',
|
|
90
|
-
'Tag which should be used for the deployment of the bundle',
|
|
91
|
-
DEFAULT_TAG,
|
|
92
|
-
)
|
|
93
|
-
.option('--nolint', 'Disable ESLint', false)
|
|
94
|
-
.action(async (options: BuildOptions & ServeOptions & DeployOptions) => {
|
|
95
|
-
await build(options)
|
|
96
|
-
|
|
97
|
-
if (options.serve) {
|
|
98
|
-
await serve(options)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (options.deploy) {
|
|
102
|
-
await deploy(options)
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
cli
|
|
107
|
-
.command('serve')
|
|
108
|
-
.description('Run a local web server for pre-built bundle')
|
|
109
|
-
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
110
|
-
.option(
|
|
111
|
-
'--https',
|
|
112
|
-
'Let local web server serve Tamaro with SSL encryption',
|
|
113
|
-
false,
|
|
114
|
-
)
|
|
115
|
-
.action(async (options: ServeOptions) => {
|
|
116
|
-
await serve(options)
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
cli
|
|
120
|
-
.command('deploy')
|
|
121
|
-
.description(
|
|
122
|
-
'Deploy a pre-built Tamaro Core or customer configuration bundle to AWS S3',
|
|
123
|
-
)
|
|
124
|
-
.option('--profile <profile>', 'AWS profile')
|
|
125
|
-
.option('--ci', 'CI environment', false)
|
|
126
|
-
.option(
|
|
127
|
-
'--tag <tag>',
|
|
128
|
-
'Tag which should be used for the deployment of the bundle',
|
|
129
|
-
DEFAULT_TAG,
|
|
130
|
-
)
|
|
131
|
-
.action(async (options: DeployOptions) => {
|
|
132
|
-
await deploy(options)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
cli
|
|
136
|
-
.command('list-deployed')
|
|
137
|
-
.description(
|
|
138
|
-
'List deployments of Tamaro Core or a particular customer configuration',
|
|
139
|
-
)
|
|
140
|
-
.option('--profile <profile>', 'AWS profile')
|
|
141
|
-
.option('--ci', 'CI environment', false)
|
|
142
|
-
.option(
|
|
143
|
-
'--config <config>',
|
|
144
|
-
'Configuration name (default: current customer configuration)',
|
|
145
|
-
)
|
|
146
|
-
.action(async (options: ListDeployedOptions) => {
|
|
147
|
-
await listDeployed(options)
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
cli
|
|
151
|
-
.command('deploy-email-config')
|
|
152
|
-
.description("Deploy a widget's email configuration to AWS S3")
|
|
153
|
-
.option('--profile <profile>', 'AWS profile')
|
|
154
|
-
.option('--ci', 'CI environment', false)
|
|
155
|
-
.option('--bucket <bucket>', 'AWS bucket for email configs')
|
|
156
|
-
.action(async (options: DeployEmailConfigOptions) => {
|
|
157
|
-
await deployEmailConfig(options)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
161
|
-
|
|
162
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
163
|
-
;(async () => {
|
|
164
|
-
try {
|
|
165
|
-
logTitle(`${pkg.name} ${pkg.version}\n`)
|
|
166
|
-
|
|
167
|
-
await cli.parseAsync(process.argv)
|
|
168
|
-
} catch (error: any) {
|
|
169
|
-
if (error.signal === 'SIGINT' && error.signalDescription) {
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
171
|
-
logError(`\n${error.signalDescription}`)
|
|
172
|
-
} else {
|
|
173
|
-
// eslint-disable-next-line no-console
|
|
174
|
-
console.log('')
|
|
175
|
-
logError(error.stack)
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
})()
|
package/src/commands/build.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {type DeployOptions} from 'commands/deploy'
|
|
2
|
-
import {assertProfilesPresent, assertProfileValid, promptProfile} from 'lib/aws'
|
|
3
|
-
import {halt, runCommandSync} from 'lib/command'
|
|
4
|
-
import {CORE_CONFIG_NAME} from 'lib/constants'
|
|
5
|
-
import {applyEnv, assertEnvValid} from 'lib/env'
|
|
6
|
-
import {assertCrtExists} from 'lib/https'
|
|
7
|
-
import {logCommand, logTitle} from 'lib/logging'
|
|
8
|
-
import {notify} from 'lib/notifier'
|
|
9
|
-
import {
|
|
10
|
-
getIfCoreFns,
|
|
11
|
-
getPaths,
|
|
12
|
-
getWidgetUuid,
|
|
13
|
-
resolveBin,
|
|
14
|
-
resolveOwn,
|
|
15
|
-
} from 'lib/resolve'
|
|
16
|
-
|
|
17
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
18
|
-
|
|
19
|
-
export type BuildOptions = {
|
|
20
|
-
localCore: boolean
|
|
21
|
-
analyze: boolean
|
|
22
|
-
https: boolean
|
|
23
|
-
serve: boolean
|
|
24
|
-
deploy: boolean
|
|
25
|
-
env?: string
|
|
26
|
-
nolint: boolean
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
30
|
-
|
|
31
|
-
export const build = async (
|
|
32
|
-
options: BuildOptions & DeployOptions,
|
|
33
|
-
): Promise<void> => {
|
|
34
|
-
const {env} = options
|
|
35
|
-
|
|
36
|
-
applyEnv(env)
|
|
37
|
-
|
|
38
|
-
if (options.deploy && !options.profile && !options.ci) {
|
|
39
|
-
assertProfilesPresent()
|
|
40
|
-
options.profile = await promptProfile()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
assertOptionsValid(options)
|
|
44
|
-
|
|
45
|
-
const flags = prepareFlags(options)
|
|
46
|
-
const {ifCore} = getIfCoreFns()
|
|
47
|
-
const paths = getPaths(ifCore)
|
|
48
|
-
const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid())
|
|
49
|
-
const title = ifCore(
|
|
50
|
-
'Building optimised (minified) bundle of Tamaro Core …',
|
|
51
|
-
`Building optimised (minified) bundle of "${configName}" customer configuration …`,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
const wpBin = resolveBin('webpack')
|
|
55
|
-
const wpConfig = resolveOwn('dist/webpack.config.js')
|
|
56
|
-
const cmd = `
|
|
57
|
-
${wpBin}
|
|
58
|
-
--config ${wpConfig}
|
|
59
|
-
--env min
|
|
60
|
-
${flags}
|
|
61
|
-
`
|
|
62
|
-
|
|
63
|
-
logTitle(title)
|
|
64
|
-
logCommand(cmd)
|
|
65
|
-
runCommandSync(cmd, {stdio: 'inherit'})
|
|
66
|
-
|
|
67
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
68
|
-
|
|
69
|
-
logTitle(`\nBundle for "${configName}" customer configuration is done.`)
|
|
70
|
-
// eslint-disable-next-line no-console
|
|
71
|
-
console.log(`Path: ${paths.appDist}\n`)
|
|
72
|
-
|
|
73
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
74
|
-
|
|
75
|
-
process.on('exit', () => {
|
|
76
|
-
notify({
|
|
77
|
-
title: 'build',
|
|
78
|
-
message: `Bundle for "${configName}" customer configuration is done.`,
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
84
|
-
|
|
85
|
-
const assertOptionsValid = (options: BuildOptions & DeployOptions) => {
|
|
86
|
-
const {localCore, https, deploy, env, profile} = options
|
|
87
|
-
const {ifCore} = getIfCoreFns()
|
|
88
|
-
|
|
89
|
-
if (ifCore() && localCore) {
|
|
90
|
-
halt('Flag "--local-core" is redundant if running in Tamaro Core context.')
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (localCore && deploy) {
|
|
94
|
-
halt('Flags "--local-core" and "--deploy" must not be used together.')
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (https) {
|
|
98
|
-
assertCrtExists()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (profile) {
|
|
102
|
-
assertProfileValid(profile)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
assertEnvValid(env)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
109
|
-
|
|
110
|
-
const prepareFlags = (options: BuildOptions) => {
|
|
111
|
-
const flags: string[] = []
|
|
112
|
-
const {localCore, analyze, https, nolint} = options
|
|
113
|
-
|
|
114
|
-
if (localCore) {
|
|
115
|
-
flags.push('--env localCore')
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (analyze) {
|
|
119
|
-
flags.push('--env analyze')
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (https) {
|
|
123
|
-
flags.push('--env https')
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (nolint) {
|
|
127
|
-
flags.push('--env nolint')
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return flags.join(' ')
|
|
131
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import {existsSync} from 'fs'
|
|
2
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
3
|
-
import prompts from 'prompts'
|
|
4
|
-
import {
|
|
5
|
-
assertProfilesPresent,
|
|
6
|
-
assertProfileValid,
|
|
7
|
-
awsAuthenticate,
|
|
8
|
-
type AwsOptions,
|
|
9
|
-
prepareFlags,
|
|
10
|
-
promptProfile,
|
|
11
|
-
} from 'lib/aws'
|
|
12
|
-
import {halt, runCommandSync} from 'lib/command'
|
|
13
|
-
import {
|
|
14
|
-
AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD,
|
|
15
|
-
AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE,
|
|
16
|
-
} from 'lib/constants'
|
|
17
|
-
import {logCommand, logDataTable, logTitle} from 'lib/logging'
|
|
18
|
-
import {notify} from 'lib/notifier'
|
|
19
|
-
import {getIfCoreFns, getPaths, getWidgetUuid} from 'lib/resolve'
|
|
20
|
-
|
|
21
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
22
|
-
|
|
23
|
-
export type DeployEmailConfigOptions = AwsOptions & {
|
|
24
|
-
bucket?: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
28
|
-
|
|
29
|
-
export const deployEmailConfig = async (
|
|
30
|
-
options: DeployEmailConfigOptions,
|
|
31
|
-
): Promise<void> => {
|
|
32
|
-
const {ifCore} = getIfCoreFns()
|
|
33
|
-
const paths = getPaths(ifCore)
|
|
34
|
-
const emailConfigPath = `${paths.app}/email-config`
|
|
35
|
-
|
|
36
|
-
assertIsNotCore()
|
|
37
|
-
assertEmailConfigPathExists(emailConfigPath)
|
|
38
|
-
|
|
39
|
-
if (!options.profile && !options.ci) {
|
|
40
|
-
assertProfilesPresent()
|
|
41
|
-
options.profile = await promptProfile()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!options.bucket) {
|
|
45
|
-
options.bucket = options.ci
|
|
46
|
-
? AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD
|
|
47
|
-
: await promptBucketTamaroEmailConfig()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
assertOptionsValid(options)
|
|
51
|
-
awsAuthenticate(options)
|
|
52
|
-
|
|
53
|
-
const flags = prepareFlags(options)
|
|
54
|
-
const configName = getWidgetUuid()
|
|
55
|
-
const deployUrl = `s3://${options.bucket}/${configName}`
|
|
56
|
-
|
|
57
|
-
const cmd = `
|
|
58
|
-
aws s3 sync ${emailConfigPath} ${deployUrl}
|
|
59
|
-
--delete
|
|
60
|
-
--exact-timestamps
|
|
61
|
-
${flags}
|
|
62
|
-
`
|
|
63
|
-
logTitle(
|
|
64
|
-
`Deploying email configuration for "${configName}" customer configuration to AWS S3 …`,
|
|
65
|
-
)
|
|
66
|
-
logCommand(cmd)
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
runCommandSync(cmd, {stdout: 'inherit'})
|
|
70
|
-
} catch (error: any) {
|
|
71
|
-
halt(error.stderr)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
75
|
-
|
|
76
|
-
logTitle(
|
|
77
|
-
`Email configuration for "${configName}" customer configuration is deployed.`,
|
|
78
|
-
)
|
|
79
|
-
logDataTable({'Deploy URL:': deployUrl})
|
|
80
|
-
|
|
81
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
82
|
-
|
|
83
|
-
process.on('exit', () => {
|
|
84
|
-
notify({
|
|
85
|
-
title: 'deploy-email-config',
|
|
86
|
-
message: `Email configuration for "${configName}" customer configuration is deployed.`,
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
92
|
-
|
|
93
|
-
const assertOptionsValid = (options: DeployEmailConfigOptions) => {
|
|
94
|
-
const {profile, bucket} = options
|
|
95
|
-
|
|
96
|
-
if (profile) {
|
|
97
|
-
assertProfileValid(profile)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (bucket) {
|
|
101
|
-
assertBucketValid(bucket)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
106
|
-
|
|
107
|
-
const assertEmailConfigPathExists = (distPath: string) => {
|
|
108
|
-
if (!existsSync(distPath)) {
|
|
109
|
-
halt('Email config folder does not exists. Nothing to deploy.')
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
114
|
-
|
|
115
|
-
const assertIsNotCore = () => {
|
|
116
|
-
const {ifCore} = getIfCoreFns()
|
|
117
|
-
|
|
118
|
-
if (ifCore()) {
|
|
119
|
-
halt('You cannot deploy widget email configuration for Tamaro Core.')
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
124
|
-
|
|
125
|
-
const assertBucketValid = (bucket: string) => {
|
|
126
|
-
const buckets = [
|
|
127
|
-
AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE,
|
|
128
|
-
AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD,
|
|
129
|
-
] as const
|
|
130
|
-
|
|
131
|
-
if (!buckets.includes(bucket as any)) {
|
|
132
|
-
halt('Invalid bucket name.')
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
137
|
-
|
|
138
|
-
const promptBucketTamaroEmailConfig = async (): Promise<string> => {
|
|
139
|
-
const buckets = [
|
|
140
|
-
{title: 'stage', value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_STAGE},
|
|
141
|
-
{title: 'prod', value: AWS_S3_BUCKET_TAMARO_EMAIL_CONFIG_PROD},
|
|
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: () => halt(),
|
|
155
|
-
},
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
return bucket
|
|
159
|
-
}
|
package/src/commands/deploy.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import {existsSync} from 'fs'
|
|
2
|
-
import stripIndent from 'strip-indent'
|
|
3
|
-
import {
|
|
4
|
-
assertProfilesPresent,
|
|
5
|
-
assertProfileValid,
|
|
6
|
-
awsAuthenticate,
|
|
7
|
-
type AwsOptions,
|
|
8
|
-
prepareFlags,
|
|
9
|
-
promptProfile,
|
|
10
|
-
} from 'lib/aws'
|
|
11
|
-
import {halt, runCommandSync} from 'lib/command'
|
|
12
|
-
import {
|
|
13
|
-
AWS_CLOUDFRONT_DISTRIBUTION_ID,
|
|
14
|
-
AWS_S3_BUCKET_TAMARO,
|
|
15
|
-
CORE_CONFIG_NAME,
|
|
16
|
-
} from 'lib/constants'
|
|
17
|
-
import {logCommand, logDataTable, logTitle} from 'lib/logging'
|
|
18
|
-
import {notify} from 'lib/notifier'
|
|
19
|
-
import {getIfCoreFns, getPaths, getWidgetUuid} from 'lib/resolve'
|
|
20
|
-
|
|
21
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
22
|
-
|
|
23
|
-
export type DeployOptions = AwsOptions & {
|
|
24
|
-
tag: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
28
|
-
|
|
29
|
-
export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
30
|
-
const {ifCore} = getIfCoreFns()
|
|
31
|
-
const paths = getPaths(ifCore)
|
|
32
|
-
|
|
33
|
-
assertDistPathExists(paths.appDist)
|
|
34
|
-
|
|
35
|
-
if (!options.profile && !options.ci) {
|
|
36
|
-
assertProfilesPresent()
|
|
37
|
-
options.profile = await promptProfile()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
assertOptionsValid(options)
|
|
41
|
-
awsAuthenticate(options)
|
|
42
|
-
|
|
43
|
-
const flags = prepareFlags(options)
|
|
44
|
-
const {tag} = options
|
|
45
|
-
const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid())
|
|
46
|
-
const deployUrl = `s3://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}`
|
|
47
|
-
const entryFilename = ifCore('index.js', 'widget.js')
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Sync all files except entrypoint (without deleting old files)
|
|
51
|
-
*/
|
|
52
|
-
const cmdSyncAll = `
|
|
53
|
-
aws s3 sync ${paths.appDist} ${deployUrl}
|
|
54
|
-
--acl public-read
|
|
55
|
-
--exclude ${paths.appDist}/${entryFilename}
|
|
56
|
-
--cache-control max-age=31536000
|
|
57
|
-
${flags}
|
|
58
|
-
`
|
|
59
|
-
logTitle('Deploying to AWS S3 …')
|
|
60
|
-
logCommand(cmdSyncAll)
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
runCommandSync(cmdSyncAll, {stdout: 'inherit'})
|
|
64
|
-
} catch (error: any) {
|
|
65
|
-
halt(error.stderr)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Copy entrypoint
|
|
70
|
-
*/
|
|
71
|
-
const cmdCpEntry = `
|
|
72
|
-
aws s3 cp ${paths.appDist}/${entryFilename} ${deployUrl}/${entryFilename}
|
|
73
|
-
--acl public-read
|
|
74
|
-
--cache-control max-age=64800
|
|
75
|
-
${flags}
|
|
76
|
-
`
|
|
77
|
-
logCommand(cmdCpEntry)
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
runCommandSync(cmdCpEntry, {stdout: 'inherit'})
|
|
81
|
-
} catch (error: any) {
|
|
82
|
-
halt(error.stderr)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Invalidate cloudfront cache
|
|
87
|
-
*/
|
|
88
|
-
const cmdInvalidateCache = `
|
|
89
|
-
aws cloudfront create-invalidation
|
|
90
|
-
--distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID}
|
|
91
|
-
--paths /${configName}/${tag}/*
|
|
92
|
-
${flags}
|
|
93
|
-
`
|
|
94
|
-
logTitle('\nInvalidating edge cache …')
|
|
95
|
-
logCommand(cmdInvalidateCache)
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
// ignore output
|
|
99
|
-
runCommandSync(cmdInvalidateCache)
|
|
100
|
-
} catch (error: any) {
|
|
101
|
-
halt(error.stderr)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
105
|
-
|
|
106
|
-
const demoPage = `https://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/index.html`
|
|
107
|
-
const entryPoint = `https://${AWS_S3_BUCKET_TAMARO}/${configName}/${tag}/${entryFilename}`
|
|
108
|
-
|
|
109
|
-
logTitle(`\nBundle for "${configName}" is deployed with tag "${tag}".`)
|
|
110
|
-
logDataTable({
|
|
111
|
-
'Demo page:': demoPage,
|
|
112
|
-
'Entry point:': entryPoint,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
116
|
-
|
|
117
|
-
process.on('exit', () => {
|
|
118
|
-
notify({
|
|
119
|
-
title: 'deploy',
|
|
120
|
-
message: `
|
|
121
|
-
Bundle for "${configName}" is deployed with tag "${tag}".
|
|
122
|
-
Demo page: ${demoPage}
|
|
123
|
-
Entry point: ${entryPoint}
|
|
124
|
-
`,
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
130
|
-
|
|
131
|
-
const assertOptionsValid = (options: DeployOptions) => {
|
|
132
|
-
const {profile, tag} = options
|
|
133
|
-
|
|
134
|
-
if (profile) {
|
|
135
|
-
assertProfileValid(profile)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
assertTagValid(tag)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
142
|
-
|
|
143
|
-
const assertDistPathExists = (distPath: string) => {
|
|
144
|
-
if (!existsSync(distPath)) {
|
|
145
|
-
halt(
|
|
146
|
-
stripIndent(`
|
|
147
|
-
Dist folder does not exists.
|
|
148
|
-
Make sure you have built the bundle before trying to deploy it.
|
|
149
|
-
`),
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
155
|
-
|
|
156
|
-
const assertTagValid = (tag: string) => {
|
|
157
|
-
const regex = /^[a-zA-Z0-9-_.]+$/
|
|
158
|
-
|
|
159
|
-
if (!regex.test(tag)) {
|
|
160
|
-
halt(
|
|
161
|
-
`Flag "--tag" has forbidden format. Allowed format: ${regex.toString()}.`,
|
|
162
|
-
)
|
|
163
|
-
}
|
|
164
|
-
}
|