@bigbongo/cli 3.0.1 → 3.1.0

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/README.md CHANGED
@@ -34,7 +34,7 @@ approve, and you're in. Your session lasts 7 days; run `bigbongo login` again to
34
34
  ### 2. Clone your app
35
35
 
36
36
  ```bash
37
- bigbongo clone # pick from your apps
37
+ bigbongo clone # pick your organization, then your app
38
38
  bigbongo clone my-app # or name one directly
39
39
  ```
40
40
 
@@ -70,15 +70,17 @@ bigbongo logs # recent logs from your running app
70
70
  | command | what it does |
71
71
  |---|---|
72
72
  | `bigbongo login` | Sign in with your BigBongo account. |
73
- | `bigbongo clone [app]` | Clone your app and set up git access. Name an app, or omit it to pick from a list. |
73
+ | `bigbongo clone [app]` | Clone your app and set up git access. Name an app, or omit it to pick your organization, then the app. |
74
74
  | `bigbongo status` | Show what's live (version, commit, URL) and any deploy in progress. |
75
- | `bigbongo logs` | Show recent runtime logs. Options: `--lines <n>` (default 100), `--search <text>`, `--level <error\|warn\|info>`. |
75
+ | `bigbongo logs` | Show recent runtime logs, newest first. Options: `--lines <n>` (default 50, max 500), `--search <text>`, `--level <error\|warn\|info>`. |
76
76
  | `bigbongo logout` | Sign out and clear your local session. |
77
77
 
78
78
  Run `bigbongo <command> --help` for details on any command.
79
79
 
80
- If you belong to more than one organization, `bigbongo clone` simply lists the apps from all
81
- of them so you can pick - there's nothing extra to set up.
80
+ If you belong to more than one organization, `bigbongo clone` asks which organization first,
81
+ then shows just that org's apps (pick `← Back to organizations` to switch). Only organizations
82
+ that actually have apps are listed, and if all your apps are in one org that step is skipped -
83
+ there's nothing extra to set up.
82
84
 
83
85
  ## How access works
84
86
 
@@ -12,6 +12,30 @@ function requireAuth() {
12
12
  }
13
13
  return c;
14
14
  }
15
+ function groupByOrg(apps) {
16
+ const byOrg = new Map();
17
+ for (const a of apps) {
18
+ const id = String(a.org_id ?? "");
19
+ let g = byOrg.get(id);
20
+ if (!g) {
21
+ g = { id, name: a.organization_name || id || "(unknown organization)", apps: [] };
22
+ byOrg.set(id, g);
23
+ }
24
+ g.apps.push(a);
25
+ }
26
+ return [...byOrg.values()].sort((x, y) => x.name.localeCompare(y.name));
27
+ }
28
+ const BACK = Symbol("back");
29
+ async function pickApp(group, allowBack) {
30
+ const choices = group.apps.map((a) => ({
31
+ name: `${a.title} (${a.app_slug})`,
32
+ value: a,
33
+ }));
34
+ if (allowBack)
35
+ choices.push({ name: "← Back to organizations", value: BACK });
36
+ const picked = await pickOne(`Pick an app to clone in ${group.name}`, choices);
37
+ return picked === BACK ? undefined : picked;
38
+ }
15
39
  export async function clone(appArg) {
16
40
  const cred = requireAuth();
17
41
  const { apps } = await api.listApps();
@@ -30,11 +54,26 @@ export async function clone(appArg) {
30
54
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
31
55
  console.error("Pass an app slug: `bigbongo clone <app>` (the picker needs a terminal).");
32
56
  console.error("Your apps:");
33
- for (const a of apps)
34
- console.error(` ${a.app_slug}`);
57
+ for (const g of groupByOrg(apps)) {
58
+ console.error(` ${g.name}:`);
59
+ for (const a of g.apps)
60
+ console.error(` ${a.app_slug}`);
61
+ }
35
62
  process.exit(1);
36
63
  }
37
- app = await pickOne("Pick an app to clone", apps.map((a) => ({ name: `${a.title} (${a.app_slug})`, value: a })));
64
+ const orgs = groupByOrg(apps);
65
+ if (orgs.length === 1) {
66
+ app = await pickApp(orgs[0], false);
67
+ }
68
+ else {
69
+ while (!app) {
70
+ const org = await pickOne("Pick an organization", orgs.map((o) => ({
71
+ name: `${o.name} (${o.apps.length} app${o.apps.length === 1 ? "" : "s"})`,
72
+ value: o,
73
+ })));
74
+ app = await pickApp(org, true);
75
+ }
76
+ }
38
77
  }
39
78
  if (!isSafeAppSlug(app.app_slug)) {
40
79
  console.error(`Refusing to clone: unexpected app slug '${app.app_slug}'.`);
@@ -17,17 +17,14 @@ function fmtTs(ms) {
17
17
  }
18
18
  export async function logs(opts = {}) {
19
19
  const cfg = requireProject();
20
- const lines = opts.lines ? parseInt(opts.lines, 10) : undefined;
21
- const { events } = await api.logs(cfg.app_id, {
22
- lines: lines && !isNaN(lines) ? lines : undefined,
23
- search: opts.search,
24
- level: opts.level,
25
- });
20
+ const parsed = opts.lines ? parseInt(opts.lines, 10) : NaN;
21
+ const lines = isNaN(parsed) ? undefined : Math.min(Math.max(parsed, 1), 500);
22
+ const { events } = await api.logs(cfg.app_id, { lines, search: opts.search, level: opts.level });
26
23
  if (!events?.length) {
27
24
  console.log("No logs yet.");
28
25
  return;
29
26
  }
30
- for (const e of events) {
27
+ for (const e of [...events].reverse()) {
31
28
  const tag = LEVEL_TAG[e.level] ?? (e.level ? String(e.level).toUpperCase().slice(0, 3) : " ");
32
29
  console.log(`${fmtTs(e.timestamp)} ${tag} ${e.message}`);
33
30
  }
@@ -22,6 +22,8 @@ export async function status() {
22
22
  const b = s.latest_build;
23
23
  if (b) {
24
24
  let line = ` Build: ${b.source_type} ${b.status}`;
25
+ if (b.git_sha)
26
+ line += ` (${String(b.git_sha).slice(0, 7)})`;
25
27
  if (b.deployment_status)
26
28
  line += ` (deploy: ${b.deployment_status})`;
27
29
  console.log(line);
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ program.command("login").description("Authenticate against BigBongo").option("--
12
12
  program.command("clone [app]").description("Clone your app's repo (BigBongo brokers GitHub access)").action(clone);
13
13
  program.command("status").description("Show app + deployment status").action(status);
14
14
  program.command("logs").description("Show app runtime logs")
15
- .option("--lines <n>", "number of log lines (default 100)")
15
+ .option("--lines <n>", "number of log lines (default 50, max 500)")
16
16
  .option("--search <text>", "filter to lines containing text")
17
17
  .option("--level <level>", "filter by level: error | warn | info")
18
18
  .action(logs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbongo/cli",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "BigBongo CLI - edit your BigBongo app locally and git push to deploy.",
5
5
  "type": "module",
6
6
  "bin": {