@bonnard/cli 0.1.2 → 0.1.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/bin/bon.mjs +58 -1
  2. package/package.json +7 -7
package/dist/bin/bon.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
2
3
  import { program } from "commander";
3
4
  import fs from "node:fs";
4
5
  import path from "node:path";
@@ -526,9 +527,64 @@ async function validateCommand() {
526
527
  if (result.views.length > 0) console.log(` ${pc.dim("Views")} (${result.views.length}): ${result.views.join(", ")}`);
527
528
  }
528
529
 
530
+ //#endregion
531
+ //#region src/commands/deploy.ts
532
+ function collectFiles(dir, rootDir) {
533
+ const files = {};
534
+ if (!fs.existsSync(dir)) return files;
535
+ function walk(current) {
536
+ for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
537
+ const fullPath = path.join(current, entry.name);
538
+ if (entry.isDirectory()) walk(fullPath);
539
+ else if (entry.name.endsWith(".yaml") || entry.name.endsWith(".yml")) {
540
+ const relativePath = path.relative(rootDir, fullPath);
541
+ files[relativePath] = fs.readFileSync(fullPath, "utf-8");
542
+ }
543
+ }
544
+ }
545
+ walk(dir);
546
+ return files;
547
+ }
548
+ async function deployCommand() {
549
+ const cwd = process.cwd();
550
+ if (!fs.existsSync(path.join(cwd, "bon.yaml"))) {
551
+ console.log(pc.red("No bon.yaml found. Are you in a Bonnard project?"));
552
+ process.exit(1);
553
+ }
554
+ console.log(pc.dim("Validating models..."));
555
+ const { validate } = await import("./validate-Bd1D39Bj.mjs");
556
+ const result = await validate(cwd);
557
+ if (!result.valid) {
558
+ console.log(pc.red("Validation failed:\n"));
559
+ for (const err of result.errors) console.log(pc.red(` • ${err}`));
560
+ process.exit(1);
561
+ }
562
+ if (result.cubes.length === 0 && result.views.length === 0) {
563
+ console.log(pc.yellow("No model or view files found in models/ or views/. Nothing to deploy."));
564
+ process.exit(1);
565
+ }
566
+ console.log(pc.dim(` Found ${result.cubes.length} cube(s) and ${result.views.length} view(s)`));
567
+ const files = {
568
+ ...collectFiles(path.join(cwd, "models"), cwd),
569
+ ...collectFiles(path.join(cwd, "views"), cwd)
570
+ };
571
+ const fileCount = Object.keys(files).length;
572
+ console.log(pc.dim(` Deploying ${fileCount} file(s)...\n`));
573
+ try {
574
+ const response = await post("/api/deploy", { files });
575
+ console.log(pc.green("Deploy successful!"));
576
+ console.log(`Deployment ID: ${pc.cyan(response.deployment.id)}`);
577
+ console.log(`Cube API: ${pc.cyan(`${response.deployment.cubeApiUrl}/cubejs-api/v1`)}`);
578
+ } catch (err) {
579
+ console.log(pc.red(`Deploy failed: ${err instanceof Error ? err.message : err}`));
580
+ process.exit(1);
581
+ }
582
+ }
583
+
529
584
  //#endregion
530
585
  //#region src/bin/bon.ts
531
- program.name("bon").description("Bonnard semantic layer CLI").version("0.1.0");
586
+ const { version } = createRequire(import.meta.url)("../../package.json");
587
+ program.name("bon").description("Bonnard semantic layer CLI").version(version);
532
588
  program.command("init").description("Create a new Bonnard project in the current directory").action(initCommand);
533
589
  program.command("login").description("Authenticate with Bonnard via your browser").action(loginCommand);
534
590
  program.command("logout").description("Remove stored credentials").action(logoutCommand);
@@ -539,6 +595,7 @@ datasource.command("test").description("Test data source connectivity").argument
539
595
  datasource.command("remove").description("Remove a data source").argument("<name>", "Data source name").action(datasourceRemoveCommand);
540
596
  program.command("query").description("Run a SQL query against a warehouse").argument("<datasource-name>", "Data source name").argument("<sql>", "SQL query to execute").option("--schema <schema>", "Override schema").option("--database <database>", "Override database").option("--limit <limit>", "Max rows to return", "1000").option("--format <format>", "Output format: toon or json", "toon").action(queryCommand);
541
597
  program.command("validate").description("Validate Cube model and view YAML files").action(validateCommand);
598
+ program.command("deploy").description("Deploy models to your Bonnard Cube instance").action(deployCommand);
542
599
  program.parse();
543
600
 
544
601
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonnard/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "bon": "./dist/bin/bon.mjs"
@@ -8,11 +8,6 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
- "scripts": {
12
- "build": "tsdown src/bin/bon.ts --format esm --out-dir dist/bin",
13
- "dev": "tsdown src/bin/bon.ts --format esm --out-dir dist/bin --watch",
14
- "test": "vitest run"
15
- },
16
11
  "dependencies": {
17
12
  "@inquirer/prompts": "^7.0.0",
18
13
  "@toon-format/toon": "^2.1.0",
@@ -28,5 +23,10 @@
28
23
  },
29
24
  "engines": {
30
25
  "node": ">=20.0.0"
26
+ },
27
+ "scripts": {
28
+ "build": "tsdown src/bin/bon.ts --format esm --out-dir dist/bin",
29
+ "dev": "tsdown src/bin/bon.ts --format esm --out-dir dist/bin --watch",
30
+ "test": "vitest run"
31
31
  }
32
- }
32
+ }