@raisenow/tamaro-cli 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.10";
19
+ var version = "1.0.11";
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,53 +36,48 @@ 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.3",
40
+ "@babel/core": "^7.17.5",
41
+ "@babel/plugin-proposal-decorators": "^7.17.2",
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.2",
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
52
  "@types/lodash": "^4.14.178",
60
- "@types/mini-css-extract-plugin": "^2.5.1",
61
- "@types/node": "^17.0.16",
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",
57
+ "@typescript-eslint/eslint-plugin": "^5.12.0",
58
+ "@typescript-eslint/parser": "^5.12.0",
67
59
  autoprefixer: "^10.4.2",
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.0",
72
63
  "clean-webpack-plugin": "^4.0.0",
73
64
  columnify: "^1.6.0",
74
65
  commander: "^9.0.0",
75
66
  "copy-webpack-plugin": "^10.2.4",
76
- "core-js": "^3.21.0",
67
+ "core-js": "^3.21.1",
77
68
  "css-loader": "^6.6.0",
78
69
  "css-minimizer-webpack-plugin": "^3.4.1",
79
- "current-script-polyfill": "^1.0.0",
80
70
  dotenv: "^16.0.0",
81
71
  "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",
72
+ "escape-string-regexp": "^5.0.0",
73
+ eslint: "^8.9.0",
74
+ "eslint-config-prettier": "^8.4.0",
86
75
  "eslint-plugin-node": "^11.1.0",
87
- "eslint-plugin-prettier": "^4.0.0",
88
76
  "eslint-plugin-promise": "^6.0.0",
89
- "eslint-webpack-plugin": "^3.1.0",
90
- execa: "^5.1.1",
77
+ "eslint-webpack-plugin": "^3.1.1",
78
+ execa: "^6.1.0",
91
79
  "file-loader": "^6.2.0",
92
- "fork-ts-checker-webpack-plugin": "^7.1.1",
80
+ "fork-ts-checker-webpack-plugin": "^7.2.1",
93
81
  glob: "^7.2.0",
94
82
  "html-loader": "^3.1.0",
95
83
  "html-webpack-plugin": "^5.5.0",
@@ -97,26 +85,23 @@ var dependencies = {
97
85
  lodash: "^4.17.21",
98
86
  "mini-css-extract-plugin": "^2.5.3",
99
87
  "node-notifier": "^10.0.1",
100
- open: "^8.4.0",
101
88
  portfinder: "^1.0.28",
102
89
  postcss: "^8.4.6",
103
90
  "postcss-custom-properties": "^12.1.4",
104
91
  "postcss-loader": "^6.2.1",
105
92
  prettier: "^2.5.1",
106
93
  "react-refresh": "^0.11.0",
107
- "resolve-bin": "^1.0.0",
108
94
  "resolve-url-loader": "^5.0.0",
109
- sass: "^1.49.7",
110
- "sass-loader": "^12.4.0",
95
+ sass: "^1.49.8",
96
+ "sass-loader": "^12.6.0",
111
97
  "source-map-loader": "^3.0.1",
112
- "strip-indent": "^3.0.0",
98
+ "strip-indent": "^4.0.0",
113
99
  "style-loader": "^3.3.1",
114
100
  "tsconfig-paths-webpack-plugin": "^3.5.2",
115
101
  tsup: "^5.11.13",
116
102
  typescript: "^4.5.5",
117
- unfetch: "^4.2.0",
118
103
  "url-loader": "^4.1.1",
119
- webpack: "^5.68.0",
104
+ webpack: "^5.69.1",
120
105
  "webpack-cli": "^4.9.2",
121
106
  "webpack-config-utils": "^2.3.1",
122
107
  "webpack-dev-server": "^4.7.4",
@@ -126,151 +111,45 @@ var package_default = {
126
111
  name,
127
112
  version,
128
113
  author,
129
- main,
114
+ type,
130
115
  scripts,
131
116
  bin,
132
117
  engines,
133
118
  dependencies
134
119
  };
135
120
 
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
- };
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";
215
135
  var fail = (message) => {
216
136
  logError(message);
217
137
  process.exit(1);
218
138
  };
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
- }));
139
+ var prepareCommand = (cmd) => {
140
+ return cmd.replace(/\n/gm, " ").replace(/[ \t]{2,}/gm, " ").trim();
249
141
  };
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
- }
142
+ var runCommandSync = (cmd, options) => {
143
+ return execaCommandSync(prepareCommand(cmd), options);
264
144
  };
