@tinybirdco/sdk 0.0.28 → 0.0.30

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.
package/src/cli/index.ts CHANGED
@@ -27,6 +27,8 @@ import {
27
27
  runBranchDelete,
28
28
  } from "./commands/branch.js";
29
29
  import { runClear } from "./commands/clear.js";
30
+ import { runInfo } from "./commands/info.js";
31
+ import { runOpenDashboard, type Environment } from "./commands/open-dashboard.js";
30
32
  import {
31
33
  detectPackageManagerInstallCmd,
32
34
  detectPackageManagerRunCmd,
@@ -170,6 +172,74 @@ function createCli(): Command {
170
172
  }
171
173
  });
172
174
 
175
+ // Info command
176
+ program
177
+ .command("info")
178
+ .description("Show information about the current project and workspace")
179
+ .option("--json", "Output as JSON")
180
+ .action(async (options) => {
181
+ const result = await runInfo({ json: options.json });
182
+
183
+ if (!result.success) {
184
+ console.error(`Error: ${result.error}`);
185
+ process.exit(1);
186
+ }
187
+
188
+ if (options.json) {
189
+ // JSON output
190
+ const jsonOutput = {
191
+ cloud: result.cloud,
192
+ local: result.local,
193
+ branch: result.branch,
194
+ project: result.project,
195
+ branches: result.branches,
196
+ };
197
+ console.log(JSON.stringify(jsonOutput, null, 2));
198
+ } else {
199
+ // Human-readable output
200
+ output.showInfo({
201
+ cloud: result.cloud,
202
+ local: result.local,
203
+ branch: result.branch,
204
+ project: result.project,
205
+ });
206
+ }
207
+ });
208
+
209
+ // Open command
210
+ program
211
+ .command("open")
212
+ .description("Open the Tinybird dashboard in the default browser")
213
+ .option(
214
+ "-e, --env <env>",
215
+ "Which environment to open: 'cloud', 'local', or 'branch'"
216
+ )
217
+ .action(async (options) => {
218
+ const validEnvs = ["cloud", "local", "branch"];
219
+ if (options.env && !validEnvs.includes(options.env)) {
220
+ console.error(
221
+ `Error: Invalid environment '${options.env}'. Use one of: ${validEnvs.join(", ")}`
222
+ );
223
+ process.exit(1);
224
+ }
225
+
226
+ const result = await runOpenDashboard({
227
+ environment: options.env as Environment | undefined,
228
+ });
229
+
230
+ if (!result.success) {
231
+ console.error(`Error: ${result.error}`);
232
+ process.exit(1);
233
+ }
234
+
235
+ console.log(`Opening ${result.environment} dashboard...`);
236
+ if (result.browserOpened) {
237
+ console.log(`Dashboard: ${result.url}`);
238
+ } else {
239
+ console.log(`Could not open browser. Please visit: ${result.url}`);
240
+ }
241
+ });
242
+
173
243
  // Build command
174
244
  program
175
245
  .command("build")
package/src/cli/output.ts CHANGED
@@ -292,6 +292,116 @@ export function showBranchInfo(info: BranchDisplayInfo): void {
292
292
  console.log("");
293
293
  }
294
294
 
295
+ /**
296
+ * Info display data
297
+ */
298
+ export interface InfoDisplayData {
299
+ cloud?: {
300
+ workspaceName: string;
301
+ workspaceId: string;
302
+ userEmail: string;
303
+ apiHost: string;
304
+ dashboardUrl?: string;
305
+ token: string;
306
+ };
307
+ local?: {
308
+ running: boolean;
309
+ workspaceName?: string;
310
+ workspaceId?: string;
311
+ apiHost: string;
312
+ dashboardUrl?: string;
313
+ token?: string;
314
+ };
315
+ project?: {
316
+ cwd: string;
317
+ configPath: string;
318
+ devMode: string;
319
+ gitBranch: string | null;
320
+ tinybirdBranch: string | null;
321
+ isMainBranch: boolean;
322
+ };
323
+ branch?: {
324
+ name: string;
325
+ id: string;
326
+ token: string;
327
+ dashboardUrl?: string;
328
+ };
329
+ }
330
+
331
+ /**
332
+ * Show project and workspace info
333
+ */
334
+ export function showInfo(data: InfoDisplayData): void {
335
+ // Cloud section
336
+ if (data.cloud) {
337
+ highlight("» Workspace:");
338
+ console.log(` Name: ${data.cloud.workspaceName}`);
339
+ console.log(` ID: ${data.cloud.workspaceId}`);
340
+ console.log(` User: ${data.cloud.userEmail}`);
341
+ console.log(` API: ${data.cloud.apiHost}`);
342
+ if (data.cloud.dashboardUrl) {
343
+ console.log(` Dashboard: ${data.cloud.dashboardUrl}`);
344
+ }
345
+ console.log(` Token: ${data.cloud.token}`);
346
+ console.log();
347
+ }
348
+
349
+ // Local section
350
+ if (data.local) {
351
+ highlight("» Local:");
352
+ if (!data.local.running) {
353
+ warning(" Tinybird local is not running.");
354
+ console.log(" Start with: docker run -d -p 7181:7181 tinybirdco/tinybird-local");
355
+ } else if (data.local.workspaceName) {
356
+ console.log(` Name: ${data.local.workspaceName}`);
357
+ console.log(` ID: ${data.local.workspaceId}`);
358
+ console.log(` API: ${data.local.apiHost}`);
359
+ if (data.local.dashboardUrl) {
360
+ console.log(` Dashboard: ${data.local.dashboardUrl}`);
361
+ }
362
+ console.log(` Token: ${data.local.token}`);
363
+ } else {
364
+ console.log(` API: ${data.local.apiHost}`);
365
+ warning(" Could not get workspace info.");
366
+ }
367
+ console.log();
368
+ }
369
+
370
+ // Branch section (current branch when working on a branch)
371
+ if (data.branch) {
372
+ highlight("» Branch:");
373
+ console.log(` Name: ${data.branch.name}`);
374
+ console.log(` ID: ${data.branch.id}`);
375
+ if (data.branch.dashboardUrl) {
376
+ console.log(` Dashboard: ${data.branch.dashboardUrl}`);
377
+ }
378
+ console.log(` Token: ${data.branch.token}`);
379
+ console.log();
380
+ } else if (data.project?.devMode === "branch") {
381
+ // Show message when in branch mode but no branch (on main or no git)
382
+ highlight("» Branch:");
383
+ if (!data.project.gitBranch) {
384
+ warning(" Git branch not detected. Switch to a git branch first.");
385
+ } else if (data.project.isMainBranch) {
386
+ warning(" On main branch. Switch to a feature branch first.");
387
+ }
388
+ console.log();
389
+ }
390
+
391
+ // Project section
392
+ if (data.project) {
393
+ highlight("» Project:");
394
+ console.log(` Directory: ${data.project.cwd}`);
395
+ console.log(` Config: ${data.project.configPath}`);
396
+ console.log(` Dev mode: ${data.project.devMode}`);
397
+ if (data.project.gitBranch) {
398
+ console.log(` Git: ${data.project.gitBranch}${data.project.isMainBranch ? " (main)" : ""}`);
399
+ }
400
+ console.log();
401
+ }
402
+
403
+ }
404
+
295
405
  /**
296
406
  * Output object containing all output functions
297
407
  */
@@ -319,4 +429,5 @@ export const output = {
319
429
  showDeploySuccess,
320
430
  showDeployFailure,
321
431
  showBranchInfo,
432
+ showInfo,
322
433
  };