@raisenow/tamaro-cli 1.0.9 → 1.0.12

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