@jtl-software/create-cloud-app 0.8.0 → 0.8.2

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 +60 -9
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -674,8 +674,46 @@ function findDotnetProject(backendDir) {
674
674
  }
675
675
  return null;
676
676
  }
677
+ var IGNORED_TOP_LEVEL_DIRS = /* @__PURE__ */ new Set([
678
+ "node_modules",
679
+ "dist",
680
+ "build",
681
+ // The scaffolded layout ("packages/backend", "packages/frontend") is always checked as its own
682
+ // fast path first; the fallback scan doesn't need to look inside "packages" too.
683
+ "packages"
684
+ ]);
685
+ function listTopLevelProjectDirs(root) {
686
+ let entries;
687
+ try {
688
+ entries = fs2.readdirSync(root, { withFileTypes: true });
689
+ } catch {
690
+ return [];
691
+ }
692
+ return entries.filter(
693
+ (e) => e.isDirectory() && !e.name.startsWith(".") && !IGNORED_TOP_LEVEL_DIRS.has(e.name)
694
+ ).map((e) => path2.join(root, e.name));
695
+ }
696
+ function envFileHasBackendKeys(filePath) {
697
+ if (!fs2.existsSync(filePath)) return false;
698
+ const keys = Object.keys(parseEnv(fs2.readFileSync(filePath, "utf-8")));
699
+ return keys.includes("CLIENT_ID") || keys.includes("CLIENT_SECRET");
700
+ }
701
+ function isNodeBackendDir(dir) {
702
+ return envFileHasBackendKeys(path2.join(dir, ".env")) || envFileHasBackendKeys(path2.join(dir, ".env.example"));
703
+ }
704
+ function findBackendDir(root) {
705
+ const scaffolded = path2.join(root, "packages", "backend");
706
+ if (fs2.existsSync(scaffolded)) return scaffolded;
707
+ for (const dir of [root, ...listTopLevelProjectDirs(root)]) {
708
+ if (isNodeBackendDir(dir) || findDotnetProject(dir)) {
709
+ return dir;
710
+ }
711
+ }
712
+ return null;
713
+ }
677
714
  function detectBackend(root) {
678
- const backendDir = path2.join(root, "packages", "backend");
715
+ const backendDir = findBackendDir(root);
716
+ if (!backendDir) return null;
679
717
  const envFile = path2.join(backendDir, ".env");
680
718
  const envExample = path2.join(backendDir, ".env.example");
681
719
  if (fs2.existsSync(envFile) || fs2.existsSync(envExample)) {
@@ -691,8 +729,14 @@ function detectBackend(root) {
691
729
  return { kind: "node", envFile: path2.join(root, ".env") };
692
730
  }
693
731
  function detectFrontend(root) {
694
- const frontendDir = path2.join(root, "packages", "frontend");
695
- return fs2.existsSync(path2.join(frontendDir, "package.json")) ? frontendDir : null;
732
+ const scaffolded = path2.join(root, "packages", "frontend");
733
+ if (fs2.existsSync(path2.join(scaffolded, "package.json"))) return scaffolded;
734
+ const backendDir = findBackendDir(root);
735
+ for (const dir of [root, ...listTopLevelProjectDirs(root)]) {
736
+ if (dir === backendDir) continue;
737
+ if (fs2.existsSync(path2.join(dir, "package.json"))) return dir;
738
+ }
739
+ return null;
696
740
  }
697
741
  function readScaffoldStack(root) {
698
742
  try {
@@ -791,7 +835,8 @@ function writeBackendCredentials(backend, clientId, clientSecret, issuer, apiBas
791
835
  ...settings.JtlPlatform ?? {},
792
836
  ClientId: clientId,
793
837
  ClientSecret: clientSecret,
794
- ...issuer ? { Issuer: issuer } : {}
838
+ ...issuer ? { Issuer: issuer } : {},
839
+ ...appId ? { AppId: appId } : {}
795
840
  };
796
841
  fs2.writeFileSync(
797
842
  backend.settingsFile,
@@ -1054,16 +1099,17 @@ function resolveBackendAuth(provisioned, legacy = false) {
1054
1099
  return { clientId: sa.clientId, clientSecret: sa.clientSecret };
1055
1100
  }
1056
1101
  async function applyProvisionResult(root, backend, opts, tenant, appId, provisioned, isInstalled, legacy) {
1102
+ let frontendWritten = null;
1057
1103
  if (provisioned.publicClientId) {
1058
- const written = writeFrontendPublicClient(
1104
+ frontendWritten = writeFrontendPublicClient(
1059
1105
  root,
1060
1106
  opts.auth,
1061
1107
  provisioned.publicClientId,
1062
1108
  opts.api
1063
1109
  );
1064
- if (written) {
1110
+ if (frontendWritten) {
1065
1111
  p2.log.success(
1066
- `Wrote VITE_JTL_CLIENT_ID/VITE_JTL_ISSUER/VITE_JTL_API_BASE to ${pc2.cyan(path2.relative(root, written))}.`
1112
+ `Wrote VITE_JTL_CLIENT_ID/VITE_JTL_ISSUER/VITE_JTL_API_BASE to ${pc2.cyan(path2.relative(root, frontendWritten))}.`
1067
1113
  );
1068
1114
  }
1069
1115
  }
@@ -1080,6 +1126,11 @@ async function applyProvisionResult(root, backend, opts, tenant, appId, provisio
1080
1126
  );
1081
1127
  return;
1082
1128
  }
1129
+ if (!frontendWritten) {
1130
+ p2.log.warn(
1131
+ "No backend or frontend directory detected under this project - nothing was written locally."
1132
+ );
1133
+ }
1083
1134
  printHubLink(opts.hub, tenant.slug, appId, isInstalled);
1084
1135
  p2.outro(pc2.green("Done. App registered."));
1085
1136
  }
@@ -1148,7 +1199,7 @@ async function register(argv = [], runOpts = {}) {
1148
1199
  console.log();
1149
1200
  p2.intro(pc2.bgCyan(pc2.black(" register cloud app ")));
1150
1201
  const opts = resolveOptions(argv);
1151
- const backend = fs2.existsSync(path2.join(root, "packages", "backend")) ? detectBackend(root) : null;
1202
+ const backend = detectBackend(root);
1152
1203
  p2.note(
1153
1204
  [
1154
1205
  `${pc2.dim("API")} ${opts.api}`,
@@ -2006,7 +2057,7 @@ import os2 from "os";
2006
2057
  import path6 from "path";
2007
2058
  import { PostHog } from "posthog-node";
2008
2059
  var TOKEN = "phc_SkFAxTIa4RUQxotci1Ftdw7xefZK2Ax0LEIGcl8zuD2";
2009
- var CLI_VERSION = "0.8.0";
2060
+ var CLI_VERSION = "0.8.2";
2010
2061
  var client = TOKEN ? new PostHog(TOKEN, { host: "https://e.jtl-cloud.com" }) : null;
2011
2062
  function telemetryDisabledByEnv() {
2012
2063
  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.8.0",
3
+ "version": "0.8.2",
4
4
  "type": "module",
5
5
  "description": "CLI tool for scaffolding JTL Platform cloud apps",
6
6
  "bin": {
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@clack/prompts": "^1.7.0",
21
- "@jtl-software/cloud-app-template-backend-dotnet": "0.1.0",
21
+ "@jtl-software/cloud-app-template-backend-dotnet": "0.2.0",
22
22
  "@jtl-software/cloud-app-template-backend-node": "0.3.0",
23
- "@jtl-software/cloud-app-template-backend-php": "0.2.0",
23
+ "@jtl-software/cloud-app-template-backend-php": "0.3.0",
24
24
  "@jtl-software/cloud-app-template-frontend-react": "0.3.1",
25
25
  "@jtl-software/cloud-app-template-shared": "0.2.0",
26
26
  "picocolors": "^1.1.1",