@raisenow/tamaro-cli 1.0.25 → 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,13 +2,14 @@
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,
11
11
  HTTPS_KEY_FILE,
12
+ applyEnv,
12
13
  assertEnvValid,
13
14
  getIfCoreFns,
14
15
  getPaths,
@@ -21,181 +22,15 @@ import {
21
22
  resolveBin,
22
23
  resolveOwn,
23
24
  runCommandSync
24
- } from "./chunk-XC5QT3RG.js";
25
+ } from "./chunk-S4M23KNZ.js";
25
26
 
26
27
  // src/cli.ts
27
28
  import { createCommand } from "commander";
28
29
 
29
- // package.json
30
- var package_default = {
31
- name: "@raisenow/tamaro-cli",
32
- version: "1.0.25",
33
- author: {
34
- name: "RaiseNow",
35
- email: "development@raisenow.com"
36
- },
37
- type: "module",
38
- scripts: {
39
- prepare: "npm run build",
40
- start: "npm run dev",
41
- build: "tsup src/cli.ts src/webpack.config.ts --clean --shims --format esm",
42
- "build:watch": "npm run build -- --watch --ignore-watch .idea",
43
- docs: "npx -y http-server . --cors -o /readme.html",
44
- lint: "eslint --fix . && prettier --write ."
45
- },
46
- bin: "dist/cli.js",
47
- engines: {
48
- node: ">=16",
49
- npm: ">=8"
50
- },
51
- dependencies: {
52
- "@babel/cli": "^7.20.7",
53
- "@babel/core": "^7.20.12",
54
- "@babel/plugin-proposal-decorators": "^7.20.13",
55
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
56
- "@babel/plugin-transform-runtime": "^7.19.6",
57
- "@babel/preset-env": "^7.20.2",
58
- "@babel/preset-react": "^7.18.6",
59
- "@babel/preset-typescript": "^7.18.6",
60
- "@babel/runtime-corejs3": "^7.20.13",
61
- "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
62
- "@statoscope/webpack-plugin": "^5.24.0",
63
- "@types/columnify": "^1.5.1",
64
- "@types/lodash": "^4.14.191",
65
- "@types/node": "^18.11.18",
66
- "@types/node-notifier": "^8.0.2",
67
- "@types/resolve-bin": "^0.4.1",
68
- "@types/webpack-config-utils": "^2.3.1",
69
- "@typescript-eslint/eslint-plugin": "^5.50.0",
70
- "@typescript-eslint/parser": "^5.50.0",
71
- autoprefixer: "^10.4.13",
72
- "babel-loader": "^9.1.2",
73
- "babel-plugin-istanbul": "^6.1.1",
74
- "babel-plugin-lodash": "^3.3.4",
75
- chalk: "^5.2.0",
76
- "clean-webpack-plugin": "^4.0.0",
77
- columnify: "^1.6.0",
78
- commander: "^10.0.0",
79
- "copy-webpack-plugin": "^11.0.0",
80
- "core-js": "^3.27.2",
81
- "css-loader": "^6.7.3",
82
- "css-minimizer-webpack-plugin": "^4.2.2",
83
- dotenv: "^16.0.3",
84
- "dotenv-expand": "^10.0.0",
85
- "escape-string-regexp": "^5.0.0",
86
- eslint: "^8.33.0",
87
- "eslint-config-prettier": "^8.6.0",
88
- "eslint-plugin-node": "^11.1.0",
89
- "eslint-plugin-promise": "^6.1.1",
90
- "eslint-webpack-plugin": "^3.2.0",
91
- execa: "^6.1.0",
92
- "file-loader": "^6.2.0",
93
- "fork-ts-checker-webpack-plugin": "^7.3.0",
94
- glob: "^8.1.0",
95
- "html-loader": "^4.2.0",
96
- "html-webpack-plugin": "^5.5.0",
97
- "json-loader": "^0.5.7",
98
- lodash: "^4.17.21",
99
- "mini-css-extract-plugin": "^2.7.2",
100
- "node-notifier": "^10.0.1",
101
- portfinder: "^1.0.32",
102
- postcss: "^8.4.21",
103
- "postcss-custom-properties": "^13.1.1",
104
- "postcss-loader": "^7.0.2",
105
- prettier: "^2.8.3",
106
- "react-refresh": "^0.14.0",
107
- "resolve-url-loader": "^5.0.0",
108
- sass: "^1.58.0",
109
- "sass-loader": "^13.2.0",
110
- "source-map-loader": "^4.0.1",
111
- "strip-indent": "^4.0.0",
112
- "style-loader": "^3.3.1",
113
- "tsconfig-paths-webpack-plugin": "^4.0.0",
114
- tsup: "^6.5.0",
115
- typescript: "^4.9.5",
116
- "url-loader": "^4.1.1",
117
- webpack: "^5.75.0",
118
- "webpack-cli": "^5.0.1",
119
- "webpack-config-utils": "^2.3.1",
120
- "webpack-dev-server": "^4.11.1",
121
- "yaml-loader": "^0.8.0"
122
- }
123
- };
124
-
125
- // src/commands/dev.ts
126
- import { getPortPromise } from "portfinder";
127
-
128
- // src/lib/https.ts
129
- import { existsSync } from "fs";
130
- import { resolve } from "path";
131
- import stripIndent from "strip-indent";
132
- var assertCrtExists = () => {
133
- const { ifCore } = getIfCoreFns();
134
- const paths = getPaths(ifCore);
135
- const certFile = resolve(paths.root, HTTPS_CRT_FILE);
136
- const keyFile = resolve(paths.root, HTTPS_KEY_FILE);
137
- if (existsSync(certFile) && existsSync(keyFile)) {
138
- return;
139
- }
140
- halt(
141
- stripIndent(`
142
- Flag \u201C--https\u201D is used, but \u201C${HTTPS_CRT_FILE}\u201D and/or \u201C${HTTPS_KEY_FILE}\u201D files are not found.
143
- You need to generate certificate first.
144
- Check docs: https://unpkg.com/@raisenow/tamaro-cli/readme.html#/?id=use-transport-level-security-https
145
- `)
146
- );
147
- };
148
-
149
- // src/commands/dev.ts
150
- var dev = async (options) => {
151
- assertOptionsValid(options);
152
- const flags = (await prepareFlags([], options)).join(" ");
153
- const { ifCore } = getIfCoreFns();
154
- const title = ifCore(
155
- "Running dev web-server for Tamaro Core \u2026",
156
- "Running dev web-server for customer configuration \u2026"
157
- );
158
- const wpBin = resolveBin("webpack");
159
- const wpConfig = resolveOwn("dist/webpack.config.js");
160
- const cmd = `
161
- ${wpBin} serve
162
- --config ${wpConfig}
163
- ${flags}
164
- `;
165
- logTitle(title);
166
- logCommand(cmd);
167
- runCommandSync(cmd, { stdio: "inherit" });
168
- };
169
- var assertOptionsValid = (options) => {
170
- const { localCore, https, port, env } = options;
171
- const { ifCore } = getIfCoreFns();
172
- if (ifCore() && localCore) {
173
- halt("Flag \u201C--local-core\u201D is redundant if running in Tamaro Core context.");
174
- }
175
- if (isNaN(Number(port))) {
176
- halt("Flag \u201C--port\u201D should be a number.");
177
- }
178
- if (https) {
179
- assertCrtExists();
180
- }
181
- assertEnvValid(env);
182
- };
183
- var prepareFlags = async (flags, options) => {
184
- const { localCore, port: defaultPort, https } = options;
185
- const port = await getPortPromise({ port: Number(defaultPort) });
186
- if (localCore) {
187
- flags.push("--env localCore");
188
- }
189
- flags.push(`--port ${port}`);
190
- if (https) {
191
- flags.push("--env https");
192
- }
193
- return flags;
194
- };
195
-
196
30
  // src/lib/aws.ts
