@schnebel-crm/cli 0.1.6 → 0.1.8-dev.1776152843

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/cli.mjs +41 -8
  2. package/package.json +16 -10
package/dist/cli.mjs CHANGED
@@ -262,6 +262,40 @@ async function loadConfig(cwd) {
262
262
 
263
263
  //#endregion
264
264
  //#region src/commands/build.ts
265
+ /**
266
+ * Extract metadata from the definition source file by building it
267
+ * standalone with stub SDK functions and evaluating via data: URL.
268
+ * This avoids importing the full bundle which may depend on native modules.
269
+ */
270
+ async function extractMetadata(cwd) {
271
+ const wrapped = ["const defineIntegration = (d) => d;", (await build({
272
+ entryPoints: [resolve(cwd, "src", "definition.ts")],
273
+ bundle: true,
274
+ format: "esm",
275
+ platform: "node",
276
+ target: "node20",
277
+ write: false,
278
+ external: ["@schnebel-crm/integration-sdk", "@schnebel-crm/*"]
279
+ })).outputFiles[0].text.replace(/import\s*\{[^}]*\}\s*from\s*["'][^"']*["'];?/g, "")].join("\n");
280
+ return (await import(`data:text/javascript;base64,${Buffer.from(wrapped).toString("base64")}`)).definition;
281
+ }
282
+ /**
283
+ * Extract action metadata (id, name, description) from the built bundle.
284
+ * Runs the bundle via import() — safe because it's on the developer's machine.
285
+ */
286
+ async function extractActions(bundlePath) {
287
+ try {
288
+ const mod = await import(pathToFileURL(bundlePath).href);
289
+ if (!mod.handler?.actions) return [];
290
+ return mod.handler.actions.map((a) => ({
291
+ id: a.id,
292
+ name: a.name,
293
+ description: a.description
294
+ }));
295
+ } catch {
296
+ return [];
297
+ }
298
+ }
265
299
  const buildCommand = new Command("build").description("Build the integration into a deployable bundle").action(async () => {
266
300
  const cwd = process.cwd();
267
301
  const config = await loadConfig(cwd);
@@ -278,20 +312,17 @@ const buildCommand = new Command("build").description("Build the integration int
278
312
  target: "node20",
279
313
  outfile: outFile,
280
314
  external: ["@schnebel-crm/integration-sdk"],
315
+ banner: { js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);" },
281
316
  minify: false,
282
317
  sourcemap: false
283
318
  });
284
319
  log.step("Generating manifest...");
285
- const mod = await import(pathToFileURL(outFile).href);
286
- if (!mod.definition) {
287
- log.error("Bundle must export a 'definition' named export.");
288
- process.exit(1);
289
- }
290
- if (!mod.handler) {
291
- log.error("Bundle must export a 'handler' named export.");
320
+ const def = await extractMetadata(cwd);
321
+ if (!def) {
322
+ log.error("src/definition.ts must export a 'definition'.");
292
323
  process.exit(1);
293
324
  }
294
- const def = mod.definition;
325
+ const actions = await extractActions(outFile);
295
326
  const manifest = {
296
327
  id: def.id,
297
328
  name: def.name,
@@ -307,6 +338,7 @@ const buildCommand = new Command("build").description("Build the integration int
307
338
  credentialFields: def.credentialFields,
308
339
  documentationUrl: def.documentationUrl,
309
340
  tags: def.tags,
341
+ actions,
310
342
  sdkVersion: "0.1.0"
311
343
  };
312
344
  await writeFile(join(outDir, "manifest.json"), JSON.stringify(manifest, null, 2));
@@ -599,6 +631,7 @@ const devCommand = new Command("dev").description("Watch and validate the integr
599
631
  target: "node20",
600
632
  outfile: `${outDir}/index.mjs`,
601
633
  external: ["@schnebel-crm/integration-sdk"],
634
+ banner: { js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);" },
602
635
  logLevel: "info"
603
636
  })).watch();
604
637
  log.success("Watching for changes...");
package/package.json CHANGED
@@ -1,21 +1,27 @@
1
1
  {
2
2
  "name": "@schnebel-crm/cli",
3
- "version": "0.1.6",
4
- "type": "module",
3
+ "version": "0.1.8-dev.1776152843",
5
4
  "description": "CLI for building and deploying Schnebel CRM integrations",
6
- "main": "./dist/cli.mjs",
5
+ "keywords": [
6
+ "cli",
7
+ "crm",
8
+ "integration",
9
+ "schnebel"
10
+ ],
11
+ "homepage": "https://schnebel-crm.de/docs/integrations",
12
+ "license": "MIT",
7
13
  "bin": {
8
14
  "schnebel": "./dist/cli.mjs"
9
15
  },
10
- "files": ["dist"],
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "type": "module",
20
+ "main": "./dist/cli.mjs",
11
21
  "scripts": {
12
22
  "build": "tsdown src/cli.ts --format esm --clean",
13
- "check-types": "tsc --noEmit",
14
- "prepublishOnly": "pnpm run build"
23
+ "check-types": "tsc --noEmit"
15
24
  },
16
- "keywords": ["schnebel", "crm", "integration", "cli"],
17
- "license": "MIT",
18
- "homepage": "https://schnebel-crm.de/docs/integrations",
19
25
  "dependencies": {
20
26
  "commander": "^13.0.0",
21
27
  "esbuild": "^0.25.0",
@@ -23,7 +29,7 @@
23
29
  "prompts": "^2.4.2"
24
30
  },
25
31
  "devDependencies": {
26
- "@schnebel-crm/integration-sdk": "workspace:^",
32
+ "@schnebel-crm/integration-sdk": "^0.1.8-dev.1776152843",
27
33
  "@types/prompts": "^2.4.9",
28
34
  "tsdown": "^0.16.5",
29
35
  "typescript": "^5"