265
145
 
266
146
  // src/commands/dev.ts
267
- var import_resolve_bin = __toESM(require("resolve-bin"));
268
147
  var dev = async (options) => {
269
148
  assertOptionsValid(options);
270
- const flags = prepareFlags(options);
149
+ const flags = (await prepareFlags([], options)).join(" ");
271
150
  const { ifCore } = getIfCoreFns();
272
151
  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");
152
+ const wpBin = resolveBin("webpack");
274
153
  const wpConfig = resolveOwn("dist/webpack.config.js");
275
154
  const cmd = `
276
155
  ${wpBin} serve
@@ -282,38 +161,40 @@ var dev = async (options) => {
282
161
  runCommandSync(cmd, { stdio: "inherit" });
283
162
  };
284
163
  var assertOptionsValid = (options) => {
285
- const { localCore } = options;
164
+ const { localCore, port } = options;
286
165
  const { ifCore } = getIfCoreFns();
287
166
  if (ifCore() && localCore) {
288
167
  fail('Flag "--local-core" is redundant if running in Tamaro Core context.');
289
168
  }
169
+ if (isNaN(Number(port))) {
170
+ fail('Flag "--port" should be a number.');
171
+ }
290
172
  };
291
- var prepareFlags = (options) => {
292
- const { localCore } = options;
293
- let flags = [];
294
- flags = localCore ? [...flags, "--env localCore"] : flags;
295
- 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;
296
181
  };
297
182
 
298
- // src/commands/build.ts
299
- var import_resolve_bin2 = __toESM(require("resolve-bin"));
300
-
301
183
  // 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);
184
+ import { execaCommandSync as execaCommandSync2 } from "execa";
185
+ import stripIndent from "strip-indent";
186
+ var withAwsAuthenticate = (fn, options) => {
187
+ awsAuthenticate(options);
188
+ return fn();
308
189
  };
309
- var authenticate = () => {
190
+ var awsAuthenticate = (options) => {
310
191
  if (isSetEnv()) {
311
192
  return;
312
193
  }
313
194
  try {
314
- checkIdentity();
195
+ checkIdentity(options);
315
196
  } catch (error) {
316
- login();
197
+ login(options);
317
198
  }
318
199
  };
319
200
  var isSetEnv = () => {
@@ -328,52 +209,121 @@ var assertProfileValid = (profile) => {
328
209
  console.log(`Using AWS profile: \u201C${profile}\u201D`);
329
210
  let message;
330
211
  if (profiles.length === 0) {
331
- message = (0, import_strip_indent2.default)(`
212
+ message = stripIndent(`
332
213
  No AWS profiles found.
333
214
  `);
334
215
  } else {
335
- message = (0, import_strip_indent2.default)(`
216
+ message = stripIndent(`
336
217
  AWS profile \u201C${profile}\u201D has not been found.
337
218
  Available profiles are: ${profiles.map((v) => `\u201C${v}\u201D`).join(", ")}.
338
219
  `);
339
220
  }
340
- message += (0, import_strip_indent2.default)(`
221
+ message += stripIndent(`
341
222
  Run \u201Caws configure sso\u201D to set up SSO-enabled profile.
342
223
  Check the wiki for more information:
343
224
  https://raisenow.atlassian.net/wiki/x/lIrWvg
344
225
  `);
345
226
  fail(message);
346
227
  }
347
- process.env.AWS_PROFILE = profile;
348
228
  };
349
229
  var getAvailableProfiles = () => {
350
- const { stdout } = (0, import_execa2.commandSync)("aws configure list-profiles");
230
+ const { stdout } = execaCommandSync2("aws configure list-profiles");
351
231
  return stdout.split("\n");
352
232
  };
