@raisenow/tamaro-cli 1.0.10 → 1.0.13

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/dist/cli.js CHANGED
@@ -1,39 +1,35 @@
1
1
  #!/usr/bin/env node
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
- var __reExport = (target, module2, copyDefault, desc) => {
10
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
11
- for (let key of __getOwnPropNames(module2))
12
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
13
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
14
- }
15
- return target;
16
- };
17
- var __toESM = (module2, isNodeMode) => {
18
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
19
- };
2
+ import {
3
+ assertEnvValid,
4
+ fail,
5
+ getIfCoreFns,
6
+ getPaths,
7
+ getWidgetUuid,
8
+ logCommand,
9
+ logDataTable,
10
+ logError,
11
+ logTitle,
12
+ resolveBin,
13
+ resolveOwn,
14
+ runCommandSync
15
+ } from "./chunk-OXDXJ5B5.js";
20
16
 
21
17
  // src/cli.ts
22
- var import_commander = require("commander");
18
+ import { createCommand } from "commander";
23
19
 
24
20
  // package.json
25
21
  var name = "@raisenow/tamaro-cli";
26
- var version = "1.0.10";
22
+ var version = "1.0.13";
27
23
  var author = {
28
24
  name: "RaiseNow",
29
25
  email: "development@raisenow.com"
30
26
  };
31
- var main = "dist/cli.js";
27
+ var type = "module";
32
28
  var scripts = {
33
29
  prepare: "npm run build",
34
30
  start: "npm run dev",
35
- dev: "npm run build -- --watch --ignore-watch .idea",
36
- build: "tsup src/cli.ts src/webpack.config.ts --format cjs",
31
+ build: "tsup src/cli.ts src/webpack.config.ts --clean --format esm",
32
+ "build:watch": "npm run build -- --watch --ignore-watch .idea",
37
33
  docs: "npx -y http-server . --cors -o /readme.html",
38
34
  lint: "eslint . --fix && prettier --write ."
39
35
  };
@@ -43,80 +39,71 @@ var engines = {
43
39
  npm: ">=8"
44
40
  };
