@raisenow/tamaro-cli 1.0.26 → 1.1.0

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
@@ -2,9 +2,9 @@
2
2
  import {
3
3
  AWS_CLOUDFRONT_DISTRIBUTION_ID,
4
4
  AWS_S3_BUCKET,
5
+ AWS_S3_EMAIL_CONFIG_PROD_BUCKET,
6
+ AWS_S3_EMAIL_CONFIG_STAGE_BUCKET,
5
7
  CORE_CONFIG_NAME,
6
- DEFAULT_AWS_PROFILE,
7
- DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET,
8
8
  DEFAULT_PORT,
9
9
  DEFAULT_TAG,
10
10
  HTTPS_CRT_FILE,
@@ -22,188 +22,15 @@ import {
22
22
  resolveBin,
23
23
  resolveOwn,
24
24
  runCommandSync
25
- } from "./chunk-ZAKDPU5F.js";
25
+ } from "./chunk-S4M23KNZ.js";
26
26
 
27
27
  // src/cli.ts
28
28
  import { createCommand } from "commander";
29
29
 
30
- // package.json
31
- var package_default = {
32
- name: "@raisenow/tamaro-cli",
33
- version: "1.0.26",
34
- author: {
35
- name: "RaiseNow",
36
- email: "development@raisenow.com"
37
- },
38
- type: "module",
39
- scripts: {
40
- prepare: "npm run build",
41
- start: "npm run dev",
42
- build: "tsup src/cli.ts src/webpack.config.ts --clean --shims --format esm",
43
- "build:watch": "npm run build -- --watch --ignore-watch .idea",
44
- docs: "npx -y http-server . --cors -o /readme.html",
45
- lint: "eslint --fix . && prettier --write ."
46
- },
47
- bin: "dist/cli.js",
48
- engines: {
49
- node: ">=16",
50
- npm: ">=8"
51
- },
52
- dependencies: {
53
- "@babel/cli": "^7.21.0",
54
- "@babel/core": "^7.21.4",
55
- "@babel/plugin-proposal-decorators": "^7.21.0",
56
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
57
- "@babel/plugin-transform-runtime": "^7.21.4",
58
- "@babel/preset-env": "^7.21.4",
59
- "@babel/preset-react": "^7.18.6",
60
- "@babel/preset-typescript": "^7.21.4",
61
- "@babel/runtime-corejs3": "^7.21.0",
62
- "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
63
- "@statoscope/webpack-plugin": "^5.26.2",
64
- "@types/columnify": "^1.5.1",
65
- "@types/lodash": "^4.14.192",
66
- "@types/node": "^18.15.11",
67
- "@types/node-notifier": "^8.0.2",
68
- "@types/resolve-bin": "^0.4.1",
69
- "@types/webpack-config-utils": "^2.3.1",
70
- "@typescript-eslint/eslint-plugin": "^5.57.1",
71
- "@typescript-eslint/parser": "^5.57.1",
72
- autoprefixer: "^10.4.14",
73
- "babel-loader": "^9.1.2",
74
- "babel-plugin-istanbul": "^6.1.1",
75
- "babel-plugin-lodash": "^3.3.4",
76
- chalk: "^5.2.0",
77
- "clean-webpack-plugin": "^4.0.0",
78
- columnify: "^1.6.0",
79
- commander: "^10.0.0",
80
- "copy-webpack-plugin": "^11.0.0",
81
- "core-js": "^3.30.0",
82
- "css-loader": "^6.7.3",
83
- "css-minimizer-webpack-plugin": "^5.0.0",
84
- dotenv: "^16.0.3",
85
- "dotenv-expand": "^10.0.0",
86
- "escape-string-regexp": "^5.0.0",
87
- eslint: "^8.37.0",
88
- "eslint-config-prettier": "^8.8.0",
89
- "eslint-plugin-node": "^11.1.0",
90
- "eslint-plugin-promise": "^6.1.1",
91
- "eslint-webpack-plugin": "^4.0.0",
92
- execa: "^7.1.1",
93
- "file-loader": "^6.2.0",
94
- "fork-ts-checker-webpack-plugin": "^8.0.0",
95
- glob: "^9.3.4",
96
- "html-loader": "^4.2.0",
97
- "html-webpack-plugin": "^5.5.0",
98
- "json-loader": "^0.5.7",
99
- lodash: "^4.17.21",
100
- "mini-css-extract-plugin": "^2.7.5",
101
- "node-notifier": "^10.0.1",
102
- portfinder: "^1.0.32",
103
- postcss: "^8.4.21",
104
- "postcss-custom-properties": "^13.1.4",
105
- "postcss-loader": "^7.2.4",
106
- prettier: "^2.8.7",
107
- "react-refresh": "^0.14.0",
108
- "resolve-url-loader": "^5.0.0",
109
- sass: "^1.60.0",
110
- "sass-loader": "^13.2.2",
111
- "source-map-loader": "^4.0.1",
112
- "strip-indent": "^4.0.0",
113
- "style-loader": "^3.3.2",
114
- "tsconfig-paths-webpack-plugin": "^4.0.1",
115
- tsup: "^6.7.0",
116
- typescript: "^5.0.3",
117
- "url-loader": "^4.1.1",
118
- webpack: "^5.78.0",
119
- "webpack-cli": "^5.0.1",
120
- "webpack-config-utils": "^2.3.1",
121
- "webpack-dev-server": "^4.13.2",
122
- "yaml-loader": "^0.8.0"
123
- },
124
- overrides: {
125
- "babel-plugin-lodash": {
126
- "@babel/types": "~7.20.0"
127
- }
128
- }
129
- };
130
-
131
- // src/commands/dev.ts
132
- import { getPortPromise } from "portfinder";
133
-
134
- // src/lib/https.ts
135
- import { existsSync } from "fs";
136
- import { resolve } from "path";
137
- import stripIndent from "strip-indent";
138
- var assertCrtExists = () => {
139
- const { ifCore } = getIfCoreFns();
140
- const paths = getPaths(ifCore);
141
- const certFile = resolve(paths.root, HTTPS_CRT_FILE);
142
- const keyFile = resolve(paths.root, HTTPS_KEY_FILE);
143
- if (existsSync(certFile) && existsSync(keyFile)) {
144
- return;
145
- }
146
- halt(
147
- stripIndent(`
148
- Flag \u201C--https\u201D is used, but \u201C${HTTPS_CRT_FILE}\u201D and/or \u201C${HTTPS_KEY_FILE}\u201D files are not found.
149
- You need to generate certificate first.
150
- Check docs: https://unpkg.com/@raisenow/tamaro-cli/readme.html#/?id=use-transport-level-security-https
151
- `)
152
- );
153
- };
154
-
155
- // src/commands/dev.ts
156
- var dev = async (options) => {
157
- const { env } = options;
158
- assertOptionsValid(options);
159
- applyEnv(env);
160
- const flags = (await prepareFlags([], options)).join(" ");
161
- const { ifCore } = getIfCoreFns();
162
- const title = ifCore(
163
- "Running dev web-server for Tamaro Core \u2026",
164
- "Running dev web-server for customer configuration \u2026"
165
- );
166
- const wpBin = resolveBin("webpack");
167
- const wpConfig = resolveOwn("dist/webpack.config.js");
168
- const cmd = `
169
- ${wpBin} serve
170
- --config ${wpConfig}
171
- ${flags}
172
- `;
173
- logTitle(title);
174
- logCommand(cmd);
175
- runCommandSync(cmd, { stdio: "inherit" });
176
- };
177
- var assertOptionsValid = (options) => {
178
- const { localCore, https, port, env } = options;
179
- const { ifCore } = getIfCoreFns();
180
- if (ifCore() && localCore) {
181
- halt("Flag \u201C--local-core\u201D is redundant if running in Tamaro Core context.");
182
- }
183
- if (isNaN(Number(port))) {
184
- halt("Flag \u201C--port\u201D should be a number.");
185
- }
186
- if (https) {
187
- assertCrtExists();
188
- }
189
- assertEnvValid(env);
190
- };
191
- var prepareFlags = async (flags, options) => {
192
- const { localCore, port: defaultPort, https } = options;
193
- const port = await getPortPromise({ port: Number(defaultPort) });
194
- if (localCore) {
195
- flags.push("--env localCore");
196
- }
197
- flags.push(`--port ${port}`);
198
- if (https) {
199
- flags.push("--env https");
200
- }
201
- return flags;
202
- };
203
-
204
30
  // src/lib/aws.ts
