@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/dist/commands/login.js
CHANGED
|
@@ -1,104 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (options.token) {
|
|
10
|
-
// Direct token login
|
|
11
|
-
(0, config_1.saveCredentials)({
|
|
12
|
-
token: options.token,
|
|
13
|
-
email: '',
|
|
14
|
-
apiUrl,
|
|
15
|
-
});
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { api } from "../api.js";
|
|
3
|
+
import { saveCredentials } from "../config.js";
|
|
4
|
+
import { openBrowser, sleep } from "../util.js";
|
|
5
|
+
export async function login(opts) {
|
|
6
|
+
const base = process.env.BIGBONGO_API_URL || "https://app.bigbongo.ai";
|
|
7
|
+
if (opts.token) {
|
|
8
|
+
saveCredentials({ token: opts.token, email: "", apiUrl: base });
|
|
16
9
|
try {
|
|
17
|
-
|
|
18
|
-
(
|
|
19
|
-
token: options.token,
|
|
20
|
-
email: result.email,
|
|
21
|
-
apiUrl,
|
|
22
|
-
});
|
|
23
|
-
console.log(`✓ Authenticated as ${result.email}`);
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error('✗ Invalid token:', error.message);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
// Check if already authenticated
|
|
32
|
-
const existing = (0, config_1.loadCredentials)();
|
|
33
|
-
if (existing) {
|
|
34
|
-
try {
|
|
35
|
-
const result = await (0, api_1.verifyToken)();
|
|
36
|
-
console.log(`Already authenticated as ${result.email}`);
|
|
37
|
-
return;
|
|
10
|
+
await api.listOrgs();
|
|
11
|
+
console.log("Logged in.");
|
|
38
12
|
}
|
|
39
13
|
catch {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
// Browser-based login flow
|
|
44
|
-
console.log('⠋ Opening browser for login...');
|
|
45
|
-
try {
|
|
46
|
-
// Create a CLI session
|
|
47
|
-
const sessionResp = await fetch(`${apiUrl}/api/auth/cli-session`, {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers: { 'Content-Type': 'application/json' },
|
|
50
|
-
});
|
|
51
|
-
const session = await sessionResp.json();
|
|
52
|
-
// Open browser
|
|
53
|
-
const url = session.url;
|
|
54
|
-
const openCmd = process.platform === 'darwin' ? 'open' :
|
|
55
|
-
process.platform === 'win32' ? 'start' : 'xdg-open';
|
|
56
|
-
(0, child_process_1.exec)(`${openCmd} "${url}"`);
|
|
57
|
-
console.log(` If browser didn't open, visit: ${url}`);
|
|
58
|
-
console.log('');
|
|
59
|
-
console.log('⠋ Waiting for login...');
|
|
60
|
-
// Poll for approval
|
|
61
|
-
const token = await pollForToken(apiUrl, session.code);
|
|
62
|
-
if (token) {
|
|
63
|
-
(0, config_1.saveCredentials)({
|
|
64
|
-
token: token.token,
|
|
65
|
-
email: token.email,
|
|
66
|
-
apiUrl,
|
|
67
|
-
});
|
|
68
|
-
console.log(`✓ Authenticated as ${token.email}`);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
console.error('✗ Login timed out. Try again or use: bigbongo login --token <token>');
|
|
14
|
+
console.error("That token was rejected.");
|
|
72
15
|
process.exit(1);
|
|
73
16
|
}
|
|
17
|
+
return;
|
|
74
18
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
for (let i = 0; i < maxAttempts; i++) {
|
|
86
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
19
|
+
const session = await api.createSession(base);
|
|
20
|
+
console.log("\n Approve this login in your browser. Confirm this code matches:\n");
|
|
21
|
+
console.log(` ${session.user_code}\n`);
|
|
22
|
+
console.log(` ${session.verification_url}\n`);
|
|
23
|
+
openBrowser(session.verification_url);
|
|
24
|
+
const spin = ora("Waiting for approval...").start();
|
|
25
|
+
const deadline = Date.now() + (session.expires_in || 900) * 1000;
|
|
26
|
+
const interval = (session.poll_interval || 5) * 1000;
|
|
27
|
+
while (Date.now() < deadline) {
|
|
28
|
+
await sleep(interval);
|
|
87
29
|
try {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
30
|
+
const r = await api.pollSession(session.code, base);
|
|
31
|
+
if (r.status === "approved") {
|
|
32
|
+
saveCredentials({ token: r.token, email: r.email || "", apiUrl: base });
|
|
33
|
+
spin.succeed(`Logged in as ${r.email || "your BigBongo account"}.`);
|
|
34
|
+
return;
|
|
92
35
|
}
|
|
93
|
-
if (data.status === 'expired') {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
// Still pending, continue polling
|
|
97
36
|
}
|
|
98
|
-
catch {
|
|
99
|
-
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (String(e?.message || "").includes("410")) {
|
|
39
|
+
spin.fail("This login expired. Run `bigbongo login` again.");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
100
42
|
}
|
|
101
43
|
}
|
|
102
|
-
|
|
44
|
+
spin.fail("Login timed out.");
|
|
45
|
+
process.exit(1);
|
|
103
46
|
}
|
|
104
|
-
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { api } from "../api.js";
|
|
2
|
+
import { clearCredentials, loadCredentials } from "../config.js";
|
|
3
|
+
export async function logout() {
|
|
4
|
+
if (loadCredentials()?.token) {
|
|
5
|
+
try {
|
|
6
|
+
await api.logout();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
clearCredentials();
|
|
12
|
+
console.log("Logged out.");
|
|
13
|
+
}
|
package/dist/commands/logs.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import { api } from "../api.js";
|
|
2
|
+
import { requireProject } from "./context.js";
|
|
3
|
+
const LEVEL_TAG = {
|
|
4
|
+
critical: "CRT",
|
|
5
|
+
error: "ERR",
|
|
6
|
+
warning: "WRN",
|
|
7
|
+
warn: "WRN",
|
|
8
|
+
info: "INF",
|
|
9
|
+
debug: "DBG",
|
|
10
|
+
log: " ",
|
|
11
|
+
};
|
|
12
|
+
function fmtTs(ms) {
|
|
13
|
+
if (!ms)
|
|
14
|
+
return " ";
|
|
15
|
+
const d = new Date(ms);
|
|
16
|
+
return isNaN(d.getTime()) ? "" : d.toISOString().replace("T", " ").slice(0, 19);
|
|
17
|
+
}
|
|
18
|
+
export async function logs(opts = {}) {
|
|
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
|
+
});
|
|
26
|
+
if (!events?.length) {
|
|
27
|
+
console.log("No logs yet.");
|
|
28
|
+
return;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
for (const e of events) {
|
|
31
|
+
const tag = LEVEL_TAG[e.level] ?? (e.level ? String(e.level).toUpperCase().slice(0, 3) : " ");
|
|
32
|
+
console.log(`${fmtTs(e.timestamp)} ${tag} ${e.message}`);
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
//# sourceMappingURL=logs.js.map
|
package/dist/commands/status.js
CHANGED
|
@@ -1,55 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
await (0, api_1.verifyToken)();
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
console.error('✗ Authentication expired. Run `bigbongo login` again.');
|
|
22
|
-
process.exit(1);
|
|
1
|
+
import { api } from "../api.js";
|
|
2
|
+
import { requireProject } from "./context.js";
|
|
3
|
+
function fmtWhen(iso) {
|
|
4
|
+
if (!iso)
|
|
5
|
+
return "-";
|
|
6
|
+
const d = new Date(iso);
|
|
7
|
+
return isNaN(d.getTime()) ? iso : d.toLocaleString();
|
|
8
|
+
}
|
|
9
|
+
export async function status() {
|
|
10
|
+
const cfg = requireProject();
|
|
11
|
+
const s = await api.status(cfg.app_id);
|
|
12
|
+
const app = s.app || {};
|
|
13
|
+
console.log(`\n${app.title || cfg.app_slug} (${app.app_slug || cfg.app_slug})`);
|
|
14
|
+
if (s.live) {
|
|
15
|
+
const sha = s.live.git_sha ? s.live.git_sha.slice(0, 7) : "-";
|
|
16
|
+
console.log(` Live: v${s.live.version} (${sha}) ${s.live.url || ""}`.trimEnd());
|
|
17
|
+
console.log(` deployed ${fmtWhen(s.live.deployed_at)}`);
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.log(`App: ${result.app.name} (${result.app.slug})`);
|
|
27
|
-
console.log(`URL: https://${result.app.slug}.apps.bigbongo.ai`);
|
|
28
|
-
console.log(`Status: ${result.app.status}`);
|
|
29
|
-
if (result.container) {
|
|
30
|
-
console.log(`Container: ${result.container.status} (${result.container.image})`);
|
|
31
|
-
}
|
|
32
|
-
if (result.deployment) {
|
|
33
|
-
const ago = timeSince(new Date(result.deployment.created_at));
|
|
34
|
-
console.log(`Last deploy: ${ago} (${result.deployment.status})`);
|
|
35
|
-
}
|
|
19
|
+
else {
|
|
20
|
+
console.log(" Live: not deployed yet");
|
|
36
21
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
const b = s.latest_build;
|
|
23
|
+
if (b) {
|
|
24
|
+
let line = ` Build: ${b.source_type} ${b.status}`;
|
|
25
|
+
if (b.deployment_status)
|
|
26
|
+
line += ` (deploy: ${b.deployment_status})`;
|
|
27
|
+
console.log(line);
|
|
28
|
+
console.log(` ${fmtWhen(b.created_at)}`);
|
|
29
|
+
if (b.error)
|
|
30
|
+
console.log(` error: ${b.error}`);
|
|
40
31
|
}
|
|
32
|
+
console.log("");
|
|
41
33
|
}
|
|
42
|
-
function timeSince(date) {
|
|
43
|
-
const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
|
|
44
|
-
if (seconds < 60)
|
|
45
|
-
return `${seconds}s ago`;
|
|
46
|
-
const minutes = Math.floor(seconds / 60);
|
|
47
|
-
if (minutes < 60)
|
|
48
|
-
return `${minutes}m ago`;
|
|
49
|
-
const hours = Math.floor(minutes / 60);
|
|
50
|
-
if (hours < 24)
|
|
51
|
-
return `${hours}h ago`;
|
|
52
|
-
const days = Math.floor(hours / 24);
|
|
53
|
-
return `${days}d ago`;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=status.js.map
|
package/dist/config.js
CHANGED
|
@@ -1,115 +1,88 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.getConfigDir = getConfigDir;
|
|
37
|
-
exports.saveCredentials = saveCredentials;
|
|
38
|
-
exports.loadCredentials = loadCredentials;
|
|
39
|
-
exports.clearCredentials = clearCredentials;
|
|
40
|
-
exports.getApiUrl = getApiUrl;
|
|
41
|
-
exports.loadProjectConfig = loadProjectConfig;
|
|
42
|
-
exports.saveProjectConfig = saveProjectConfig;
|
|
43
|
-
exports.getBigBongoUrl = getBigBongoUrl;
|
|
44
|
-
const fs = __importStar(require("fs"));
|
|
45
|
-
const os = __importStar(require("os"));
|
|
46
|
-
const path = __importStar(require("path"));
|
|
47
|
-
const CONFIG_DIR = path.join(os.homedir(), '.bigbongo');
|
|
48
|
-
const CREDENTIALS_FILE = path.join(CONFIG_DIR, 'credentials.json');
|
|
49
|
-
function getConfigDir() {
|
|
50
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
51
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
52
|
-
}
|
|
53
|
-
return CONFIG_DIR;
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync, chmodSync } from "node:fs";
|
|
4
|
+
const DIR = join(homedir(), ".bigbongo");
|
|
5
|
+
const CRED = join(DIR, "credentials.json");
|
|
6
|
+
export function saveCredentials(c) {
|
|
7
|
+
mkdirSync(DIR, { recursive: true });
|
|
8
|
+
chmodSync(DIR, 0o700);
|
|
9
|
+
writeFileSync(CRED, JSON.stringify(c, null, 2));
|
|
10
|
+
chmodSync(CRED, 0o600);
|
|
54
11
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
fs.writeFileSync(CREDENTIALS_FILE, JSON.stringify(credentials, null, 2), { mode: 0o600 });
|
|
58
|
-
}
|
|
59
|
-
function loadCredentials() {
|
|
60
|
-
if (!fs.existsSync(CREDENTIALS_FILE)) {
|
|
12
|
+
export function loadCredentials() {
|
|
13
|
+
if (!existsSync(CRED))
|
|
61
14
|
return null;
|
|
62
|
-
}
|
|
63
15
|
try {
|
|
64
|
-
|
|
65
|
-
return JSON.parse(data);
|
|
16
|
+
return JSON.parse(readFileSync(CRED, "utf8"));
|
|
66
17
|
}
|
|
67
18
|
catch {
|
|
68
19
|
return null;
|
|
69
20
|
}
|
|
70
21
|
}
|
|
71
|
-
function clearCredentials() {
|
|
72
|
-
if (
|
|
73
|
-
|
|
22
|
+
export function clearCredentials() {
|
|
23
|
+
if (existsSync(CRED)) {
|
|
24
|
+
writeFileSync(CRED, "{}");
|
|
25
|
+
chmodSync(CRED, 0o600);
|
|
74
26
|
}
|
|
75
27
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
28
|
+
const GIT_TOKENS = join(DIR, "git-tokens.json");
|
|
29
|
+
const TOKEN_REFRESH_SKEW_MS = 5 * 60 * 1000;
|
|
30
|
+
function readTokenCache() {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(readFileSync(GIT_TOKENS, "utf8"));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
79
37
|
}
|
|
80
|
-
function
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
38
|
+
export function loadCachedGitToken(appId) {
|
|
39
|
+
const entry = readTokenCache()[appId];
|
|
40
|
+
if (!entry?.token || !entry?.expires_at)
|
|
41
|
+
return null;
|
|
42
|
+
const remaining = new Date(entry.expires_at).getTime() - Date.now();
|
|
43
|
+
if (!(remaining > TOKEN_REFRESH_SKEW_MS))
|
|
83
44
|
return null;
|
|
45
|
+
return entry.token;
|
|
46
|
+
}
|
|
47
|
+
export function saveCachedGitToken(appId, token, expiresAt) {
|
|
48
|
+
const all = readTokenCache();
|
|
49
|
+
all[appId] = { token, expires_at: expiresAt };
|
|
50
|
+
mkdirSync(DIR, { recursive: true });
|
|
51
|
+
chmodSync(DIR, 0o700);
|
|
52
|
+
writeFileSync(GIT_TOKENS, JSON.stringify(all));
|
|
53
|
+
chmodSync(GIT_TOKENS, 0o600);
|
|
54
|
+
}
|
|
55
|
+
export function clearCachedGitToken(appId) {
|
|
56
|
+
const all = readTokenCache();
|
|
57
|
+
if (appId in all) {
|
|
58
|
+
delete all[appId];
|
|
59
|
+
writeFileSync(GIT_TOKENS, JSON.stringify(all));
|
|
60
|
+
chmodSync(GIT_TOKENS, 0o600);
|
|
84
61
|
}
|
|
62
|
+
}
|
|
63
|
+
export function loadProject(dir = process.cwd()) {
|
|
64
|
+
const p = join(dir, ".bigbongo.json");
|
|
65
|
+
if (!existsSync(p))
|
|
66
|
+
return null;
|
|
85
67
|
try {
|
|
86
|
-
|
|
87
|
-
return JSON.parse(data);
|
|
68
|
+
return JSON.parse(readFileSync(p, "utf8"));
|
|
88
69
|
}
|
|
89
70
|
catch {
|
|
90
71
|
return null;
|
|
91
72
|
}
|
|
92
73
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
74
|
+
export function saveProject(cfg, dir = process.cwd()) {
|
|
75
|
+
writeFileSync(join(dir, ".bigbongo.json"), JSON.stringify(cfg, null, 2));
|
|
96
76
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (creds?.apiUrl) {
|
|
108
|
-
// Turn "https://deploy.bigbongo.ai" → "https://app.bigbongo.ai"
|
|
109
|
-
return creds.apiUrl.includes('deploy.')
|
|
110
|
-
? creds.apiUrl.replace('deploy.', 'app.')
|
|
111
|
-
: 'https://app.bigbongo.ai';
|
|
77
|
+
export function findProjectUp(startDir = process.cwd()) {
|
|
78
|
+
let dir = startDir;
|
|
79
|
+
for (;;) {
|
|
80
|
+
const cfg = loadProject(dir);
|
|
81
|
+
if (cfg)
|
|
82
|
+
return cfg;
|
|
83
|
+
const parent = dirname(dir);
|
|
84
|
+
if (parent === dir)
|
|
85
|
+
return null;
|
|
86
|
+
dir = parent;
|
|
112
87
|
}
|
|
113
|
-
return process.env.BIGBONGO_URL || 'https://app.bigbongo.ai';
|
|
114
88
|
}
|
|
115
|
-
//# sourceMappingURL=config.js.map
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { appendFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { simpleGit } from "simple-git";
|
|
4
|
+
export function tokenRemote(repoUrl, token) {
|
|
5
|
+
let u;
|
|
6
|
+
try {
|
|
7
|
+
u = new URL(repoUrl);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
throw new Error(`Refusing to use a non-URL git remote: ${repoUrl}`);
|
|
11
|
+
}
|
|
12
|
+
if (u.protocol !== "https:" || u.host !== "github.com") {
|
|
13
|
+
throw new Error(`Refusing to attach a token to a non-github.com remote: ${u.host || repoUrl}`);
|
|
14
|
+
}
|
|
15
|
+
return repoUrl.replace("https://", `https://x-access-token:${token}@`);
|
|
16
|
+
}
|
|
17
|
+
export async function cloneApp(repoUrl, token, dir, author) {
|
|
18
|
+
await simpleGit().clone(tokenRemote(repoUrl, token), dir);
|
|
19
|
+
const local = simpleGit(dir, { unsafe: { allowUnsafeCredentialHelper: true } });
|
|
20
|
+
await local.remote(["set-url", "origin", repoUrl]);
|
|
21
|
+
await local.addConfig("user.name", author.name);
|
|
22
|
+
await local.addConfig("user.email", author.email);
|
|
23
|
+
await local.addConfig("credential.helper", "", false);
|
|
24
|
+
await local.addConfig("credential.helper", "!bigbongo git-token --helper", true);
|
|
25
|
+
appendFileSync(join(dir, ".git", "info", "exclude"), "\n.bigbongo.json\n");
|
|
26
|
+
}
|