45
41
  var dependencies = {
46
- "@babel/cli": "^7.17.0",
47
- "@babel/core": "^7.17.0",
48
- "@babel/plugin-proposal-decorators": "^7.17.0",
42
+ "@babel/cli": "^7.17.6",
43
+ "@babel/core": "^7.17.8",
44
+ "@babel/plugin-proposal-decorators": "^7.17.8",
49
45
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
50
46
  "@babel/plugin-transform-runtime": "^7.17.0",
51
47
  "@babel/preset-env": "^7.16.11",
52
48
  "@babel/preset-react": "^7.16.7",
53
49
  "@babel/preset-typescript": "^7.16.7",
54
- "@babel/runtime-corejs3": "^7.17.0",
50
+ "@babel/runtime-corejs3": "^7.17.8",
55
51
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
56
52
  "@statoscope/webpack-plugin": "^5.20.1",
57
- "@svgr/webpack": "^6.2.1",
58
53
  "@types/columnify": "^1.5.1",
59
- "@types/lodash": "^4.14.178",
60
- "@types/mini-css-extract-plugin": "^2.5.1",
61
- "@types/node": "^17.0.16",
54
+ "@types/lodash": "^4.14.181",
55
+ "@types/node": "^17.0.23",
62
56
  "@types/node-notifier": "^8.0.2",
63
57
  "@types/resolve-bin": "^0.4.1",
64
58
  "@types/webpack-config-utils": "^2.3.1",
65
- "@typescript-eslint/eslint-plugin": "^5.11.0",
66
- "@typescript-eslint/parser": "^5.11.0",
67
- autoprefixer: "^10.4.2",
68
- "babel-loader": "^8.2.3",
59
+ "@typescript-eslint/eslint-plugin": "^5.17.0",
60
+ "@typescript-eslint/parser": "^5.17.0",
61
+ autoprefixer: "^10.4.4",
62
+ "babel-loader": "^8.2.4",
69
63
  "babel-plugin-lodash": "^3.3.4",
70
- boxen: "^5.1.2",
71
- chalk: "^4.1.2",
64
+ chalk: "^5.0.1",
72
65
  "clean-webpack-plugin": "^4.0.0",
73
66
  columnify: "^1.6.0",
74
- commander: "^9.0.0",
67
+ commander: "^9.1.0",
75
68
  "copy-webpack-plugin": "^10.2.4",
76
- "core-js": "^3.21.0",
77
- "css-loader": "^6.6.0",
69
+ "core-js": "^3.21.1",
70
+ "css-loader": "^6.7.1",
78
71
  "css-minimizer-webpack-plugin": "^3.4.1",
79
- "current-script-polyfill": "^1.0.0",
80
72
  dotenv: "^16.0.0",
81
- "dotenv-expand": "^8.0.1",
82
- "element-closest": "^3.0.2",
83
- "escape-string-regexp": "^4.0.0",
84
- eslint: "^8.8.0",
85
- "eslint-config-prettier": "^8.3.0",
73
+ "dotenv-expand": "^8.0.3",
74
+ "escape-string-regexp": "^5.0.0",
75
+ eslint: "^8.12.0",
76
+ "eslint-config-prettier": "^8.5.0",
86
77
  "eslint-plugin-node": "^11.1.0",
87
- "eslint-plugin-prettier": "^4.0.0",
88
78
  "eslint-plugin-promise": "^6.0.0",
89
- "eslint-webpack-plugin": "^3.1.0",
90
- execa: "^5.1.1",
79
+ "eslint-webpack-plugin": "^3.1.1",
80
+ execa: "^6.1.0",
91
81
  "file-loader": "^6.2.0",
92
- "fork-ts-checker-webpack-plugin": "^7.1.1",
82
+ "fork-ts-checker-webpack-plugin": "^7.2.1",
93
83
  glob: "^7.2.0",
94
84
  "html-loader": "^3.1.0",
95
85
  "html-webpack-plugin": "^5.5.0",
96
86
  "json-loader": "^0.5.7",
97
87
  lodash: "^4.17.21",
98
- "mini-css-extract-plugin": "^2.5.3",
88
+ "mini-css-extract-plugin": "^2.6.0",
99
89
  "node-notifier": "^10.0.1",
100
- open: "^8.4.0",
101
90
  portfinder: "^1.0.28",
102
- postcss: "^8.4.6",
103
- "postcss-custom-properties": "^12.1.4",
91
+ postcss: "^8.4.12",
92
+ "postcss-custom-properties": "^12.1.5",
104
93
  "postcss-loader": "^6.2.1",
105
- prettier: "^2.5.1",
94
+ prettier: "^2.6.1",
106
95
  "react-refresh": "^0.11.0",
107
- "resolve-bin": "^1.0.0",
108
96
  "resolve-url-loader": "^5.0.0",
109
- sass: "^1.49.7",
110
- "sass-loader": "^12.4.0",
97
+ sass: "^1.49.10",
98
+ "sass-loader": "^12.6.0",
111
99
  "source-map-loader": "^3.0.1",
112
- "strip-indent": "^3.0.0",
100
+ "strip-indent": "^4.0.0",
113
101
  "style-loader": "^3.3.1",
114
102
  "tsconfig-paths-webpack-plugin": "^3.5.2",
115
- tsup: "^5.11.13",
116
- typescript: "^4.5.5",
117
- unfetch: "^4.2.0",
103
+ tsup: "^5.12.1",
104
+ typescript: "^4.6.3",
118
105
  "url-loader": "^4.1.1",
119
- webpack: "^5.68.0",
106
+ webpack: "^5.70.0",
120
107
  "webpack-cli": "^4.9.2",
121
108
  "webpack-config-utils": "^2.3.1",
122
109
  "webpack-dev-server": "^4.7.4",
@@ -126,151 +113,30 @@ var package_default = {
126
113
  name,
127
114
  version,
128
115
  author,
129
- main,
116
+ type,
130
117
  scripts,
131
118
  bin,
132
119
  engines,
133
120
  dependencies
134
121
  };
135
122
 
136
- // src/lib/helpers.ts
137
- var import_path = require("path");
138
- var import_fs = require("fs");
139
- var import_chalk = __toESM(require("chalk"));
140
- var import_node_notifier = __toESM(require("node-notifier"));
141
- var import_webpack_config_utils = require("webpack-config-utils");
142
- var import_columnify = __toESM(require("columnify"));
143
- var import_boxen = __toESM(require("boxen"));
144
- var import_dotenv_expand = require("dotenv-expand");
145
- var import_dotenv = require("dotenv");
146
- var import_open = __toESM(require("open"));
147
- var import_strip_indent = __toESM(require("strip-indent"));
148
- var import_execa = require("execa");
149
- var TAMARO_CORE_PACKAGE_NAMES = ["@raisenow/tamaro-core"];
150
- var TAMARO_CONFIGURATIONS_PACKAGE_NAMES = ["@raisenow/tamaro-configurations"];
151
- var getIfCoreFns = () => {
152
- const corePkgPath = resolveApp("package.json");
153
- const configsPkgPath = resolveApp("../../package.json");
154
- if ((0, import_fs.existsSync)(corePkgPath)) {
155
- const { name: name2 } = require(corePkgPath);
156
- if (TAMARO_CORE_PACKAGE_NAMES.includes(name2)) {
157
- return (0, import_webpack_config_utils.getIfUtils)({ core: true }, ["core"]);
158
- }
159
- }
160
- if ((0, import_fs.existsSync)(configsPkgPath)) {
161
- const { name: name2 } = require(configsPkgPath);
162
- if (TAMARO_CONFIGURATIONS_PACKAGE_NAMES.includes(name2)) {
163
- return (0, import_webpack_config_utils.getIfUtils)({ core: false }, ["core"]);
164
- }
165
- }
166
- logError((0, import_strip_indent.default)(` You must run "npx @raisenow/tamaro-cli" commands from:
167
- 1. Root of "${import_chalk.default.bold(TAMARO_CORE_PACKAGE_NAMES[0])}" package folder.
168
- 2. Root of particular customer configuration folder of "${import_chalk.default.bold(TAMARO_CONFIGURATIONS_PACKAGE_NAMES[0])}" package.
169
- You are currently in "${import_chalk.default.bold((0, import_fs.realpathSync)(process.cwd()))}".
170
- `));
171
- process.exit(1);
172
- };
173
- var moduleFileExtensions = ["ts", "tsx", "js", "jsx"];
174
- var extensions = moduleFileExtensions.map((v) => `.${v}`);
175
- var resolveApp = (relativePath) => (0, import_path.resolve)((0, import_fs.realpathSync)(process.cwd()), relativePath);
176
- var resolveOwn = (relativePath) => (0, import_path.resolve)(__dirname, "..", relativePath);
177
- var resolveModule = (resolveFn, filePath) => {
178
- const extension = moduleFileExtensions.find((extension2) => (0, import_fs.existsSync)(resolveFn(`${filePath}.${extension2}`)));
179
- if (extension) {
180
- return resolveFn(`${filePath}.${extension}`);
181
- }
182
- return resolveFn(`${filePath}.js`);
183
- };
184
- var getWidgetUuid = () => (0, import_path.basename)(resolveApp("."));
185
- var getPaths = (ifCore) => {
186
- return ifCore({
187
- app: resolveApp("."),
188
- appEntry: resolveModule(resolveApp, "src/index"),
189
- appDist: resolveApp("dist"),
190
- appNodeModules: resolveApp("node_modules"),
191
- appTsConfig: resolveApp("tsconfig.json"),
192
- appHtml: resolveApp("src/*.html"),
193
- appEnv: resolveApp(".env"),
194
- appTailwindConfig: resolveApp("tailwind.config.js")
195
- }, {
196
- app: resolveApp("."),
197
- appEntry: resolveModule(resolveApp, "widget"),
198
- appDist: resolveApp(`../../dist/${getWidgetUuid()}`),
199
- appNodeModules: resolveApp("../../node_modules"),
200
- appTsConfig: resolveApp("tsconfig.json"),
201
- appHtml: resolveApp("*.html"),
202
- appEnv: resolveApp(".env"),
203
- appTailwindConfig: void 0
204
- });
205
- };
206
- var logTitle = (title) => {
207
- console.log(`
208
- ${import_chalk.default.bold(title)}`);
209
- };
210
- var logError = (message) => {
211
- if (message) {
212
- console.log(import_chalk.default.red(message));
213
- }
214
- };
215
- var fail = (message) => {
216
- logError(message);
217
- process.exit(1);
218
- };
219
- var logCommand = (command) => {
220
- console.log(import_chalk.default.dim((0, import_strip_indent.default)(command)));
221
- };
222
- var prepareCommand = (command) => {
223
- return command.replace(/\n/gm, " ").replace(/[ \t]{2,}/gm, " ").trim();
224
- };
225
- var runCommandSync = (command, options) => {
226
- return (0, import_execa.commandSync)(prepareCommand(command), options);
227
- };
228
- var logDataTable = (vars, title) => {
229
- logTable((0, import_columnify.default)(vars, { showHeaders: false }), title);
230
- };
231
- var logTable = (text, title) => {
232
- let out = "";
233
- const boxTitle = title ? import_chalk.default.bold(`${title}`) : void 0;
234
- if (boxTitle) {
235
- out += `${boxTitle}
236
- `;
237
- }
238
- out += text;
239
- console.log((0, import_boxen.default)(out, {
240
- margin: 0,
241
- padding: {
242
- top: 0,
243
- right: 1,
244
- bottom: 0,
245
- left: 1
246
- },
247
- borderColor: "green"
248
- }));
249
- };
250
- var notify = (args) => {
251
- const { title, message, target } = args;
252
- import_node_notifier.default.notify({
253
- title,
254
- message,
255
- contentImage: "https://assets.raisenow.io/favicon.png",
256
- sound: "Funk",
257
- timeout: 30
258
- });
259
- if (target) {
260
- import_node_notifier.default.on("click", () => {
261
- (0, import_open.default)(target);
262
- });
263
- }
264
- };
123
+ // src/lib/constants.ts
124
+ var DEFAULT_TAG = "latest";
125
+ var DEFAULT_PORT = 1234;
126
+ var DEFAULT_AWS_PROFILE = "payments-prod-cs-deployer";
127
+ var DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET = "rnw-email-service";
128
+ var AWS_S3_BUCKET = "tamaro.raisenow.com";
129
+ var CORE_CONFIG_NAME = "tamaro-core";
130
+ var AWS_CLOUDFRONT_DISTRIBUTION_ID = "EHJ1OM458YQ0I";
265
131
 
266
132
  // src/commands/dev.ts
267
- var import_resolve_bin = __toESM(require("resolve-bin"));
133
+ import { getPortPromise } from "portfinder";
268
134
  var dev = async (options) => {
269
135
  assertOptionsValid(options);
270
- const flags = prepareFlags(options);
136
+ const flags = (await prepareFlags([], options)).join(" ");
271
137
  const { ifCore } = getIfCoreFns();
272
138
  const title = ifCore("Running dev web-server for Tamaro Core \u2026", "Running dev web-server for customer configuration \u2026");
273
- const wpBin = import_resolve_bin.default.sync("webpack");
139
+ const wpBin = resolveBin("webpack");
274
140
  const wpConfig = resolveOwn("dist/webpack.config.js");
275
141
  const cmd = `
276
142
  ${wpBin} serve
@@ -282,38 +148,41 @@ var dev = async (options) => {
282
148
  runCommandSync(cmd, { stdio: "inherit" });
283
149
  };
284
150
  var assertOptionsValid = (options) => {
285
- const { localCore } = options;
151
+ const { localCore, port, env } = options;
286
152
  const { ifCore } = getIfCoreFns();
287
153
  if (ifCore() && localCore) {
288
- fail('Flag "--local-core" is redundant if running in Tamaro Core context.');
154
+ fail("Flag \u201C--local-core\u201D is redundant if running in Tamaro Core context.");
289
155
  }
156
+ if (isNaN(Number(port))) {
157
+ fail("Flag \u201C--port\u201D should be a number.");
158
+ }
159
+ assertEnvValid(env);
290
160
  };
291
- var prepareFlags = (options) => {
292
- const { localCore } = options;
293
- let flags = [];
294
- flags = localCore ? [...flags, "--env localCore"] : flags;
295
- return flags.join(" ");
161
+ var prepareFlags = async (flags, options) => {
162
+ const { localCore, port: defaultPort } = options;
163
+ const port = await getPortPromise({ port: Number(defaultPort) });
164
+ if (localCore) {
165
+ flags.push("--env localCore");
166
+ }
167
+ flags.push(`--port ${port}`);
168
+ return flags;
296
169
  };
297
170
 
298
- // src/commands/build.ts
299
- var import_resolve_bin2 = __toESM(require("resolve-bin"));
300
-
301
171
  // src/lib/aws.ts
302
- var import_execa2 = require("execa");
303
- var import_strip_indent2 = __toESM(require("strip-indent"));
304
- var DEFAULT_AWS_PROFILE = "payments-prod-cs-deployer";
305
- var runAwsCommandSync = (command, options) => {
306
- authenticate();
307
- return (0, import_execa2.commandSync)(prepareCommand(command), options);
172
+ import { execaCommandSync } from "execa";
173
+ import stripIndent from "strip-indent";
174
+ var withAwsAuthenticate = (fn, options) => {
175
+ awsAuthenticate(options);
176
+ return fn();
308
177
  };
309
- var authenticate = () => {
178
+ var awsAuthenticate = (options) => {
310
179
  if (isSetEnv()) {
311
180
  return;
312
181
  }
313
182
  try {
314
- checkIdentity();
183
+ checkIdentity(options);
315
184
  } catch (error) {
316
- login();
185
+ login(options);
317
186
  }
318
187
  };
319
188
  var isSetEnv = () => {
@@ -328,78 +197,151 @@ var assertProfileValid = (profile) => {
328
197
  console.log(`Using AWS profile: \u201C${profile}\u201D`);
329
198
  let message;
330
199
  if (profiles.length === 0) {
331
- message = (0, import_strip_indent2.default)(`
200
+ message = stripIndent(`
332
201
  No AWS profiles found.
333
202
  `);
334
203
  } else {
335
- message = (0, import_strip_indent2.default)(`
204
+ message = stripIndent(`
336
205
  AWS profile \u201C${profile}\u201D has not been found.
337
206
  Available profiles are: ${profiles.map((v) => `\u201C${v}\u201D`).join(", ")}.
338
207
  `);
339
208
  }
340
- message += (0, import_strip_indent2.default)(`
209
+ message += stripIndent(`
341
210
  Run \u201Caws configure sso\u201D to set up SSO-enabled profile.
342
211
  Check the wiki for more information:
343
212
  https://raisenow.atlassian.net/wiki/x/lIrWvg
344
213
  `);
345
214
  fail(message);
346
215
  }
347
- process.env.AWS_PROFILE = profile;
348
216
  };
349
217
  var getAvailableProfiles = () => {
350
- const { stdout } = (0, import_execa2.commandSync)("aws configure list-profiles");
218
+ const { stdout } = execaCommandSync("aws configure list-profiles");
351
219
  return stdout.split("\n");
352
220
  };
353
- var checkIdentity = () => {
354
- (0, import_execa2.commandSync)("aws sts get-caller-identity");
221
+ var checkIdentity = (options) => {
222
+ const flags = prepareFlags2([], options).join(" ");
223
+ execaCommandSync(`aws sts get-caller-identity ${flags}`);
355
224
  };
356
- var login = () => {
225
+ var login = (options) => {
226
+ const flags = prepareFlags2([], options).join(" ");
357
227
  try {
358
- (0, import_execa2.commandSync)("aws sso login", { stdio: "inherit" });
228
+ execaCommandSync(`aws sso login ${flags}`, { stdio: "inherit" });
359
229
  console.log("");
360
230
  } catch (error) {
361
- fail("Login failed");
231
+ fail("Login failed.");
232
+ }
233
+ };
234
+ var prepareFlags2 = (flags, options) => {
235
+ const { profile } = options;
236
+ if (!isSetEnv()) {
237
+ flags.push(`--profile ${profile}`);
238
+ }
239
+ return flags;
240
+ };
241
+
242
+ // src/lib/notifier.ts
243
+ import notifier from "node-notifier";
244
+ import stripIndent2 from "strip-indent";
245
+ var notify = (args) => {
246
+ const { title, message = "" } = args;
247
+ notifier.notify({
248
+ title,
249
+ message: stripIndent2(message).trim(),
250
+ contentImage: "https://assets.raisenow.io/favicon.png",
251
+ sound: "Funk"
252
+ });
253
+ };
254
+
255
+ // src/commands/build.ts
256
+ var build = async (options) => {
257
+ assertOptionsValid2(options);
258
+ const flags = prepareFlags3([], options).join(" ");
259
+ const { ifCore } = getIfCoreFns();
260
+ const paths = getPaths(ifCore);
261
+ const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
262
+ const title = ifCore("Building optimised (minified) bundle of Tamaro Core \u2026", `Building optimised (minified) bundle of \u201C${configName}\u201D customer configuration \u2026`);
263
+ const wpBin = resolveBin("webpack");
264
+ const wpConfig = resolveOwn("dist/webpack.config.js");
265
+ const cmd = `
266
+ ${wpBin}
267
+ --config ${wpConfig}
268
+ --env min
269
+ ${flags}
270
+ `;
271
+ logTitle(title);
272
+ logCommand(cmd);
273
+ runCommandSync(cmd, { stdio: "inherit" });
274
+ logTitle(`
275
+ Bundle for \u201C${configName}\u201D customer configuration is done.`);
276
+ console.log(`Path: ${paths.appDist}
277
+ `);
278
+ process.on("exit", () => {
279
+ notify({
280
+ title: "build",
281
+ message: `Bundle for \u201C${configName}\u201D customer configuration is done.`
282
+ });
283
+ });
284
+ };
285
+ var assertOptionsValid2 = (options) => {
286
+ const { localCore, deploy: deploy2, profile, env } = options;
287
+ const { ifCore } = getIfCoreFns();
288
+ if (ifCore() && localCore) {
289
+ fail("Flag \u201C--local-core\u201D is redundant if running in Tamaro Core context.");
290
+ }
291
+ if (localCore && deploy2) {
292
+ fail("Flags \u201C--local-core\u201D and \u201C--deploy\u201D must not be used together.");
293
+ }
294
+ assertProfileValid(profile);
295
+ assertEnvValid(env);
296
+ };
297
+ var prepareFlags3 = (flags, options) => {
298
+ const { localCore, analyze } = options;
299
+ if (localCore) {
300
+ flags.push("--env localCore");
301
+ }
302
+ if (analyze) {
303
+ flags.push("--env analyze");
362
304
  }
305
+ return flags;
363
306
  };
364
307
 
365
308
  // src/commands/deploy.ts
366
- var import_fs2 = require("fs");
367
- var import_strip_indent3 = __toESM(require("strip-indent"));
368
- var AWS_S3_BUCKET = "tamaro.raisenow.com";
369
- var CORE_CONFIG_NAME = "tamaro-core";
370
- var AWS_CLOUDFRONT_DISTRIBUTION_ID = "EHJ1OM458YQ0I";
371
- var DEFAULT_TAG = "latest";
309
+ import { existsSync } from "fs";
372
310
  var deploy = async (options) => {
373
311
  const { ifCore } = getIfCoreFns();
374
312
  const paths = getPaths(ifCore);
375
- assertOptionsValid2(options);
313
+ assertOptionsValid3(options);
376
314
  assertDistPathExists(paths.appDist);
315
+ const flags = prepareFlags4([], options).join(" ");
377
316
  const { tag } = options;
378
317
  const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
379
318
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/${tag}`;
380
319
  const entryFilename = ifCore("index.js", "widget.js");
381
320
  const cmdSyncAll = `
382
321
  aws s3 sync ${paths.appDist} ${deployUrl}
322
+ --quiet
383
323
  --acl public-read
384
- --size-only
385
324
  --exclude ${paths.appDist}/${entryFilename}
386
325
  --cache-control max-age=31536000
326
+ ${flags}
387
327
  `;
388
328
  logTitle("Deploying to AWS S3 \u2026");
389
329
  logCommand(cmdSyncAll);
390
330
  try {
391
- runAwsCommandSync(cmdSyncAll, { stdout: "inherit" });
331
+ withAwsAuthenticate(() => runCommandSync(cmdSyncAll, { stdout: "inherit" }), options);
392
332
  } catch (error) {
393
333
  fail(error.stderr);
394
334
  }
395
335
  const cmdCpEntry = `
396
336
  aws s3 cp ${paths.appDist}/${entryFilename} ${deployUrl}/${entryFilename}
337
+ --quiet
397
338
  --acl public-read
398
339
  --cache-control max-age=64800
340
+ ${flags}
399
341
  `;
400
342
  logCommand(cmdCpEntry);
401
343
  try {
402
- runAwsCommandSync(cmdCpEntry, { stdout: "inherit" });
344
+ withAwsAuthenticate(() => runCommandSync(cmdCpEntry, { stdout: "inherit" }), options);
403
345
  } catch (error) {
404
346
  fail(error.stderr);
405
347
  }
@@ -407,36 +349,41 @@ var deploy = async (options) => {
407
349
  aws cloudfront create-invalidation
408
350
  --distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID}
409
351
  --paths /${configName}/${tag}/*
352
+ ${flags}
410
353
  `;
411
- logTitle("Invalidating edge cache \u2026");
354
+ logTitle("\nInvalidating edge cache \u2026");
412
355
  logCommand(cmdInvalidateCache);
413
356
  try {
414
- runAwsCommandSync(cmdInvalidateCache);
357
+ withAwsAuthenticate(() => runCommandSync(cmdInvalidateCache), options);
415
358
  } catch (error) {
416
359
  fail(error.stderr);
417
360
  }
418
361
  const demoPage = `https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`;
419
362
  const entryPoint = `https://${AWS_S3_BUCKET}/${configName}/${tag}/${entryFilename}`;
363
+ logTitle(`
364
+ Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.`);
420
365
  logDataTable({
421
366
  "Demo page:": demoPage,
422
367
  "Entry point:": entryPoint
423
- }, `Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D`);
424
- notify({
425
- title: "deploy",
426
- message: (0, import_strip_indent3.default)(`
427
- Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.
428
- Demo page: ${demoPage}
429
- `),
430
- target: demoPage
368
+ });
369
+ process.on("exit", () => {
370
+ notify({
371
+ title: "deploy",
372
+ message: `
373
+ Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.
374
+ Demo page: ${demoPage}
375
+ Entry point: ${entryPoint}
376
+ `
377
+ });
431
378
  });
432
379
  };
433
- var assertOptionsValid2 = (options) => {
380
+ var assertOptionsValid3 = (options) => {
434
381
  const { tag, profile } = options;
435
382
  assertTagValid(tag);
436
383
  assertProfileValid(profile);
437
384
  };
438
385
  var assertDistPathExists = (distPath) => {
439
- if (!(0, import_fs2.existsSync)(distPath)) {
386
+ if (!existsSync(distPath)) {
440
387
  fail(`
441
388
  Dist folder does not exists.
442
389
  Make sure you have built the bundle before trying to deploy it.
@@ -444,87 +391,59 @@ var assertDistPathExists = (distPath) => {
444
391
  }
445
392
  };
446
393
  var assertTagValid = (tag) => {
447
- const regex = /^[a-zA-Z0-9-_]+$/;
394
+ const regex = /^[a-zA-Z0-9-_.]+$/;
448
395
  if (!regex.test(tag)) {
449
- fail(`Flag "--tag" has forbidden format. Allowed format: ${regex}.`);
450
- }
451
- };
452
-
453
- // src/commands/build.ts
454
- var build = async (options) => {
455
- assertOptionsValid3(options);
456
- const flags = prepareFlags2(options);
457
- const { ifCore } = getIfCoreFns();
458
- const paths = getPaths(ifCore);
459
- const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
460
- const title = ifCore("Building optimised (minified) bundle of Tamaro Core \u2026", `Building optimised (minified) bundle of \u201C${configName}\u201D customer configuration \u2026`);
461
- const wpBin = import_resolve_bin2.default.sync("webpack");
462
- const wpConfig = resolveOwn("dist/webpack.config.js");
463
- const cmd = `
464
- ${wpBin}
465
- --config ${wpConfig}
466
- --env min
467
- ${flags}
468
- `;
469
- logTitle(title);
470
- logCommand(cmd);
471
- runCommandSync(cmd, { stdio: "inherit" });
472
- logDataTable({ "Path:": paths.appDist }, `Bundle for \u201C${configName}\u201D customer configuration is done.`);
473
- notify({
474
- title: "build",
475
- message: `Bundle for \u201C${configName}\u201D customer configuration is done.`
476
- });
477
- };
478
- var assertOptionsValid3 = (options) => {
479
- const { localCore, deploy: deploy2, profile } = options;
480
- const { ifCore } = getIfCoreFns();
481
- if (ifCore() && localCore) {
482
- fail('Flag "--local-core" is redundant if running in Tamaro Core context.');
396
+ fail(`Flag \u201C--tag\u201D has forbidden format. Allowed format: ${regex}.`);
483
397
  }
484
- if (localCore && deploy2) {
485
- fail('Flags "--local-core" and "--deploy" must not be used together.');
486
- }
487
- assertProfileValid(profile);
488
398
  };
489
- var prepareFlags2 = (options) => {
490
- const { localCore, analyze } = options;
491
- let flags = [];
492
- flags = localCore ? [...flags, "--env localCore"] : flags;
493
- flags = analyze ? [...flags, "--env analyze"] : flags;
494
- return flags.join(" ");
399
+ var prepareFlags4 = (flags, options) => {
400
+ return prepareFlags2(flags, options);
495
401
  };
496
402
 
497
403
  // src/commands/serve.ts
498
- var import_portfinder = require("portfinder");
499
- var DEFAULT_PORT = 1234;
500
- var serve = async () => {
404
+ import { getPortPromise as getPortPromise2 } from "portfinder";
405
+ var serve = async (options) => {
406
+ assertOptionsValid4(options);
407
+ const flags = (await prepareFlags5([], options)).join(" ");
501
408
  const { ifCore } = getIfCoreFns();
502
409
  const paths = getPaths(ifCore);
503
- const port = await (0, import_portfinder.getPortPromise)({ port: DEFAULT_PORT });
504
410
  const cmd = `
505
- npx -y http-server ${paths.appDist}
411
+ npx -y serve ${paths.appDist}
506
412
  --cors
507
- --port ${port}
413
+ ${flags}
508
414
  `;
509
415
  logTitle(`Running web-server for pre-built bundle \u2026`);
510
416
  logCommand(cmd);
511
417
  runCommandSync(cmd, { stdio: "inherit" });
512
418
  };
419
+ var assertOptionsValid4 = (options) => {
420
+ const { port } = options;
421
+ if (isNaN(Number(port))) {
422
+ fail('Flag "--port" should be a number.');
423
+ }
424
+ };
425
+ var prepareFlags5 = async (flags, options) => {
426
+ const { port: defaultPort } = options;
427
+ const port = await getPortPromise2({ port: Number(defaultPort) });
428
+ flags.push(`-p ${port}`);
429
+ return flags;
430
+ };
513
431
 
514
432
  // src/commands/list-deployed.ts
515
433
  var listDeployed = async (options) => {
516
- assertOptionsValid4(options);
434
+ assertOptionsValid5(options);
435
+ const flags = prepareFlags6([], options).join(" ");
517
436
  const { config } = options;
518
437
  const { ifCore } = getIfCoreFns();
519
438
  const configName = config != null ? config : ifCore(CORE_CONFIG_NAME, getWidgetUuid());
520
439
  const title = !config && ifCore() ? `Listing deployments of Tamaro Core \u2026` : `Listing deployments of \u201C${configName}\u201D customer configuration \u2026`;
521
440
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/`;
522
- const cmd = `aws s3 ls ${deployUrl}`;
441
+ const cmd = `aws s3 ls ${deployUrl} ${flags}`;
523
442
  let out = "";
524
443
  logTitle(title);
525
444
  logCommand(cmd);
526
445
  try {
527
- const result = runAwsCommandSync(cmd);
446
+ const result = withAwsAuthenticate(() => runCommandSync(cmd), options);
528
447
  out = result.stdout;
529
448
  } catch (error) {
530
449
  out = error.stdout;
@@ -542,9 +461,10 @@ var listDeployed = async (options) => {
542
461
  return `${idx + 1}. https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`;
543
462
  }).join("\n");
544
463
  }
545
- logTable(text);
464
+ console.log(`${text}
465
+ `);
546
466
  };
547
- var assertOptionsValid4 = (options) => {
467
+ var assertOptionsValid5 = (options) => {
548
468
  const { config, profile } = options;
549
469
  assertConfigValid(config);
550
470
  assertProfileValid(profile);
@@ -555,24 +475,27 @@ var assertConfigValid = (config) => {
555
475
  }
556
476
  const regex = /^[a-zA-Z0-9-_]+$/;
557
477
  if (!regex.test(config)) {
558
- fail(`Flag "--config" has forbidden format. Allowed format: ${regex}.`);
478
+ fail(`Flag \u201C--config\u201D has forbidden format. Allowed format: ${regex}.`);
559
479
  }
560
480
  };
481
+ var prepareFlags6 = (flags, options) => {
482
+ return prepareFlags2(flags, options);
483
+ };
561
484
  var parseTags = (lines) => {
562
485
  const regex = /^\s*PRE\s*/;
563
486
  return lines.filter((line) => regex.test(line)).map((line) => line.replace(regex, "").replace(/\/$/, ""));
564
487
  };
565
488
 
566
489
  // src/commands/deploy-email-config.ts
567
- var import_fs3 = require("fs");
568
- var DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET = "rnw-email-service";
490
+ import { existsSync as existsSync2 } from "fs";
569
491
  var deployEmailConfig = async (options) => {
570
492
  const { ifCore } = getIfCoreFns();
571
493
  const paths = getPaths(ifCore);
572
494
  const emailConfigPath = `${paths.app}/email-config`;
573
- assertOptionsValid5(options);
495
+ assertOptionsValid6(options);
574
496
  assertEmailConfigPathExists(emailConfigPath);
575
497
  assertIsNotCore();
498
+ const flags = prepareFlags7([], options).join(" ");
576
499
  const { bucket } = options;
577
500
  const configName = getWidgetUuid();
578
501
  const deployUrl = `s3://${bucket}/${configName}`;
@@ -580,34 +503,38 @@ var deployEmailConfig = async (options) => {
580
503
  aws s3 sync ${emailConfigPath} ${deployUrl}
581
504
  --delete
582
505
  --exact-timestamps
506
+ ${flags}
583
507
  `;
584
508
  logTitle(`Deploying email configuration for \u201C${configName}\u201D customer configuration to AWS S3 \u2026`);
585
509
  logCommand(cmd);
586
510
  try {
587
- runAwsCommandSync(cmd, { stdout: "inherit" });
511
+ withAwsAuthenticate(() => runCommandSync(cmd, { stdout: "inherit" }), options);
588
512
  } catch (error) {
589
513
  fail(error.stderr);
590
514
  }
591
- logDataTable({ "Deploy URL:": deployUrl }, `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`);
592
- notify({
593
- title: `deploy-email-config`,
594
- message: `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`
515
+ logTitle(`Email configuration for \u201C${configName}\u201D customer configuration is deployed.`);
516
+ logDataTable({ "Deploy URL:": deployUrl });
517
+ process.on("exit", () => {
518
+ notify({
519
+ title: `deploy-email-config`,
520
+ message: `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`
521
+ });
595
522
  });
596
523
  };
597
- var assertOptionsValid5 = (options) => {
524
+ var assertOptionsValid6 = (options) => {
598
525
  const { bucket, profile } = options;
599
526
  assertBucketValid(bucket);
600
527
  assertProfileValid(profile);
601
528
  };
602
529
  var assertEmailConfigPathExists = (distPath) => {
603
- if (!(0, import_fs3.existsSync)(distPath)) {
530
+ if (!existsSync2(distPath)) {
604
531
  fail("Email config folder does not exists. Nothing to deploy.");
605
532
  }
606
533
  };
607
534
  var assertBucketValid = (tag) => {
608
535
  const regex = /^[a-zA-Z0-9-_]+$/;
609
536
  if (!regex.test(tag)) {
610
- fail(`Flag "--bucket" has forbidden format. Allowed format: ${regex}.`);
537
+ fail(`Flag \u201C--bucket\u201D has forbidden format. Allowed format: ${regex}.`);
611
538
  }
612
539
  };
613
540
  var assertIsNotCore = () => {
@@ -616,6 +543,9 @@ var assertIsNotCore = () => {
616
543
  fail("You cannot deploy widget email configuration for Tamaro Core.");
617
544
  }
618
545
  };
546
+ var prepareFlags7 = (flags, options) => {
547
+ return prepareFlags2(flags, options);
548
+ };
619
549
 
620
550
  // src/cli.ts
621
551
  process.on("unhandledRejection", (error) => {
@@ -624,25 +554,25 @@ process.on("unhandledRejection", (error) => {
624
554
  process.on("SIGINT", () => {
625
555
  process.exit(1);
626
556
  });
627
- var cli = (0, import_commander.createCommand)().name(package_default.name).version(package_default.version, "-v, --version");
628
- 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 instead of the CDN", false).action(async (options) => {
557
+ var cli = createCommand().name(package_default.name).version(package_default.version, "-v, --version");
558
+ 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) => {
629
559
  await dev(options);
630
560
  });
631
- cli.command("build").description("Build an optimised (minified) bundle of Tamaro Core or a customer configuration").option("--local-core", "Load Tamaro Core from localhost instead of the CDN", false).option("--analyze", 'Generate bundle statistics to "reports" folder', false).option("--deploy", "Deploy Tamaro Core or a customer configuration bundle to AWS S3", false).option("--serve", "Run the generated bundle with a local web server", 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) => {
561
+ 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) => {
632
562
  await build(options);
563
+ if (options.serve) {
564
+ await serve(options);
565
+ }
633
566
  if (options.deploy) {
634
567
  await deploy(options);
635
568
  }
636
- if (options.serve) {
637
- await serve();
638
- }
569
+ });
570
+ cli.command("serve").description("Run a local web server for pre-built bundle").option("--port <port>", "Web server port", `${DEFAULT_PORT}`).action(async (options) => {
571
+ await serve(options);
639
572
  });
640
573
  cli.command("deploy").description("Deploy a pre-built Tamaro Core or customer configuration bundle to AWS S3").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) => {
641
574
  await deploy(options);
642
575
  });
643
- cli.command("serve").description("Run a local web server for pre-built bundle").action(async () => {
644
- await serve();
645
- });
646
576
  cli.command("list-deployed").description("List deployments of Tamaro Core or a particular customer configuration").option("--config <config>", "Configuration name (default: current customer configuration)").option("--profile <profile>", "AWS profile which should be used for fetching deployments", DEFAULT_AWS_PROFILE).action(async (options) => {
647
577
  await listDeployed(options);
648
578
  });
@@ -656,6 +586,9 @@ cli.command("deploy-email-config").description("Deploy a widget\u2019s email con
656
586
  if (error.signal === "SIGINT" && error.signalDescription) {
657
587
  logError(`
658
588
  ${error.signalDescription}`);
589
+ } else {
590
+ console.log("");
591
+ logError(error.stack);
659
592
  }
660
593
  }
661
594
  })();