205
31
  import { execaCommandSync } from "execa";
206
- import stripIndent2 from "strip-indent";
32
+ import prompts from "prompts";
33
+ import stripIndent from "strip-indent";
207
34
  var withAwsAuthenticate = (fn, options) => {
208
35
  awsAuthenticate(options);
209
36
  return fn();
@@ -221,30 +48,20 @@ var awsAuthenticate = (options) => {
221
48
  var isSetEnv = () => {
222
49
  return !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY);
223
50
  };
224
- var assertProfileValid = (profile) => {
51
+ var assertProfilesPresent = () => {
225
52
  if (isSetEnv()) {
226
53
  return;
227
54
  }
228
55
  const profiles = getAvailableProfiles();
229
- if (!profiles.includes(profile)) {
230
- console.log(`Using AWS profile: \u201C${profile}\u201D`);
231
- let message;
232
- if (profiles.length === 0) {
233
- message = stripIndent2(`
56
+ if (profiles.length === 0) {
57
+ halt(
58
+ stripIndent(`
234
59
  No AWS profiles found.
235
- `);
236
- } else {
237
- message = stripIndent2(`
238
- AWS profile \u201C${profile}\u201D has not been found.
239
- Available profiles are: ${profiles.map((v) => `\u201C${v}\u201D`).join(", ")}.
240
- `);
241
- }
242
- message += stripIndent2(`
243
- Run \u201Caws configure sso\u201D to set up SSO-enabled profile.
244
- Check the wiki for more information:
245
- https://raisenow.atlassian.net/wiki/x/lIrWvg
246
- `);
247
- halt(message);
60
+ Run "aws configure sso" to set up SSO-enabled profile.
61
+ Check the wiki for more information:
62
+ https://raisenow.atlassian.net/wiki/x/lIrWvg
63
+ `)
64
+ );
248
65
  }
249
66
  };
250
67
  var getAvailableProfiles = () => {
@@ -252,11 +69,11 @@ var getAvailableProfiles = () => {
252
69
  return stdout.split("\n");
253
70
  };
254
71
  var checkIdentity = (options) => {
255
- const flags = prepareFlags2([], options).join(" ");
72
+ const flags = prepareFlags([], options).join(" ");
256
73
  execaCommandSync(`aws sts get-caller-identity ${flags}`);
257
74
  };
258
75
  var login = (options) => {
259
- const flags = prepareFlags2([], options).join(" ");
76
+ const flags = prepareFlags([], options).join(" ");
260
77
  try {
261
78
  execaCommandSync(`aws sso login ${flags}`, { stdio: "inherit" });
262
79
  console.log("");
@@ -264,13 +81,74 @@ var login = (options) => {
264
81
  halt("Login failed.");
265
82
  }
266
83
  };
267
- var prepareFlags2 = (flags, options) => {
84
+ var prepareFlags = (flags, options) => {
268
85
  const { profile } = options;
269
- if (!isSetEnv()) {
86
+ if (!isSetEnv() && profile) {
270
87
  flags.push(`--profile ${profile}`);
271
88
  }
272
89
  return flags;
273
90
  };
91
+ var promptProfile = async () => {
92
+ if (isSetEnv()) {
93
+ return;
94
+ }
95
+ const profiles = getAvailableProfiles().filter((v) => !!v).map((v) => ({ title: v, value: v }));
96
+ const { profile } = await prompts(
97
+ [
98
+ {
99
+ type: "select",
100
+ name: "profile",
101
+ message: "Select AWS profile",
102
+ choices: profiles
103
+ }
104
+ ],
105
+ {
106
+ onCancel: () => process.exit(1)
107
+ }
108
+ );
109
+ return profile;
110
+ };
111
+ var promptBucket = async () => {
112
+ const buckets = [
113
+ { title: "stage", value: AWS_S3_EMAIL_CONFIG_STAGE_BUCKET },
114
+ { title: "prod", value: AWS_S3_EMAIL_CONFIG_PROD_BUCKET }
115
+ ];
116
+ const { bucket } = await prompts(
117
+ [
118
+ {
119
+ type: "select",
120
+ name: "bucket",
121
+ message: "Select environment",
122
+ choices: buckets
123
+ }
124
+ ],
125
+ {
126
+ onCancel: () => process.exit(1)
127
+ }
128
+ );
129
+ return bucket;
130
+ };
131
+
132
+ // src/lib/https.ts
133
+ import { existsSync } from "fs";
134
+ import { resolve } from "path";
135
+ import stripIndent2 from "strip-indent";
136
+ var assertCrtExists = () => {
137
+ const { ifCore } = getIfCoreFns();
138
+ const paths = getPaths(ifCore);
139
+ const certFile = resolve(paths.root, HTTPS_CRT_FILE);
140
+ const keyFile = resolve(paths.root, HTTPS_KEY_FILE);
141
+ if (existsSync(certFile) && existsSync(keyFile)) {
142
+ return;
143
+ }
144
+ halt(
145
+ stripIndent2(`
146
+ Flag "--https" is used, but "${HTTPS_CRT_FILE}" and/or "${HTTPS_KEY_FILE}" files are not found.
147
+ You need to generate certificate first.
148
+ Check docs: https://unpkg.com/@raisenow/tamaro-cli/readme.html#/?id=use-transport-level-security-https
149
+ `)
150
+ );
151
+ };
274
152
 
275
153
  // src/lib/notifier.ts
276
154
  import notifier from "node-notifier";
@@ -288,15 +166,19 @@ var notify = (args) => {
288
166
  // src/commands/build.ts
289
167
  var build = async (options) => {
290
168
  const { env } = options;
291
- assertOptionsValid2(options);
169
+ assertOptionsValid(options);
170
+ assertProfilesPresent();
292
171
  applyEnv(env);
293
- const flags = prepareFlags3([], options).join(" ");
172
+ if (options.deploy) {
173
+ options.profile = await promptProfile();
174
+ }
175
+ const flags = prepareFlags2([], options).join(" ");
294
176
  const { ifCore } = getIfCoreFns();
295
177
  const paths = getPaths(ifCore);
296
178
  const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
297
179
  const title = ifCore(
298
180
  "Building optimised (minified) bundle of Tamaro Core \u2026",
299
- `Building optimised (minified) bundle of \u201C${configName}\u201D customer configuration \u2026`
181
+ `Building optimised (minified) bundle of "${configName}" customer configuration \u2026`
300
182
  );
301
183
  const wpBin = resolveBin("webpack");
302
184
  const wpConfig = resolveOwn("dist/webpack.config.js");
@@ -310,32 +192,31 @@ var build = async (options) => {
310
192
  logCommand(cmd);
311
193
  runCommandSync(cmd, { stdio: "inherit" });
312
194
  logTitle(`
313
- Bundle for \u201C${configName}\u201D customer configuration is done.`);
195
+ Bundle for "${configName}" customer configuration is done.`);
314
196
  console.log(`Path: ${paths.appDist}
315
197
  `);
316
198
  process.on("exit", () => {
317
199
  notify({
318
200
  title: "build",
319
- message: `Bundle for \u201C${configName}\u201D customer configuration is done.`
201
+ message: `Bundle for "${configName}" customer configuration is done.`
320
202
  });
321
203
  });
322
204
  };
323
- var assertOptionsValid2 = (options) => {
324
- const { localCore, https, deploy: deploy2, profile, env } = options;
205
+ var assertOptionsValid = (options) => {
206
+ const { localCore, https, deploy: deploy2, env } = options;
325
207
  const { ifCore } = getIfCoreFns();
326
208
  if (ifCore() && localCore) {
327
- halt("Flag \u201C--local-core\u201D is redundant if running in Tamaro Core context.");
209
+ halt('Flag "--local-core" is redundant if running in Tamaro Core context.');
328
210
  }
329
211
  if (localCore && deploy2) {
330
- halt("Flags \u201C--local-core\u201D and \u201C--deploy\u201D must not be used together.");
212
+ halt('Flags "--local-core" and "--deploy" must not be used together.');
331
213
  }
332
214
  if (https) {
333
215
  assertCrtExists();
334
216
  }
335
- assertProfileValid(profile);
336
217
  assertEnvValid(env);
337
218
  };
338
- var prepareFlags3 = (flags, options) => {
219
+ var prepareFlags2 = (flags, options) => {
339
220
  const { localCore, analyze, https } = options;
340
221
  if (localCore) {
341
222
  flags.push("--env localCore");
@@ -355,9 +236,13 @@ import stripIndent4 from "strip-indent";
355
236
  var deploy = async (options) => {
356
237
  const { ifCore } = getIfCoreFns();
357
238
  const paths = getPaths(ifCore);
358
- assertOptionsValid3(options);
239
+ assertOptionsValid2(options);
359
240
  assertDistPathExists(paths.appDist);
360
- const flags = prepareFlags4([], options).join(" ");
241
+ assertProfilesPresent();
242
+ if (!options.profile) {
243
+ options.profile = await promptProfile();
244
+ }
245
+ const flags = prepareFlags([], options).join(" ");
361
246
  const { tag } = options;
362
247
  const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
363
248
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/${tag}`;
@@ -410,7 +295,7 @@ var deploy = async (options) => {
410
295
  const demoPage = `https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`;
411
296
  const entryPoint = `https://${AWS_S3_BUCKET}/${configName}/${tag}/${entryFilename}`;
412
297
  logTitle(`
413
- Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.`);
298
+ Bundle for "${configName}" is deployed with tag "${tag}".`);
414
299
  logDataTable({
415
300
  "Demo page:": demoPage,
416
301
  "Entry point:": entryPoint
@@ -419,17 +304,16 @@ Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.`);
419
304
  notify({
420
305
  title: "deploy",
421
306
  message: `
422
- Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.
307
+ Bundle for "${configName}" is deployed with tag "${tag}".
423
308
  Demo page: ${demoPage}
424
309
  Entry point: ${entryPoint}
425
310
  `
426
311
  });
427
312
  });
428
313
  };
429
- var assertOptionsValid3 = (options) => {
430
- const { tag, profile } = options;
314
+ var assertOptionsValid2 = (options) => {
315
+ const { tag } = options;
431
316
  assertTagValid(tag);
432
- assertProfileValid(profile);
433
317
  };
434
318
  var assertDistPathExists = (distPath) => {
435
319
  if (!existsSync2(distPath)) {
@@ -445,63 +329,125 @@ var assertTagValid = (tag) => {
445
329
  const regex = /^[a-zA-Z0-9-_.]+$/;
446
330
  if (!regex.test(tag)) {
447
331
  halt(
448
- `Flag \u201C--tag\u201D has forbidden format. Allowed format: ${regex.toString()}.`
332
+ `Flag "--tag" has forbidden format. Allowed format: ${regex.toString()}.`
449
333
  );
450
334
  }
451
335
  };
452
- var prepareFlags4 = (flags, options) => {
453
- return prepareFlags2(flags, options);
454
- };
455
336
 
456
- // src/commands/serve.ts
457
- import { resolve as resolve2 } from "path";
458
- import { getPortPromise as getPortPromise2 } from "portfinder";
459
- var serve = async (options) => {
460
- assertOptionsValid4(options);
461
- const flags = (await prepareFlags5([], options)).join(" ");
337
+ // src/commands/deploy-email-config.ts
338
+ import { existsSync as existsSync3 } from "fs";
339
+ var deployEmailConfig = async () => {
462
340
  const { ifCore } = getIfCoreFns();
463
341
  const paths = getPaths(ifCore);
342
+ const emailConfigPath = `${paths.app}/email-config`;
343
+ assertIsNotCore();
344
+ assertEmailConfigPathExists(emailConfigPath);
345
+ assertProfilesPresent();
346
+ const profile = await promptProfile();
347
+ const bucket = await promptBucket();
348
+ const flags = prepareFlags([], { profile }).join(" ");
349
+ const configName = getWidgetUuid();
350
+ const deployUrl = `s3://${bucket}/${configName}`;
464
351
  const cmd = `
465
- npx -y serve ${paths.appDist}
466
- --cors
352
+ aws s3 sync ${emailConfigPath} ${deployUrl}
353
+ --delete
354
+ --exact-timestamps
467
355
  ${flags}
468
356
  `;
469
- logTitle(`Running web-server for pre-built bundle \u2026`);
357
+ logTitle(
358
+ `Deploying email configuration for "${configName}" customer configuration to AWS S3 \u2026`
359
+ );
360
+ logCommand(cmd);
361
+ try {
362
+ withAwsAuthenticate(() => runCommandSync(cmd, { stdout: "inherit" }), {
363
+ profile
364
+ });
365
+ } catch (error) {
366
+ halt(error.stderr);
367
+ }
368
+ logTitle(
369
+ `Email configuration for "${configName}" customer configuration is deployed.`
370
+ );
371
+ logDataTable({ "Deploy URL:": deployUrl });
372
+ process.on("exit", () => {
373
+ notify({
374
+ title: "deploy-email-config",
375
+ message: `Email configuration for "${configName}" customer configuration is deployed.`
376
+ });
377
+ });
378
+ };
379
+ var assertEmailConfigPathExists = (distPath) => {
380
+ if (!existsSync3(distPath)) {
381
+ halt("Email config folder does not exists. Nothing to deploy.", 0);
382
+ }
383
+ };
384
+ var assertIsNotCore = () => {
385
+ const { ifCore } = getIfCoreFns();
386
+ if (ifCore()) {
387
+ halt("You cannot deploy widget email configuration for Tamaro Core.");
388
+ }
389
+ };
390
+
391
+ // src/commands/dev.ts
392
+ import { getPortPromise } from "portfinder";
393
+ var dev = async (options) => {
394
+ const { env } = options;
395
+ assertOptionsValid3(options);
396
+ applyEnv(env);
397
+ const flags = (await prepareFlags3([], options)).join(" ");
398
+ const { ifCore } = getIfCoreFns();
399
+ const title = ifCore(
400
+ "Running dev web-server for Tamaro Core \u2026",
401
+ "Running dev web-server for customer configuration \u2026"
402
+ );
403
+ const wpBin = resolveBin("webpack");
404
+ const wpConfig = resolveOwn("dist/webpack.config.js");
405
+ const cmd = `
406
+ ${wpBin} serve
407
+ --config ${wpConfig}
408
+ ${flags}
409
+ `;
410
+ logTitle(title);
470
411
  logCommand(cmd);
471
412
  runCommandSync(cmd, { stdio: "inherit" });
472
413
  };
473
- var assertOptionsValid4 = (options) => {
474
- const { port, https } = options;
414
+ var assertOptionsValid3 = (options) => {
415
+ const { localCore, https, port, env } = options;
416
+ const { ifCore } = getIfCoreFns();
417
+ if (ifCore() && localCore) {
418
+ halt('Flag "--local-core" is redundant if running in Tamaro Core context.');
419
+ }
475
420
  if (isNaN(Number(port))) {
476
421
  halt('Flag "--port" should be a number.');
477
422
  }
478
423
  if (https) {
479
424
  assertCrtExists();
480
425
  }
426
+ assertEnvValid(env);
481
427
  };
482
- var prepareFlags5 = async (flags, options) => {
483
- const { port: defaultPort, https } = options;
484
- const port = await getPortPromise2({ port: Number(defaultPort) });
485
- flags.push(`-p ${port}`);
428
+ var prepareFlags3 = async (flags, options) => {
429
+ const { localCore, port: defaultPort, https } = options;
430
+ const port = await getPortPromise({ port: Number(defaultPort) });
431
+ if (localCore) {
432
+ flags.push("--env localCore");
433
+ }
434
+ flags.push(`--port ${port}`);
486
435
  if (https) {
487
- const { ifCore } = getIfCoreFns();
488
- const paths = getPaths(ifCore);
489
- const certFile = resolve2(paths.root, HTTPS_CRT_FILE);
490
- const keyFile = resolve2(paths.root, HTTPS_KEY_FILE);
491
- flags.push(`--ssl-cert ${certFile}`);
492
- flags.push(`--ssl-key ${keyFile}`);
436
+ flags.push("--env https");
493
437
  }
494
438
  return flags;
495
439
  };
496
440
 
497
441
  // src/commands/list-deployed.ts
498
442
  var listDeployed = async (options) => {
499
- assertOptionsValid5(options);
500
- const flags = prepareFlags6([], options).join(" ");
443
+ assertOptionsValid4(options);
444
+ assertProfilesPresent();
445
+ options.profile = await promptProfile();
446
+ const flags = prepareFlags([], options).join(" ");
501
447
  const { config } = options;
502
448
  const { ifCore } = getIfCoreFns();
503
449
  const configName = config ?? ifCore(CORE_CONFIG_NAME, getWidgetUuid());
504
- const title = !config && ifCore() ? `Listing deployments of Tamaro Core \u2026` : `Listing deployments of \u201C${configName}\u201D customer configuration \u2026`;
450
+ const title = !config && ifCore() ? `Listing deployments of Tamaro Core \u2026` : `Listing deployments of "${configName}" customer configuration \u2026`;
505
451
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/`;
506
452
  const cmd = `aws s3 ls ${deployUrl} ${flags}`;
507
453
  let out = "";
@@ -529,10 +475,9 @@ var listDeployed = async (options) => {
529
475
  console.log(`${text}
530
476
  `);
531
477
  };
532
- var assertOptionsValid5 = (options) => {
533
- const { config, profile } = options;
478
+ var assertOptionsValid4 = (options) => {
479
+ const { config } = options;
534
480
  assertConfigValid(config);
535
- assertProfileValid(profile);
536
481
  };
537
482
  var assertConfigValid = (config) => {
538
483
  if (!config) {
@@ -541,83 +486,160 @@ var assertConfigValid = (config) => {
541
486
  const regex = /^[a-zA-Z0-9-_]+$/;
542
487
  if (!regex.test(config)) {
543
488
  halt(
544
- `Flag \u201C--config\u201D has forbidden format. Allowed format: ${regex.toString()}.`
489
+ `Flag "--config" has forbidden format. Allowed format: ${regex.toString()}.`
545
490
  );
546
491
  }
547
492
  };
548
- var prepareFlags6 = (flags, options) => {
549
- return prepareFlags2(flags, options);
550
- };
551
493
  var parseTags = (lines) => {
552
494
  const regex = /^\s*PRE\s*/;
553
495
  return lines.filter((line) => regex.test(line)).map((line) => line.replace(regex, "").replace(/\/$/, ""));
554
496
  };
555
497
 
556
- // src/commands/deploy-email-config.ts
557
- import { existsSync as existsSync3 } from "fs";
558
- var deployEmailConfig = async (options) => {
498
+ // src/commands/serve.ts
499
+ import { resolve as resolve2 } from "path";
500
+ import { getPortPromise as getPortPromise2 } from "portfinder";
501
+ var serve = async (options) => {
502
+ assertOptionsValid5(options);
503
+ const flags = (await prepareFlags4([], options)).join(" ");
559
504
  const { ifCore } = getIfCoreFns();
560
505
  const paths = getPaths(ifCore);
561
- const emailConfigPath = `${paths.app}/email-config`;
562
- assertOptionsValid6(options);
563
- assertIsNotCore();
564
- assertEmailConfigPathExists(emailConfigPath);
565
- const flags = prepareFlags7([], options).join(" ");
566
- const { bucket } = options;
567
- const configName = getWidgetUuid();
568
- const deployUrl = `s3://${bucket}/${configName}`;
569
506
  const cmd = `
570
- aws s3 sync ${emailConfigPath} ${deployUrl}
571
- --delete
572
- --exact-timestamps
507
+ npx -y serve ${paths.appDist}
508
+ --cors
573
509
  ${flags}
574
510
  `;
575
- logTitle(
576
- `Deploying email configuration for \u201C${configName}\u201D customer configuration to AWS S3 \u2026`
577
- );
511
+ logTitle(`Running web-server for pre-built bundle \u2026`);
578
512
  logCommand(cmd);
579
- try {
580
- withAwsAuthenticate(() => runCommandSync(cmd, { stdout: "inherit" }), options);
581
- } catch (error) {
582
- halt(error.stderr);
583
- }
584
- logTitle(
585
- `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`
586
- );
587
- logDataTable({ "Deploy URL:": deployUrl });
588
- process.on("exit", () => {
589
- notify({
590
- title: `deploy-email-config`,
591
- message: `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`
592
- });
593
- });
594
- };
595
- var assertOptionsValid6 = (options) => {
596
- const { bucket, profile } = options;
597
- assertBucketValid(bucket);
598
- assertProfileValid(profile);
513
+ runCommandSync(cmd, { stdio: "inherit" });
599
514
  };
600
- var assertEmailConfigPathExists = (distPath) => {
601
- if (!existsSync3(distPath)) {
602
- halt("Email config folder does not exists. Nothing to deploy.", 0);
515
+ var assertOptionsValid5 = (options) => {
516
+ const { port, https } = options;
517
+ if (isNaN(Number(port))) {
518
+ halt('Flag "--port" should be a number.');
603
519
  }
604
- };
605
- var assertBucketValid = (tag) => {
606
- const regex = /^[a-zA-Z0-9-_]+$/;
607
- if (!regex.test(tag)) {
608
- halt(
609
- `Flag \u201C--bucket\u201D has forbidden format. Allowed format: ${regex.toString()}.`
610
- );
520
+ if (https) {
521
+ assertCrtExists();
611
522
  }
612
523
  };
613
- var assertIsNotCore = () => {
614
- const { ifCore } = getIfCoreFns();
615
- if (ifCore()) {
616
- halt("You cannot deploy widget email configuration for Tamaro Core.");
524
+ var prepareFlags4 = async (flags, options) => {
525
+ const { port: defaultPort, https } = options;
526
+ const port = await getPortPromise2({ port: Number(defaultPort) });
527
+ flags.push(`-p ${port}`);
528
+ if (https) {
529
+ const { ifCore } = getIfCoreFns();
530
+ const paths = getPaths(ifCore);
531
+ const certFile = resolve2(paths.root, HTTPS_CRT_FILE);
532
+ const keyFile = resolve2(paths.root, HTTPS_KEY_FILE);
533
+ flags.push(`--ssl-cert ${certFile}`);
534
+ flags.push(`--ssl-key ${keyFile}`);
617
535
  }
536
+ return flags;
618
537
  };
619
- var prepareFlags7 = (flags, options) => {
620
- return prepareFlags2(flags, options);
538
+
539
+ // package.json
540
+ var package_default = {
541
+ name: "@raisenow/tamaro-cli",
542
+ version: "1.1.0",
543
+ author: {
544
+ name: "RaiseNow",
545
+ email: "development@raisenow.com"
546
+ },
547
+ type: "module",
548
+ scripts: {
549
+ prepare: "pnpm build",
550
+ tscheck: "tsc --noEmit",
551
+ build: "tsup src/cli.ts src/webpack.config.ts --clean --shims --format esm",
552
+ "build:watch": "pnpm build --watch --ignore-watch .history --ignore-watch .idea",
553
+ readme: "pnpx http-server . --cors -o /readme.html",
554
+ lint: "eslint .",
555
+ "lint:fix": "eslint --fix .",
556
+ format: "prettier --write ."
557
+ },
558
+ bin: "dist/cli.js",
559
+ engines: {
560
+ node: ">=18",
561
+ npm: ">=10"
562
+ },
563
+ dependencies: {
564
+ "@babel/cli": "^7.22.15",
565
+ "@babel/core": "^7.22.17",
566
+ "@babel/plugin-proposal-decorators": "^7.22.15",
567
+ "@babel/plugin-syntax-dynamic-import": "^7.8.3",
568
+ "@babel/plugin-transform-runtime": "^7.22.15",
569
+ "@babel/preset-env": "^7.22.15",
570
+ "@babel/preset-react": "^7.22.15",
571
+ "@babel/preset-typescript": "^7.22.15",
572
+ "@babel/runtime-corejs3": "^7.22.15",
573
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
574
+ "@statoscope/webpack-plugin": "^5.27.0",
575
+ "@types/columnify": "^1.5.2",
576
+ "@types/lodash": "^4.14.198",
577
+ "@types/node": "^18.17.15",
578
+ "@types/node-notifier": "^8.0.2",
579
+ "@types/prompts": "^2.4.4",
580
+ "@types/resolve-bin": "^0.4.1",
581
+ "@types/webpack-config-utils": "^2.3.1",
582
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
583
+ "@typescript-eslint/parser": "^6.7.0",
584
+ autoprefixer: "^10.4.15",
585
+ "babel-loader": "^9.1.3",
586
+ "babel-plugin-istanbul": "^6.1.1",
587
+ "babel-plugin-lodash": "^3.3.4",
588
+ chalk: "^5.3.0",
589
+ "clean-webpack-plugin": "^4.0.0",
590
+ columnify: "^1.6.0",
591
+ commander: "^11.0.0",
592
+ "copy-webpack-plugin": "^11.0.0",
593
+ "core-js": "^3.32.2",
594
+ "css-loader": "^6.8.1",
595
+ "css-minimizer-webpack-plugin": "^5.0.1",
596
+ dotenv: "^16.3.1",
597
+ "dotenv-expand": "^10.0.0",
598
+ "escape-string-regexp": "^5.0.0",
599
+ eslint: "^8.49.0",
600
+ "eslint-config-prettier": "^9.0.0",
601
+ "eslint-import-resolver-typescript": "^3.6.0",
602
+ "eslint-plugin-deprecation": "^1.5.0",
603
+ "eslint-plugin-import": "^2.28.1",
604
+ "eslint-plugin-markdownlint": "^0.5.0",
605
+ "eslint-plugin-promise": "^6.1.1",
606
+ "eslint-plugin-unused-imports": "^3.0.0",
607
+ "eslint-plugin-yml": "^1.9.0",
608
+ "eslint-webpack-plugin": "^4.0.1",
609
+ execa: "^8.0.1",
610
+ "file-loader": "^6.2.0",
611
+ "fork-ts-checker-webpack-plugin": "^8.0.0",
612
+ glob: "^10.3.4",
613
+ "html-loader": "^4.2.0",
614
+ "html-webpack-plugin": "^5.5.3",
615
+ "json-loader": "^0.5.7",
616
+ lodash: "^4.17.21",
617
+ "mini-css-extract-plugin": "^2.7.6",
618
+ "node-notifier": "^10.0.1",
619
+ portfinder: "^1.0.32",
620
+ postcss: "^8.4.29",
621
+ "postcss-custom-properties": "^13.3.0",
622
+ "postcss-loader": "^7.3.3",
623
+ prettier: "^3.0.3",
624
+ prompts: "^2.4.2",
625
+ "react-refresh": "^0.14.0",
626
+ "resolve-url-loader": "^5.0.0",
627
+ sass: "^1.66.1",
628
+ "sass-loader": "^13.3.2",
629
+ "source-map-loader": "^4.0.1",
630
+ "strip-indent": "^4.0.0",
631
+ "style-loader": "^3.3.3",
632
+ "tsconfig-paths-webpack-plugin": "^4.1.0",
633
+ tsup: "^7.2.0",
634
+ typescript: "^5.2.2",
635
+ "url-loader": "^4.1.1",
636
+ webpack: "^5.88.2",
637
+ "webpack-cli": "^5.1.4",
638
+ "webpack-config-utils": "^2.3.1",
639
+ "webpack-dev-server": "^4.15.1",
640
+ "yaml-loader": "^0.8.0"
641
+ },
642
+ packageManager: "pnpm@8.7.5"
621
643
  };
622
644
 
623
645
  // src/cli.ts
@@ -659,10 +681,6 @@ cli.command("build").description(
659
681
  "--tag <tag>",
660
682
  "Tag which should be used for the deployment of the bundle",
661
683
  DEFAULT_TAG
662
- ).option(
663
- "--profile <profile>",
664
- "AWS profile which should be used for the deployment of the bundle",
665
- DEFAULT_AWS_PROFILE
666
684
  ).action(async (options) => {
667
685
  await build(options);
668
686
  if (options.serve) {
@@ -685,10 +703,6 @@ cli.command("deploy").description(
685
703
  "--tag <tag>",
686
704
  "Tag which should be used for the deployment of the bundle",
687
705
  DEFAULT_TAG
688
- ).option(
689
- "--profile <profile>",
690
- "AWS profile which should be used for the deployment of the bundle",
691
- DEFAULT_AWS_PROFILE
692
706
  ).action(async (options) => {
693
707
  await deploy(options);
694
708
  });
@@ -697,23 +711,11 @@ cli.command("list-deployed").description(
697
711
  ).option(
698
712
  "--config <config>",
699
713
  "Configuration name (default: current customer configuration)"
700
- ).option(
701
- "--profile <profile>",
702
- "AWS profile which should be used for fetching deployments",
703
- DEFAULT_AWS_PROFILE
704
714
  ).action(async (options) => {
705
715
  await listDeployed(options);
706
716
  });
707
- cli.command("deploy-email-config").description("Deploy a widget\u2019s email configuration to AWS S3").option(
708
- "--bucket <bucket>",
709
- "AWS S3 bucket where it should be deployed",
710
- DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET
711
- ).option(
712
- "--profile <profile>",
713
- "AWS profile which should be used for the deployment of email configuration",
714
- DEFAULT_AWS_PROFILE
715
- ).action(async (options) => {
716
- await deployEmailConfig(options);
717
+ cli.command("deploy-email-config").description("Deploy a widget's email configuration to AWS S3").action(async () => {
718
+ await deployEmailConfig();
717
719
  });
718
720
  (async () => {
719
721
  try {