cap-copilot-sdk 0.2.2 → 0.2.4

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/package.json +1 -1
  2. package/postinstall.js +19 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cap-copilot-sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "CDS plugin: auto-extracts entity schemas, relationships, project structure and registers with BTP Copilot backend",
5
5
  "main": "cds-plugin.js",
6
6
  "exports": {
package/postinstall.js CHANGED
@@ -21,7 +21,9 @@ if (process.env.BTP_COPILOT_SKIP_POSTINSTALL === "1") process.exit(0);
21
21
  // INIT_CWD = directory from which `npm install` was run (the consuming app root)
22
22
  const appRoot = process.env.INIT_CWD;
23
23
 
24
- if (!appRoot || appRoot === __dirname || appRoot === path.resolve(__dirname, "../..")) {
24
+
25
+ const isInstalledPackage = __dirname.includes("node_modules");
26
+ if (!appRoot || !isInstalledPackage) {
25
27
  process.exit(0);
26
28
  }
27
29
 
@@ -56,7 +58,10 @@ const changed =
56
58
  existing.backendUrl !== undefined ||
57
59
  existing.iframeUrl !== undefined;
58
60
 
59
- if (!changed) {
61
+ const pluginsArr = Array.isArray(cdsSection.plugins) ? cdsSection.plugins : [];
62
+ const needsPlugin = !pluginsArr.includes("cap-copilot-sdk");
63
+
64
+ if (!changed && !needsPlugin) {
60
65
  process.exit(0);
61
66
  }
62
67
 
@@ -67,15 +72,24 @@ delete requires["btp-copilot"].backendUrl;
67
72
  delete requires["btp-copilot"].iframeUrl;
68
73
 
69
74
  cdsSection.requires = requires;
75
+
76
+ // Ensure cap-copilot-sdk is listed in cds.plugins so CDS loads it automatically
77
+ const plugins = Array.isArray(cdsSection.plugins) ? cdsSection.plugins : [];
78
+ const pluginAlreadyListed = plugins.includes("cap-copilot-sdk");
79
+ if (!pluginAlreadyListed) {
80
+ plugins.push("cap-copilot-sdk");
81
+ cdsSection.plugins = plugins;
82
+ }
83
+
70
84
  pkg.cds = cdsSection;
71
85
 
72
86
  try {
73
87
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
74
88
  console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m \u2714 Configured cds.requires["btp-copilot"] in package.json`);
75
89
  console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m appId="${appDefaults.appId}" | appName="${appDefaults.appName}"`);
76
- console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m To use custom backend/frontend URLs set env vars:`);
77
- console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m BTP_COPILOT_URL=https://your-backend.cfapps.eu10.hana.ondemand.com`);
78
- console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m BTP_COPILOT_IFRAME_URL=https://your-frontend.cfapps.eu10.hana.ondemand.com`);
90
+ if (!pluginAlreadyListed) {
91
+ console.log(`\x1b[36m[cap-copilot-sdk]\x1b[0m \u2714 Registered "cap-copilot-sdk" in cds.plugins`);
92
+ }
79
93
  } catch {
80
94
  // Non-fatal
81
95
  }