thinkncollab-cli 0.0.46 → 0.0.48

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/bin/index.js CHANGED
@@ -12,6 +12,7 @@ import pull from "../commands/pull.js";
12
12
  import whoami from "../commands/whoami.js";
13
13
  import help from "../commands/help.js";
14
14
  import version from "../commands/version.js";
15
+ import createBranch from "../commands/branch.js"
15
16
 
16
17
 
17
18
  const RC_FILE = path.join(os.homedir(), ".tncrc");
@@ -447,10 +448,28 @@ async function main() {
447
448
  case "init":
448
449
  await projectInit();
449
450
  break;
451
+
452
+ case "create":
453
+ const roomIdx = args.indexOf("--room");
454
+ if (roomIdx === -1 || !args[roomIdx + 1]) {
455
+ console.log("Usage: tnc-cli create-branch --room <roomId>");
456
+ console.log("Example: tnc-cli create-branch --room 507f1f77bcf86cd799439011");
457
+ process.exit(1);
458
+ }
459
+
460
+ const roomId = args[roomIdx + 1];
461
+
462
+ // Basic roomId validation (MongoDB ObjectId format)
463
+ if (!/^[0-9a-fA-F]{24}$/.test(roomId)) {
464
+ console.log("❌ Error: Invalid room ID format");
465
+ process.exit(1);
466
+ }
467
+
468
+ await createBranch(roomId);
469
+ break;
450
470
 
451
471
  case "pull": {
452
472
  const roomIndex = args.indexOf("--room");
453
-
454
473
  if (roomIndex === -1 || !args[roomIndex + 1]) {
455
474
  console.error("Usage: tnc pull --room <roomId> [--version <version>]");
456
475
  process.exit(1);
@@ -473,11 +492,11 @@ async function main() {
473
492
  await whoami();
474
493
  break;
475
494
 
476
- case "help":
495
+ case "help":
477
496
  await help();
478
497
  break;
479
498
 
480
- case "version":
499
+ case "version":
481
500
  await version();
482
501
  break;
483
502
 
@@ -487,8 +506,13 @@ async function main() {
487
506
  console.log(" tnc-cli login");
488
507
  console.log(" tnc-cli init");
489
508
  console.log(" tnc-cli push --room <roomId> <path>");
509
+ console.log(" tnc-cli pull --room <roomId>");
510
+ console.log(" tnc-cli status");
511
+ console.log(" tnc-cli whoami");
490
512
  console.log(" tnc-cli logout");
491
- }
513
+ console.log(" tnc-cli help");
514
+ console.log(" tnc-cli version");
515
+ }
492
516
  }
493
517
 
494
518
  main().catch(err => console.error(err));
@@ -0,0 +1,66 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import axios from "axios";
4
+ import os from "os";
5
+ import inquirer from "inquirer";
6
+
7
+ async function createBranch(roomId) {
8
+ try {
9
+ const branchName = await inquirer.prompt([
10
+ {
11
+ type: "input",
12
+ name: "branchName",
13
+ message: "Enter the new branch name:",
14
+ validate: (input) => {
15
+ if (!input || input.trim().length === 0) {
16
+ return "Branch name cannot be empty";
17
+ }
18
+ // Basic validation - you might want to add more rules
19
+ if (!/^[a-zA-Z0-9_-]+$/.test(input.trim())) {
20
+ return "Branch name can only contain letters, numbers, hyphens, and underscores";
21
+ }
22
+ return true;
23
+ }
24
+ }
25
+ ]);
26
+
27
+ const homeDir = os.homedir();
28
+ const tncfilepath = path.join(homeDir, ".tncrc");
29
+
30
+ if (!fs.existsSync(tncfilepath)) {
31
+ throw new Error("Configuration file not found. Please login first.");
32
+ }
33
+
34
+ const doc = fs.readFileSync(tncfilepath, "utf-8");
35
+ const obj = JSON.parse(doc);
36
+ const email = obj.email;
37
+
38
+ if (!email) {
39
+ throw new Error("User email not found in configuration. Please login again.");
40
+ }
41
+
42
+ const res = await axios.post("http://localhost:3001/cli/createBranch", {
43
+ branchName: branchName.branchName.trim(),
44
+ roomId: roomId,
45
+ email: email
46
+ });
47
+
48
+ if (res.data.success) {
49
+ console.log(`✅ Branch '${branchName.branchName}' created successfully!`);
50
+ } else {
51
+ console.log(`❌ Failed to create branch: ${res.data.message}`);
52
+ }
53
+
54
+ } catch (error) {
55
+ if (error.response?.data?.message) {
56
+ console.error(`❌ Error: ${error.response.data.message}`);
57
+ } else if (error.message) {
58
+ console.error(`❌ Error: ${error.message}`);
59
+ } else {
60
+ console.error("❌ An unexpected error occurred");
61
+ }
62
+ process.exit(1);
63
+ }
64
+ }
65
+
66
+ export default createBranch;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "thinkncollab-cli",
3
3
  "author": "Raman Singh",
4
- "version": "0.0.46",
4
+ "version": "0.0.48",
5
5
  "description": "CLI tool for ThinkNCollab",
6
6
  "main": "index.js",
7
7
  "bin": {