genbox 1.0.42 → 1.0.44
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/dist/commands/create.js +69 -0
- package/package.json +1 -1
package/dist/commands/create.js
CHANGED
|
@@ -51,6 +51,20 @@ const ssh_config_1 = require("../ssh-config");
|
|
|
51
51
|
const schema_v4_1 = require("../schema-v4");
|
|
52
52
|
const child_process_1 = require("child_process");
|
|
53
53
|
const random_name_1 = require("../random-name");
|
|
54
|
+
// Credits consumed per hour for each size (matches API billing.config.ts)
|
|
55
|
+
const CREDITS_PER_HOUR = {
|
|
56
|
+
cx22: 1,
|
|
57
|
+
cx32: 2,
|
|
58
|
+
cx42: 4,
|
|
59
|
+
cx52: 8,
|
|
60
|
+
small: 1,
|
|
61
|
+
medium: 2,
|
|
62
|
+
large: 4,
|
|
63
|
+
xl: 8,
|
|
64
|
+
};
|
|
65
|
+
function getCreditsPerHour(size) {
|
|
66
|
+
return CREDITS_PER_HOUR[size.toLowerCase()] || 2; // Default to medium
|
|
67
|
+
}
|
|
54
68
|
/**
|
|
55
69
|
* Spawn a background process to poll for IP and add SSH config
|
|
56
70
|
* This runs detached so the main process can exit immediately
|
|
@@ -100,6 +114,27 @@ function getPrivateSshKey() {
|
|
|
100
114
|
}
|
|
101
115
|
return undefined;
|
|
102
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Get local git config for commits on genbox
|
|
119
|
+
*/
|
|
120
|
+
function getGitConfig() {
|
|
121
|
+
const { execSync } = require('child_process');
|
|
122
|
+
let userName;
|
|
123
|
+
let userEmail;
|
|
124
|
+
try {
|
|
125
|
+
userName = execSync('git config --global user.name', { encoding: 'utf-8' }).trim();
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// Git config not set
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
userEmail = execSync('git config --global user.email', { encoding: 'utf-8' }).trim();
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Git config not set
|
|
135
|
+
}
|
|
136
|
+
return { userName, userEmail };
|
|
137
|
+
}
|
|
103
138
|
/**
|
|
104
139
|
* Prompt user for environment name
|
|
105
140
|
*/
|
|
@@ -296,11 +331,41 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
296
331
|
if (!selectedProfile && !options.yes && !options.dryRun) {
|
|
297
332
|
await profileResolver.askSaveProfile(config, resolved);
|
|
298
333
|
}
|
|
334
|
+
// Calculate credits that will be consumed
|
|
335
|
+
const creditsPerHour = getCreditsPerHour(resolved.size);
|
|
336
|
+
// Fetch user's current credit balance
|
|
337
|
+
let userCredits = 0;
|
|
338
|
+
let addonCredits = 0;
|
|
339
|
+
try {
|
|
340
|
+
const user = await (0, api_1.fetchApi)('/users/me');
|
|
341
|
+
userCredits = user.credits || 0;
|
|
342
|
+
addonCredits = user.addonCredits || 0;
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
// Continue without balance info if fetch fails
|
|
346
|
+
}
|
|
347
|
+
const totalCredits = userCredits + addonCredits;
|
|
348
|
+
const estimatedHours = totalCredits > 0 ? Math.floor(totalCredits / creditsPerHour) : 0;
|
|
349
|
+
// Display billing info
|
|
350
|
+
console.log(chalk_1.default.blue('=== Billing ==='));
|
|
351
|
+
console.log(` Credits to start: ${chalk_1.default.yellow(creditsPerHour)} (${creditsPerHour} credit${creditsPerHour > 1 ? 's' : ''}/hr for ${resolved.size})`);
|
|
352
|
+
if (totalCredits > 0) {
|
|
353
|
+
console.log(` Your balance: ${chalk_1.default.green(totalCredits)} credits${addonCredits > 0 ? chalk_1.default.dim(` (${userCredits} regular + ${addonCredits} addon)`) : ''}`);
|
|
354
|
+
console.log(` After creation: ${chalk_1.default.cyan(totalCredits - creditsPerHour)} credits`);
|
|
355
|
+
console.log(` Estimated runtime: ${chalk_1.default.cyan('~' + estimatedHours + ' hours')}`);
|
|
356
|
+
}
|
|
357
|
+
console.log('');
|
|
299
358
|
// Dry run mode
|
|
300
359
|
if (options.dryRun) {
|
|
301
360
|
console.log(chalk_1.default.yellow('\nDry run mode - no genbox created'));
|
|
302
361
|
return;
|
|
303
362
|
}
|
|
363
|
+
// Check if user has enough credits
|
|
364
|
+
if (totalCredits < creditsPerHour) {
|
|
365
|
+
console.log(chalk_1.default.red(`Insufficient credits. Need ${creditsPerHour}, have ${totalCredits}.`));
|
|
366
|
+
console.log(chalk_1.default.dim('Run `genbox balance` to check your balance or purchase more credits.'));
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
304
369
|
// Confirm creation
|
|
305
370
|
if (!options.yes) {
|
|
306
371
|
const confirm = await prompts.confirm({
|
|
@@ -750,6 +815,8 @@ function buildPayload(resolved, config, publicKey, privateKey, configLoader) {
|
|
|
750
815
|
sourceBranch: repo.sourceBranch,
|
|
751
816
|
};
|
|
752
817
|
}
|
|
818
|
+
// Get local git config for commits
|
|
819
|
+
const gitConfig = getGitConfig();
|
|
753
820
|
return {
|
|
754
821
|
name: resolved.name,
|
|
755
822
|
size: resolved.size,
|
|
@@ -761,6 +828,8 @@ function buildPayload(resolved, config, publicKey, privateKey, configLoader) {
|
|
|
761
828
|
repos,
|
|
762
829
|
privateKey,
|
|
763
830
|
gitToken: envVars.GIT_TOKEN,
|
|
831
|
+
gitUserName: gitConfig.userName,
|
|
832
|
+
gitUserEmail: gitConfig.userEmail,
|
|
764
833
|
envVars: resolved.env,
|
|
765
834
|
apps: resolved.apps.map(a => a.name),
|
|
766
835
|
appConfigs: resolved.apps.map(a => ({
|