@jtl-software/create-cloud-app 0.8.1 → 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 +58 -8
  2. package/package.json +1 -1
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 {
@@ -1055,16 +1099,17 @@ function resolveBackendAuth(provisioned, legacy = false) {
1055
1099
  return { clientId: sa.clientId, clientSecret: sa.clientSecret };
1056
1100
  }
1057
1101
  async function applyProvisionResult(root, backend, opts, tenant, appId, provisioned, isInstalled, legacy) {
1102
+ let frontendWritten = null;
1058
1103
  if (provisioned.publicClientId) {
1059
- const written = writeFrontendPublicClient(
1104
+ frontendWritten = writeFrontendPublicClient(
1060
1105
  root,
1061
1106
  opts.auth,
1062
1107
  provisioned.publicClientId,
1063
1108
  opts.api
1064
1109
  );
1065
- if (written) {
1110
+ if (frontendWritten) {
1066
1111
  p2.log.success(
1067
- `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))}.`
1068
1113
  );
1069
1114
  }
1070
1115
  }
@@ -1081,6 +1126,11 @@ async function applyProvisionResult(root, backend, opts, tenant, appId, provisio
1081
1126
  );
1082
1127
  return;
1083
1128
  }
1129
+ if (!frontendWritten) {
1130
+ p2.log.warn(
1131
+ "No backend or frontend directory detected under this project - nothing was written locally."
1132
+ );
1133
+ }
1084
1134
  printHubLink(opts.hub, tenant.slug, appId, isInstalled);
1085
1135
  p2.outro(pc2.green("Done. App registered."));
1086
1136
  }
@@ -1149,7 +1199,7 @@ async function register(argv = [], runOpts = {}) {
1149
1199
  console.log();
1150
1200
  p2.intro(pc2.bgCyan(pc2.black(" register cloud app ")));
1151
1201
  const opts = resolveOptions(argv);
1152
- const backend = fs2.existsSync(path2.join(root, "packages", "backend")) ? detectBackend(root) : null;
1202
+ const backend = detectBackend(root);
1153
1203
  p2.note(
1154
1204
  [
1155
1205
  `${pc2.dim("API")} ${opts.api}`,
@@ -2007,7 +2057,7 @@ import os2 from "os";
2007
2057
  import path6 from "path";
2008
2058
  import { PostHog } from "posthog-node";
2009
2059
  var TOKEN = "phc_SkFAxTIa4RUQxotci1Ftdw7xefZK2Ax0LEIGcl8zuD2";
2010
- var CLI_VERSION = "0.8.1";
2060
+ var CLI_VERSION = "0.8.2";
2011
2061
  var client = TOKEN ? new PostHog(TOKEN, { host: "https://e.jtl-cloud.com" }) : null;
2012
2062
  function telemetryDisabledByEnv() {
2013
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.1",
3
+ "version": "0.8.2",
4
4
  "type": "module",
5
5
  "description": "CLI tool for scaffolding JTL Platform cloud apps",
6
6
  "bin": {