@jtl-software/create-cloud-app 0.5.1 → 0.5.3

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.
Files changed (2) hide show
  1. package/dist/index.js +94 -29
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -704,6 +704,23 @@ function writeFrontendPublicClient(root, authIssuer, publicClientId) {
704
704
  });
705
705
  return envFile;
706
706
  }
707
+ function readBackendPort(backend) {
708
+ if (backend.kind === "node") {
709
+ for (const file of [backend.envFile, `${backend.envFile}.example`]) {
710
+ const value = readEnvFile(file).PORT;
711
+ if (value && /^\d+$/.test(value)) return Number(value);
712
+ }
713
+ }
714
+ return 3005;
715
+ }
716
+ function writeVerifyDemoEnv(root, backend) {
717
+ if (!backend) return;
718
+ const frontendDir = detectFrontend(root);
719
+ if (!frontendDir) return;
720
+ upsertEnv(path2.join(frontendDir, ".env"), {
721
+ VITE_BACKEND_URL: `http://localhost:${readBackendPort(backend)}`
722
+ });
723
+ }
707
724
  function readExistingCredentials(backend) {
708
725
  if (backend.kind === "node") {
709
726
  const values = readEnvFile(backend.envFile);
@@ -720,11 +737,12 @@ function readExistingCredentials(backend) {
720
737
  return {};
721
738
  }
722
739
  }
723
- function writeBackendCredentials(backend, clientId, clientSecret) {
740
+ function writeBackendCredentials(backend, clientId, clientSecret, issuer) {
724
741
  if (backend.kind === "node") {
725
742
  upsertEnv(backend.envFile, {
726
743
  CLIENT_ID: clientId,
727
- CLIENT_SECRET: clientSecret
744
+ CLIENT_SECRET: clientSecret,
745
+ ...issuer ? { JTL_ISSUER: issuer } : {}
728
746
  });
729
747
  return backend.envFile;
730
748
  }
@@ -739,7 +757,8 @@ function writeBackendCredentials(backend, clientId, clientSecret) {
739
757
  settings.JtlPlatform = {
740
758
  ...settings.JtlPlatform ?? {},
741
759
  ClientId: clientId,
742
- ClientSecret: clientSecret
760
+ ClientSecret: clientSecret,
761
+ ...issuer ? { Issuer: issuer } : {}
743
762
  };
744
763
  fs2.writeFileSync(
745
764
  backend.settingsFile,
@@ -983,6 +1002,34 @@ async function provisionApp(apiBaseUrl, jwt, tenantId, appId, appServicePath = "
983
1002
  publicClientId: provisioned.credentials?.publicClient?.clientId
984
1003
  };
985
1004
  }
1005
+ async function applyProvisionResult(root, backend, opts, tenant, appId, provisioned, isInstalled) {
1006
+ if (provisioned.publicClientId) {
1007
+ const written = writeFrontendPublicClient(
1008
+ root,
1009
+ opts.auth,
1010
+ provisioned.publicClientId
1011
+ );
1012
+ if (written) {
1013
+ p2.log.success(
1014
+ `Wrote VITE_JTL_CLIENT_ID/VITE_JTL_ISSUER to ${pc2.cyan(path2.relative(root, written))}.`
1015
+ );
1016
+ }
1017
+ }
1018
+ writeVerifyDemoEnv(root, backend);
1019
+ if (backend) {
1020
+ await persistCredentials(
1021
+ backend,
1022
+ provisioned.clientId,
1023
+ provisioned.clientSecret,
1024
+ root,
1025
+ opts,
1026
+ { hub: opts.hub, tenantSlug: tenant.slug, appId, isInstalled }
1027
+ );
1028
+ return;
1029
+ }
1030
+ printHubLink(opts.hub, tenant.slug, appId, isInstalled);
1031
+ p2.outro(pc2.green("Done. App registered."));
1032
+ }
986
1033
  function credentialLabels(backend) {
987
1034
  if (backend.kind === "node") {
988
1035
  return {
@@ -1022,7 +1069,12 @@ async function persistCredentials(backend, clientId, clientSecret, root, opts, c
1022
1069
  p2.outro(pc2.green("Done. Credentials printed above; file left untouched."));
1023
1070
  return;
1024
1071
  }
1025
- const written = writeBackendCredentials(backend, clientId, clientSecret);
1072
+ const written = writeBackendCredentials(
1073
+ backend,
1074
+ clientId,
1075
+ clientSecret,
1076
+ opts.auth
1077
+ );
1026
1078
  printHubLink(
1027
1079
  context.hub,
1028
1080
  context.tenantSlug,
@@ -1157,6 +1209,33 @@ async function register(argv = [], runOpts = {}) {
1157
1209
  spinner4.stop("Failed to update manifest");
1158
1210
  bail(err.message);
1159
1211
  }
1212
+ if (existing.provisioningStatus === "DRAFT") {
1213
+ spinner4.start("Provisioning app");
1214
+ let provisioned;
1215
+ try {
1216
+ provisioned = await provisionApp(
1217
+ opts.api,
1218
+ apiJwt,
1219
+ tenant.id,
1220
+ existing.id,
1221
+ opts.appServicePath
1222
+ );
1223
+ spinner4.stop("Provisioned");
1224
+ } catch (err) {
1225
+ spinner4.stop("Failed to provision app");
1226
+ bail(err.message);
1227
+ }
1228
+ await applyProvisionResult(
1229
+ root,
1230
+ backend,
1231
+ opts,
1232
+ tenant,
1233
+ existing.id,
1234
+ provisioned,
1235
+ existing.isInstalled ?? false
1236
+ );
1237
+ return;
1238
+ }
1160
1239
  if (existing.publicClientId) {
1161
1240
  const written = writeFrontendPublicClient(
1162
1241
  root,
@@ -1169,6 +1248,7 @@ async function register(argv = [], runOpts = {}) {
1169
1248
  );
1170
1249
  }
1171
1250
  }
1251
+ writeVerifyDemoEnv(root, backend);
1172
1252
  printHubLink(
1173
1253
  opts.hub,
1174
1254
  tenant.slug,
@@ -1230,30 +1310,15 @@ async function register(argv = [], runOpts = {}) {
1230
1310
  spinner4.stop("Failed to provision app");
1231
1311
  bail(err.message);
1232
1312
  }
1233
- if (publicClientId) {
1234
- const written = writeFrontendPublicClient(
1235
- root,
1236
- opts.auth,
1237
- publicClientId
1238
- );
1239
- if (written) {
1240
- p2.log.success(
1241
- `Wrote VITE_JTL_CLIENT_ID/VITE_JTL_ISSUER to ${pc2.cyan(path2.relative(root, written))}.`
1242
- );
1243
- }
1244
- }
1245
- if (backend) {
1246
- await persistCredentials(backend, clientId, clientSecret, root, opts, {
1247
- hub: opts.hub,
1248
- tenantSlug: tenant.slug,
1249
- appId,
1250
- // A freshly created app can't be installed yet.
1251
- isInstalled: false
1252
- });
1253
- return;
1254
- }
1255
- printHubLink(opts.hub, tenant.slug, appId, false);
1256
- p2.outro(pc2.green("Done. App registered."));
1313
+ await applyProvisionResult(
1314
+ root,
1315
+ backend,
1316
+ opts,
1317
+ tenant,
1318
+ appId,
1319
+ { clientId, clientSecret, publicClientId },
1320
+ false
1321
+ );
1257
1322
  return;
1258
1323
  }
1259
1324
  }
@@ -1797,7 +1862,7 @@ import os2 from "os";
1797
1862
  import path6 from "path";
1798
1863
  import { PostHog } from "posthog-node";
1799
1864
  var TOKEN = "phc_SkFAxTIa4RUQxotci1Ftdw7xefZK2Ax0LEIGcl8zuD2";
1800
- var CLI_VERSION = "0.5.1";
1865
+ var CLI_VERSION = "0.5.3";
1801
1866
  var client = TOKEN ? new PostHog(TOKEN, { host: "https://e.jtl-cloud.com" }) : null;
1802
1867
  function telemetryDisabledByEnv() {
1803
1868
  const dnt = process.env.DO_NOT_TRACK;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jtl-software/create-cloud-app",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "description": "CLI tool for scaffolding JTL Platform cloud apps",
6
6
  "bin": {
@@ -18,13 +18,13 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@clack/prompts": "^1.7.0",
21
- "@jtl-software/cloud-app-template-backend-dotnet": "0.0.12",
22
- "@jtl-software/cloud-app-template-backend-node": "0.0.15",
23
- "@jtl-software/cloud-app-template-backend-php": "0.1.2",
24
- "@jtl-software/cloud-app-template-frontend-react": "0.1.1",
21
+ "@jtl-software/cloud-app-template-backend-dotnet": "0.0.13",
22
+ "@jtl-software/cloud-app-template-backend-node": "0.0.16",
23
+ "@jtl-software/cloud-app-template-backend-php": "0.1.3",
24
+ "@jtl-software/cloud-app-template-frontend-react": "0.1.3",
25
25
  "@jtl-software/cloud-app-template-shared": "0.1.2",
26
26
  "picocolors": "^1.1.1",
27
- "posthog-node": "^5.48.1"
27
+ "posthog-node": "^5.49.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^26.2.0",