197
31
  import { execaCommandSync } from "execa";
198
- import stripIndent2 from "strip-indent";
32
+ import prompts from "prompts";
33
+ import stripIndent from "strip-indent";
199
34
  var withAwsAuthenticate = (fn, options) => {
200
35
  awsAuthenticate(options);
201
36
  return fn();
@@ -213,30 +48,20 @@ var awsAuthenticate = (options) => {
213
48
  var isSetEnv = () => {
214
49
  return !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY);
215
50
  };
216
- var assertProfileValid = (profile) => {
51
+ var assertProfilesPresent = () => {
217
52
  if (isSetEnv()) {
218
53
  return;
219
54
  }
220
55
  const profiles = getAvailableProfiles();
221
- if (!profiles.includes(profile)) {
222
- console.log(`Using AWS profile: \u201C${profile}\u201D`);
223
- let message;
224
- if (profiles.length === 0) {
225
- message = stripIndent2(`
56
+ if (profiles.length === 0) {
57
+ halt(
58
+ stripIndent(`
226
59
  No AWS profiles found.
227
- `);
228
- } else {
229
- message = stripIndent2(`
230
- AWS profile \u201C${profile}\u201D has not been found.
231
- Available profiles are: ${profiles.map((v) => `\u201C${v}\u201D`).join(", ")}.
232
- `);
233
- }
234
- message += stripIndent2(`
235
- Run \u201Caws configure sso\u201D to set up SSO-enabled profile.
236
- Check the wiki for more information:
237
- https://raisenow.atlassian.net/wiki/x/lIrWvg
238
- `);
239
- 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
+ );
240
65
  }
241
66
  };
242
67
  var getAvailableProfiles = () => {
@@ -244,11 +69,11 @@ var getAvailableProfiles = () => {
244
69
  return stdout.split("\n");
245
70
  };
246
71
  var checkIdentity = (options) => {
247
- const flags = prepareFlags2([], options).join(" ");
72
+ const flags = prepareFlags([], options).join(" ");
248
73
  execaCommandSync(`aws sts get-caller-identity ${flags}`);
249
74
  };
250
75
  var login = (options) => {
251
- const flags = prepareFlags2([], options).join(" ");
76
+ const flags = prepareFlags([], options).join(" ");
252
77
  try {
253
78
  execaCommandSync(`aws sso login ${flags}`, { stdio: "inherit" });
254
79
  console.log("");
@@ -256,13 +81,74 @@ var login = (options) => {
256
81
  halt("Login failed.");
257
82
  }
258
83
  };
259
- var prepareFlags2 = (flags, options) => {
84
+ var prepareFlags = (flags, options) => {
260
85
  const { profile } = options;
261
- if (!isSetEnv()) {
86
+ if (!isSetEnv() && profile) {
262
87
  flags.push(`--profile ${profile}`);
263
88
  }
264
89
  return flags;
265
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
+ };
266
152
 
267
153
  // src/lib/notifier.ts
268
154
  import notifier from "node-notifier";
@@ -279,14 +165,20 @@ var notify = (args) => {
279
165
 
280
166
  // src/commands/build.ts
281
167
  var build = async (options) => {
282
- assertOptionsValid2(options);
283
- const flags = prepareFlags3([], options).join(" ");
168
+ const { env } = options;
169
+ assertOptionsValid(options);
170
+ assertProfilesPresent();
171
+ applyEnv(env);
172
+ if (options.deploy) {
173
+ options.profile = await promptProfile();
174
+ }
175
+ const flags = prepareFlags2([], options).join(" ");
284
176
  const { ifCore } = getIfCoreFns();
285
177
  const paths = getPaths(ifCore);
286
178
  const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
287
179
  const title = ifCore(
288
180
  "Building optimised (minified) bundle of Tamaro Core \u2026",
289
- `Building optimised (minified) bundle of \u201C${configName}\u201D customer configuration \u2026`
181
+ `Building optimised (minified) bundle of "${configName}" customer configuration \u2026`
290
182
  );
291
183
  const wpBin = resolveBin("webpack");
292
184
  const wpConfig = resolveOwn("dist/webpack.config.js");
@@ -300,32 +192,31 @@ var build = async (options) => {
300
192
  logCommand(cmd);
301
193
  runCommandSync(cmd, { stdio: "inherit" });
302
194
  logTitle(`
303
- Bundle for \u201C${configName}\u201D customer configuration is done.`);
195
+ Bundle for "${configName}" customer configuration is done.`);
304
196
  console.log(`Path: ${paths.appDist}
305
197
  `);
306
198
  process.on("exit", () => {
307
199
  notify({
308
200
  title: "build",
309
- message: `Bundle for \u201C${configName}\u201D customer configuration is done.`
201
+ message: `Bundle for "${configName}" customer configuration is done.`
310
202
  });
311
203
  });
312
204
  };
313
- var assertOptionsValid2 = (options) => {
314
- const { localCore, https, deploy: deploy2, profile, env } = options;
205
+ var assertOptionsValid = (options) => {
206
+ const { localCore, https, deploy: deploy2, env } = options;
315
207
  const { ifCore } = getIfCoreFns();
316
208
  if (ifCore() && localCore) {
317
- 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.');
318
210
  }
319
211
  if (localCore && deploy2) {
320
- 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.');
321
213
  }
322
214
  if (https) {
323
215
  assertCrtExists();
324
216
  }
325
- assertProfileValid(profile);
326
217
  assertEnvValid(env);
327
218
  };
328
- var prepareFlags3 = (flags, options) => {
219
+ var prepareFlags2 = (flags, options) => {
329
220
  const { localCore, analyze, https } = options;
330
221
  if (localCore) {
331
222
  flags.push("--env localCore");
@@ -345,9 +236,13 @@ import stripIndent4 from "strip-indent";
345
236
  var deploy = async (options) => {
346
237
  const { ifCore } = getIfCoreFns();
347
238
  const paths = getPaths(ifCore);
348
- assertOptionsValid3(options);
239
+ assertOptionsValid2(options);
349
240
  assertDistPathExists(paths.appDist);
350
- const flags = prepareFlags4([], options).join(" ");
241
+ assertProfilesPresent();
242
+ if (!options.profile) {
243
+ options.profile = await promptProfile();
244
+ }
245
+ const flags = prepareFlags([], options).join(" ");
351
246
  const { tag } = options;
352
247
  const configName = ifCore(CORE_CONFIG_NAME, getWidgetUuid());
353
248
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/${tag}`;
@@ -400,7 +295,7 @@ var deploy = async (options) => {
400
295
  const demoPage = `https://${AWS_S3_BUCKET}/${configName}/${tag}/index.html`;
401
296
  const entryPoint = `https://${AWS_S3_BUCKET}/${configName}/${tag}/${entryFilename}`;
402
297
  logTitle(`
403
- Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.`);
298
+ Bundle for "${configName}" is deployed with tag "${tag}".`);
404
299
  logDataTable({
405
300
  "Demo page:": demoPage,
406
301
  "Entry point:": entryPoint
@@ -409,17 +304,16 @@ Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.`);
409
304
  notify({
410
305
  title: "deploy",
411
306
  message: `
412
- Bundle for \u201C${configName}\u201D is deployed with tag \u201C${tag}\u201D.
307
+ Bundle for "${configName}" is deployed with tag "${tag}".
413
308
  Demo page: ${demoPage}
414
309
  Entry point: ${entryPoint}
415
310
  `
416
311
  });
417
312
  });
418
313
  };
419
- var assertOptionsValid3 = (options) => {
420
- const { tag, profile } = options;
314
+ var assertOptionsValid2 = (options) => {
315
+ const { tag } = options;
421
316
  assertTagValid(tag);
422
- assertProfileValid(profile);
423
317
  };
424
318
  var assertDistPathExists = (distPath) => {
425
319
  if (!existsSync2(distPath)) {
@@ -435,63 +329,125 @@ var assertTagValid = (tag) => {
435
329
  const regex = /^[a-zA-Z0-9-_.]+$/;
436
330
  if (!regex.test(tag)) {
437
331
  halt(
438
- `Flag \u201C--tag\u201D has forbidden format. Allowed format: ${regex.toString()}.`
332
+ `Flag "--tag" has forbidden format. Allowed format: ${regex.toString()}.`
439
333
  );
440
334
  }
441
335
  };
442
- var prepareFlags4 = (flags, options) => {
443
- return prepareFlags2(flags, options);
444
- };
445
336
 
446
- // src/commands/serve.ts
447
- import { resolve as resolve2 } from "path";
448
- import { getPortPromise as getPortPromise2 } from "portfinder";
449
- var serve = async (options) => {
450
- assertOptionsValid4(options);
451
- const flags = (await prepareFlags5([], options)).join(" ");
337
+ // src/commands/deploy-email-config.ts
338
+ import { existsSync as existsSync3 } from "fs";
339
+ var deployEmailConfig = async () => {
452
340
  const { ifCore } = getIfCoreFns();
453
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}`;
454
351
  const cmd = `
455
- npx -y serve ${paths.appDist}
456
- --cors
352
+ aws s3 sync ${emailConfigPath} ${deployUrl}
353
+ --delete
354
+ --exact-timestamps
457
355
  ${flags}
458
356
  `;
459
- 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);
460
411
  logCommand(cmd);
461
412
  runCommandSync(cmd, { stdio: "inherit" });
462
413
  };
463
- var assertOptionsValid4 = (options) => {
464
- 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
+ }
465
420
  if (isNaN(Number(port))) {
466
421
  halt('Flag "--port" should be a number.');
467
422
  }
468
423
  if (https) {
469
424
  assertCrtExists();
470
425
  }
426
+ assertEnvValid(env);
471
427
  };
472
- var prepareFlags5 = async (flags, options) => {
473
- const { port: defaultPort, https } = options;
474
- const port = await getPortPromise2({ port: Number(defaultPort) });
475
- 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}`);
476
435
  if (https) {
477
- const { ifCore } = getIfCoreFns();
478
- const paths = getPaths(ifCore);
479
- const certFile = resolve2(paths.root, HTTPS_CRT_FILE);
480
- const keyFile = resolve2(paths.root, HTTPS_KEY_FILE);
481
- flags.push(`--ssl-cert ${certFile}`);
482
- flags.push(`--ssl-key ${keyFile}`);
436
+ flags.push("--env https");
483
437
  }
484
438
  return flags;
485
439
  };
486
440
 
487
441
  // src/commands/list-deployed.ts
488
442
  var listDeployed = async (options) => {
489
- assertOptionsValid5(options);
490
- const flags = prepareFlags6([], options).join(" ");
443
+ assertOptionsValid4(options);
444
+ assertProfilesPresent();
445
+ options.profile = await promptProfile();
446
+ const flags = prepareFlags([], options).join(" ");
491
447
  const { config } = options;
492
448
  const { ifCore } = getIfCoreFns();
493
449
  const configName = config ?? ifCore(CORE_CONFIG_NAME, getWidgetUuid());
494
- 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`;
495
451
  const deployUrl = `s3://${AWS_S3_BUCKET}/${configName}/`;
496
452
  const cmd = `aws s3 ls ${deployUrl} ${flags}`;
497
453
  let out = "";
@@ -519,10 +475,9 @@ var listDeployed = async (options) => {
519
475
  console.log(`${text}
520
476
  `);
521
477
  };
522
- var assertOptionsValid5 = (options) => {
523
- const { config, profile } = options;
478
+ var assertOptionsValid4 = (options) => {
479
+ const { config } = options;
524
480
  assertConfigValid(config);
525
- assertProfileValid(profile);
526
481
  };
527
482
  var assertConfigValid = (config) => {
528
483
  if (!config) {
@@ -531,83 +486,160 @@ var assertConfigValid = (config) => {
531
486
  const regex = /^[a-zA-Z0-9-_]+$/;
532
487
  if (!regex.test(config)) {
533
488
  halt(
534
- `Flag \u201C--config\u201D has forbidden format. Allowed format: ${regex.toString()}.`
489
+ `Flag "--config" has forbidden format. Allowed format: ${regex.toString()}.`
535
490
  );
536
491
  }
537
492
  };
538
- var prepareFlags6 = (flags, options) => {
539
- return prepareFlags2(flags, options);
540
- };
541
493
  var parseTags = (lines) => {
542
494
  const regex = /^\s*PRE\s*/;
543
495
  return lines.filter((line) => regex.test(line)).map((line) => line.replace(regex, "").replace(/\/$/, ""));
544
496
  };
545
497
 
546
- // src/commands/deploy-email-config.ts
547
- import { existsSync as existsSync3 } from "fs";
548
- 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(" ");
549
504
  const { ifCore } = getIfCoreFns();
550
505
  const paths = getPaths(ifCore);
551
- const emailConfigPath = `${paths.app}/email-config`;
552
- assertOptionsValid6(options);
553
- assertIsNotCore();
554
- assertEmailConfigPathExists(emailConfigPath);
555
- const flags = prepareFlags7([], options).join(" ");
556
- const { bucket } = options;
557
- const configName = getWidgetUuid();
558
- const deployUrl = `s3://${bucket}/${configName}`;
559
506
  const cmd = `
560
- aws s3 sync ${emailConfigPath} ${deployUrl}
561
- --delete
562
- --exact-timestamps
507
+ npx -y serve ${paths.appDist}
508
+ --cors
563
509
  ${flags}
564
510
  `;
565
- logTitle(
566
- `Deploying email configuration for \u201C${configName}\u201D customer configuration to AWS S3 \u2026`
567
- );
511
+ logTitle(`Running web-server for pre-built bundle \u2026`);
568
512
  logCommand(cmd);
569
- try {
570
- withAwsAuthenticate(() => runCommandSync(cmd, { stdout: "inherit" }), options);
571
- } catch (error) {
572
- halt(error.stderr);
573
- }
574
- logTitle(
575
- `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`
576
- );
577
- logDataTable({ "Deploy URL:": deployUrl });
578
- process.on("exit", () => {
579
- notify({
580
- title: `deploy-email-config`,
581
- message: `Email configuration for \u201C${configName}\u201D customer configuration is deployed.`
582
- });
583
- });
584
- };
585
- var assertOptionsValid6 = (options) => {
586
- const { bucket, profile } = options;
587
- assertBucketValid(bucket);
588
- assertProfileValid(profile);
513
+ runCommandSync(cmd, { stdio: "inherit" });
589
514
  };
590
- var assertEmailConfigPathExists = (distPath) => {
591
- if (!existsSync3(distPath)) {
592
- 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.');
593
519
  }
594
- };
595
- var assertBucketValid = (tag) => {
596
- const regex = /^[a-zA-Z0-9-_]+$/;
597
- if (!regex.test(tag)) {
598
- halt(
599
- `Flag \u201C--bucket\u201D has forbidden format. Allowed format: ${regex.toString()}.`
600
- );
520
+ if (https) {
521
+ assertCrtExists();
601
522
  }
602
523
  };
603
- var assertIsNotCore = () => {
604
- const { ifCore } = getIfCoreFns();
605
- if (ifCore()) {
606
- 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}`);
607
535
  }
536
+ return flags;
608
537
  };
609
- var prepareFlags7 = (flags, options) => {
610
- 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"
611
643
  };
612
644
 
613
645
  // src/cli.ts
@@ -649,10 +681,6 @@ cli.command("build").description(
649
681
  "--tag <tag>",
650
682
  "Tag which should be used for the deployment of the bundle",
651
683
  DEFAULT_TAG
652
- ).option(
653
- "--profile <profile>",
654
- "AWS profile which should be used for the deployment of the bundle",
655
- DEFAULT_AWS_PROFILE
656
684
  ).action(async (options) => {
657
685
  await build(options);
658
686
  if (options.serve) {
@@ -675,10 +703,6 @@ cli.command("deploy").description(
675
703
  "--tag <tag>",
676
704
  "Tag which should be used for the deployment of the bundle",
677
705
  DEFAULT_TAG
678
- ).option(
679
- "--profile <profile>",
680
- "AWS profile which should be used for the deployment of the bundle",
681
- DEFAULT_AWS_PROFILE
682
706
  ).action(async (options) => {
683
707
  await deploy(options);
684
708
  });
@@ -687,23 +711,11 @@ cli.command("list-deployed").description(
687
711
  ).option(
688
712
  "--config <config>",
689
713
  "Configuration name (default: current customer configuration)"
690
- ).option(
691
- "--profile <profile>",
692
- "AWS profile which should be used for fetching deployments",
693
- DEFAULT_AWS_PROFILE
694
714
  ).action(async (options) => {
695
715
  await listDeployed(options);
696
716
  });
697
- cli.command("deploy-email-config").description("Deploy a widget\u2019s email configuration to AWS S3").option(
698
- "--bucket <bucket>",
699
- "AWS S3 bucket where it should be deployed",
700
- DEFAULT_AWS_S3_EMAIL_CONFIG_BUCKET
701
- ).option(
702
- "--profile <profile>",
703
- "AWS profile which should be used for the deployment of email configuration",
704
- DEFAULT_AWS_PROFILE
705
- ).action(async (options) => {
706
- await deployEmailConfig(options);
717
+ cli.command("deploy-email-config").description("Deploy a widget's email configuration to AWS S3").action(async () => {
718
+ await deployEmailConfig();
707
719
  });
708
720
  (async () => {
709
721
  try {