@raisenow/tamaro-cli 1.0.12 → 1.0.15
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/README.md +2 -0
- package/dist/{chunk-PIEFLCDU.js → chunk-BWJBN44Y.js} +110 -3
- package/dist/cli.js +63 -73
- package/dist/webpack.config.js +37 -126
- package/package.json +25 -26
- package/src/cli.ts +2 -0
- package/src/commands/build.ts +7 -4
- package/src/commands/deploy-email-config.ts +6 -6
- package/src/commands/deploy.ts +12 -9
- package/src/commands/dev.ts +8 -4
- package/src/commands/list-deployed.ts +3 -3
- package/src/commands/serve.ts +2 -2
- package/src/lib/InterpolateHtmlPlugin.ts +3 -1
- package/src/lib/aws.ts +3 -3
- package/src/lib/command.ts +2 -2
- package/src/lib/env.ts +47 -2
- package/src/lib/resolve.ts +2 -2
- package/src/webpack.config.ts +7 -47
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ Runs the local development server for _Tamaro Core_ or a particular customer con
|
|
|
39
39
|
|
|
40
40
|
- `--local-core` – Load _Tamaro Core_ from localhost:1234 instead of the CDN
|
|
41
41
|
- `--port <port>` – Web server port (default: 1234)
|
|
42
|
+
- `--env <env>` – Environment (dev, stage, prod)
|
|
42
43
|
|
|
43
44
|
### Run local server using Tamaro Core from CDN
|
|
44
45
|
|
|
@@ -75,6 +76,7 @@ Build an optimised (minified) bundle of _Tamaro Core_ or a customer configuratio
|
|
|
75
76
|
- `--analyze` – Generate bundle statistics to `reports` folder
|
|
76
77
|
- `--serve` – Run the generated bundle with a local web server
|
|
77
78
|
- `--port <port>` – Web server port (default: 1234)
|
|
79
|
+
- `--env <env>` – Environment (dev, stage, prod)
|
|
78
80
|
- `--deploy` – Deploy _Tamaro Core_ or a customer configuration bundle to AWS S3
|
|
79
81
|
- `--tag <tag>` – Tag which should be used for the deployment of the bundle (default: “latest”)
|
|
80
82
|
- `--profile <profile>` – AWS profile which should be used for the deployment of the bundle (default: “payments-prod-cs-deployer”)
|
|
@@ -81,7 +81,7 @@ var getPaths = (ifCore) => {
|
|
|
81
81
|
appNodeModules: resolveApp("node_modules"),
|
|
82
82
|
appTsConfig: resolveApp("tsconfig.json"),
|
|
83
83
|
appHtml: resolveApp("src/*.html"),
|
|
84
|
-
appEnv: resolveApp(".env"),
|
|
84
|
+
appEnv: resolveApp(".env*"),
|
|
85
85
|
appTailwindConfig: resolveApp("tailwind.config.js")
|
|
86
86
|
}, {
|
|
87
87
|
app: resolveApp("."),
|
|
@@ -90,7 +90,7 @@ var getPaths = (ifCore) => {
|
|
|
90
90
|
appNodeModules: resolveApp("../../node_modules"),
|
|
91
91
|
appTsConfig: resolveApp("tsconfig.json"),
|
|
92
92
|
appHtml: resolveApp("*.html"),
|
|
93
|
-
appEnv: resolveApp(".env"),
|
|
93
|
+
appEnv: resolveApp(".env*"),
|
|
94
94
|
appTailwindConfig: void 0
|
|
95
95
|
});
|
|
96
96
|
};
|
|
@@ -126,6 +126,109 @@ var getIfCoreFns = () => {
|
|
|
126
126
|
process.exit(1);
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
+
// src/lib/env.ts
|
|
130
|
+
import { createRequire as createRequire2 } from "module";
|
|
131
|
+
import { basename as basename2 } from "path";
|
|
132
|
+
import glob from "glob";
|
|
133
|
+
import { expand as dotenvExpand } from "dotenv-expand";
|
|
134
|
+
import { config as dotenvConfig } from "dotenv";
|
|
135
|
+
import stripIndent3 from "strip-indent";
|
|
136
|
+
|
|
137
|
+
// src/lib/command.ts
|
|
138
|
+
import { execaCommandSync } from "execa";
|
|
139
|
+
var halt = (message, exitCode = 1) => {
|
|
140
|
+
logError(message);
|
|
141
|
+
process.exit(exitCode);
|
|
142
|
+
};
|
|
143
|
+
var prepareCommand = (cmd) => {
|
|
144
|
+
return cmd.replace(/\n/gm, " ").replace(/[ \t]{2,}/gm, " ").trim();
|
|
145
|
+
};
|
|
146
|
+
var runCommandSync = (cmd, options) => {
|
|
147
|
+
return execaCommandSync(prepareCommand(cmd), options);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/lib/env.ts
|
|
151
|
+
var require3 = createRequire2(import.meta.url);
|
|
152
|
+
var getEnvVars = (files, ifMin, ifCore, ifLocalCore) => {
|
|
153
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
154
|
+
const filePath = files.find((file) => basename2(file) === ".env");
|
|
155
|
+
dotenvExpand(dotenvConfig({ path: filePath }));
|
|
156
|
+
(_b = (_a = process.env).NODE_ENV) != null ? _b : _a.NODE_ENV = ifMin("production", "development");
|
|
157
|
+
(_d = (_c = process.env).BABEL_ENV) != null ? _d : _c.BABEL_ENV = ifMin("production", "development");
|
|
158
|
+
(_f = (_e = process.env).EXPOSE_VAR) != null ? _f : _e.EXPOSE_VAR = ifCore("rnw.tamaroCore", "rnw.tamaro");
|
|
159
|
+
(_h = (_g = process.env).ELEMENT_ATTRIBUTE_DATA_WIDGET) != null ? _h : _g.ELEMENT_ATTRIBUTE_DATA_WIDGET = ifCore("rnw-tamaro-core", "rnw-tamaro");
|
|
160
|
+
(_j = (_i = process.env).WEBPACK_UNIQUE_NAME) != null ? _j : _i.WEBPACK_UNIQUE_NAME = ifCore("RnwTamaroCore", "RnwTamaro");
|
|
161
|
+
process.env.BUILD_DATE = new Date().toISOString();
|
|
162
|
+
(_l = (_k = process.env).PUBLIC_URL) != null ? _l : _k.PUBLIC_URL = "";
|
|
163
|
+
(_n = (_m = process.env).HMR_ENABLED) != null ? _n : _m.HMR_ENABLED = ifMin("false", "true");
|
|
164
|
+
if (ifCore()) {
|
|
165
|
+
process.env.PRODUCT_NAME = "tamaro";
|
|
166
|
+
const corePkgPath = resolveApp("package.json");
|
|
167
|
+
const { version } = require3(corePkgPath);
|
|
168
|
+
process.env.PRODUCT_VERSION = version;
|
|
169
|
+
}
|
|
170
|
+
if (!ifCore()) {
|
|
171
|
+
process.env.WIDGET_UUID = getWidgetUuid();
|
|
172
|
+
if (ifLocalCore()) {
|
|
173
|
+
process.env.CORE_URL = `http://0.0.0.0:1234/index.js`;
|
|
174
|
+
} else {
|
|
175
|
+
let version = process.env.CORE_VERSION;
|
|
176
|
+
version = version ? `@${version}` : "";
|
|
177
|
+
(_p = (_o = process.env).CORE_URL) != null ? _p : _o.CORE_URL = `https://cdn.jsdelivr.net/npm/@raisenow/tamaro-core${version}/dist/index.js`;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const varNames = [
|
|
181
|
+
"NODE_ENV",
|
|
182
|
+
"BABEL_ENV",
|
|
183
|
+
"EXPOSE_VAR",
|
|
184
|
+
"ELEMENT_ATTRIBUTE_DATA_WIDGET",
|
|
185
|
+
"WEBPACK_UNIQUE_NAME",
|
|
186
|
+
"BUILD_DATE",
|
|
187
|
+
"PUBLIC_URL",
|
|
188
|
+
"PRODUCT_NAME",
|
|
189
|
+
"PRODUCT_VERSION",
|
|
190
|
+
"WIDGET_UUID",
|
|
191
|
+
"CORE_URL",
|
|
192
|
+
"CORE_VERSION",
|
|
193
|
+
"IS_CREDIT_CARD_IFRAME"
|
|
194
|
+
];
|
|
195
|
+
const raw = Object.keys(process.env).filter((key) => /^PUBLIC_/.test(key) || varNames.includes(key)).reduce((env, key) => {
|
|
196
|
+
env[key] = process.env[key];
|
|
197
|
+
return env;
|
|
198
|
+
}, {});
|
|
199
|
+
const stringified = {
|
|
200
|
+
"process.env": Object.keys(raw).reduce((env, key) => {
|
|
201
|
+
env[key] = JSON.stringify(raw[key]);
|
|
202
|
+
return env;
|
|
203
|
+
}, {})
|
|
204
|
+
};
|
|
205
|
+
return { raw, stringified };
|
|
206
|
+
};
|
|
207
|
+
var assertEnvValid = (env) => {
|
|
208
|
+
const { ifCore } = getIfCoreFns();
|
|
209
|
+
const paths = getPaths(ifCore);
|
|
210
|
+
const files = glob.sync(paths.appEnv);
|
|
211
|
+
const envs = files.map((file) => basename2(file).replace(/^\.env\.?/, "")).filter((v) => !!v);
|
|
212
|
+
if (envs.length === 0) {
|
|
213
|
+
if (env) {
|
|
214
|
+
console.log("Flag \u201C--env\u201D is ignored.");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (envs.length !== 0) {
|
|
218
|
+
if (!env) {
|
|
219
|
+
halt("Flag \u201C--env\u201D is required.");
|
|
220
|
+
}
|
|
221
|
+
if (!envs.includes(env)) {
|
|
222
|
+
halt(stripIndent3(`
|
|
223
|
+
Flag \u201C--env\u201D has wrong value.
|
|
224
|
+
Available values are: ${envs.map((v) => `\u201C${v}\u201D`).join(", ")}.
|
|
225
|
+
`));
|
|
226
|
+
}
|
|
227
|
+
const filePath = files.find((file) => basename2(file) === `.env.${env}`);
|
|
228
|
+
dotenvExpand(dotenvConfig({ path: filePath }));
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
129
232
|
export {
|
|
130
233
|
__spreadValues,
|
|
131
234
|
logTitle,
|
|
@@ -140,5 +243,9 @@ export {
|
|
|
140
243
|
getWidgetUuid,
|
|
141
244
|
getPaths,
|
|
142
245
|
getRelativePaths,
|
|
143
|
-
getIfCoreFns
|
|
246
|
+
getIfCoreFns,
|
|
247
|
+
halt,
|
|
248
|
+
runCommandSync,
|
|
249
|
+
getEnvVars,
|
|
250
|
+
assertEnvValid
|
|
144
251
|
};
|
package/dist/cli.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
assertEnvValid,
|
|
3
4
|
getIfCoreFns,
|
|
4
5
|
getPaths,
|
|
5
6
|
getWidgetUuid,
|
|
7
|
+
halt,
|
|
6
8
|
logCommand,
|
|
7
9
|
logDataTable,
|
|
8
10
|
logError,
|
|
9
11
|
logTitle,
|
|
10
12
|
resolveBin,
|
|
11
|
-
resolveOwn
|
|
12
|
-
|
|
13
|
+
resolveOwn,
|
|
14
|
+
runCommandSync
|
|
15
|
+
} from "./chunk-BWJBN44Y.js";
|
|
13
16
|
|
|
14
17
|
// src/cli.ts
|
|
15
18
|
import { createCommand } from "commander";
|
|
16
19
|
|
|
17
20
|
// package.json
|
|
18
21
|
var name = "@raisenow/tamaro-cli";
|
|
19
|
-
var version = "1.0.
|
|
22
|
+
var version = "1.0.15";
|
|
20
23
|
var author = {
|
|
21
24
|
name: "RaiseNow",
|
|
22
25
|
email: "development@raisenow.com"
|
|
@@ -37,48 +40,47 @@ var engines = {
|
|
|
37
40
|
};
|
|
38
41
|
var dependencies = {
|
|
39
42
|
"@babel/cli": "^7.17.6",
|
|
40
|
-
"@babel/core": "^7.17.
|
|
41
|
-
"@babel/plugin-proposal-decorators": "^7.17.
|
|
43
|
+
"@babel/core": "^7.17.9",
|
|
44
|
+
"@babel/plugin-proposal-decorators": "^7.17.9",
|
|
42
45
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
43
46
|
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
44
47
|
"@babel/preset-env": "^7.16.11",
|
|
45
48
|
"@babel/preset-react": "^7.16.7",
|
|
46
49
|
"@babel/preset-typescript": "^7.16.7",
|
|
47
|
-
"@babel/runtime-corejs3": "^7.17.
|
|
48
|
-
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.
|
|
50
|
+
"@babel/runtime-corejs3": "^7.17.9",
|
|
51
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
|
|
49
52
|
"@statoscope/webpack-plugin": "^5.20.1",
|
|
50
|
-
"@svgr/webpack": "^6.2.1",
|
|
51
53
|
"@types/columnify": "^1.5.1",
|
|
52
|
-
"@types/lodash": "^4.14.
|
|
53
|
-
"@types/node": "^17.0.
|
|
54
|
+
"@types/lodash": "^4.14.182",
|
|
55
|
+
"@types/node": "^17.0.26",
|
|
54
56
|
"@types/node-notifier": "^8.0.2",
|
|
55
57
|
"@types/resolve-bin": "^0.4.1",
|
|
56
58
|
"@types/webpack-config-utils": "^2.3.1",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
58
|
-
"@typescript-eslint/parser": "^5.
|
|
59
|
-
autoprefixer: "^10.4.
|
|
60
|
-
"babel-loader": "^8.2.
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.20.0",
|
|
61
|
+
autoprefixer: "^10.4.5",
|
|
62
|
+
"babel-loader": "^8.2.5",
|
|
61
63
|
"babel-plugin-lodash": "^3.3.4",
|
|
62
64
|
chalk: "^5.0.1",
|
|
63
65
|
"clean-webpack-plugin": "^4.0.0",
|
|
64
66
|
columnify: "^1.6.0",
|
|
65
|
-
commander: "^9.
|
|
67
|
+
commander: "^9.2.0",
|
|
66
68
|
"copy-webpack-plugin": "^10.2.4",
|
|
67
|
-
"core-js": "^3.
|
|
69
|
+
"core-js": "^3.22.2",
|
|
68
70
|
"css-loader": "^6.7.1",
|
|
69
71
|
"css-minimizer-webpack-plugin": "^3.4.1",
|
|
70
72
|
dotenv: "^16.0.0",
|
|
71
73
|
"dotenv-expand": "^8.0.3",
|
|
72
74
|
"escape-string-regexp": "^5.0.0",
|
|
73
|
-
eslint: "^8.
|
|
75
|
+
eslint: "^8.14.0",
|
|
74
76
|
"eslint-config-prettier": "^8.5.0",
|
|
75
77
|
"eslint-plugin-node": "^11.1.0",
|
|
76
78
|
"eslint-plugin-promise": "^6.0.0",
|
|
77
79
|
"eslint-webpack-plugin": "^3.1.1",
|
|
78
80
|
execa: "^6.1.0",
|
|
79
81
|
"file-loader": "^6.2.0",
|
|
80
|
-
"fork-ts-checker-webpack-plugin": "^7.2.
|
|
81
|
-
glob: "^
|
|
82
|
+
"fork-ts-checker-webpack-plugin": "^7.2.7",
|
|
83
|
+
glob: "^8.0.1",
|
|
82
84
|
"html-loader": "^3.1.0",
|
|
83
85
|
"html-webpack-plugin": "^5.5.0",
|
|
84
86
|
"json-loader": "^0.5.7",
|
|
@@ -87,25 +89,25 @@ var dependencies = {
|
|
|
87
89
|
"node-notifier": "^10.0.1",
|
|
88
90
|
portfinder: "^1.0.28",
|
|
89
91
|
postcss: "^8.4.12",
|
|
90
|
-
"postcss-custom-properties": "^12.1.
|
|
92
|
+
"postcss-custom-properties": "^12.1.7",
|
|
91
93
|
"postcss-loader": "^6.2.1",
|
|
92
|
-
prettier: "^2.6.
|
|
93
|
-
"react-refresh": "^0.
|
|
94
|
+
prettier: "^2.6.2",
|
|
95
|
+
"react-refresh": "^0.12.0",
|
|
94
96
|
"resolve-url-loader": "^5.0.0",
|
|
95
|
-
sass: "^1.
|
|
97
|
+
sass: "^1.50.1",
|
|
96
98
|
"sass-loader": "^12.6.0",
|
|
97
99
|
"source-map-loader": "^3.0.1",
|
|
98
100
|
"strip-indent": "^4.0.0",
|
|
99
101
|
"style-loader": "^3.3.1",
|
|
100
102
|
"tsconfig-paths-webpack-plugin": "^3.5.2",
|
|
101
|
-
tsup: "^5.12.
|
|
102
|
-
typescript: "^4.6.
|
|
103
|
+
tsup: "^5.12.6",
|
|
104
|
+
typescript: "^4.6.3",
|
|
103
105
|
"url-loader": "^4.1.1",
|
|
104
|
-
webpack: "^5.
|
|
106
|
+
webpack: "^5.72.0",
|
|
105
107
|
"webpack-cli": "^4.9.2",
|
|
106
108
|
"webpack-config-utils": "^2.3.1",
|
|
107
|
-
"webpack-dev-server": "^4.
|
|
108
|
-
"yaml-loader": "^0.
|
|
109
|
+
"webpack-dev-server": "^4.8.1",
|
|
110
|
+
"yaml-loader": "^0.7.0"
|
|
109
111
|
};
|
|
110
112
|
var package_default = {
|
|
111
113
|
name,
|
|
@@ -129,21 +131,6 @@ var AWS_CLOUDFRONT_DISTRIBUTION_ID = "EHJ1OM458YQ0I";
|
|
|
129
131
|
|
|
130
132
|
// src/commands/dev.ts
|
|
131
133
|
import { getPortPromise } from "portfinder";
|
|
132
|
-
|
|
133
|
-
// src/lib/command.ts
|
|
134
|
-
import { execaCommandSync } from "execa";
|
|
135
|
-
var fail = (message) => {
|
|
136
|
-
logError(message);
|
|
137
|
-
process.exit(1);
|
|
138
|
-
};
|
|
139
|
-
var prepareCommand = (cmd) => {
|
|
140
|
-
return cmd.replace(/\n/gm, " ").replace(/[ \t]{2,}/gm, " ").trim();
|
|
141
|
-
};
|
|
142
|
-
var runCommandSync = (cmd, options) => {
|
|
143
|
-
return execaCommandSync(prepareCommand(cmd), options);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// src/commands/dev.ts
|
|
147
134
|
var dev = async (options) => {
|
|
148
135
|
assertOptionsValid(options);
|
|
149
136
|
const flags = (await prepareFlags([], options)).join(" ");
|
|
@@ -161,14 +148,15 @@ var dev = async (options) => {
|
|
|
161
148
|
runCommandSync(cmd, { stdio: "inherit" });
|
|
162
149
|
};
|
|
163
150
|
var assertOptionsValid = (options) => {
|
|
164
|
-
const { localCore, port } = options;
|
|
151
|
+
const { localCore, port, env } = options;
|
|
165
152
|
const { ifCore } = getIfCoreFns();
|
|
166
153
|
if (ifCore() && localCore) {
|
|
167
|
-
|
|
154
|
+
halt("Flag \u201C--local-core\u201D is redundant if running in Tamaro Core context.");
|
|
168
155
|
}
|
|
169
156
|
if (isNaN(Number(port))) {
|
|
170
|
-
|
|
157
|
+
halt("Flag \u201C--port\u201D should be a number.");
|
|
171
158
|
}
|
|
159
|
+
assertEnvValid(env);
|
|
172
160
|
};
|
|
173
161
|
var prepareFlags = async (flags, options) => {
|
|
174
162
|
const { localCore, port: defaultPort } = options;
|
|
@@ -181,7 +169,7 @@ var prepareFlags = async (flags, options) => {
|
|
|
181
169
|
};
|
|
182
170
|
|
|
183
171
|
// src/lib/aws.ts
|
|
184
|
-
import { execaCommandSync
|
|
172
|
+
import { execaCommandSync } from "execa";
|
|
185
173
|
import stripIndent from "strip-indent";
|
|
186
174
|
var withAwsAuthenticate = (fn, options) => {
|
|
187
175
|
awsAuthenticate(options);
|
|
@@ -223,24 +211,24 @@ var assertProfileValid = (profile) => {
|
|
|
223
211
|
Check the wiki for more information:
|
|
224
212
|
https://raisenow.atlassian.net/wiki/x/lIrWvg
|
|
225
213
|
`);
|
|
226
|
-
|
|
214
|
+
halt(message);
|
|
227
215
|
}
|
|
228
216
|
};
|
|
229
217
|
var getAvailableProfiles = () => {
|
|
230
|
-
const { stdout } =
|
|
218
|
+
const { stdout } = execaCommandSync("aws configure list-profiles");
|
|
231
219
|
return stdout.split("\n");
|
|
232
220
|
};
|
|
233
221
|
var checkIdentity = (options) => {
|
|
234
222
|
const flags = prepareFlags2([], options).join(" ");
|
|
235
|
-
|
|
223
|
+
execaCommandSync(`aws sts get-caller-identity ${flags}`);
|
|
236
224
|
};
|
|
237
225
|
var login = (options) => {
|
|
238
226
|
const flags = prepareFlags2([], options).join(" ");
|
|
239
227
|
try {
|
|
240
|
-
|
|
228
|
+
execaCommandSync(`aws sso login ${flags}`, { stdio: "inherit" });
|
|
241
229
|
console.log("");
|
|
242
230
|
} catch (error) {
|
|
243
|
-
|
|
231
|
+
halt("Login failed.");
|
|
244
232
|
}
|
|
245
233
|
};
|
|
246
234
|
var prepareFlags2 = (flags, options) => {
|
|
@@ -295,15 +283,16 @@ Bundle for \u201C${configName}\u201D customer configuration is done.`);
|
|
|
295
283
|
});
|
|
296
284
|
};
|
|
297
285
|
var assertOptionsValid2 = (options) => {
|
|
298
|
-
const { localCore, deploy: deploy2, profile } = options;
|
|
286
|
+
const { localCore, deploy: deploy2, profile, env } = options;
|
|
299
287
|
const { ifCore } = getIfCoreFns();
|
|
300
288
|
if (ifCore() && localCore) {
|
|
301
|
-
|
|
289
|
+
halt("Flag \u201C--local-core\u201D is redundant if running in Tamaro Core context.");
|
|
302
290
|
}
|
|
303
291
|
if (localCore && deploy2) {
|
|
304
|
-
|
|
292
|
+
halt("Flags \u201C--local-core\u201D and \u201C--deploy\u201D must not be used together.");
|
|
305
293
|
}
|
|
306
294
|
assertProfileValid(profile);
|
|
295
|
+
assertEnvValid(env);
|
|
307
296
|
};
|
|
308
297
|
var prepareFlags3 = (flags, options) => {
|
|
309
298
|
const { localCore, analyze } = options;
|
|
@@ -318,6 +307,7 @@ var prepareFlags3 = (flags, options) => {
|
|
|
318
307
|
|
|
319
308
|
// src/commands/deploy.ts
|
|
320
309
|
import { existsSync } from "fs";
|
|
310
|
+
import stripIndent3 from "strip-indent";
|
|
321
311
|
var deploy = async (options) => {
|
|
322
312
|
const { ifCore } = getIfCoreFns();
|
|
323
313
|
const paths = getPaths(ifCore);
|
|
@@ -341,7 +331,7 @@ var deploy = async (options) => {
|
|
|
341
331
|
try {
|
|
342
332
|
withAwsAuthenticate(() => runCommandSync(cmdSyncAll, { stdout: "inherit" }), options);
|
|
343
333
|
} catch (error) {
|
|
344
|
-
|
|
334
|
+
halt(error.stderr);
|
|
345
335
|
}
|
|
346
336
|
const cmdCpEntry = `
|
|
347
337
|
aws s3 cp ${paths.appDist}/${entryFilename} ${deployUrl}/${entryFilename}
|
|
@@ -354,7 +344,7 @@ var deploy = async (options) => {
|
|
|
354
344
|
try {
|
|
355
345
|
withAwsAuthenticate(() => runCommandSync(cmdCpEntry, { stdout: "inherit" }), options);
|
|
356
346
|
} catch (error) {
|
|
357
|
-
|
|
347
|
+
halt(error.stderr);
|
|
358
348
|
}
|
|
359
349
|
const cmdInvalidateCache = `
|
|
360
350
|
aws cloudfront create-invalidation
|
|
@@ -367,7 +357,7 @@ var deploy = async (options) => {
|
|
|
367
357
|
try {
|
|
368
358
|
withAwsAuthenticate(() => runCommandSync(cmdInvalidateCache), options);
|
|
369
359
|
} catch (error) {
|
|
370
|
-
|
|
360
|
+
halt(error.stderr);
|
|
371
361
|
}
|
|
372
362
|
const demoPage = `https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`;
|
|
373
363
|
const entryPoint = `https://${AWS_S3_BUCKET}/${configName}/${tag}/${entryFilename}`;
|
|
@@ -395,16 +385,16 @@ var assertOptionsValid3 = (options) => {
|
|
|
395
385
|
};
|
|
396
386
|
var assertDistPathExists = (distPath) => {
|
|
397
387
|
if (!existsSync(distPath)) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
388
|
+
halt(stripIndent3(`
|
|
389
|
+
Dist folder does not exists.
|
|
390
|
+
Make sure you have built the bundle before trying to deploy it.
|
|
391
|
+
`));
|
|
402
392
|
}
|
|
403
393
|
};
|
|
404
394
|
var assertTagValid = (tag) => {
|
|
405
395
|
const regex = /^[a-zA-Z0-9-_.]+$/;
|
|
406
396
|
if (!regex.test(tag)) {
|
|
407
|
-
|
|
397
|
+
halt(`Flag \u201C--tag\u201D has forbidden format. Allowed format: ${regex}.`);
|
|
408
398
|
}
|
|
409
399
|
};
|
|
410
400
|
var prepareFlags4 = (flags, options) => {
|
|
@@ -430,7 +420,7 @@ var serve = async (options) => {
|
|
|
430
420
|
var assertOptionsValid4 = (options) => {
|
|
431
421
|
const { port } = options;
|
|
432
422
|
if (isNaN(Number(port))) {
|
|
433
|
-
|
|
423
|
+
halt('Flag "--port" should be a number.');
|
|
434
424
|
}
|
|
435
425
|
};
|
|
436
426
|
var prepareFlags5 = async (flags, options) => {
|
|
@@ -459,7 +449,7 @@ var listDeployed = async (options) => {
|
|
|
459
449
|
} catch (error) {
|
|
460
450
|
out = error.stdout;
|
|
461
451
|
if (error.stderr) {
|
|
462
|
-
|
|
452
|
+
halt(error.stderr);
|
|
463
453
|
}
|
|
464
454
|
}
|
|
465
455
|
const lines = out.split("\n");
|
|
@@ -486,7 +476,7 @@ var assertConfigValid = (config) => {
|
|
|
486
476
|
}
|
|
487
477
|
const regex = /^[a-zA-Z0-9-_]+$/;
|
|
488
478
|
if (!regex.test(config)) {
|
|
489
|
-
|
|
479
|
+
halt(`Flag \u201C--config\u201D has forbidden format. Allowed format: ${regex}.`);
|
|
490
480
|
}
|
|
491
481
|
};
|
|
492
482
|
var prepareFlags6 = (flags, options) => {
|
|
@@ -504,8 +494,8 @@ var deployEmailConfig = async (options) => {
|
|
|
504
494
|
const paths = getPaths(ifCore);
|
|
505
495
|
const emailConfigPath = `${paths.app}/email-config`;
|
|
506
496
|
assertOptionsValid6(options);
|
|
507
|
-
assertEmailConfigPathExists(emailConfigPath);
|
|
508
497
|
assertIsNotCore();
|
|
498
|
+
assertEmailConfigPathExists(emailConfigPath);
|
|
509
499
|
const flags = prepareFlags7([], options).join(" ");
|
|
510
500
|
const { bucket } = options;
|
|
511
501
|
const configName = getWidgetUuid();
|
|
@@ -521,7 +511,7 @@ var deployEmailConfig = async (options) => {
|
|
|
521
511
|
try {
|
|
522
512
|
withAwsAuthenticate(() => runCommandSync(cmd, { stdout: "inherit" }), options);
|
|
523
513
|
} catch (error) {
|
|
524
|
-
|
|
514
|
+
halt(error.stderr);
|
|
525
515
|
}
|
|
526
516
|
logTitle(`Email configuration for \u201C${configName}\u201D customer configuration is deployed.`);
|
|
527
517
|
logDataTable({ "Deploy URL:": deployUrl });
|
|
@@ -539,19 +529,19 @@ var assertOptionsValid6 = (options) => {
|
|
|
539
529
|
};
|
|
540
530
|
var assertEmailConfigPathExists = (distPath) => {
|
|
541
531
|
if (!existsSync2(distPath)) {
|
|
542
|
-
|
|
532
|
+
halt("Email config folder does not exists. Nothing to deploy.", 0);
|
|
543
533
|
}
|
|
544
534
|
};
|
|
545
535
|
var assertBucketValid = (tag) => {
|
|
546
536
|
const regex = /^[a-zA-Z0-9-_]+$/;
|
|
547
537
|
if (!regex.test(tag)) {
|
|
548
|
-
|
|
538
|
+
halt(`Flag \u201C--bucket\u201D has forbidden format. Allowed format: ${regex}.`);
|
|
549
539
|
}
|
|
550
540
|
};
|
|
551
541
|
var assertIsNotCore = () => {
|
|
552
542
|
const { ifCore } = getIfCoreFns();
|
|
553
543
|
if (ifCore()) {
|
|
554
|
-
|
|
544
|
+
halt("You cannot deploy widget email configuration for Tamaro Core.");
|
|
555
545
|
}
|
|
556
546
|
};
|
|
557
547
|
var prepareFlags7 = (flags, options) => {
|
|
@@ -566,10 +556,10 @@ process.on("SIGINT", () => {
|
|
|
566
556
|
process.exit(1);
|
|
567
557
|
});
|
|
568
558
|
var cli = createCommand().name(package_default.name).version(package_default.version, "-v, --version");
|
|
569
|
-
cli.command("dev").description("Run the local development server for Tamaro Core or a particular customer configuration").option("--local-core", "Load Tamaro Core from localhost:1234 instead of the CDN", false).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).action(async (options) => {
|
|
559
|
+
cli.command("dev").description("Run the local development server for Tamaro Core or a particular customer configuration").option("--local-core", "Load Tamaro Core from localhost:1234 instead of the CDN", false).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--env <env>", "Environment (dev, stage, prod)").action(async (options) => {
|
|
570
560
|
await dev(options);
|
|
571
561
|
});
|
|
572
|
-
cli.command("build").description("Build an optimised (minified) bundle of Tamaro Core or a customer configuration").option("--local-core", "Load Tamaro Core from localhost:1234 instead of the CDN", false).option("--analyze", 'Generate bundle statistics to "reports" folder', false).option("--serve", "Run the generated bundle with a local web server", false).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--deploy", "Deploy Tamaro Core or a customer configuration bundle to AWS S3", false).option("--tag <tag>", "Tag which should be used for the deployment of the bundle", DEFAULT_TAG).option("--profile <profile>", "AWS profile which should be used for the deployment of the bundle", DEFAULT_AWS_PROFILE).action(async (options) => {
|
|
562
|
+
cli.command("build").description("Build an optimised (minified) bundle of Tamaro Core or a customer configuration").option("--local-core", "Load Tamaro Core from localhost:1234 instead of the CDN", false).option("--analyze", 'Generate bundle statistics to "reports" folder', false).option("--serve", "Run the generated bundle with a local web server", false).option("--port <port>", "Web server port", `${DEFAULT_PORT}`).option("--env <env>", "Environment (dev, stage, prod)").option("--deploy", "Deploy Tamaro Core or a customer configuration bundle to AWS S3", false).option("--tag <tag>", "Tag which should be used for the deployment of the bundle", DEFAULT_TAG).option("--profile <profile>", "AWS profile which should be used for the deployment of the bundle", DEFAULT_AWS_PROFILE).action(async (options) => {
|
|
573
563
|
await build(options);
|
|
574
564
|
if (options.serve) {
|
|
575
565
|
await serve(options);
|