353
- var checkIdentity = () => {
354
- (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}`);
355
236
  };
356
- var login = () => {
237
+ var login = (options) => {
238
+ const flags = prepareFlags2([], options).join(" ");
357
239
  try {
358
- (0, import_execa2.commandSync)("aws sso login", { stdio: "inherit" });
240
+ execaCommandSync2(`aws sso login ${flags}`, { stdio: "inherit" });
359
241
  console.log("");
360
242
  } catch (error) {
361
- fail("Login failed");
243
+ fail("Login failed.");
362
244
  }
363
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
+ };
364
318
 
365
319
  // 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";
320
+ import { existsSync } from "fs";
372
321
  var deploy = async (options) => {
373
322
  const { ifCore } = getIfCoreFns();
374
323
  const paths = getPaths(ifCore);
375
- assertOptionsValid2(options);
324
+ assertOptionsValid3(options);
376
325
  assertDistPathExists(paths.appDist);
326
+ const flags = prepareFlags4([], options).join(" ");
377
327
  const { tag } = options;
378
328
  const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
379
329
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/${tag}`;
@@ -384,11 +334,12 @@ var deploy = async (options) => {
384
334
  --size-only
385
335
  --exclude ${paths.appDist}/${entryFilename}
386
336
  --cache-control max-age=31536000
337
+ ${flags}
387
338
  `;
388
339
  logTitle("Deploying to AWS S3 \u2026");
389
340
  logCommand(cmdSyncAll);
390
341
  try {
391
- runAwsCommandSync(cmdSyncAll, { stdout: "inherit" });
342
+ withAwsAuthenticate(() => runCommandSync(cmdSyncAll, { stdout: "inherit" }), options);
392
343
  } catch (error) {
393
344
  fail(error.stderr);
394
345
  }
@@ -396,10 +347,11 @@ var deploy = async (options) => {
396
347
  aws s3 cp ${paths.appDist}/${entryFilename} ${deployUrl}/${entryFilename}
397
348
  --acl public-read
398
349
  --cache-control max-age=64800
350
+ ${flags}
399
351
  `;
400
352
  logCommand(cmdCpEntry);
401
353
  try {
402
- runAwsCommandSync(cmdCpEntry, { stdout: "inherit" });
354
+ withAwsAuthenticate(() => runCommandSync(cmdCpEntry, { stdout: "inherit" }), options);
403
355
  } catch (error) {
404
356
  fail(error.stderr);
405
357
  }
@@ -407,36 +359,41 @@ var deploy = async (options) => {
407
359
  aws cloudfront create-invalidation
408
360
  --distribution-id ${AWS_CLOUDFRONT_DISTRIBUTION_ID}
409
361
  --paths /${configName}/${tag}/*
362
+ ${flags}
410
363
  `;
411
- logTitle("Invalidating edge cache \u2026");
364
+ logTitle("\nInvalidating edge cache \u2026");
412
365
  logCommand(cmdInvalidateCache);
413
366
  try {
414
- runAwsCommandSync(cmdInvalidateCache);
367
+ withAwsAuthenticate(() => runCommandSync(cmdInvalidateCache), options);
415
368
  } catch (error) {
416
369
  fail(error.stderr);
417
370
  }
418
371
  const demoPage = `https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`;
419
372
  const entryPoint = `https://${AWS_S3_BUCKET}/${configName}/${tag}/${entryFilename}`;
373
+ logTitle(`
374
+ Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.`);
420
375
  logDataTable({
421
376
  "Demo page:": demoPage,
422
377
  "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
378
+ });
379
+ process.on("exit", () => {
380
+ notify({
381
+ title: "deploy",
382
+ message: `
383
+ Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.
384
+ Demo page: ${demoPage}
385
+ Entry point: ${entryPoint}
386
+ `
387
+ });
431
388
  });
432
389
  };
433
- var assertOptionsValid2 = (options) => {
390
+ var assertOptionsValid3 = (options) => {
434
391
  const { tag, profile } = options;
435
392
  assertTagValid(tag);
436
393
  assertProfileValid(profile);
437
394
  };
438
395
  var assertDistPathExists = (distPath) => {
439
- if (!(0, import_fs2.existsSync)(distPath)) {
396
+ if (!existsSync(distPath)) {
440
397
  fail(`
441
398
  Dist folder does not exists.
442
399
  Make sure you have built the bundle before trying to deploy it.
@@ -444,87 +401,59 @@ var assertDistPathExists = (distPath) => {
444
401
  }
445
402
  };
446
403
  var assertTagValid = (tag) => {
447
- const regex = /^[a-zA-Z0-9-_]+$/;
404
+ const regex = /^[a-zA-Z0-9-_.]+$/;
448
405
  if (!regex.test(tag)) {
449
406
  fail(`Flag "--tag" has forbidden format. Allowed format: ${regex}.`);
450
407
  }
451
408
  };
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.');
483
- }
484
- if (localCore && deploy2) {
485
- fail('Flags "--local-core" and "--deploy" must not be used together.');
486
- }
487
- assertProfileValid(profile);
488
- };
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(" ");
409
+ var prepareFlags4 = (flags, options) => {
410
+ return prepareFlags2(flags, options);
495
411
  };
496
412
 
497
413
  // src/commands/serve.ts
498
- var import_portfinder = require("portfinder");
499
- var DEFAULT_PORT = 1234;
500
- var serve = async () => {
414
+ import { getPortPromise as getPortPromise2 } from "portfinder";
415
+ var serve = async (options) => {
416
+ assertOptionsValid4(options);
417
+ const flags = (await prepareFlags5([], options)).join(" ");
501
418
  const { ifCore } = getIfCoreFns();
502
419
  const paths = getPaths(ifCore);
503
- const port = await (0, import_portfinder.getPortPromise)({ port: DEFAULT_PORT });
504
420
  const cmd = `
505
- npx -y http-server ${paths.appDist}
421
+ npx -y serve ${paths.appDist}
506
422
  --cors
507
- --port ${port}
423
+ ${flags}
508
424
  `;
509
425
  logTitle(`Running web-server for pre-built bundle \u2026`);
510
426
  logCommand(cmd);
511
427
  runCommandSync(cmd, { stdio: "inherit" });
512
428
  };
429
+ var assertOptionsValid4 = (options) => {
430
+ const { port } = options;
431
+ if (isNaN(Number(port))) {
432
+ fail('Flag "--port" should be a number.');
433
+ }
434
+ };
435
+ var prepareFlags5 = async (flags, options) => {
436
+ const { port: defaultPort } = options;
437
+ const port = await getPortPromise2({ port: Number(defaultPort) });
438
+ flags.push(`-p ${port}`);
439
+ return flags;
440
+ };
513
441
 
514
442
  // src/commands/list-deployed.ts
515
443
  var listDeployed = async (options) => {
516
- assertOptionsValid4(options);
444
+ assertOptionsValid5(options);
445
+ const flags = prepareFlags6([], options).join(" ");
517
446
  const { config } = options;
518
447
  const { ifCore } = getIfCoreFns();
519
448
  const configName = config != null ? config : ifCore(CORE_CONFIG_NAME, getWidgetUuid());
520
449
  const title = !config && ifCore() ? `Listing deployments of Tamaro Core \u2026` : `Listing deployments of \u201C${configName}\u201D customer configuration \u2026`;
521
450
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/`;
522
- const cmd = `aws s3 ls ${deployUrl}`;
451
+ const cmd = `aws s3 ls ${deployUrl} ${flags}`;
523
452
  let out = "";
524
453
  logTitle(title);
525
454
  logCommand(cmd);
526
455
  try {
527
- const result = runAwsCommandSync(cmd);
456
+ const result = withAwsAuthenticate(() => runCommandSync(cmd), options);
528
457
  out = result.stdout;
529
458
  } catch (error) {
530
459
  out = error.stdout;
@@ -542,9 +471,10 @@ var listDeployed = async (options) => {
542
471
  return `${idx + 1}. https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`;
543
472
  }).join("\n");
544
473
  }
545
- logTable(text);
474
+ console.log(`${text}
475
+ `);
546
476
  };
547
- var assertOptionsValid4 = (options) => {
477
+ var assertOptionsValid5 = (options) => {
548
478
  const { config, profile } = options;
549
479
  assertConfigValid(config);
550
480
  assertProfileValid(profile);
@@ -558,21 +488,24 @@ var assertConfigValid = (config) => {
558
488
  fail(`Flag "--config" has forbidden format. Allowed format: ${regex}.`);
559
489
  }
560
490
  };
491
+ var prepareFlags6 = (flags, options) => {
492
+ return prepareFlags2(flags, options);
493
+ };
561
494
  var parseTags = (lines) => {
562
495
  const regex = /^\s*PRE\s*/;
563
496
  return lines.filter((line) => regex.test(line)).map((line) => line.replace(regex, "").replace(/\/$/, ""));
564
497
  };
565
498
 
566
499
  // src/commands/deploy-email-config.ts
567
- var import_fs3 = require("fs");
568
- var DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET = "rnw-email-service";
500
+ import { existsSync as existsSync2 } from "fs";
569
501
  var deployEmailConfig = async (options) => {
570
502
  const { ifCore } = getIfCoreFns();
571
503
  const paths = getPaths(ifCore);
572
504
  const emailConfigPath = `${paths.app}/email-config`;
573
- assertOptionsValid5(options);
505
+ assertOptionsValid6(options);
574
506
  assertEmailConfigPathExists(emailConfigPath);
575
507
  assertIsNotCore();
508
+ const flags = prepareFlags7([], options).join(" ");
576
509
  const { bucket } = options;
577
510
  const configName = getWidgetUuid();
578
511
  const deployUrl = `s3://${bucket}/${configName}`;
@@ -580,27 +513,31 @@ var deployEmailConfig = async (options) => {
580
513
  aws s3 sync ${emailConfigPath} ${deployUrl}
581
514
  --delete
582
515
  --exact-timestamps
516
+ ${flags}
583
517
  `;
584
518
  logTitle(`Deploying email configuration for \u201C${configName}\u201D customer configuration to AWS S3 \u2026`);
585
519
  logCommand(cmd);
586
520
  try {
587
- runAwsCommandSync(cmd, { stdout: "inherit" });
521
+ withAwsAuthenticate(() => runCommandSync(cmd, { stdout: "inherit" }), options);
588
522
  } catch (error) {
589
523
  fail(error.stderr);
590
524
  }
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.`
525
+ logTitle(`Email configuration for \u201C${configName}\u201D customer configuration is deployed.`);
526
+ logDataTable({ "Deploy URL:": deployUrl });
527
+ process.on("exit", () => {
528
+ notify({
529
+ title: `deploy-email-config`,
530
+ message: `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`
531
+ });
595
532
  });
596
533
  };
597
- var assertOptionsValid5 = (options) => {
534
+ var assertOptionsValid6 = (options) => {
598
535
  const { bucket, profile } = options;
599
536
  assertBucketValid(bucket);
600
537
  assertProfileValid(profile);
601
538
  };
602
539
  var assertEmailConfigPathExists = (distPath) => {
603
- if (!(0, import_fs3.existsSync)(distPath)) {
540
+ if (!existsSync2(distPath)) {
604
541
  fail("Email config folder does not exists. Nothing to deploy.");
605
542
  }
606
543
  };
@@ -616,6 +553,9 @@ var assertIsNotCore = () => {
616
553
  fail("You cannot deploy widget email configuration for Tamaro Core.");
617
554
  }
618
555
  };
556
+ var prepareFlags7 = (flags, options) => {
557
+ return prepareFlags2(flags, options);
558
+ };
619
559
 
620
560
  // src/cli.ts
621
561
  process.on("unhandledRejection", (error) => {
@@ -624,25 +564,25 @@ process.on("unhandledRejection", (error) => {
624
564
  process.on("SIGINT", () => {
625
565
  process.exit(1);
626
566
  });
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) => {
567
+ var cli = createCommand().name(package_default.name).version(package_default.version, "-v, --version");
568
+ 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) => {
629
569
  await dev(options);
630
570
  });
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) => {
571
+ 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) => {
632
572
  await build(options);
573
+ if (options.serve) {
574
+ await serve(options);
575
+ }
633
576
  if (options.deploy) {
634
577
  await deploy(options);
635
578
  }
636
- if (options.serve) {
637
- await serve();
638
- }
579
+ });
580
+ cli.command("serve").description("Run a local web server for pre-built bundle").option("--port <port>", "Web server port", `${DEFAULT_PORT}`).action(async (options) => {
581
+ await serve(options);
639
582
  });
640
583
  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
584
  await deploy(options);
642
585
  });
643
- cli.command("serve").description("Run a local web server for pre-built bundle").action(async () => {
644
- await serve();
645
- });
646
586
  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
587
  await listDeployed(options);
648
588
  });
@@ -656,6 +596,9 @@ cli.command("deploy-email-config").description("Deploy a widget\u2019s email con
656
596
  if (error.signal === "SIGINT" && error.signalDescription) {
657
597
  logError(`
658
598
  ${error.signalDescription}`);
599
+ } else {
600
+ console.log("");
601
+ logError(error.stack);
659
602
  }
660
603
  }
661
604
  })();