@raisenow/tamaro-cli 1.0.10 → 1.0.11
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/{.eslintrc.js → .eslintrc.cjs} +2 -9
- package/.gitignore +3 -3
- package/.nvmrc +1 -1
- package/{.prettierrc.js → .prettierrc.cjs} +0 -0
- package/{readme.md → README.md} +34 -32
- package/dist/chunk-PIEFLCDU.js +144 -0
- package/dist/cli.js +243 -300
- package/dist/webpack.config.js +114 -252
- package/package.json +23 -31
- package/readme.html +1 -1
- package/src/cli.ts +29 -19
- package/src/commands/build.ts +27 -25
- package/src/commands/deploy-email-config.ts +28 -20
- package/src/commands/deploy.ts +49 -37
- package/src/commands/dev.ts +24 -17
- package/src/commands/list-deployed.ts +22 -12
- package/src/commands/serve.ts +36 -12
- package/src/lib/InterpolateHtmlPlugin.ts +10 -8
- package/src/lib/aws.ts +43 -35
- package/src/lib/command.ts +27 -0
- package/src/lib/constants.ts +7 -0
- package/src/lib/env.ts +102 -0
- package/src/lib/logging.ts +32 -0
- package/src/lib/notifier.ts +22 -0
- package/src/lib/resolve.ts +144 -0
- package/src/webpack.config.ts +23 -31
- package/tsconfig.json +1 -1
- package/src/lib/helpers.ts +0 -356
- package/src/lib/polyfills.js +0 -8
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raisenow/tamaro-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "RaiseNow",
|
|
6
6
|
"email": "development@raisenow.com"
|
|
7
7
|
},
|
|
8
|
-
"
|
|
8
|
+
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"prepare": "npm run build",
|
|
11
11
|
"start": "npm run dev",
|
|
12
|
-
"
|
|
13
|
-
"build": "
|
|
12
|
+
"build": "tsup src/cli.ts src/webpack.config.ts --clean --format esm",
|
|
13
|
+
"build:watch": "npm run build -- --watch --ignore-watch .idea",
|
|
14
14
|
"docs": "npx -y http-server . --cors -o /readme.html",
|
|
15
15
|
"lint": "eslint . --fix && prettier --write ."
|
|
16
16
|
},
|
|
@@ -20,53 +20,48 @@
|
|
|
20
20
|
"npm": ">=8"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@babel/cli": "^7.17.
|
|
24
|
-
"@babel/core": "^7.17.
|
|
25
|
-
"@babel/plugin-proposal-decorators": "^7.17.
|
|
23
|
+
"@babel/cli": "^7.17.3",
|
|
24
|
+
"@babel/core": "^7.17.5",
|
|
25
|
+
"@babel/plugin-proposal-decorators": "^7.17.2",
|
|
26
26
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
27
27
|
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
28
28
|
"@babel/preset-env": "^7.16.11",
|
|
29
29
|
"@babel/preset-react": "^7.16.7",
|
|
30
30
|
"@babel/preset-typescript": "^7.16.7",
|
|
31
|
-
"@babel/runtime-corejs3": "^7.17.
|
|
31
|
+
"@babel/runtime-corejs3": "^7.17.2",
|
|
32
32
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
|
|
33
33
|
"@statoscope/webpack-plugin": "^5.20.1",
|
|
34
34
|
"@svgr/webpack": "^6.2.1",
|
|
35
35
|
"@types/columnify": "^1.5.1",
|
|
36
36
|
"@types/lodash": "^4.14.178",
|
|
37
|
-
"@types/
|
|
38
|
-
"@types/node": "^17.0.16",
|
|
37
|
+
"@types/node": "^17.0.21",
|
|
39
38
|
"@types/node-notifier": "^8.0.2",
|
|
40
39
|
"@types/resolve-bin": "^0.4.1",
|
|
41
40
|
"@types/webpack-config-utils": "^2.3.1",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
43
|
-
"@typescript-eslint/parser": "^5.
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.12.0",
|
|
42
|
+
"@typescript-eslint/parser": "^5.12.0",
|
|
44
43
|
"autoprefixer": "^10.4.2",
|
|
45
44
|
"babel-loader": "^8.2.3",
|
|
46
45
|
"babel-plugin-lodash": "^3.3.4",
|
|
47
|
-
"
|
|
48
|
-
"chalk": "^4.1.2",
|
|
46
|
+
"chalk": "^5.0.0",
|
|
49
47
|
"clean-webpack-plugin": "^4.0.0",
|
|
50
48
|
"columnify": "^1.6.0",
|
|
51
49
|
"commander": "^9.0.0",
|
|
52
50
|
"copy-webpack-plugin": "^10.2.4",
|
|
53
|
-
"core-js": "^3.21.
|
|
51
|
+
"core-js": "^3.21.1",
|
|
54
52
|
"css-loader": "^6.6.0",
|
|
55
53
|
"css-minimizer-webpack-plugin": "^3.4.1",
|
|
56
|
-
"current-script-polyfill": "^1.0.0",
|
|
57
54
|
"dotenv": "^16.0.0",
|
|
58
55
|
"dotenv-expand": "^8.0.1",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"eslint": "^8.
|
|
62
|
-
"eslint-config-prettier": "^8.3.0",
|
|
56
|
+
"escape-string-regexp": "^5.0.0",
|
|
57
|
+
"eslint": "^8.9.0",
|
|
58
|
+
"eslint-config-prettier": "^8.4.0",
|
|
63
59
|
"eslint-plugin-node": "^11.1.0",
|
|
64
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
65
60
|
"eslint-plugin-promise": "^6.0.0",
|
|
66
|
-
"eslint-webpack-plugin": "^3.1.
|
|
67
|
-
"execa": "^
|
|
61
|
+
"eslint-webpack-plugin": "^3.1.1",
|
|
62
|
+
"execa": "^6.1.0",
|
|
68
63
|
"file-loader": "^6.2.0",
|
|
69
|
-
"fork-ts-checker-webpack-plugin": "^7.
|
|
64
|
+
"fork-ts-checker-webpack-plugin": "^7.2.1",
|
|
70
65
|
"glob": "^7.2.0",
|
|
71
66
|
"html-loader": "^3.1.0",
|
|
72
67
|
"html-webpack-plugin": "^5.5.0",
|
|
@@ -74,26 +69,23 @@
|
|
|
74
69
|
"lodash": "^4.17.21",
|
|
75
70
|
"mini-css-extract-plugin": "^2.5.3",
|
|
76
71
|
"node-notifier": "^10.0.1",
|
|
77
|
-
"open": "^8.4.0",
|
|
78
72
|
"portfinder": "^1.0.28",
|
|
79
73
|
"postcss": "^8.4.6",
|
|
80
74
|
"postcss-custom-properties": "^12.1.4",
|
|
81
75
|
"postcss-loader": "^6.2.1",
|
|
82
76
|
"prettier": "^2.5.1",
|
|
83
77
|
"react-refresh": "^0.11.0",
|
|
84
|
-
"resolve-bin": "^1.0.0",
|
|
85
78
|
"resolve-url-loader": "^5.0.0",
|
|
86
|
-
"sass": "^1.49.
|
|
87
|
-
"sass-loader": "^12.
|
|
79
|
+
"sass": "^1.49.8",
|
|
80
|
+
"sass-loader": "^12.6.0",
|
|
88
81
|
"source-map-loader": "^3.0.1",
|
|
89
|
-
"strip-indent": "^
|
|
82
|
+
"strip-indent": "^4.0.0",
|
|
90
83
|
"style-loader": "^3.3.1",
|
|
91
84
|
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
|
92
85
|
"tsup": "^5.11.13",
|
|
93
86
|
"typescript": "^4.5.5",
|
|
94
|
-
"unfetch": "^4.2.0",
|
|
95
87
|
"url-loader": "^4.1.1",
|
|
96
|
-
"webpack": "^5.
|
|
88
|
+
"webpack": "^5.69.1",
|
|
97
89
|
"webpack-cli": "^4.9.2",
|
|
98
90
|
"webpack-config-utils": "^2.3.1",
|
|
99
91
|
"webpack-dev-server": "^4.7.4",
|
package/readme.html
CHANGED
package/src/cli.ts
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
import {createCommand} from 'commander'
|
|
4
4
|
import pkg from '../package.json'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_AWS_PROFILE,
|
|
7
|
+
DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET,
|
|
8
|
+
DEFAULT_PORT,
|
|
9
|
+
DEFAULT_TAG,
|
|
10
|
+
} from 'lib/constants'
|
|
11
|
+
import {logError} from 'lib/logging'
|
|
6
12
|
import {dev, DevOptions} from 'commands/dev'
|
|
7
13
|
import {build, BuildOptions} from 'commands/build'
|
|
8
|
-
import {
|
|
9
|
-
import {serve} from 'commands/serve'
|
|
14
|
+
import {deploy, DeployOptions} from 'commands/deploy'
|
|
15
|
+
import {serve, ServeOptions} from 'commands/serve'
|
|
10
16
|
import {listDeployed, ListDeployedOptions} from 'commands/list-deployed'
|
|
11
17
|
import {
|
|
12
|
-
DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET,
|
|
13
18
|
deployEmailConfig,
|
|
14
19
|
DeployEmailConfigOptions,
|
|
15
20
|
} from 'commands/deploy-email-config'
|
|
16
|
-
import {DEFAULT_AWS_PROFILE} from 'lib/aws'
|
|
17
21
|
|
|
18
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
19
23
|
|
|
@@ -42,9 +46,10 @@ cli
|
|
|
42
46
|
)
|
|
43
47
|
.option(
|
|
44
48
|
'--local-core',
|
|
45
|
-
'Load Tamaro Core from localhost instead of the CDN',
|
|
49
|
+
'Load Tamaro Core from localhost:1234 instead of the CDN',
|
|
46
50
|
false,
|
|
47
51
|
)
|
|
52
|
+
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
48
53
|
.action(async (options: DevOptions) => {
|
|
49
54
|
await dev(options)
|
|
50
55
|
})
|
|
@@ -56,16 +61,17 @@ cli
|
|
|
56
61
|
)
|
|
57
62
|
.option(
|
|
58
63
|
'--local-core',
|
|
59
|
-
'Load Tamaro Core from localhost instead of the CDN',
|
|
64
|
+
'Load Tamaro Core from localhost:1234 instead of the CDN',
|
|
60
65
|
false,
|
|
61
66
|
)
|
|
62
67
|
.option('--analyze', 'Generate bundle statistics to "reports" folder', false)
|
|
68
|
+
.option('--serve', 'Run the generated bundle with a local web server', false)
|
|
69
|
+
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
63
70
|
.option(
|
|
64
71
|
'--deploy',
|
|
65
72
|
'Deploy Tamaro Core or a customer configuration bundle to AWS S3',
|
|
66
73
|
false,
|
|
67
74
|
)
|
|
68
|
-
.option('--serve', 'Run the generated bundle with a local web server', false)
|
|
69
75
|
.option(
|
|
70
76
|
'--tag <tag>',
|
|
71
77
|
'Tag which should be used for the deployment of the bundle',
|
|
@@ -76,16 +82,24 @@ cli
|
|
|
76
82
|
'AWS profile which should be used for the deployment of the bundle',
|
|
77
83
|
DEFAULT_AWS_PROFILE,
|
|
78
84
|
)
|
|
79
|
-
.action(async (options: BuildOptions & DeployOptions) => {
|
|
85
|
+
.action(async (options: BuildOptions & ServeOptions & DeployOptions) => {
|
|
80
86
|
await build(options)
|
|
81
87
|
|
|
88
|
+
if (options.serve) {
|
|
89
|
+
await serve(options)
|
|
90
|
+
}
|
|
91
|
+
|
|
82
92
|
if (options.deploy) {
|
|
83
93
|
await deploy(options)
|
|
84
94
|
}
|
|
95
|
+
})
|
|
85
96
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
97
|
+
cli
|
|
98
|
+
.command('serve')
|
|
99
|
+
.description('Run a local web server for pre-built bundle')
|
|
100
|
+
.option('--port <port>', 'Web server port', `${DEFAULT_PORT}`)
|
|
101
|
+
.action(async (options: ServeOptions) => {
|
|
102
|
+
await serve(options)
|
|
89
103
|
})
|
|
90
104
|
|
|
91
105
|
cli
|
|
@@ -107,13 +121,6 @@ cli
|
|
|
107
121
|
await deploy(options)
|
|
108
122
|
})
|
|
109
123
|
|
|
110
|
-
cli
|
|
111
|
-
.command('serve')
|
|
112
|
-
.description('Run a local web server for pre-built bundle')
|
|
113
|
-
.action(async () => {
|
|
114
|
-
await serve()
|
|
115
|
-
})
|
|
116
|
-
|
|
117
124
|
cli
|
|
118
125
|
.command('list-deployed')
|
|
119
126
|
.description(
|
|
@@ -156,6 +163,9 @@ cli
|
|
|
156
163
|
} catch (error: any) {
|
|
157
164
|
if (error.signal === 'SIGINT' && error.signalDescription) {
|
|
158
165
|
logError(`\n${error.signalDescription}`)
|
|
166
|
+
} else {
|
|
167
|
+
console.log('')
|
|
168
|
+
logError(error.stack)
|
|
159
169
|
}
|
|
160
170
|
}
|
|
161
171
|
})()
|
package/src/commands/build.ts
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {CORE_CONFIG_NAME} from 'lib/constants'
|
|
2
|
+
import {assertProfileValid} from 'lib/aws'
|
|
2
3
|
import {
|
|
3
|
-
fail,
|
|
4
4
|
getIfCoreFns,
|
|
5
5
|
getPaths,
|
|
6
6
|
getWidgetUuid,
|
|
7
|
-
|
|
8
|
-
logDataTable,
|
|
9
|
-
logTitle,
|
|
10
|
-
notify,
|
|
7
|
+
resolveBin,
|
|
11
8
|
resolveOwn,
|
|
12
|
-
|
|
13
|
-
} from 'lib/
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
9
|
+
} from 'lib/resolve'
|
|
10
|
+
import {logCommand, logTitle} from 'lib/logging'
|
|
11
|
+
import {notify} from 'lib/notifier'
|
|
12
|
+
import {fail, runCommandSync} from 'lib/command'
|
|
13
|
+
import {DeployOptions} from 'commands/deploy'
|
|
16
14
|
|
|
17
15
|
///////////////////////////////////////////////////////////////////////////////
|
|
18
16
|
|
|
19
17
|
export type BuildOptions = {
|
|
20
18
|
localCore: boolean
|
|
21
19
|
analyze: boolean
|
|
22
|
-
deploy: boolean
|
|
23
20
|
serve: boolean
|
|
21
|
+
deploy: boolean
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -30,7 +28,7 @@ export const build = async (
|
|
|
30
28
|
): Promise<void> => {
|
|
31
29
|
assertOptionsValid(options)
|
|
32
30
|
|
|
33
|
-
const flags = prepareFlags(options)
|
|
31
|
+
const flags = prepareFlags([], options).join(' ')
|
|
34
32
|
const {ifCore} = getIfCoreFns()
|
|
35
33
|
const paths = getPaths(ifCore)
|
|
36
34
|
const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid())
|
|
@@ -39,7 +37,7 @@ export const build = async (
|
|
|
39
37
|
`Building optimised (minified) bundle of “${configName}” customer configuration …`,
|
|
40
38
|
)
|
|
41
39
|
|
|
42
|
-
const wpBin = resolveBin
|
|
40
|
+
const wpBin = resolveBin('webpack')
|
|
43
41
|
const wpConfig = resolveOwn('dist/webpack.config.js')
|
|
44
42
|
const cmd = `
|
|
45
43
|
${wpBin}
|
|
@@ -54,16 +52,16 @@ export const build = async (
|
|
|
54
52
|
|
|
55
53
|
/////////////////////////////////////////////////////////////////////////////
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
`Bundle for “${configName}” customer configuration is done.`,
|
|
60
|
-
)
|
|
55
|
+
logTitle(`\nBundle for “${configName}” customer configuration is done.`)
|
|
56
|
+
console.log(`Path: ${paths.appDist}\n`)
|
|
61
57
|
|
|
62
58
|
/////////////////////////////////////////////////////////////////////////////
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
process.on('exit', () => {
|
|
61
|
+
notify({
|
|
62
|
+
title: 'build',
|
|
63
|
+
message: `Bundle for “${configName}” customer configuration is done.`,
|
|
64
|
+
})
|
|
67
65
|
})
|
|
68
66
|
}
|
|
69
67
|
|
|
@@ -86,12 +84,16 @@ const assertOptionsValid = (options: BuildOptions & DeployOptions) => {
|
|
|
86
84
|
|
|
87
85
|
///////////////////////////////////////////////////////////////////////////////
|
|
88
86
|
|
|
89
|
-
const prepareFlags = (options: BuildOptions): string => {
|
|
87
|
+
const prepareFlags = (flags: string[], options: BuildOptions): string[] => {
|
|
90
88
|
const {localCore, analyze} = options
|
|
91
|
-
let flags: string[] = []
|
|
92
89
|
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
if (localCore) {
|
|
91
|
+
flags.push('--env localCore')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (analyze) {
|
|
95
|
+
flags.push('--env analyze')
|
|
96
|
+
}
|
|
95
97
|
|
|
96
|
-
return flags
|
|
98
|
+
return flags
|
|
97
99
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {existsSync} from 'fs'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from 'lib/
|
|
12
|
-
import {assertProfileValid, AwsOptions, runAwsCommandSync} from 'lib/aws'
|
|
3
|
+
assertProfileValid,
|
|
4
|
+
AwsOptions,
|
|
5
|
+
withAwsAuthenticate,
|
|
6
|
+
prepareFlags as prepareAwsFlags,
|
|
7
|
+
} from 'lib/aws'
|
|
8
|
+
import {logCommand, logDataTable, logTitle} from 'lib/logging'
|
|
9
|
+
import {getIfCoreFns, getPaths, getWidgetUuid} from 'lib/resolve'
|
|
10
|
+
import {notify} from 'lib/notifier'
|
|
11
|
+
import {fail, runCommandSync} from 'lib/command'
|
|
13
12
|
|
|
14
13
|
///////////////////////////////////////////////////////////////////////////////
|
|
15
14
|
|
|
@@ -19,10 +18,6 @@ export type DeployEmailConfigOptions = AwsOptions & {
|
|
|
19
18
|
|
|
20
19
|
///////////////////////////////////////////////////////////////////////////////
|
|
21
20
|
|
|
22
|
-
export const DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET = 'rnw-email-service'
|
|
23
|
-
|
|
24
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
25
|
-
|
|
26
21
|
export const deployEmailConfig = async (
|
|
27
22
|
options: DeployEmailConfigOptions,
|
|
28
23
|
): Promise<void> => {
|
|
@@ -34,6 +29,7 @@ export const deployEmailConfig = async (
|
|
|
34
29
|
assertEmailConfigPathExists(emailConfigPath)
|
|
35
30
|
assertIsNotCore()
|
|
36
31
|
|
|
32
|
+
const flags = prepareFlags([], options).join(' ')
|
|
37
33
|
const {bucket} = options
|
|
38
34
|
const configName = getWidgetUuid()
|
|
39
35
|
const deployUrl = `s3://${bucket}/${configName}`
|
|
@@ -42,6 +38,7 @@ export const deployEmailConfig = async (
|
|
|
42
38
|
aws s3 sync ${emailConfigPath} ${deployUrl}
|
|
43
39
|
--delete
|
|
44
40
|
--exact-timestamps
|
|
41
|
+
${flags}
|
|
45
42
|
`
|
|
46
43
|
logTitle(
|
|
47
44
|
`Deploying email configuration for “${configName}” customer configuration to AWS S3 …`,
|
|
@@ -49,23 +46,25 @@ export const deployEmailConfig = async (
|
|
|
49
46
|
logCommand(cmd)
|
|
50
47
|
|
|
51
48
|
try {
|
|
52
|
-
|
|
49
|
+
withAwsAuthenticate(() => runCommandSync(cmd, {stdout: 'inherit'}), options)
|
|
53
50
|
} catch (error: any) {
|
|
54
51
|
fail(error.stderr)
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
/////////////////////////////////////////////////////////////////////////////
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
{'Deploy URL:': deployUrl},
|
|
56
|
+
logTitle(
|
|
61
57
|
`Email configuration for “${configName}” customer configuration is deployed.`,
|
|
62
58
|
)
|
|
59
|
+
logDataTable({'Deploy URL:': deployUrl})
|
|
63
60
|
|
|
64
61
|
/////////////////////////////////////////////////////////////////////////////
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
process.on('exit', () => {
|
|
64
|
+
notify({
|
|
65
|
+
title: `deploy-email-config`,
|
|
66
|
+
message: `Email configuration for “${configName}” customer configuration is deployed.`,
|
|
67
|
+
})
|
|
69
68
|
})
|
|
70
69
|
}
|
|
71
70
|
|
|
@@ -105,3 +104,12 @@ const assertIsNotCore = () => {
|
|
|
105
104
|
fail('You cannot deploy widget email configuration for Tamaro Core.')
|
|
106
105
|
}
|
|
107
106
|
}
|
|
107
|
+
|
|
108
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
109
|
+
|
|
110
|
+
const prepareFlags = (
|
|
111
|
+
flags: string[],
|
|
112
|
+
options: DeployEmailConfigOptions,
|
|
113
|
+
): string[] => {
|
|
114
|
+
return prepareAwsFlags(flags, options)
|
|
115
|
+
}
|
package/src/commands/deploy.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import {existsSync} from 'fs'
|
|
2
|
-
import stripIndent from 'strip-indent'
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
AWS_CLOUDFRONT_DISTRIBUTION_ID,
|
|
4
|
+
AWS_S3_BUCKET,
|
|
5
|
+
CORE_CONFIG_NAME,
|
|
6
|
+
} from 'lib/constants'
|
|
7
|
+
import {
|
|
8
|
+
assertProfileValid,
|
|
9
|
+
AwsOptions,
|
|
10
|
+
withAwsAuthenticate,
|
|
11
|
+
prepareFlags as prepareAwsFlags,
|
|
12
|
+
} from 'lib/aws'
|
|
13
|
+
import {getIfCoreFns, getPaths, getWidgetUuid} from 'lib/resolve'
|
|
14
|
+
import {logCommand, logDataTable, logTitle} from 'lib/logging'
|
|
15
|
+
import {notify} from 'lib/notifier'
|
|
16
|
+
import {fail, runCommandSync} from 'lib/command'
|
|
14
17
|
|
|
15
18
|
///////////////////////////////////////////////////////////////////////////////
|
|
16
19
|
|
|
@@ -20,13 +23,6 @@ export type DeployOptions = AwsOptions & {
|
|
|
20
23
|
|
|
21
24
|
///////////////////////////////////////////////////////////////////////////////
|
|
22
25
|
|
|
23
|
-
export const AWS_S3_BUCKET = 'tamaro.raisenow.com'
|
|
24
|
-
export const CORE_CONFIG_NAME = 'tamaro-core'
|
|
25
|
-
const AWS_CLOUDFRONT_DISTRIBUTION_ID = 'EHJ1OM458YQ0I'
|
|
26
|
-
export const DEFAULT_TAG = 'latest'
|
|
27
|
-
|
|
28
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
29
|
-
|
|
30
26
|
export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
31
27
|
const {ifCore} = getIfCoreFns()
|
|
32
28
|
const paths = getPaths(ifCore)
|
|
@@ -34,6 +30,7 @@ export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
|
34
30
|
assertOptionsValid(options)
|
|
35
31
|
assertDistPathExists(paths.appDist)
|
|
36
32
|
|
|
33
|
+
const flags = prepareFlags([], options).join(' ')
|
|
37
34
|
const {tag} = options
|
|
38
35
|
const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid())
|
|
39
36
|
const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/${tag}`
|
|
@@ -49,12 +46,16 @@ export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
|
49
46
|
--size-only
|
|
50
47
|
--exclude ${paths.appDist}/${entryFilename}
|
|
51
48
|
--cache-control max-age=31536000
|
|
49
|
+
${flags}
|
|
52
50
|
`
|
|
53
51
|
logTitle('Deploying to AWS S3 …')
|
|
54
52
|
logCommand(cmdSyncAll)
|
|
55
53
|
|
|
56
54
|
try {
|
|
57
|
-
|
|
55
|
+
withAwsAuthenticate(
|
|
56
|
+
() => runCommandSync(cmdSyncAll, {stdout: 'inherit'}),
|
|
57
|
+
options,
|
|
58
|
+
)
|
|
58
59
|
} catch (error: any) {
|
|
59
60
|
fail(error.stderr)
|
|
60
61
|
}
|
|
@@ -67,11 +68,15 @@ export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
|
67
68
|
aws s3 cp ${paths.appDist}/${entryFilename} ${deployUrl}/${entryFilename}
|
|
68
69
|
--acl public-read
|
|
69
70
|
--cache-control max-age=64800
|
|
71
|
+
${flags}
|
|
70
72
|
`
|
|
71
73
|
logCommand(cmdCpEntry)
|
|
72
74
|
|
|
73
75
|
try {
|
|
74
|
-
|
|
76
|
+
withAwsAuthenticate(
|
|
77
|
+
() => runCommandSync(cmdCpEntry, {stdout: 'inherit'}),
|
|
78
|
+
options,
|
|
79
|
+
)
|
|
75
80
|
} catch (error: any) {
|
|
76
81
|
fail(error.stderr)
|
|
77
82
|
}
|
|
@@ -84,13 +89,14 @@ export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
|
84
89
|
aws cloudfront create-invalidation
|
|
85
90
|
--distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID}
|
|
86
91
|
--paths /${configName}/${tag}/*
|
|
92
|
+
${flags}
|
|
87
93
|
`
|
|
88
|
-
logTitle('
|
|
94
|
+
logTitle('\nInvalidating edge cache …')
|
|
89
95
|
logCommand(cmdInvalidateCache)
|
|
90
96
|
|
|
91
97
|
try {
|
|
92
98
|
// ignore output
|
|
93
|
-
|
|
99
|
+
withAwsAuthenticate(() => runCommandSync(cmdInvalidateCache), options)
|
|
94
100
|
} catch (error: any) {
|
|
95
101
|
fail(error.stderr)
|
|
96
102
|
}
|
|
@@ -100,23 +106,23 @@ export const deploy = async (options: DeployOptions): Promise<void> => {
|
|
|
100
106
|
const demoPage = `https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`
|
|
101
107
|
const entryPoint = `https://${AWS_S3_BUCKET}/${configName}/${tag}/${entryFilename}`
|
|
102
108
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
`Bundle for “${configName}” is deployed with tag “${tag}”`,
|
|
109
|
-
)
|
|
109
|
+
logTitle(`\nBundle for “${configName}” is deployed with tag “${tag}”.`)
|
|
110
|
+
logDataTable({
|
|
111
|
+
'Demo page:': demoPage,
|
|
112
|
+
'Entry point:': entryPoint,
|
|
113
|
+
})
|
|
110
114
|
|
|
111
115
|
/////////////////////////////////////////////////////////////////////////////
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
})
|
|
120
126
|
})
|
|
121
127
|
}
|
|
122
128
|
|
|
@@ -143,9 +149,15 @@ const assertDistPathExists = (distPath: string) => {
|
|
|
143
149
|
///////////////////////////////////////////////////////////////////////////////
|
|
144
150
|
|
|
145
151
|
const assertTagValid = (tag: string) => {
|
|
146
|
-
const regex = /^[a-zA-Z0-9-_]+$/
|
|
152
|
+
const regex = /^[a-zA-Z0-9-_.]+$/
|
|
147
153
|
|
|
148
154
|
if (!regex.test(tag)) {
|
|
149
155
|
fail(`Flag "--tag" has forbidden format. Allowed format: ${regex}.`)
|
|
150
156
|
}
|
|
151
157
|
}
|
|
158
|
+
|
|
159
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
160
|
+
|
|
161
|
+
const prepareFlags = (flags: string[], options: DeployOptions): string[] => {
|
|
162
|
+
return prepareAwsFlags(flags, options)
|
|
163
|
+
}
|