@bigbongo/cli 2.4.1 → 3.0.1
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 +93 -0
- package/dist/api.js +37 -130
- package/dist/commands/clone.js +37 -181
- package/dist/commands/context.js +14 -0
- package/dist/commands/gitToken.js +45 -0
- package/dist/commands/login.js +34 -92
- package/dist/commands/logout.js +13 -0
- package/dist/commands/logs.js +31 -30
- package/dist/commands/status.js +29 -51
- package/dist/config.js +66 -93
- package/dist/git.js +26 -0
- package/dist/index.js +26 -134
- package/dist/prompt.js +25 -0
- package/dist/util.js +55 -0
- package/package.json +25 -15
- package/dist/api.d.ts +0 -86
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js.map +0 -1
- package/dist/commands/clone.d.ts +0 -13
- package/dist/commands/clone.d.ts.map +0 -1
- package/dist/commands/clone.js.map +0 -1
- package/dist/commands/deploy.d.ts +0 -8
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js +0 -277
- package/dist/commands/deploy.js.map +0 -1
- package/dist/commands/init.d.ts +0 -2
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -88
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/login.d.ts +0 -7
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logs.d.ts +0 -2
- package/dist/commands/logs.d.ts.map +0 -1
- package/dist/commands/logs.js.map +0 -1
- package/dist/commands/pull.d.ts +0 -22
- package/dist/commands/pull.d.ts.map +0 -1
- package/dist/commands/pull.js +0 -166
- package/dist/commands/pull.js.map +0 -1
- package/dist/commands/rollback.d.ts +0 -6
- package/dist/commands/rollback.d.ts.map +0 -1
- package/dist/commands/rollback.js +0 -55
- package/dist/commands/rollback.js.map +0 -1
- package/dist/commands/status.d.ts +0 -2
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js.map +0 -1
- package/dist/config.d.ts +0 -32
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @bigbongo/cli
|
|
2
|
+
|
|
3
|
+
Edit your BigBongo app on your own machine and `git push` to deploy it.
|
|
4
|
+
|
|
5
|
+
You sign in with your **BigBongo** account - not GitHub. BigBongo handles GitHub access for
|
|
6
|
+
you, so you never need a GitHub account. Once you've cloned your app it's all plain git:
|
|
7
|
+
`git commit` + `git push` is the deploy.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- **Node.js 18+**
|
|
12
|
+
- **git** installed and on your PATH
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @bigbongo/cli
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
This gives you the `bigbongo` command.
|
|
21
|
+
|
|
22
|
+
## How to use
|
|
23
|
+
|
|
24
|
+
### 1. Sign in
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bigbongo login
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Your browser opens to a BigBongo approval page showing a short code. Check the code matches,
|
|
31
|
+
approve, and you're in. Your session lasts 7 days; run `bigbongo login` again to refresh it or
|
|
32
|
+
`bigbongo logout` to sign out.
|
|
33
|
+
|
|
34
|
+
### 2. Clone your app
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bigbongo clone # pick from your apps
|
|
38
|
+
bigbongo clone my-app # or name one directly
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This clones your app into `./my-app` and sets everything up so plain git just works - no
|
|
42
|
+
tokens or GitHub setup to worry about.
|
|
43
|
+
|
|
44
|
+
### 3. Edit and deploy
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
cd my-app
|
|
48
|
+
# ...make your changes...
|
|
49
|
+
git add -A
|
|
50
|
+
git commit -m "Update the homepage"
|
|
51
|
+
git push # this deploys
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Deploys come from the **`main`** branch: every push to `main` is deployed as your app's new
|
|
55
|
+
live version. After `bigbongo clone` you're already on `main`, so a plain `git push` deploys.
|
|
56
|
+
If you prefer to work on a separate branch, merge it into `main` and push to deploy.
|
|
57
|
+
|
|
58
|
+
There's no separate deploy step - pushing to `main` is the deploy. `git pull` and other git
|
|
59
|
+
commands work normally too.
|
|
60
|
+
|
|
61
|
+
### 4. Check on it
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
bigbongo status # what's live, and whether a deploy is still in progress
|
|
65
|
+
bigbongo logs # recent logs from your running app
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Commands
|
|
69
|
+
|
|
70
|
+
| command | what it does |
|
|
71
|
+
|---|---|
|
|
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. |
|
|
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>`. |
|
|
76
|
+
| `bigbongo logout` | Sign out and clear your local session. |
|
|
77
|
+
|
|
78
|
+
Run `bigbongo <command> --help` for details on any command.
|
|
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.
|
|
82
|
+
|
|
83
|
+
## How access works
|
|
84
|
+
|
|
85
|
+
You never handle a GitHub credential yourself. When git needs access, BigBongo issues a
|
|
86
|
+
short-lived, single-repo token behind the scenes - read access for cloning and pulling, write
|
|
87
|
+
access for pushing. Your deploys are attributed to you: commits are authored with your
|
|
88
|
+
BigBongo email, and only pushes from a member of the app's organization are deployed. (If you
|
|
89
|
+
ever commit with a different email, set it back to your BigBongo email or re-clone.)
|
|
90
|
+
|
|
91
|
+
## Support
|
|
92
|
+
|
|
93
|
+
Questions or problems? Contact your BigBongo administrator.
|
package/dist/api.js
CHANGED
|
@@ -1,133 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.createDeployment = createDeployment;
|
|
11
|
-
exports.getDeployment = getDeployment;
|
|
12
|
-
exports.rollbackViaBigBongo = rollbackViaBigBongo;
|
|
13
|
-
exports.listReleases = listReleases;
|
|
14
|
-
exports.getRepoHead = getRepoHead;
|
|
15
|
-
exports.getRepoSnapshot = getRepoSnapshot;
|
|
16
|
-
const config_1 = require("./config");
|
|
17
|
-
class ApiError extends Error {
|
|
18
|
-
statusCode;
|
|
19
|
-
constructor(statusCode, message) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.statusCode = statusCode;
|
|
22
|
-
this.name = 'ApiError';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.ApiError = ApiError;
|
|
26
|
-
async function request(method, path, body) {
|
|
27
|
-
const creds = (0, config_1.loadCredentials)();
|
|
28
|
-
if (!creds) {
|
|
29
|
-
throw new Error('Not authenticated. Run `bigbongo login` first.');
|
|
30
|
-
}
|
|
31
|
-
const url = `${(0, config_1.getApiUrl)()}${path}`;
|
|
32
|
-
const headers = {
|
|
33
|
-
'Authorization': `Bearer ${creds.token}`,
|
|
34
|
-
'Content-Type': 'application/json',
|
|
35
|
-
};
|
|
36
|
-
const response = await fetch(url, {
|
|
37
|
-
method,
|
|
38
|
-
headers,
|
|
39
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
40
|
-
});
|
|
41
|
-
if (!response.ok) {
|
|
42
|
-
let errorMessage;
|
|
43
|
-
try {
|
|
44
|
-
const errorData = await response.json();
|
|
45
|
-
errorMessage = errorData.error || response.statusText;
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
errorMessage = response.statusText;
|
|
49
|
-
}
|
|
50
|
-
throw new ApiError(response.status, errorMessage);
|
|
51
|
-
}
|
|
52
|
-
return response.json();
|
|
53
|
-
}
|
|
54
|
-
async function verifyToken() {
|
|
55
|
-
return request('POST', '/api/auth/verify');
|
|
56
|
-
}
|
|
57
|
-
async function getStatus(slug) {
|
|
58
|
-
return request('GET', `/api/status/${slug}`);
|
|
59
|
-
}
|
|
60
|
-
async function getLogs(slug) {
|
|
61
|
-
return request('GET', `/api/logs/${slug}`);
|
|
62
|
-
}
|
|
63
|
-
async function rollback(slug) {
|
|
64
|
-
return request('POST', `/api/rollback/${slug}`);
|
|
65
|
-
}
|
|
66
|
-
// BigBongo main app API calls
|
|
67
|
-
async function bigbongoRequest(method, path, body) {
|
|
68
|
-
const creds = (0, config_1.loadCredentials)();
|
|
69
|
-
if (!creds) {
|
|
70
|
-
throw new Error('Not authenticated. Run `bigbongo login` first.');
|
|
71
|
-
}
|
|
72
|
-
const url = `${(0, config_1.getBigBongoUrl)()}${path}`;
|
|
73
|
-
const response = await fetch(url, {
|
|
74
|
-
method,
|
|
1
|
+
import { loadCredentials } from "./config.js";
|
|
2
|
+
export function apiBase() {
|
|
3
|
+
const c = loadCredentials();
|
|
4
|
+
return process.env.BIGBONGO_API_URL || c?.apiUrl || "https://app.bigbongo.ai";
|
|
5
|
+
}
|
|
6
|
+
async function req(path, init = {}, base) {
|
|
7
|
+
const c = loadCredentials();
|
|
8
|
+
const res = await fetch((base || apiBase()) + path, {
|
|
9
|
+
...init,
|
|
75
10
|
headers: {
|
|
76
|
-
|
|
77
|
-
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
...(c?.token ? { Authorization: `Bearer ${c.token}` } : {}),
|
|
13
|
+
...(init.headers || {}),
|
|
78
14
|
},
|
|
79
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
80
15
|
});
|
|
81
|
-
if (!
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function createDeployment(params) {
|
|
107
|
-
return bigbongoRequest('POST', '/api/cli/deployments/', params);
|
|
108
|
-
}
|
|
109
|
-
async function getDeployment(deploymentId) {
|
|
110
|
-
return bigbongoRequest('GET', `/api/cli/deployments/${deploymentId}`);
|
|
111
|
-
}
|
|
112
|
-
// v2 — Django-orchestrated rollback. Selects target Release (previous if not
|
|
113
|
-
// specified), creates a Deployment(pending), calls the platform to redeploy,
|
|
114
|
-
// marks Deployment live on success.
|
|
115
|
-
async function rollbackViaBigBongo(params) {
|
|
116
|
-
return bigbongoRequest('POST', '/api/cli/rollback/', params);
|
|
117
|
-
}
|
|
118
|
-
async function listReleases(appId) {
|
|
119
|
-
return bigbongoRequest('GET', `/api/cli/releases/?bigbongo_app_id=${appId}`);
|
|
120
|
-
}
|
|
121
|
-
// 108-build-path-sync: read current platform-side HEAD for the given app.
|
|
122
|
-
// Used by `bigbongo deploy` pre-flight to detect drift since last pull/deploy.
|
|
123
|
-
async function getRepoHead(slug) {
|
|
124
|
-
return request('GET', `/api/git/${encodeURIComponent(slug)}/head`);
|
|
125
|
-
}
|
|
126
|
-
// 108-build-path-sync: full snapshot of the repo at the given SHA (or HEAD).
|
|
127
|
-
// Used by `bigbongo pull` to materialize current code into the local
|
|
128
|
-
// working directory.
|
|
129
|
-
async function getRepoSnapshot(slug, sha) {
|
|
130
|
-
const qs = sha ? `?sha=${encodeURIComponent(sha)}` : '';
|
|
131
|
-
return request('GET', `/api/git/${encodeURIComponent(slug)}/snapshot${qs}`);
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=api.js.map
|
|
16
|
+
if (!res.ok)
|
|
17
|
+
throw new Error(`${res.status} ${res.statusText} on ${path}`);
|
|
18
|
+
const t = await res.text();
|
|
19
|
+
return t ? JSON.parse(t) : {};
|
|
20
|
+
}
|
|
21
|
+
export const api = {
|
|
22
|
+
createSession: (base) => req("/api/cli/auth/session", { method: "POST" }, base),
|
|
23
|
+
pollSession: (code, base) => req(`/api/cli/auth/poll/${code}`, {}, base),
|
|
24
|
+
listOrgs: () => req("/api/cli/orgs/"),
|
|
25
|
+
listApps: (orgId) => req(`/api/cli/apps/${orgId ? `?organization=${orgId}` : ""}`),
|
|
26
|
+
gitToken: (appId, mode = "write") => req(`/api/cli/apps/${appId}/git-token`, { method: "POST", body: JSON.stringify({ mode }) }),
|
|
27
|
+
status: (appId) => req(`/api/cli/apps/${appId}/status`),
|
|
28
|
+
logs: (appId, opts = {}) => {
|
|
29
|
+
const qs = new URLSearchParams();
|
|
30
|
+
if (opts.lines)
|
|
31
|
+
qs.set("lines", String(opts.lines));
|
|
32
|
+
if (opts.search)
|
|
33
|
+
qs.set("search", opts.search);
|
|
34
|
+
if (opts.level)
|
|
35
|
+
qs.set("level", opts.level);
|
|
36
|
+
const q = qs.toString();
|
|
37
|
+
return req(`/api/cli/apps/${appId}/logs${q ? `?${q}` : ""}`);
|
|
38
|
+
},
|
|
39
|
+
logout: () => req("/api/cli/auth/logout", { method: "POST" }),
|
|
40
|
+
};
|
package/dist/commands/clone.js
CHANGED
|
@@ -1,193 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.cloneCommand = cloneCommand;
|
|
40
|
-
const fs = __importStar(require("fs"));
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
|
-
const select_1 = __importDefault(require("@inquirer/select"));
|
|
43
|
-
const config_1 = require("../config");
|
|
44
|
-
const api_1 = require("../api");
|
|
45
|
-
/**
|
|
46
|
-
* `bigbongo clone [slug]` — bootstrap a fresh local folder from a deployed app
|
|
47
|
-
* on the platform. Unlike `pull`, no `.bigbongo.json` is required upfront; this
|
|
48
|
-
* command creates one. Use case: lost-laptop recovery, new dev onboarding, or
|
|
49
|
-
* any situation where you know the slug (or can pick from a list) but don't
|
|
50
|
-
* have the code locally.
|
|
51
|
-
*/
|
|
52
|
-
async function cloneCommand(slugArg, options) {
|
|
53
|
-
const creds = (0, config_1.loadCredentials)();
|
|
54
|
-
if (!creds) {
|
|
55
|
-
console.error('✗ Not authenticated. Run `bigbongo login` first.');
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { loadCredentials, saveProject } from "../config.js";
|
|
4
|
+
import { cloneApp } from "../git.js";
|
|
5
|
+
import { pickOne } from "../prompt.js";
|
|
6
|
+
import { isSafeAppSlug } from "../util.js";
|
|
7
|
+
function requireAuth() {
|
|
8
|
+
const c = loadCredentials();
|
|
9
|
+
if (!c?.token) {
|
|
10
|
+
console.error("Not authenticated. Run `bigbongo login` first.");
|
|
56
11
|
process.exit(1);
|
|
57
12
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
13
|
+
return c;
|
|
14
|
+
}
|
|
15
|
+
export async function clone(appArg) {
|
|
16
|
+
const cred = requireAuth();
|
|
17
|
+
const { apps } = await api.listApps();
|
|
18
|
+
if (!apps?.length) {
|
|
19
|
+
console.error("No apps found for your account.");
|
|
63
20
|
process.exit(1);
|
|
64
21
|
}
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!match) {
|
|
72
|
-
console.error(`✗ No app with slug "${slugArg}" found in any of your organizations.`);
|
|
22
|
+
let app = appArg
|
|
23
|
+
? apps.find((a) => a.app_slug === appArg || a.id === appArg)
|
|
24
|
+
: undefined;
|
|
25
|
+
if (!app) {
|
|
26
|
+
if (appArg) {
|
|
27
|
+
console.error(`No app matching '${appArg}'.`);
|
|
73
28
|
process.exit(1);
|
|
74
29
|
}
|
|
75
|
-
|
|
76
|
-
slug:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
chosen = await pickAppInteractively();
|
|
84
|
-
}
|
|
85
|
-
// Resolve output dir. Default: ./<slug>.
|
|
86
|
-
const outputDir = path.resolve(options.output || `./${chosen.slug}`);
|
|
87
|
-
// Refuse non-empty existing dir (no merging — user picks fresh).
|
|
88
|
-
if (fs.existsSync(outputDir)) {
|
|
89
|
-
const entries = fs.readdirSync(outputDir);
|
|
90
|
-
if (entries.length > 0) {
|
|
91
|
-
console.error(`✗ Target directory is not empty: ${outputDir}`);
|
|
92
|
-
console.error(' Pick a new folder or pass --output <dir>.');
|
|
30
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
31
|
+
console.error("Pass an app slug: `bigbongo clone <app>` (the picker needs a terminal).");
|
|
32
|
+
console.error("Your apps:");
|
|
33
|
+
for (const a of apps)
|
|
34
|
+
console.error(` ${a.app_slug}`);
|
|
93
35
|
process.exit(1);
|
|
94
36
|
}
|
|
37
|
+
app = await pickOne("Pick an app to clone", apps.map((a) => ({ name: `${a.title} (${a.app_slug})`, value: a })));
|
|
95
38
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
console.log(`⠋ Fetching snapshot for ${chosen.slug}...`);
|
|
100
|
-
let snapshot;
|
|
101
|
-
try {
|
|
102
|
-
snapshot = await (0, api_1.getRepoSnapshot)(chosen.slug);
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
if (err instanceof api_1.ApiError && err.statusCode === 404) {
|
|
106
|
-
console.error(`✗ No code on the platform for "${chosen.slug}" yet.`);
|
|
107
|
-
console.error(' This app has never been deployed. Nothing to clone.');
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
console.error(`✗ Failed to fetch snapshot: ${err.message}`);
|
|
39
|
+
if (!isSafeAppSlug(app.app_slug)) {
|
|
40
|
+
console.error(`Refusing to clone: unexpected app slug '${app.app_slug}'.`);
|
|
111
41
|
process.exit(1);
|
|
112
42
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// Write .bigbongo.json matching the format `init` produces, so future
|
|
120
|
-
// `pull` / `deploy` / `status` / `logs` / `rollback` all work in this dir.
|
|
121
|
-
const configPath = path.join(outputDir, '.bigbongo.json');
|
|
122
|
-
fs.writeFileSync(configPath, JSON.stringify({
|
|
123
|
-
schema_version: 2,
|
|
124
|
-
bigbongo_app_id: chosen.app_id,
|
|
125
|
-
org_id: chosen.org_id,
|
|
126
|
-
default_env: 'prod',
|
|
127
|
-
app_title: chosen.title,
|
|
128
|
-
app_slug: chosen.slug,
|
|
129
|
-
last_known_sha: snapshot.sha,
|
|
130
|
-
}, null, 2));
|
|
131
|
-
console.log(`✓ Wrote ${snapshot.files.length} file(s) to ${outputDir}`);
|
|
132
|
-
console.log(`✓ Created ${path.relative(process.cwd(), configPath)}`);
|
|
133
|
-
console.log('');
|
|
134
|
-
console.log(`Tip: cd ${path.relative(process.cwd(), outputDir) || '.'} && git init && git add -A && git commit -m 'initial'`);
|
|
135
|
-
}
|
|
136
|
-
async function pickAppInteractively() {
|
|
137
|
-
// Step 1: pick org (skip prompt when there's only one — same UX as `init`).
|
|
138
|
-
const { organizations } = await (0, api_1.listOrgs)();
|
|
139
|
-
if (organizations.length === 0) {
|
|
140
|
-
console.error('✗ No organizations found for your account.');
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
let orgId;
|
|
144
|
-
let orgName;
|
|
145
|
-
if (organizations.length === 1) {
|
|
146
|
-
orgId = organizations[0].id;
|
|
147
|
-
orgName = organizations[0].name;
|
|
148
|
-
console.log(`✓ Organization: ${orgName}`);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
orgId = await (0, select_1.default)({
|
|
152
|
-
message: 'Select organization:',
|
|
153
|
-
choices: organizations.map((o) => ({ name: o.name, value: o.id })),
|
|
154
|
-
});
|
|
155
|
-
orgName = organizations.find((o) => o.id === orgId).name;
|
|
156
|
-
}
|
|
157
|
-
// Step 2: list apps in that org and keep only the ones with at least one
|
|
158
|
-
// Release on the platform. Apps that have been `init`d but never deployed
|
|
159
|
-
// have no code to clone (snapshot endpoint would 404).
|
|
160
|
-
const { apps } = await (0, api_1.listApps)(orgId);
|
|
161
|
-
const deployable = apps.filter((a) => (a.release_count ?? 0) > 0 && a.app_slug);
|
|
162
|
-
if (deployable.length === 0) {
|
|
163
|
-
console.error(`✗ No deployed apps found in ${orgName}.`);
|
|
164
|
-
console.error(' Deploy an app first with `bigbongo init && bigbongo deploy`.');
|
|
165
|
-
process.exit(1);
|
|
166
|
-
}
|
|
167
|
-
const pickedSlug = await (0, select_1.default)({
|
|
168
|
-
message: 'Select an app to clone:',
|
|
169
|
-
choices: deployable.map((a) => ({
|
|
170
|
-
name: `${a.title} (${a.app_slug})`,
|
|
171
|
-
value: a.app_slug,
|
|
172
|
-
description: a.description || undefined,
|
|
173
|
-
})),
|
|
174
|
-
});
|
|
175
|
-
const picked = deployable.find((a) => a.app_slug === pickedSlug);
|
|
176
|
-
return {
|
|
177
|
-
slug: picked.app_slug,
|
|
178
|
-
app_id: picked.id,
|
|
179
|
-
org_id: picked.org_id,
|
|
180
|
-
title: picked.title,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function shortSha(sha) {
|
|
184
|
-
return sha.length > 7 ? sha.slice(0, 7) : sha;
|
|
185
|
-
}
|
|
186
|
-
function formatBytes(n) {
|
|
187
|
-
if (n < 1024)
|
|
188
|
-
return `${n}B`;
|
|
189
|
-
if (n < 1024 * 1024)
|
|
190
|
-
return `${(n / 1024).toFixed(1)}KB`;
|
|
191
|
-
return `${(n / (1024 * 1024)).toFixed(2)}MB`;
|
|
43
|
+
const { token, repo_url } = await api.gitToken(app.id, "read");
|
|
44
|
+
const dir = join(process.cwd(), app.app_slug);
|
|
45
|
+
await cloneApp(repo_url, token, dir, { name: cred.email, email: cred.email });
|
|
46
|
+
saveProject({ app_id: app.id, org_id: app.org_id, app_slug: app.app_slug, repo_url }, dir);
|
|
47
|
+
console.log(`\nCloned ${app.app_slug} into ./${app.app_slug}`);
|
|
48
|
+
console.log("Edit, commit, and 'git push' to deploy.\n");
|
|
192
49
|
}
|
|
193
|
-
//# sourceMappingURL=clone.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { loadCredentials, findProjectUp } from "../config.js";
|
|
2
|
+
export function requireProject() {
|
|
3
|
+
const cred = loadCredentials();
|
|
4
|
+
if (!cred?.token) {
|
|
5
|
+
console.error("Not authenticated. Run `bigbongo login` first.");
|
|
6
|
+
process.exit(1);
|
|
7
|
+
}
|
|
8
|
+
const cfg = findProjectUp();
|
|
9
|
+
if (!cfg) {
|
|
10
|
+
console.error("Not in a BigBongo app directory (no .bigbongo.json). cd into your app folder, or run `bigbongo clone <app>` first.");
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
return cfg;
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { api } from "../api.js";
|
|
2
|
+
import { clearCachedGitToken, findProjectUp, loadCachedGitToken, saveCachedGitToken } from "../config.js";
|
|
3
|
+
import { isGitHubHttpsRequest, parseGitCredential, readStdin } from "../util.js";
|
|
4
|
+
export async function gitToken(app, opts) {
|
|
5
|
+
if (opts.helper) {
|
|
6
|
+
const op = app;
|
|
7
|
+
if (op === "erase") {
|
|
8
|
+
const proj = findProjectUp(process.cwd());
|
|
9
|
+
if (proj)
|
|
10
|
+
clearCachedGitToken(proj.app_id);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (op !== "get")
|
|
14
|
+
return;
|
|
15
|
+
const request = parseGitCredential(await readStdin());
|
|
16
|
+
if (!isGitHubHttpsRequest(request))
|
|
17
|
+
return;
|
|
18
|
+
const proj = findProjectUp(process.cwd());
|
|
19
|
+
if (!proj)
|
|
20
|
+
process.exit(1);
|
|
21
|
+
const cached = loadCachedGitToken(proj.app_id);
|
|
22
|
+
if (cached) {
|
|
23
|
+
process.stdout.write(`username=x-access-token\npassword=${cached}\n`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const { token, expires_at } = await api.gitToken(proj.app_id, "write");
|
|
28
|
+
if (expires_at)
|
|
29
|
+
saveCachedGitToken(proj.app_id, token, expires_at);
|
|
30
|
+
process.stdout.write(`username=x-access-token\npassword=${token}\n`);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const proj = findProjectUp(process.cwd());
|
|
38
|
+
const appId = app || proj?.app_id;
|
|
39
|
+
if (!appId) {
|
|
40
|
+
console.error("No app. Run inside a cloned app, or pass an app id.");
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
const { token } = await api.gitToken(appId, "write");
|
|
44
|
+
console.log(token);
|
|
45
|
+
}
|