thinkncollab-cli 0.0.60 → 0.0.62

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.
Files changed (2) hide show
  1. package/commands/branch.js +36 -17
  2. package/package.json +1 -1
@@ -4,23 +4,43 @@ import axios from "axios";
4
4
  import os from "os";
5
5
  import inquirer from "inquirer";
6
6
 
7
+ // Updates the current branch name in .tnc/.tncmeta.json
7
8
  async function updateBranch(branchName) {
8
- const currenDir = process.cwd();
9
- const tncmetaFile = path.join(currenDir, ".tncmeta.json")
9
+ const currentDir = process.cwd();
10
+ const tncFolder = path.join(currentDir, ".tnc");
11
+ const tncmetaFile = path.join(tncFolder, ".tncmeta.json");
10
12
 
11
- if(!fs.readFileSync(tncmetaFile)) {
13
+ // Ensure .tnc folder exists
14
+ if (!fs.existsSync(tncFolder)) {
15
+ fs.mkdirSync(tncFolder, { recursive: true });
16
+ }
17
+
18
+ let meta = {};
12
19
 
20
+ // Read existing meta if exists
21
+ if (fs.existsSync(tncmetaFile)) {
22
+ try {
23
+ const data = fs.readFileSync(tncmetaFile, "utf-8");
24
+ meta = JSON.parse(data);
25
+ } catch {
26
+ console.warn("⚠️ Warning: Corrupted .tncmeta.json, creating a new one.");
27
+ meta = {};
28
+ }
13
29
  }
14
- const content = ` "currentBranch": "${branchName}",`;
15
-
16
30
 
17
- fs.writeFileSync(tncmetaFile, content, "utf-8" );
18
-
31
+ // Update the current branch
32
+ meta.currentBranch = branchName;
33
+
34
+ // Write updated data
35
+ fs.writeFileSync(tncmetaFile, JSON.stringify(meta, null, 2), "utf-8");
36
+
37
+ console.log(`🌿 Switched to branch '${branchName}'`);
19
38
  }
20
39
 
40
+ // Creates a new branch for a room
21
41
  async function createBranch(roomId) {
22
42
  try {
23
- const branchName = await inquirer.prompt([
43
+ const { branchName } = await inquirer.prompt([
24
44
  {
25
45
  type: "input",
26
46
  name: "branchName",
@@ -29,18 +49,17 @@ async function createBranch(roomId) {
29
49
  if (!input || input.trim().length === 0) {
30
50
  return "Branch name cannot be empty";
31
51
  }
32
- // Basic validation - you might want to add more rules
33
52
  if (!/^[a-zA-Z0-9_-]+$/.test(input.trim())) {
34
53
  return "Branch name can only contain letters, numbers, hyphens, and underscores";
35
54
  }
36
55
  return true;
37
- }
38
- }
56
+ },
57
+ },
39
58
  ]);
40
59
 
41
60
  const homeDir = os.homedir();
42
61
  const tncfilepath = path.join(homeDir, ".tncrc");
43
-
62
+
44
63
  if (!fs.existsSync(tncfilepath)) {
45
64
  throw new Error("Configuration file not found. Please login first.");
46
65
  }
@@ -54,14 +73,14 @@ async function createBranch(roomId) {
54
73
  }
55
74
 
56
75
  const res = await axios.post("https://thinkncollab.in/cli/createBranch", {
57
- branchName: branchName.branchName.trim(),
58
- roomId: roomId,
59
- email: email
76
+ branchName: branchName.trim(),
77
+ roomId,
78
+ email,
60
79
  });
61
80
 
62
81
  if (res.data.success) {
63
- console.log(`✅ Branch '${branchName.branchName}' created successfully!`);
64
- updateBranch(branchName.branchName);
82
+ console.log(`✅ Branch '${branchName}' created successfully!`);
83
+ await updateBranch(branchName);
65
84
  } else {
66
85
  console.log(`❌ Failed to create branch: ${res.data.message}`);
67
86
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "thinkncollab-cli",
3
3
  "author": "Raman Singh",
4
- "version": "0.0.60",
4
+ "version": "0.0.62",
5
5
  "description": "CLI tool for ThinkNCollab",
6
6
  "main": "index.js",
7
7
  "bin": {