commet 1.0.0 → 1.2.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 +11 -10
- package/dist/index.js +627 -380
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -24,13 +24,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
));
|
|
25
25
|
|
|
26
26
|
// src/index.ts
|
|
27
|
-
var
|
|
28
|
-
var
|
|
27
|
+
var import_chalk13 = __toESM(require("chalk"));
|
|
28
|
+
var import_commander11 = require("commander");
|
|
29
29
|
|
|
30
30
|
// package.json
|
|
31
31
|
var package_default = {
|
|
32
32
|
name: "commet",
|
|
33
|
-
version: "1.
|
|
33
|
+
version: "1.2.0",
|
|
34
34
|
description: "Commet CLI - Manage your billing platform from the command line",
|
|
35
35
|
bin: {
|
|
36
36
|
commet: "./bin/commet"
|
|
@@ -61,7 +61,8 @@ var package_default = {
|
|
|
61
61
|
commander: "14.0.2",
|
|
62
62
|
"jsonc-parser": "3.3.1",
|
|
63
63
|
open: "11.0.0",
|
|
64
|
-
ora: "9.0.0"
|
|
64
|
+
ora: "9.0.0",
|
|
65
|
+
tar: "^7.5.13"
|
|
65
66
|
},
|
|
66
67
|
devDependencies: {
|
|
67
68
|
"@types/node": "24.10.1",
|
|
@@ -83,9 +84,15 @@ var package_default = {
|
|
|
83
84
|
}
|
|
84
85
|
};
|
|
85
86
|
|
|
86
|
-
// src/commands/
|
|
87
|
-
var
|
|
87
|
+
// src/commands/create.ts
|
|
88
|
+
var fs2 = __toESM(require("fs"));
|
|
89
|
+
var os2 = __toESM(require("os"));
|
|
90
|
+
var path2 = __toESM(require("path"));
|
|
91
|
+
var import_prompts = require("@inquirer/prompts");
|
|
92
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
88
93
|
var import_commander = require("commander");
|
|
94
|
+
var import_ora2 = __toESM(require("ora"));
|
|
95
|
+
var import_tar = require("tar");
|
|
89
96
|
|
|
90
97
|
// src/utils/config.ts
|
|
91
98
|
var fs = __toESM(require("fs"));
|
|
@@ -154,42 +161,6 @@ function clearProjectConfig() {
|
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
|
|
157
|
-
// src/commands/info.ts
|
|
158
|
-
var infoCommand = new import_commander.Command("info").description("Display information about the current project").action(async () => {
|
|
159
|
-
console.log(import_chalk.default.bold("\n\u{1F4E6} Project Information\n"));
|
|
160
|
-
if (!authExists()) {
|
|
161
|
-
console.log(import_chalk.default.yellow("Authentication: Not logged in"));
|
|
162
|
-
console.log(import_chalk.default.dim("Run `commet login` to authenticate\n"));
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
console.log(import_chalk.default.green("Authentication: Logged in \u2713"));
|
|
166
|
-
if (!projectConfigExists()) {
|
|
167
|
-
console.log(import_chalk.default.yellow("\nProject: Not linked"));
|
|
168
|
-
console.log(
|
|
169
|
-
import_chalk.default.dim("Run `commet link` to connect to an organization\n")
|
|
170
|
-
);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const projectConfig = loadProjectConfig();
|
|
174
|
-
if (!projectConfig) {
|
|
175
|
-
console.log(import_chalk.default.red("\nProject: Invalid configuration"));
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
console.log(import_chalk.default.green("\nProject: Linked \u2713"));
|
|
179
|
-
console.log(import_chalk.default.dim(" Organization:"), projectConfig.orgName);
|
|
180
|
-
console.log(import_chalk.default.dim(" Organization ID:"), projectConfig.orgId);
|
|
181
|
-
console.log(import_chalk.default.dim(" Environment:"), projectConfig.environment);
|
|
182
|
-
console.log(
|
|
183
|
-
import_chalk.default.dim("\nRun `commet pull` to generate type definitions\n")
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// src/commands/link.ts
|
|
188
|
-
var import_prompts = require("@inquirer/prompts");
|
|
189
|
-
var import_chalk3 = __toESM(require("chalk"));
|
|
190
|
-
var import_commander2 = require("commander");
|
|
191
|
-
var import_ora = __toESM(require("ora"));
|
|
192
|
-
|
|
193
164
|
// src/utils/api.ts
|
|
194
165
|
function getBaseURL(environment) {
|
|
195
166
|
if (environment === "production") {
|
|
@@ -226,16 +197,422 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
226
197
|
}
|
|
227
198
|
}
|
|
228
199
|
|
|
200
|
+
// src/utils/login-flow.ts
|
|
201
|
+
var import_chalk = __toESM(require("chalk"));
|
|
202
|
+
var import_open = __toESM(require("open"));
|
|
203
|
+
var import_ora = __toESM(require("ora"));
|
|
204
|
+
function sleep(ms) {
|
|
205
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
206
|
+
}
|
|
207
|
+
async function performLogin(environment) {
|
|
208
|
+
const baseURL = getBaseURL(environment);
|
|
209
|
+
const spinner = (0, import_ora.default)("Initiating login flow...").start();
|
|
210
|
+
try {
|
|
211
|
+
const deviceResponse = await fetch(`${baseURL}/api/auth/device/code`, {
|
|
212
|
+
method: "POST",
|
|
213
|
+
headers: { "Content-Type": "application/json" },
|
|
214
|
+
body: JSON.stringify({
|
|
215
|
+
client_id: "commet-cli",
|
|
216
|
+
scope: "openid profile email"
|
|
217
|
+
})
|
|
218
|
+
});
|
|
219
|
+
if (!deviceResponse.ok) {
|
|
220
|
+
spinner.fail("Failed to initiate login");
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
const deviceData = await deviceResponse.json();
|
|
224
|
+
const {
|
|
225
|
+
device_code,
|
|
226
|
+
user_code,
|
|
227
|
+
verification_uri_complete,
|
|
228
|
+
interval = 5
|
|
229
|
+
} = deviceData;
|
|
230
|
+
spinner.stop();
|
|
231
|
+
console.log(import_chalk.default.bold("\n\u{1F510} Commet CLI Login\n"));
|
|
232
|
+
console.log("Visit the following URL in your browser:");
|
|
233
|
+
console.log(import_chalk.default.cyan.underline(verification_uri_complete));
|
|
234
|
+
console.log("\nOr enter this code manually:");
|
|
235
|
+
console.log(import_chalk.default.bold.green(` ${user_code}`));
|
|
236
|
+
console.log(import_chalk.default.dim("\nOpening browser...\n"));
|
|
237
|
+
try {
|
|
238
|
+
await (0, import_open.default)(verification_uri_complete);
|
|
239
|
+
} catch {
|
|
240
|
+
console.log(import_chalk.default.yellow("\u26A0 Could not open browser automatically."));
|
|
241
|
+
}
|
|
242
|
+
const pollSpinner = (0, import_ora.default)("Waiting for authorization...").start();
|
|
243
|
+
let pollingInterval = interval;
|
|
244
|
+
let attempts = 0;
|
|
245
|
+
const maxAttempts = Math.floor(180 / pollingInterval);
|
|
246
|
+
while (attempts < maxAttempts) {
|
|
247
|
+
attempts++;
|
|
248
|
+
await sleep(pollingInterval * 1e3);
|
|
249
|
+
try {
|
|
250
|
+
const tokenResponse = await fetch(`${baseURL}/api/auth/device/token`, {
|
|
251
|
+
method: "POST",
|
|
252
|
+
headers: { "Content-Type": "application/json" },
|
|
253
|
+
body: JSON.stringify({
|
|
254
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
255
|
+
device_code,
|
|
256
|
+
client_id: "commet-cli"
|
|
257
|
+
})
|
|
258
|
+
});
|
|
259
|
+
const tokenData = await tokenResponse.json();
|
|
260
|
+
if (tokenData.access_token) {
|
|
261
|
+
const authConfig = {
|
|
262
|
+
token: tokenData.access_token,
|
|
263
|
+
environment
|
|
264
|
+
};
|
|
265
|
+
if (tokenData.refresh_token) {
|
|
266
|
+
authConfig.refreshToken = tokenData.refresh_token;
|
|
267
|
+
}
|
|
268
|
+
if (tokenData.expires_in) {
|
|
269
|
+
authConfig.expiresAt = Date.now() + tokenData.expires_in * 1e3;
|
|
270
|
+
}
|
|
271
|
+
saveAuth(authConfig);
|
|
272
|
+
pollSpinner.succeed("Successfully logged in!");
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
if (tokenData.error === "authorization_pending") {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (tokenData.error === "slow_down") {
|
|
279
|
+
pollingInterval += 5;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (tokenData.error === "access_denied") {
|
|
283
|
+
pollSpinner.fail("Authorization denied");
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
if (tokenData.error === "expired_token") {
|
|
287
|
+
pollSpinner.fail("Code expired");
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
pollSpinner.fail("Authorization failed");
|
|
291
|
+
return false;
|
|
292
|
+
} catch {
|
|
293
|
+
pollSpinner.fail("Network error");
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
pollSpinner.fail("Login timed out");
|
|
298
|
+
return false;
|
|
299
|
+
} catch {
|
|
300
|
+
spinner.fail("Login failed");
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/utils/prompt-theme.ts
|
|
306
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
307
|
+
var commetColor = import_chalk2.default.hex("#5BC0B0");
|
|
308
|
+
var promptTheme = {
|
|
309
|
+
prefix: commetColor("\u276F"),
|
|
310
|
+
style: {
|
|
311
|
+
answer: commetColor,
|
|
312
|
+
message: import_chalk2.default.bold,
|
|
313
|
+
error: import_chalk2.default.red,
|
|
314
|
+
help: import_chalk2.default.dim,
|
|
315
|
+
highlight: commetColor.bold,
|
|
316
|
+
// Selected option in mint
|
|
317
|
+
description: import_chalk2.default.dim,
|
|
318
|
+
defaultAnswer: import_chalk2.default.dim
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/commands/create.ts
|
|
323
|
+
var GITHUB_REPO = "commet-labs/commet";
|
|
324
|
+
var TEMPLATES = [
|
|
325
|
+
{
|
|
326
|
+
name: "fixed",
|
|
327
|
+
dir: "fixed-saas",
|
|
328
|
+
templateId: "fixed-saas",
|
|
329
|
+
description: "Fixed subscriptions (monthly/yearly plans)"
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: "seats",
|
|
333
|
+
dir: "team-saas",
|
|
334
|
+
templateId: "seat-based-saas",
|
|
335
|
+
description: "Seat-based billing (per team member)"
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
name: "credits",
|
|
339
|
+
dir: "credits-saas",
|
|
340
|
+
templateId: "credits-saas",
|
|
341
|
+
description: "Credit-based billing (prepaid usage blocks)"
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: "usage-based",
|
|
345
|
+
dir: "usage-based-saas",
|
|
346
|
+
templateId: "usage-based-saas",
|
|
347
|
+
description: "Usage-based billing (metered, pay for what you use)"
|
|
348
|
+
}
|
|
349
|
+
];
|
|
350
|
+
async function downloadTemplate(templateDir, dest, ref) {
|
|
351
|
+
const url = `https://codeload.github.com/${GITHUB_REPO}/tar.gz/${ref}`;
|
|
352
|
+
const response = await fetch(url);
|
|
353
|
+
if (!response.ok) {
|
|
354
|
+
throw new Error(`Failed to download (HTTP ${response.status})`);
|
|
355
|
+
}
|
|
356
|
+
const tempFile = path2.join(os2.tmpdir(), `commet-${Date.now()}.tar.gz`);
|
|
357
|
+
try {
|
|
358
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
359
|
+
fs2.writeFileSync(tempFile, buffer);
|
|
360
|
+
fs2.mkdirSync(dest, { recursive: true });
|
|
361
|
+
await (0, import_tar.extract)({
|
|
362
|
+
file: tempFile,
|
|
363
|
+
cwd: dest,
|
|
364
|
+
strip: 3,
|
|
365
|
+
filter: (entryPath) => {
|
|
366
|
+
const parts = entryPath.split("/");
|
|
367
|
+
return parts[1] === "examples" && parts[2] === templateDir;
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
} finally {
|
|
371
|
+
if (fs2.existsSync(tempFile)) {
|
|
372
|
+
fs2.unlinkSync(tempFile);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const files = fs2.readdirSync(dest);
|
|
376
|
+
if (files.length === 0) {
|
|
377
|
+
throw new Error(`Template "${templateDir}" not found in repository`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function updatePackageJson(dest, projectName) {
|
|
381
|
+
const pkgPath = path2.join(dest, "package.json");
|
|
382
|
+
const pkg = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"));
|
|
383
|
+
pkg.name = projectName;
|
|
384
|
+
pkg.version = "0.0.1";
|
|
385
|
+
pkg.private = true;
|
|
386
|
+
fs2.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
387
|
+
`);
|
|
388
|
+
}
|
|
389
|
+
function copyEnvExample(dest) {
|
|
390
|
+
const examplePath = path2.join(dest, ".env.example");
|
|
391
|
+
const envPath = path2.join(dest, ".env");
|
|
392
|
+
if (fs2.existsSync(examplePath)) {
|
|
393
|
+
fs2.copyFileSync(examplePath, envPath);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function linkProject(dest, orgId, orgName, environment) {
|
|
397
|
+
const commetDir = path2.join(dest, ".commet");
|
|
398
|
+
fs2.mkdirSync(commetDir, { recursive: true });
|
|
399
|
+
fs2.writeFileSync(
|
|
400
|
+
path2.join(commetDir, "config.json"),
|
|
401
|
+
JSON.stringify({ orgId, orgName, environment }, null, 2),
|
|
402
|
+
"utf8"
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
var createCommand = new import_commander.Command("create").description("Create a new Commet app from a template").argument("[name]", "Project name").option(
|
|
406
|
+
"-t, --template <template>",
|
|
407
|
+
"Template to use (fixed, seats, credits, usage-based)"
|
|
408
|
+
).option("--ref <ref>", "Git ref to fetch templates from", "main").option("--list", "List available templates").action(async (argName, opts) => {
|
|
409
|
+
if (opts.list) {
|
|
410
|
+
console.log(import_chalk3.default.bold("\nAvailable templates:\n"));
|
|
411
|
+
for (const t of TEMPLATES) {
|
|
412
|
+
console.log(
|
|
413
|
+
` ${commetColor(t.name.padEnd(14))}${import_chalk3.default.dim(t.description)}`
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
console.log();
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
let projectName = argName;
|
|
420
|
+
try {
|
|
421
|
+
if (!projectName) {
|
|
422
|
+
projectName = await (0, import_prompts.input)({
|
|
423
|
+
message: "Project name:",
|
|
424
|
+
theme: promptTheme
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
} catch {
|
|
428
|
+
console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const dest = path2.resolve(projectName);
|
|
432
|
+
if (fs2.existsSync(dest)) {
|
|
433
|
+
console.log(
|
|
434
|
+
import_chalk3.default.red(`\u2717 Directory "${projectName}" already exists`)
|
|
435
|
+
);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (!authExists()) {
|
|
439
|
+
let environment;
|
|
440
|
+
try {
|
|
441
|
+
environment = await (0, import_prompts.select)({
|
|
442
|
+
message: "Environment:",
|
|
443
|
+
choices: [
|
|
444
|
+
{
|
|
445
|
+
name: `Sandbox ${import_chalk3.default.dim("(Development)")}`,
|
|
446
|
+
value: "sandbox"
|
|
447
|
+
},
|
|
448
|
+
{ name: "Production", value: "production" }
|
|
449
|
+
],
|
|
450
|
+
default: "sandbox",
|
|
451
|
+
theme: promptTheme
|
|
452
|
+
});
|
|
453
|
+
} catch {
|
|
454
|
+
console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const loggedIn = await performLogin(environment);
|
|
458
|
+
if (!loggedIn) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const auth = loadAuth();
|
|
463
|
+
const baseURL = getBaseURL(auth.environment);
|
|
464
|
+
const orgsSpinner = (0, import_ora2.default)("Fetching organizations...").start();
|
|
465
|
+
const orgsResult = await apiRequest(`${baseURL}/api/cli/organizations`);
|
|
466
|
+
if (orgsResult.error || !orgsResult.data) {
|
|
467
|
+
orgsSpinner.fail("Failed to fetch organizations");
|
|
468
|
+
console.log(import_chalk3.default.dim(orgsResult.error));
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const { organizations } = orgsResult.data;
|
|
472
|
+
orgsSpinner.stop();
|
|
473
|
+
if (organizations.length === 0) {
|
|
474
|
+
console.log(import_chalk3.default.yellow("\u26A0 No organizations found"));
|
|
475
|
+
console.log(
|
|
476
|
+
import_chalk3.default.dim("Create an organization at https://commet.co first")
|
|
477
|
+
);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
let selectedOrg;
|
|
481
|
+
if (organizations.length === 1) {
|
|
482
|
+
selectedOrg = organizations[0];
|
|
483
|
+
} else {
|
|
484
|
+
try {
|
|
485
|
+
const orgId = await (0, import_prompts.select)({
|
|
486
|
+
message: "Organization:",
|
|
487
|
+
choices: organizations.map((org) => ({
|
|
488
|
+
name: `${org.name} ${import_chalk3.default.dim(`(${org.slug})`)}`,
|
|
489
|
+
value: org.id
|
|
490
|
+
})),
|
|
491
|
+
theme: promptTheme
|
|
492
|
+
});
|
|
493
|
+
selectedOrg = organizations.find((org) => org.id === orgId);
|
|
494
|
+
} catch {
|
|
495
|
+
console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
let template = TEMPLATES.find((t) => t.name === opts.template);
|
|
500
|
+
if (opts.template && !template) {
|
|
501
|
+
console.log(import_chalk3.default.red(`\u2717 Unknown template "${opts.template}"`));
|
|
502
|
+
console.log(
|
|
503
|
+
import_chalk3.default.dim("Run `commet create --list` to see available templates")
|
|
504
|
+
);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
if (!template) {
|
|
509
|
+
const selected = await (0, import_prompts.select)({
|
|
510
|
+
message: "Billing model:",
|
|
511
|
+
choices: TEMPLATES.map((t) => ({
|
|
512
|
+
name: `${t.name.padEnd(14)} ${import_chalk3.default.dim(t.description)}`,
|
|
513
|
+
value: t.name
|
|
514
|
+
})),
|
|
515
|
+
theme: promptTheme
|
|
516
|
+
});
|
|
517
|
+
template = TEMPLATES.find((t) => t.name === selected);
|
|
518
|
+
}
|
|
519
|
+
} catch {
|
|
520
|
+
console.log(import_chalk3.default.yellow("\n\u26A0 Cancelled"));
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const downloadSpinner = (0, import_ora2.default)("Downloading template...").start();
|
|
524
|
+
try {
|
|
525
|
+
await downloadTemplate(template.dir, dest, opts.ref);
|
|
526
|
+
downloadSpinner.succeed("Template downloaded");
|
|
527
|
+
} catch (error) {
|
|
528
|
+
downloadSpinner.fail("Failed to download template");
|
|
529
|
+
if (error instanceof Error) {
|
|
530
|
+
console.error(import_chalk3.default.red(error.message));
|
|
531
|
+
}
|
|
532
|
+
if (fs2.existsSync(dest)) {
|
|
533
|
+
fs2.rmSync(dest, { recursive: true, force: true });
|
|
534
|
+
}
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
updatePackageJson(dest, projectName);
|
|
538
|
+
copyEnvExample(dest);
|
|
539
|
+
const planSpinner = (0, import_ora2.default)("Creating plans...").start();
|
|
540
|
+
const templateResult = await apiRequest(`${baseURL}/api/cli/templates`, {
|
|
541
|
+
method: "POST",
|
|
542
|
+
body: JSON.stringify({
|
|
543
|
+
templateId: template.templateId,
|
|
544
|
+
organizationId: selectedOrg.id
|
|
545
|
+
})
|
|
546
|
+
});
|
|
547
|
+
if (templateResult.error || !templateResult.data) {
|
|
548
|
+
planSpinner.fail("Failed to create plans");
|
|
549
|
+
console.log(import_chalk3.default.dim(templateResult.error));
|
|
550
|
+
} else {
|
|
551
|
+
planSpinner.succeed(
|
|
552
|
+
`Created ${templateResult.data.plansCreated} plans and ${templateResult.data.featuresCreated} features`
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
linkProject(dest, selectedOrg.id, selectedOrg.name, auth.environment);
|
|
556
|
+
console.log(import_chalk3.default.green(`
|
|
557
|
+
\u2713 Created ${projectName}`));
|
|
558
|
+
console.log(import_chalk3.default.dim(` Template: ${template.name}`));
|
|
559
|
+
console.log(import_chalk3.default.dim(` Organization: ${selectedOrg.name}`));
|
|
560
|
+
console.log();
|
|
561
|
+
console.log(` ${import_chalk3.default.cyan("cd")} ${projectName}`);
|
|
562
|
+
console.log(` ${import_chalk3.default.dim("Update .env with your keys")}`);
|
|
563
|
+
console.log(` ${import_chalk3.default.cyan("npm install")}`);
|
|
564
|
+
console.log(` ${import_chalk3.default.cyan("npm run dev")}`);
|
|
565
|
+
console.log();
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
// src/commands/info.ts
|
|
569
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
570
|
+
var import_commander2 = require("commander");
|
|
571
|
+
var infoCommand = new import_commander2.Command("info").description("Display information about the current project").action(async () => {
|
|
572
|
+
console.log(import_chalk4.default.bold("\n\u{1F4E6} Project Information\n"));
|
|
573
|
+
if (!authExists()) {
|
|
574
|
+
console.log(import_chalk4.default.yellow("Authentication: Not logged in"));
|
|
575
|
+
console.log(import_chalk4.default.dim("Run `commet login` to authenticate\n"));
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
console.log(import_chalk4.default.green("Authentication: Logged in \u2713"));
|
|
579
|
+
if (!projectConfigExists()) {
|
|
580
|
+
console.log(import_chalk4.default.yellow("\nProject: Not linked"));
|
|
581
|
+
console.log(
|
|
582
|
+
import_chalk4.default.dim("Run `commet link` to connect to an organization\n")
|
|
583
|
+
);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const projectConfig = loadProjectConfig();
|
|
587
|
+
if (!projectConfig) {
|
|
588
|
+
console.log(import_chalk4.default.red("\nProject: Invalid configuration"));
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
console.log(import_chalk4.default.green("\nProject: Linked \u2713"));
|
|
592
|
+
console.log(import_chalk4.default.dim(" Organization:"), projectConfig.orgName);
|
|
593
|
+
console.log(import_chalk4.default.dim(" Organization ID:"), projectConfig.orgId);
|
|
594
|
+
console.log(import_chalk4.default.dim(" Environment:"), projectConfig.environment);
|
|
595
|
+
console.log(
|
|
596
|
+
import_chalk4.default.dim("\nRun `commet pull` to generate type definitions\n")
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// src/commands/link.ts
|
|
601
|
+
var import_prompts2 = require("@inquirer/prompts");
|
|
602
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
603
|
+
var import_commander3 = require("commander");
|
|
604
|
+
var import_ora3 = __toESM(require("ora"));
|
|
605
|
+
|
|
229
606
|
// src/utils/gitignore-updater.ts
|
|
230
|
-
var
|
|
231
|
-
var
|
|
607
|
+
var fs3 = __toESM(require("fs"));
|
|
608
|
+
var path3 = __toESM(require("path"));
|
|
232
609
|
function updateGitignore(entry) {
|
|
233
610
|
const cwd = process.cwd();
|
|
234
|
-
const gitignorePath =
|
|
611
|
+
const gitignorePath = path3.join(cwd, ".gitignore");
|
|
235
612
|
try {
|
|
236
613
|
let content = "";
|
|
237
|
-
if (
|
|
238
|
-
content =
|
|
614
|
+
if (fs3.existsSync(gitignorePath)) {
|
|
615
|
+
content = fs3.readFileSync(gitignorePath, "utf8");
|
|
239
616
|
const lines = content.split("\n");
|
|
240
617
|
for (const line of lines) {
|
|
241
618
|
const trimmed = line.trim();
|
|
@@ -249,7 +626,7 @@ function updateGitignore(entry) {
|
|
|
249
626
|
}
|
|
250
627
|
content += `${entry}
|
|
251
628
|
`;
|
|
252
|
-
|
|
629
|
+
fs3.writeFileSync(gitignorePath, content, "utf8");
|
|
253
630
|
return { success: true };
|
|
254
631
|
} catch (error) {
|
|
255
632
|
return {
|
|
@@ -259,48 +636,31 @@ function updateGitignore(entry) {
|
|
|
259
636
|
}
|
|
260
637
|
}
|
|
261
638
|
|
|
262
|
-
// src/utils/prompt-theme.ts
|
|
263
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
264
|
-
var commetColor = import_chalk2.default.hex("#5BC0B0");
|
|
265
|
-
var promptTheme = {
|
|
266
|
-
prefix: commetColor("\u276F"),
|
|
267
|
-
style: {
|
|
268
|
-
answer: commetColor,
|
|
269
|
-
message: import_chalk2.default.bold,
|
|
270
|
-
error: import_chalk2.default.red,
|
|
271
|
-
help: import_chalk2.default.dim,
|
|
272
|
-
highlight: commetColor.bold,
|
|
273
|
-
// Selected option in mint
|
|
274
|
-
description: import_chalk2.default.dim,
|
|
275
|
-
defaultAnswer: import_chalk2.default.dim
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
|
|
279
639
|
// src/commands/link.ts
|
|
280
|
-
var linkCommand = new
|
|
640
|
+
var linkCommand = new import_commander3.Command("link").description("Link this project to a Commet organization").action(async () => {
|
|
281
641
|
if (!authExists()) {
|
|
282
|
-
console.log(
|
|
283
|
-
console.log(
|
|
642
|
+
console.log(import_chalk5.default.red("\u2717 Not authenticated"));
|
|
643
|
+
console.log(import_chalk5.default.dim("Run `commet login` first"));
|
|
284
644
|
return;
|
|
285
645
|
}
|
|
286
646
|
if (projectConfigExists()) {
|
|
287
647
|
const config = loadProjectConfig();
|
|
288
|
-
console.log(
|
|
648
|
+
console.log(import_chalk5.default.yellow("\u26A0 This project is already linked"));
|
|
289
649
|
console.log(
|
|
290
|
-
|
|
650
|
+
import_chalk5.default.dim(`Organization: ${config?.orgName} (${config?.environment})`)
|
|
291
651
|
);
|
|
292
652
|
console.log(
|
|
293
|
-
|
|
653
|
+
import_chalk5.default.dim(
|
|
294
654
|
"\nRun `commet unlink` first if you want to change the organization"
|
|
295
655
|
)
|
|
296
656
|
);
|
|
297
657
|
return;
|
|
298
658
|
}
|
|
299
|
-
const spinner = (0,
|
|
659
|
+
const spinner = (0, import_ora3.default)("Fetching organizations...").start();
|
|
300
660
|
const auth = loadAuth();
|
|
301
661
|
if (!auth) {
|
|
302
662
|
spinner.fail("Authentication error");
|
|
303
|
-
console.log(
|
|
663
|
+
console.log(import_chalk5.default.red("\u2717 Could not load authentication"));
|
|
304
664
|
return;
|
|
305
665
|
}
|
|
306
666
|
const baseURL = getBaseURL(auth.environment);
|
|
@@ -309,36 +669,36 @@ var linkCommand = new import_commander2.Command("link").description("Link this p
|
|
|
309
669
|
);
|
|
310
670
|
if (result.error || !result.data) {
|
|
311
671
|
spinner.fail("Failed to fetch organizations");
|
|
312
|
-
console.error(
|
|
672
|
+
console.error(import_chalk5.default.red("Error:"), result.error);
|
|
313
673
|
return;
|
|
314
674
|
}
|
|
315
675
|
const { organizations } = result.data;
|
|
316
676
|
if (organizations.length === 0) {
|
|
317
677
|
spinner.stop();
|
|
318
|
-
console.log(
|
|
678
|
+
console.log(import_chalk5.default.yellow("\u26A0 No organizations found"));
|
|
319
679
|
console.log(
|
|
320
|
-
|
|
680
|
+
import_chalk5.default.dim("Create an organization at https://commet.co first")
|
|
321
681
|
);
|
|
322
682
|
return;
|
|
323
683
|
}
|
|
324
684
|
spinner.stop();
|
|
325
685
|
let orgId;
|
|
326
686
|
try {
|
|
327
|
-
orgId = await (0,
|
|
687
|
+
orgId = await (0, import_prompts2.select)({
|
|
328
688
|
message: "Select organization:",
|
|
329
689
|
choices: organizations.map((org) => ({
|
|
330
|
-
name: `${org.name} ${
|
|
690
|
+
name: `${org.name} ${import_chalk5.default.dim(`(${org.slug})`)}`,
|
|
331
691
|
value: org.id
|
|
332
692
|
})),
|
|
333
693
|
theme: promptTheme
|
|
334
694
|
});
|
|
335
695
|
} catch (error) {
|
|
336
|
-
console.log(
|
|
696
|
+
console.log(import_chalk5.default.yellow("\n\u26A0 Link cancelled"));
|
|
337
697
|
return;
|
|
338
698
|
}
|
|
339
699
|
const selectedOrg = organizations.find((org) => org.id === orgId);
|
|
340
700
|
if (!selectedOrg) {
|
|
341
|
-
console.log(
|
|
701
|
+
console.log(import_chalk5.default.red("\u2717 Organization not found"));
|
|
342
702
|
return;
|
|
343
703
|
}
|
|
344
704
|
saveProjectConfig({
|
|
@@ -347,97 +707,119 @@ var linkCommand = new import_commander2.Command("link").description("Link this p
|
|
|
347
707
|
environment: auth.environment
|
|
348
708
|
});
|
|
349
709
|
const gitignoreResult = updateGitignore(".commet/");
|
|
350
|
-
console.log(
|
|
351
|
-
console.log(
|
|
352
|
-
console.log(
|
|
710
|
+
console.log(import_chalk5.default.green("\n\u2713 Project linked successfully"));
|
|
711
|
+
console.log(import_chalk5.default.dim(`Organization: ${selectedOrg.name}`));
|
|
712
|
+
console.log(import_chalk5.default.dim(`Environment: ${auth.environment}`));
|
|
353
713
|
if (gitignoreResult.success) {
|
|
354
|
-
console.log(
|
|
714
|
+
console.log(import_chalk5.default.green("\u2713 Updated .gitignore"));
|
|
355
715
|
} else {
|
|
356
|
-
console.log(
|
|
357
|
-
console.log(
|
|
716
|
+
console.log(import_chalk5.default.yellow("\u26A0 No .gitignore found"));
|
|
717
|
+
console.log(import_chalk5.default.dim("Add .commet/ to your .gitignore file"));
|
|
358
718
|
}
|
|
359
|
-
console.log(
|
|
719
|
+
console.log(import_chalk5.default.dim("\nRun 'commet pull' to generate TypeScript types"));
|
|
360
720
|
});
|
|
361
721
|
|
|
362
722
|
// src/commands/list.ts
|
|
363
|
-
var
|
|
364
|
-
var
|
|
365
|
-
var
|
|
366
|
-
var
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
console.log(
|
|
370
|
-
|
|
371
|
-
|
|
723
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
724
|
+
var import_commander4 = require("commander");
|
|
725
|
+
var import_ora4 = __toESM(require("ora"));
|
|
726
|
+
var validTypes = ["features", "seats", "plans"];
|
|
727
|
+
var listCommand = new import_commander4.Command("list").description("List features, seat types, or plans").argument("<type>", "Type to list (features, seats, or plans)").action(async (type) => {
|
|
728
|
+
if (!validTypes.includes(type)) {
|
|
729
|
+
console.log(
|
|
730
|
+
import_chalk6.default.red('\u2717 Invalid type. Use "features", "seats", or "plans"')
|
|
731
|
+
);
|
|
732
|
+
console.log(import_chalk6.default.dim("\nExamples:"));
|
|
733
|
+
console.log(import_chalk6.default.dim(" commet list features"));
|
|
734
|
+
console.log(import_chalk6.default.dim(" commet list seats"));
|
|
735
|
+
console.log(import_chalk6.default.dim(" commet list plans"));
|
|
372
736
|
return;
|
|
373
737
|
}
|
|
374
738
|
if (!authExists()) {
|
|
375
|
-
console.log(
|
|
376
|
-
console.log(
|
|
739
|
+
console.log(import_chalk6.default.red("\u2717 Not authenticated"));
|
|
740
|
+
console.log(import_chalk6.default.dim("Run `commet login` first"));
|
|
377
741
|
return;
|
|
378
742
|
}
|
|
379
743
|
if (!projectConfigExists()) {
|
|
380
|
-
console.log(
|
|
744
|
+
console.log(import_chalk6.default.red("\u2717 Project not linked"));
|
|
381
745
|
console.log(
|
|
382
|
-
|
|
746
|
+
import_chalk6.default.dim("Run `commet link` first to connect to an organization")
|
|
383
747
|
);
|
|
384
748
|
return;
|
|
385
749
|
}
|
|
386
750
|
const projectConfig = loadProjectConfig();
|
|
387
751
|
if (!projectConfig) {
|
|
388
|
-
console.log(
|
|
752
|
+
console.log(import_chalk6.default.red("\u2717 Invalid project configuration"));
|
|
389
753
|
return;
|
|
390
754
|
}
|
|
391
|
-
const spinner = (0,
|
|
755
|
+
const spinner = (0, import_ora4.default)(`Fetching ${type}...`).start();
|
|
392
756
|
const baseURL = getBaseURL(projectConfig.environment);
|
|
393
757
|
const result = await apiRequest(
|
|
394
758
|
`${baseURL}/api/cli/types?orgId=${projectConfig.orgId}`
|
|
395
759
|
);
|
|
396
760
|
if (result.error || !result.data) {
|
|
397
761
|
spinner.fail(`Failed to fetch ${type}`);
|
|
398
|
-
console.error(
|
|
762
|
+
console.error(import_chalk6.default.red("Error:"), result.error);
|
|
399
763
|
return;
|
|
400
764
|
}
|
|
401
765
|
spinner.stop();
|
|
402
|
-
if (type === "
|
|
403
|
-
const {
|
|
404
|
-
if (
|
|
405
|
-
console.log(
|
|
766
|
+
if (type === "features") {
|
|
767
|
+
const { features } = result.data;
|
|
768
|
+
if (features.length === 0) {
|
|
769
|
+
console.log(import_chalk6.default.yellow("\u26A0 No features found"));
|
|
406
770
|
console.log(
|
|
407
|
-
|
|
771
|
+
import_chalk6.default.dim("Create features in your Commet dashboard first")
|
|
408
772
|
);
|
|
409
773
|
return;
|
|
410
774
|
}
|
|
411
|
-
console.log(
|
|
412
|
-
\u{1F4CA}
|
|
775
|
+
console.log(import_chalk6.default.bold(`
|
|
776
|
+
\u{1F4CA} Features (${features.length})
|
|
413
777
|
`));
|
|
414
|
-
for (const
|
|
415
|
-
console.log(
|
|
416
|
-
console.log(
|
|
417
|
-
if (
|
|
418
|
-
console.log(
|
|
778
|
+
for (const feature of features) {
|
|
779
|
+
console.log(import_chalk6.default.green(`\u2022 ${feature.code} (${feature.type})`));
|
|
780
|
+
console.log(import_chalk6.default.dim(` ${feature.name}`));
|
|
781
|
+
if (feature.description) {
|
|
782
|
+
console.log(import_chalk6.default.dim(` ${feature.description}`));
|
|
419
783
|
}
|
|
420
784
|
console.log("");
|
|
421
785
|
}
|
|
422
|
-
} else {
|
|
786
|
+
} else if (type === "seats") {
|
|
423
787
|
const { seatTypes } = result.data;
|
|
424
788
|
if (seatTypes.length === 0) {
|
|
425
|
-
console.log(
|
|
789
|
+
console.log(import_chalk6.default.yellow("\u26A0 No seat types found"));
|
|
426
790
|
console.log(
|
|
427
|
-
|
|
791
|
+
import_chalk6.default.dim("Create seat types in your Commet dashboard first")
|
|
428
792
|
);
|
|
429
793
|
return;
|
|
430
794
|
}
|
|
431
|
-
console.log(
|
|
795
|
+
console.log(import_chalk6.default.bold(`
|
|
432
796
|
\u{1F4BA} Seat Types (${seatTypes.length})
|
|
433
797
|
`));
|
|
434
798
|
for (const seatType of seatTypes) {
|
|
435
799
|
console.log(
|
|
436
|
-
|
|
800
|
+
import_chalk6.default.green(`\u2022 ${seatType.code}${seatType.isFree ? " (Free)" : ""}`)
|
|
437
801
|
);
|
|
438
|
-
console.log(
|
|
802
|
+
console.log(import_chalk6.default.dim(` ${seatType.name}`));
|
|
439
803
|
if (seatType.description) {
|
|
440
|
-
console.log(
|
|
804
|
+
console.log(import_chalk6.default.dim(` ${seatType.description}`));
|
|
805
|
+
}
|
|
806
|
+
console.log("");
|
|
807
|
+
}
|
|
808
|
+
} else {
|
|
809
|
+
const { plans } = result.data;
|
|
810
|
+
if (plans.length === 0) {
|
|
811
|
+
console.log(import_chalk6.default.yellow("\u26A0 No plans found"));
|
|
812
|
+
console.log(import_chalk6.default.dim("Create plans in your Commet dashboard first"));
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
console.log(import_chalk6.default.bold(`
|
|
816
|
+
\u{1F4CB} Plans (${plans.length})
|
|
817
|
+
`));
|
|
818
|
+
for (const plan of plans) {
|
|
819
|
+
console.log(import_chalk6.default.green(`\u2022 ${plan.code}`));
|
|
820
|
+
console.log(import_chalk6.default.dim(` ${plan.name}`));
|
|
821
|
+
if (plan.description) {
|
|
822
|
+
console.log(import_chalk6.default.dim(` ${plan.description}`));
|
|
441
823
|
}
|
|
442
824
|
console.log("");
|
|
443
825
|
}
|
|
@@ -445,17 +827,14 @@ var listCommand = new import_commander3.Command("list").description("List event
|
|
|
445
827
|
});
|
|
446
828
|
|
|
447
829
|
// src/commands/login.ts
|
|
448
|
-
var
|
|
449
|
-
var
|
|
450
|
-
var
|
|
451
|
-
var
|
|
452
|
-
var import_ora3 = __toESM(require("ora"));
|
|
453
|
-
var loginCommand = new import_commander4.Command("login").description("Authenticate with Commet").action(async () => {
|
|
830
|
+
var import_prompts3 = require("@inquirer/prompts");
|
|
831
|
+
var import_chalk7 = __toESM(require("chalk"));
|
|
832
|
+
var import_commander5 = require("commander");
|
|
833
|
+
var loginCommand = new import_commander5.Command("login").description("Authenticate with Commet").action(async () => {
|
|
454
834
|
if (authExists()) {
|
|
455
|
-
|
|
456
|
-
console.log(import_chalk5.default.yellow("\u26A0 You are already logged in."));
|
|
835
|
+
console.log(import_chalk7.default.yellow("\u26A0 You are already logged in."));
|
|
457
836
|
console.log(
|
|
458
|
-
|
|
837
|
+
import_chalk7.default.dim(
|
|
459
838
|
"Run `commet logout` first if you want to login with a different account."
|
|
460
839
|
)
|
|
461
840
|
);
|
|
@@ -463,11 +842,11 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
463
842
|
}
|
|
464
843
|
let environment;
|
|
465
844
|
try {
|
|
466
|
-
environment = await (0,
|
|
845
|
+
environment = await (0, import_prompts3.select)({
|
|
467
846
|
message: "Select environment to login:",
|
|
468
847
|
choices: [
|
|
469
848
|
{
|
|
470
|
-
name: `Sandbox ${
|
|
849
|
+
name: `Sandbox ${import_chalk7.default.dim("(Development)")}`,
|
|
471
850
|
value: "sandbox"
|
|
472
851
|
},
|
|
473
852
|
{
|
|
@@ -478,164 +857,51 @@ var loginCommand = new import_commander4.Command("login").description("Authentic
|
|
|
478
857
|
default: "sandbox",
|
|
479
858
|
theme: promptTheme
|
|
480
859
|
});
|
|
481
|
-
} catch
|
|
482
|
-
console.log(
|
|
860
|
+
} catch {
|
|
861
|
+
console.log(import_chalk7.default.yellow("\n\u26A0 Login cancelled"));
|
|
483
862
|
return;
|
|
484
863
|
}
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
client_id: "commet-cli",
|
|
493
|
-
scope: "openid profile email"
|
|
494
|
-
})
|
|
495
|
-
});
|
|
496
|
-
if (!deviceResponse.ok) {
|
|
497
|
-
spinner.fail("Failed to initiate login");
|
|
498
|
-
console.error(import_chalk5.default.red("Error:"), await deviceResponse.text());
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
const deviceData = await deviceResponse.json();
|
|
502
|
-
const {
|
|
503
|
-
device_code,
|
|
504
|
-
user_code,
|
|
505
|
-
verification_uri_complete,
|
|
506
|
-
interval = 5
|
|
507
|
-
} = deviceData;
|
|
508
|
-
spinner.stop();
|
|
509
|
-
console.log(import_chalk5.default.bold("\n\u{1F510} Commet CLI Login\n"));
|
|
510
|
-
console.log("Visit the following URL in your browser:");
|
|
511
|
-
console.log(import_chalk5.default.cyan.underline(verification_uri_complete));
|
|
512
|
-
console.log("\nOr enter this code manually:");
|
|
513
|
-
console.log(import_chalk5.default.bold.green(` ${user_code}`));
|
|
514
|
-
console.log(import_chalk5.default.dim("\nOpening browser...\n"));
|
|
515
|
-
try {
|
|
516
|
-
await (0, import_open.default)(verification_uri_complete);
|
|
517
|
-
} catch {
|
|
518
|
-
console.log(import_chalk5.default.yellow("\u26A0 Could not open browser automatically."));
|
|
519
|
-
}
|
|
520
|
-
const pollSpinner = (0, import_ora3.default)("Waiting for authorization...").start();
|
|
521
|
-
let pollingInterval = interval;
|
|
522
|
-
let attempts = 0;
|
|
523
|
-
const maxAttempts = 180 / pollingInterval;
|
|
524
|
-
const poll = async () => {
|
|
525
|
-
if (attempts >= maxAttempts) {
|
|
526
|
-
pollSpinner.fail("Login timed out");
|
|
527
|
-
console.log(import_chalk5.default.red("Authorization timed out. Please try again."));
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
attempts++;
|
|
531
|
-
try {
|
|
532
|
-
const tokenResponse = await fetch(
|
|
533
|
-
`${baseURL}/api/auth/device/token`,
|
|
534
|
-
{
|
|
535
|
-
method: "POST",
|
|
536
|
-
headers: { "Content-Type": "application/json" },
|
|
537
|
-
body: JSON.stringify({
|
|
538
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
539
|
-
device_code,
|
|
540
|
-
client_id: "commet-cli"
|
|
541
|
-
})
|
|
542
|
-
}
|
|
543
|
-
);
|
|
544
|
-
const tokenData = await tokenResponse.json();
|
|
545
|
-
if (tokenData.access_token) {
|
|
546
|
-
const authConfig = {
|
|
547
|
-
token: tokenData.access_token,
|
|
548
|
-
environment
|
|
549
|
-
};
|
|
550
|
-
if (tokenData.refresh_token) {
|
|
551
|
-
authConfig.refreshToken = tokenData.refresh_token;
|
|
552
|
-
}
|
|
553
|
-
if (tokenData.expires_in) {
|
|
554
|
-
authConfig.expiresAt = Date.now() + tokenData.expires_in * 1e3;
|
|
555
|
-
}
|
|
556
|
-
saveAuth(authConfig);
|
|
557
|
-
pollSpinner.succeed("Successfully logged in!");
|
|
558
|
-
console.log(import_chalk5.default.green("\n\u2713 Authentication complete"));
|
|
559
|
-
console.log(
|
|
560
|
-
import_chalk5.default.dim(
|
|
561
|
-
"\nNext steps:\n 1. Run `commet link` to connect a project\n 2. Run `commet pull` to generate types\n"
|
|
562
|
-
)
|
|
563
|
-
);
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
if (tokenData.error === "authorization_pending") {
|
|
567
|
-
setTimeout(() => poll(), pollingInterval * 1e3);
|
|
568
|
-
} else if (tokenData.error === "slow_down") {
|
|
569
|
-
pollingInterval += 5;
|
|
570
|
-
setTimeout(() => poll(), pollingInterval * 1e3);
|
|
571
|
-
} else if (tokenData.error === "access_denied") {
|
|
572
|
-
pollSpinner.fail("Authorization denied");
|
|
573
|
-
console.log(import_chalk5.default.red("\n\u2717 You denied the authorization request."));
|
|
574
|
-
return;
|
|
575
|
-
} else if (tokenData.error === "expired_token") {
|
|
576
|
-
pollSpinner.fail("Code expired");
|
|
577
|
-
console.log(
|
|
578
|
-
import_chalk5.default.red(
|
|
579
|
-
"\n\u2717 The authorization code expired. Please try again."
|
|
580
|
-
)
|
|
581
|
-
);
|
|
582
|
-
return;
|
|
583
|
-
} else {
|
|
584
|
-
pollSpinner.fail("Authorization failed");
|
|
585
|
-
console.log(
|
|
586
|
-
import_chalk5.default.red("\n\u2717 Error:"),
|
|
587
|
-
tokenData.error || "Unknown error"
|
|
588
|
-
);
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
} catch (error) {
|
|
592
|
-
pollSpinner.fail("Network error");
|
|
593
|
-
console.error(
|
|
594
|
-
import_chalk5.default.red("Error:"),
|
|
595
|
-
error instanceof Error ? error.message : "Unknown error"
|
|
596
|
-
);
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
poll();
|
|
600
|
-
} catch (error) {
|
|
601
|
-
spinner.fail("Login failed");
|
|
602
|
-
console.error(
|
|
603
|
-
import_chalk5.default.red("Error:"),
|
|
604
|
-
error instanceof Error ? error.message : "Unknown error"
|
|
864
|
+
const success = await performLogin(environment);
|
|
865
|
+
if (success) {
|
|
866
|
+
console.log(import_chalk7.default.green("\n\u2713 Authentication complete"));
|
|
867
|
+
console.log(
|
|
868
|
+
import_chalk7.default.dim(
|
|
869
|
+
"\nNext steps:\n 1. Run `commet link` to connect a project\n 2. Run `commet pull` to generate types\n"
|
|
870
|
+
)
|
|
605
871
|
);
|
|
606
872
|
}
|
|
607
873
|
});
|
|
608
874
|
|
|
609
875
|
// src/commands/logout.ts
|
|
610
|
-
var
|
|
611
|
-
var
|
|
612
|
-
var logoutCommand = new
|
|
876
|
+
var import_chalk8 = __toESM(require("chalk"));
|
|
877
|
+
var import_commander6 = require("commander");
|
|
878
|
+
var logoutCommand = new import_commander6.Command("logout").description("Log out of Commet").action(async () => {
|
|
613
879
|
if (!authExists()) {
|
|
614
|
-
console.log(
|
|
880
|
+
console.log(import_chalk8.default.yellow("\u26A0 You are not logged in."));
|
|
615
881
|
return;
|
|
616
882
|
}
|
|
617
883
|
clearAuth();
|
|
618
|
-
console.log(
|
|
884
|
+
console.log(import_chalk8.default.green("\u2713 Successfully logged out"));
|
|
619
885
|
});
|
|
620
886
|
|
|
621
887
|
// src/commands/pull.ts
|
|
622
|
-
var
|
|
623
|
-
var
|
|
624
|
-
var
|
|
625
|
-
var
|
|
626
|
-
var
|
|
888
|
+
var fs6 = __toESM(require("fs"));
|
|
889
|
+
var path6 = __toESM(require("path"));
|
|
890
|
+
var import_chalk9 = __toESM(require("chalk"));
|
|
891
|
+
var import_commander7 = require("commander");
|
|
892
|
+
var import_ora5 = __toESM(require("ora"));
|
|
627
893
|
|
|
628
894
|
// src/utils/environment-validator.ts
|
|
629
|
-
var
|
|
630
|
-
var
|
|
895
|
+
var fs4 = __toESM(require("fs"));
|
|
896
|
+
var path4 = __toESM(require("path"));
|
|
631
897
|
function validateTypeScriptProject() {
|
|
632
898
|
const cwd = process.cwd();
|
|
633
|
-
const tsconfigPath =
|
|
634
|
-
if (!
|
|
899
|
+
const tsconfigPath = path4.join(cwd, "tsconfig.json");
|
|
900
|
+
if (!fs4.existsSync(tsconfigPath)) {
|
|
635
901
|
return false;
|
|
636
902
|
}
|
|
637
903
|
try {
|
|
638
|
-
const content =
|
|
904
|
+
const content = fs4.readFileSync(tsconfigPath, "utf8");
|
|
639
905
|
JSON.parse(content);
|
|
640
906
|
return true;
|
|
641
907
|
} catch (error) {
|
|
@@ -644,14 +910,10 @@ function validateTypeScriptProject() {
|
|
|
644
910
|
}
|
|
645
911
|
|
|
646
912
|
// src/utils/generator.ts
|
|
647
|
-
function generateTypes(
|
|
648
|
-
const eventTypeUnion = eventTypes.length > 0 ? eventTypes.map((e) => `"${e.code}"`).join(" | ") : "string";
|
|
913
|
+
function generateTypes(seatTypes, features, plans) {
|
|
649
914
|
const seatTypeUnion = seatTypes.length > 0 ? seatTypes.map((s) => `"${s.code}"`).join(" | ") : "string";
|
|
650
915
|
const planCodeUnion = plans.length > 0 ? plans.map((p) => `"${p.code}"`).join(" | ") : "string";
|
|
651
916
|
const featureCodeUnion = features.length > 0 ? features.map((f) => `"${f.code}"`).join(" | ") : "string";
|
|
652
|
-
const eventComments = eventTypes.map(
|
|
653
|
-
(e) => ` * - "${e.code}": ${e.name}${e.description ? ` - ${e.description}` : ""}`
|
|
654
|
-
).join("\n");
|
|
655
917
|
const seatComments = seatTypes.map(
|
|
656
918
|
(s) => ` * - "${s.code}": ${s.name}${s.description ? ` - ${s.description}` : ""} ${s.isFree ? "(Free)" : ""}`
|
|
657
919
|
).join("\n");
|
|
@@ -665,52 +927,46 @@ function generateTypes(eventTypes, seatTypes, features, plans) {
|
|
|
665
927
|
// Do not edit this file manually - run 'commet pull' to update
|
|
666
928
|
|
|
667
929
|
/**
|
|
668
|
-
* This augments the Commet SDK
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
${
|
|
673
|
-
*
|
|
930
|
+
* This augments the Commet SDK with your organization's
|
|
931
|
+
* feature codes, seat types, and plan codes for autocomplete.
|
|
932
|
+
*
|
|
933
|
+
* Features available in your organization:
|
|
934
|
+
${featureComments || " * (none)"}
|
|
935
|
+
*
|
|
674
936
|
* Seat types available in your organization:
|
|
675
937
|
${seatComments || " * (none)"}
|
|
676
|
-
*
|
|
938
|
+
*
|
|
677
939
|
* Plans available in your organization:
|
|
678
940
|
${planComments || " * (none)"}
|
|
679
|
-
*
|
|
680
|
-
|
|
681
|
-
${featureComments || " * (none)"}
|
|
682
|
-
*
|
|
683
|
-
*/
|
|
941
|
+
*
|
|
942
|
+
*/
|
|
684
943
|
declare module '@commet/node' {
|
|
685
944
|
interface CommetGeneratedTypes {
|
|
686
|
-
eventType: ${eventTypeUnion};
|
|
687
945
|
seatType: ${seatTypeUnion};
|
|
688
946
|
planCode: ${planCodeUnion};
|
|
689
947
|
featureCode: ${featureCodeUnion};
|
|
690
948
|
}
|
|
691
949
|
}
|
|
692
950
|
|
|
693
|
-
// This export is required for TypeScript to treat this file as a module
|
|
694
|
-
// and apply the module augmentation above
|
|
695
951
|
export {};
|
|
696
952
|
`;
|
|
697
953
|
}
|
|
698
954
|
|
|
699
955
|
// src/utils/tsconfig-updater.ts
|
|
700
|
-
var
|
|
701
|
-
var
|
|
956
|
+
var fs5 = __toESM(require("fs"));
|
|
957
|
+
var path5 = __toESM(require("path"));
|
|
702
958
|
var import_jsonc_parser = require("jsonc-parser");
|
|
703
959
|
function updateTsConfig(entry) {
|
|
704
960
|
const cwd = process.cwd();
|
|
705
|
-
const tsconfigPath =
|
|
961
|
+
const tsconfigPath = path5.join(cwd, "tsconfig.json");
|
|
706
962
|
try {
|
|
707
|
-
if (!
|
|
963
|
+
if (!fs5.existsSync(tsconfigPath)) {
|
|
708
964
|
return {
|
|
709
965
|
success: false,
|
|
710
966
|
error: "tsconfig.json not found"
|
|
711
967
|
};
|
|
712
968
|
}
|
|
713
|
-
const content =
|
|
969
|
+
const content = fs5.readFileSync(tsconfigPath, "utf8");
|
|
714
970
|
const config = (0, import_jsonc_parser.parse)(content);
|
|
715
971
|
if (config.include && Array.isArray(config.include)) {
|
|
716
972
|
if (config.include.includes(entry)) {
|
|
@@ -726,7 +982,7 @@ function updateTsConfig(entry) {
|
|
|
726
982
|
}
|
|
727
983
|
});
|
|
728
984
|
const updatedContent = (0, import_jsonc_parser.applyEdits)(content, edits);
|
|
729
|
-
|
|
985
|
+
fs5.writeFileSync(tsconfigPath, updatedContent, "utf8");
|
|
730
986
|
return { success: true };
|
|
731
987
|
} catch (error) {
|
|
732
988
|
return {
|
|
@@ -737,130 +993,120 @@ function updateTsConfig(entry) {
|
|
|
737
993
|
}
|
|
738
994
|
|
|
739
995
|
// src/commands/pull.ts
|
|
740
|
-
var pullCommand = new
|
|
996
|
+
var pullCommand = new import_commander7.Command("pull").description("Pull type definitions from Commet").action(async () => {
|
|
741
997
|
if (!authExists()) {
|
|
742
|
-
console.log(
|
|
743
|
-
console.log(
|
|
998
|
+
console.log(import_chalk9.default.red("\u2717 Not authenticated"));
|
|
999
|
+
console.log(import_chalk9.default.dim("Run `commet login` first"));
|
|
744
1000
|
return;
|
|
745
1001
|
}
|
|
746
1002
|
const hasTsConfig = validateTypeScriptProject();
|
|
747
1003
|
if (!projectConfigExists()) {
|
|
748
|
-
console.log(
|
|
1004
|
+
console.log(import_chalk9.default.red("\u2717 Project not linked"));
|
|
749
1005
|
console.log(
|
|
750
|
-
|
|
1006
|
+
import_chalk9.default.dim("Run `commet link` first to connect to an organization")
|
|
751
1007
|
);
|
|
752
1008
|
return;
|
|
753
1009
|
}
|
|
754
1010
|
const projectConfig = loadProjectConfig();
|
|
755
1011
|
if (!projectConfig) {
|
|
756
|
-
console.log(
|
|
1012
|
+
console.log(import_chalk9.default.red("\u2717 Invalid project configuration"));
|
|
757
1013
|
return;
|
|
758
1014
|
}
|
|
759
|
-
const spinner = (0,
|
|
1015
|
+
const spinner = (0, import_ora5.default)("Fetching type definitions...").start();
|
|
760
1016
|
const baseURL = getBaseURL(projectConfig.environment);
|
|
761
1017
|
const result = await apiRequest(
|
|
762
1018
|
`${baseURL}/api/cli/types?orgId=${projectConfig.orgId}`
|
|
763
1019
|
);
|
|
764
1020
|
if (result.error || !result.data) {
|
|
765
1021
|
spinner.fail("Failed to fetch types");
|
|
766
|
-
console.error(
|
|
1022
|
+
console.error(import_chalk9.default.red("Error:"), result.error);
|
|
767
1023
|
return;
|
|
768
1024
|
}
|
|
769
|
-
const {
|
|
770
|
-
const typeDefinitions = generateTypes(
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
);
|
|
776
|
-
const commetDir = path5.resolve(process.cwd(), ".commet");
|
|
777
|
-
const outputPath = path5.join(commetDir, "types.d.ts");
|
|
778
|
-
fs5.mkdirSync(commetDir, { recursive: true });
|
|
779
|
-
fs5.writeFileSync(outputPath, typeDefinitions, "utf8");
|
|
1025
|
+
const { seatTypes, features, plans } = result.data;
|
|
1026
|
+
const typeDefinitions = generateTypes(seatTypes, features, plans);
|
|
1027
|
+
const commetDir = path6.resolve(process.cwd(), ".commet");
|
|
1028
|
+
const outputPath = path6.join(commetDir, "types.d.ts");
|
|
1029
|
+
fs6.mkdirSync(commetDir, { recursive: true });
|
|
1030
|
+
fs6.writeFileSync(outputPath, typeDefinitions, "utf8");
|
|
780
1031
|
spinner.succeed("Type definitions generated!");
|
|
781
1032
|
if (hasTsConfig) {
|
|
782
1033
|
const tsconfigResult = updateTsConfig(".commet/types.d.ts");
|
|
783
1034
|
if (tsconfigResult.success) {
|
|
784
|
-
console.log(
|
|
1035
|
+
console.log(import_chalk9.default.green("\u2713 Updated tsconfig.json"));
|
|
785
1036
|
} else {
|
|
786
|
-
console.log(
|
|
1037
|
+
console.log(import_chalk9.default.yellow("\u26A0 Could not update tsconfig.json"));
|
|
787
1038
|
console.log(
|
|
788
|
-
|
|
1039
|
+
import_chalk9.default.dim(
|
|
789
1040
|
'Add ".commet/types.d.ts" to your tsconfig.json include array'
|
|
790
1041
|
)
|
|
791
1042
|
);
|
|
792
1043
|
}
|
|
793
1044
|
} else {
|
|
794
|
-
console.log(
|
|
1045
|
+
console.log(import_chalk9.default.yellow("\u26A0 No tsconfig.json found"));
|
|
795
1046
|
console.log(
|
|
796
|
-
|
|
1047
|
+
import_chalk9.default.dim(
|
|
797
1048
|
'Add ".commet/types.d.ts" to your tsconfig.json to enable types'
|
|
798
1049
|
)
|
|
799
1050
|
);
|
|
800
1051
|
}
|
|
801
1052
|
const gitignoreResult = updateGitignore(".commet/");
|
|
802
1053
|
if (gitignoreResult.success) {
|
|
803
|
-
console.log(
|
|
1054
|
+
console.log(import_chalk9.default.green("\u2713 Updated .gitignore"));
|
|
804
1055
|
} else {
|
|
805
|
-
console.log(
|
|
806
|
-
console.log(
|
|
1056
|
+
console.log(import_chalk9.default.yellow("\u26A0 No .gitignore found"));
|
|
1057
|
+
console.log(import_chalk9.default.dim("Add .commet/ to your .gitignore file"));
|
|
807
1058
|
}
|
|
808
|
-
console.log(
|
|
809
|
-
console.log(
|
|
1059
|
+
console.log(import_chalk9.default.green("\nSuccess!"));
|
|
1060
|
+
console.log(import_chalk9.default.dim("\nGenerated types:"));
|
|
810
1061
|
console.log(
|
|
811
|
-
|
|
812
|
-
`
|
|
1062
|
+
import_chalk9.default.dim(
|
|
1063
|
+
` Features: ${features.length > 0 ? features.map((f) => f.code).join(", ") : "none"}`
|
|
813
1064
|
)
|
|
814
1065
|
);
|
|
815
1066
|
console.log(
|
|
816
|
-
|
|
1067
|
+
import_chalk9.default.dim(
|
|
817
1068
|
` Seat types: ${seatTypes.length > 0 ? seatTypes.map((s) => s.code).join(", ") : "none"}`
|
|
818
1069
|
)
|
|
819
1070
|
);
|
|
820
1071
|
console.log(
|
|
821
|
-
|
|
1072
|
+
import_chalk9.default.dim(
|
|
822
1073
|
` Plans: ${plans.length > 0 ? plans.map((p) => p.code).join(", ") : "none"}`
|
|
823
1074
|
)
|
|
824
1075
|
);
|
|
825
|
-
console.log(
|
|
826
|
-
import_chalk7.default.dim(
|
|
827
|
-
` Features: ${features.length > 0 ? features.map((f) => f.code).join(", ") : "none"}`
|
|
828
|
-
)
|
|
829
|
-
);
|
|
830
|
-
console.log(import_chalk7.default.dim(`
|
|
1076
|
+
console.log(import_chalk9.default.dim(`
|
|
831
1077
|
Output: ${outputPath}`));
|
|
832
|
-
if (
|
|
1078
|
+
if (seatTypes.length === 0 && plans.length === 0 && features.length === 0) {
|
|
833
1079
|
console.log(
|
|
834
|
-
|
|
835
|
-
"\n\u26A0 No types found. Create
|
|
1080
|
+
import_chalk9.default.yellow(
|
|
1081
|
+
"\n\u26A0 No types found. Create features, seat types, and plans in your Commet dashboard."
|
|
836
1082
|
)
|
|
837
1083
|
);
|
|
838
1084
|
}
|
|
839
1085
|
});
|
|
840
1086
|
|
|
841
1087
|
// src/commands/switch.ts
|
|
842
|
-
var
|
|
843
|
-
var
|
|
844
|
-
var
|
|
845
|
-
var
|
|
846
|
-
var switchCommand = new
|
|
1088
|
+
var import_prompts4 = require("@inquirer/prompts");
|
|
1089
|
+
var import_chalk10 = __toESM(require("chalk"));
|
|
1090
|
+
var import_commander8 = require("commander");
|
|
1091
|
+
var import_ora6 = __toESM(require("ora"));
|
|
1092
|
+
var switchCommand = new import_commander8.Command("switch").description("Switch to a different organization").action(async () => {
|
|
847
1093
|
if (!authExists()) {
|
|
848
|
-
console.log(
|
|
849
|
-
console.log(
|
|
1094
|
+
console.log(import_chalk10.default.red("\u2717 Not authenticated"));
|
|
1095
|
+
console.log(import_chalk10.default.dim("Run `commet login` first"));
|
|
850
1096
|
return;
|
|
851
1097
|
}
|
|
852
1098
|
if (!projectConfigExists()) {
|
|
853
|
-
console.log(
|
|
1099
|
+
console.log(import_chalk10.default.yellow("\u26A0 Project not linked"));
|
|
854
1100
|
console.log(
|
|
855
|
-
|
|
1101
|
+
import_chalk10.default.dim("Run `commet link` first to connect to an organization")
|
|
856
1102
|
);
|
|
857
1103
|
return;
|
|
858
1104
|
}
|
|
859
|
-
const spinner = (0,
|
|
1105
|
+
const spinner = (0, import_ora6.default)("Fetching organizations...").start();
|
|
860
1106
|
const auth = loadAuth();
|
|
861
1107
|
if (!auth) {
|
|
862
1108
|
spinner.fail("Authentication error");
|
|
863
|
-
console.log(
|
|
1109
|
+
console.log(import_chalk10.default.red("\u2717 Could not load authentication"));
|
|
864
1110
|
return;
|
|
865
1111
|
}
|
|
866
1112
|
const baseURL = getBaseURL(auth.environment);
|
|
@@ -869,33 +1115,33 @@ var switchCommand = new import_commander7.Command("switch").description("Switch
|
|
|
869
1115
|
);
|
|
870
1116
|
if (result.error || !result.data) {
|
|
871
1117
|
spinner.fail("Failed to fetch organizations");
|
|
872
|
-
console.error(
|
|
1118
|
+
console.error(import_chalk10.default.red("Error:"), result.error);
|
|
873
1119
|
return;
|
|
874
1120
|
}
|
|
875
1121
|
const { organizations } = result.data;
|
|
876
1122
|
if (organizations.length === 0) {
|
|
877
1123
|
spinner.stop();
|
|
878
|
-
console.log(
|
|
1124
|
+
console.log(import_chalk10.default.yellow("\u26A0 No organizations found"));
|
|
879
1125
|
return;
|
|
880
1126
|
}
|
|
881
1127
|
spinner.stop();
|
|
882
1128
|
let orgId;
|
|
883
1129
|
try {
|
|
884
|
-
orgId = await (0,
|
|
1130
|
+
orgId = await (0, import_prompts4.select)({
|
|
885
1131
|
message: "Select organization:",
|
|
886
1132
|
choices: organizations.map((org) => ({
|
|
887
|
-
name: `${org.name} ${
|
|
1133
|
+
name: `${org.name} ${import_chalk10.default.dim(`(${org.slug})`)}`,
|
|
888
1134
|
value: org.id
|
|
889
1135
|
})),
|
|
890
1136
|
theme: promptTheme
|
|
891
1137
|
});
|
|
892
1138
|
} catch (error) {
|
|
893
|
-
console.log(
|
|
1139
|
+
console.log(import_chalk10.default.yellow("\n\u26A0 Switch cancelled"));
|
|
894
1140
|
return;
|
|
895
1141
|
}
|
|
896
1142
|
const selectedOrg = organizations.find((org) => org.id === orgId);
|
|
897
1143
|
if (!selectedOrg) {
|
|
898
|
-
console.log(
|
|
1144
|
+
console.log(import_chalk10.default.red("\u2717 Organization not found"));
|
|
899
1145
|
return;
|
|
900
1146
|
}
|
|
901
1147
|
saveProjectConfig({
|
|
@@ -903,54 +1149,54 @@ var switchCommand = new import_commander7.Command("switch").description("Switch
|
|
|
903
1149
|
orgName: selectedOrg.name,
|
|
904
1150
|
environment: auth.environment
|
|
905
1151
|
});
|
|
906
|
-
console.log(
|
|
907
|
-
console.log(
|
|
908
|
-
console.log(
|
|
909
|
-
console.log(
|
|
1152
|
+
console.log(import_chalk10.default.green("\n\u2713 Switched organization successfully!"));
|
|
1153
|
+
console.log(import_chalk10.default.dim("\nNew configuration:"));
|
|
1154
|
+
console.log(import_chalk10.default.dim(` Organization: ${selectedOrg.name}`));
|
|
1155
|
+
console.log(import_chalk10.default.dim(` Environment: ${auth.environment}`));
|
|
910
1156
|
console.log(
|
|
911
|
-
|
|
1157
|
+
import_chalk10.default.dim(
|
|
912
1158
|
"\nRun `commet pull` to update TypeScript types for this organization"
|
|
913
1159
|
)
|
|
914
1160
|
);
|
|
915
1161
|
});
|
|
916
1162
|
|
|
917
1163
|
// src/commands/unlink.ts
|
|
918
|
-
var
|
|
919
|
-
var
|
|
920
|
-
var unlinkCommand = new
|
|
1164
|
+
var import_chalk11 = __toESM(require("chalk"));
|
|
1165
|
+
var import_commander9 = require("commander");
|
|
1166
|
+
var unlinkCommand = new import_commander9.Command("unlink").description("Unlink this project from Commet").action(async () => {
|
|
921
1167
|
if (!projectConfigExists()) {
|
|
922
1168
|
console.log(
|
|
923
|
-
|
|
1169
|
+
import_chalk11.default.yellow("\u26A0 This project is not linked to any organization")
|
|
924
1170
|
);
|
|
925
1171
|
return;
|
|
926
1172
|
}
|
|
927
1173
|
clearProjectConfig();
|
|
928
|
-
console.log(
|
|
929
|
-
console.log(
|
|
1174
|
+
console.log(import_chalk11.default.green("\u2713 Project unlinked successfully"));
|
|
1175
|
+
console.log(import_chalk11.default.dim("\u2713 Removed .commet/ directory"));
|
|
930
1176
|
console.log(
|
|
931
|
-
|
|
1177
|
+
import_chalk11.default.dim("\nRun `commet link` to connect to a different organization")
|
|
932
1178
|
);
|
|
933
1179
|
});
|
|
934
1180
|
|
|
935
1181
|
// src/commands/whoami.ts
|
|
936
|
-
var
|
|
937
|
-
var
|
|
938
|
-
var whoamiCommand = new
|
|
1182
|
+
var import_chalk12 = __toESM(require("chalk"));
|
|
1183
|
+
var import_commander10 = require("commander");
|
|
1184
|
+
var whoamiCommand = new import_commander10.Command("whoami").description("Display current authentication and project status").action(async () => {
|
|
939
1185
|
if (!authExists()) {
|
|
940
|
-
console.log(
|
|
941
|
-
console.log(
|
|
1186
|
+
console.log(import_chalk12.default.yellow("\u26A0 Not logged in"));
|
|
1187
|
+
console.log(import_chalk12.default.dim("Run `commet login` to authenticate"));
|
|
942
1188
|
return;
|
|
943
1189
|
}
|
|
944
|
-
console.log(
|
|
1190
|
+
console.log(import_chalk12.default.green("\u2713 Logged in"));
|
|
945
1191
|
const projectConfig = loadProjectConfig();
|
|
946
1192
|
if (projectConfig) {
|
|
947
|
-
console.log(
|
|
948
|
-
console.log(
|
|
949
|
-
console.log(
|
|
1193
|
+
console.log(import_chalk12.default.bold("\nProject:"));
|
|
1194
|
+
console.log(import_chalk12.default.dim("Organization:"), projectConfig.orgName);
|
|
1195
|
+
console.log(import_chalk12.default.dim("Environment:"), projectConfig.environment);
|
|
950
1196
|
} else {
|
|
951
|
-
console.log(
|
|
1197
|
+
console.log(import_chalk12.default.yellow("\n\u26A0 No project linked"));
|
|
952
1198
|
console.log(
|
|
953
|
-
|
|
1199
|
+
import_chalk12.default.dim(
|
|
954
1200
|
"Run `commet link` to connect this directory to an organization"
|
|
955
1201
|
)
|
|
956
1202
|
);
|
|
@@ -958,10 +1204,11 @@ var whoamiCommand = new import_commander9.Command("whoami").description("Display
|
|
|
958
1204
|
});
|
|
959
1205
|
|
|
960
1206
|
// src/index.ts
|
|
961
|
-
var program = new
|
|
1207
|
+
var program = new import_commander11.Command();
|
|
962
1208
|
program.name("commet").description(
|
|
963
1209
|
"Commet CLI - Manage your billing platform from the command line"
|
|
964
1210
|
).version(package_default.version);
|
|
1211
|
+
program.addCommand(createCommand);
|
|
965
1212
|
program.addCommand(loginCommand);
|
|
966
1213
|
program.addCommand(logoutCommand);
|
|
967
1214
|
program.addCommand(whoamiCommand);
|
|
@@ -979,7 +1226,7 @@ try {
|
|
|
979
1226
|
if (error.message.includes("outputHelp")) {
|
|
980
1227
|
process.exit(0);
|
|
981
1228
|
}
|
|
982
|
-
console.error(
|
|
1229
|
+
console.error(import_chalk13.default.red("Error:"), error.message);
|
|
983
1230
|
}
|
|
984
1231
|
process.exit(1);
|
|
985
1232
|
}
|