thinkncollab-cli 0.0.61 → 0.0.63

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
@@ -20,7 +20,7 @@ import sendInvite from '../commands/sendInvite.js'
20
20
 
21
21
  const RC_FILE = path.join(os.homedir(), ".tncrc");
22
22
  const VERSION_FILE = path.join(process.cwd(), ".tncversions");
23
- const BASE_URL = "https://thinkncollab.in/rooms";
23
+ const BASE_URL = "http://localhost:3001/rooms";
24
24
  const CWD = process.cwd();
25
25
 
26
26
  /** ------------------ LOGIN ------------------ **/
@@ -368,7 +368,7 @@ async function push(roomId, targetPath) {
368
368
  const uploadedTree = await uploadTree(contentWithChanges, folderHex, roomId, token, email, previousVersions);
369
369
 
370
370
  console.log("🗂️ Sending metadata...");
371
- await axios.post(
371
+ const res = await axios.post(
372
372
  `${BASE_URL}/${roomId}/upload`,
373
373
  { folderId: folderHex, content: uploadedTree, uploadedBy: email, projectId },
374
374
  { headers: { authorization: `Bearer ${token}`, email } }
@@ -402,7 +402,8 @@ async function push(roomId, targetPath) {
402
402
  pushedAt: new Date().toISOString(),
403
403
  roomId: roomId,
404
404
  pushedBy: email,
405
- projectId: projectId
405
+ projectId: projectId,
406
+ folderId: res.folderId
406
407
  };
407
408
 
408
409
 
@@ -4,24 +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 tncFolder = path.join(currenDir, ".tnc");
10
- const tncmetaFile = path.join(tncFolder, ".tncmeta.json")
9
+ const currentDir = process.cwd();
10
+ const tncFolder = path.join(currentDir, ".tnc");
11
+ const tncmetaFile = path.join(tncFolder, ".tncmeta.json");
11
12
 
12
- 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 = {};
13
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
+ }
14
29
  }
15
- const content = ` "currentBranch": "${branchName}",`;
16
-
17
30
 
18
- fs.writeFileSync(tncmetaFile, content, "utf-8" );
31
+ // Update the current branch
32
+ meta.currentBranch = branchName;
19
33
 
34
+ // Write updated data
35
+ fs.writeFileSync(tncmetaFile, JSON.stringify(meta, null, 2), "utf-8");
36
+
37
+ console.log(`🌿 Switched to branch '${branchName}'`);
20
38
  }
21
39
 
40
+ // Creates a new branch for a room
22
41
  async function createBranch(roomId) {
23
42
  try {
24
- const branchName = await inquirer.prompt([
43
+ const { branchName } = await inquirer.prompt([
25
44
  {
26
45
  type: "input",
27
46
  name: "branchName",
@@ -30,18 +49,17 @@ async function createBranch(roomId) {
30
49
  if (!input || input.trim().length === 0) {
31
50
  return "Branch name cannot be empty";
32
51
  }
33
- // Basic validation - you might want to add more rules
34
52
  if (!/^[a-zA-Z0-9_-]+$/.test(input.trim())) {
35
53
  return "Branch name can only contain letters, numbers, hyphens, and underscores";
36
54
  }
37
55
  return true;
38
- }
39
- }
56
+ },
57
+ },
40
58
  ]);
41
59
 
42
60
  const homeDir = os.homedir();
43
61
  const tncfilepath = path.join(homeDir, ".tncrc");
44
-
62
+
45
63
  if (!fs.existsSync(tncfilepath)) {
46
64
  throw new Error("Configuration file not found. Please login first.");
47
65
  }
@@ -55,14 +73,14 @@ async function createBranch(roomId) {
55
73
  }
56
74
 
57
75
  const res = await axios.post("https://thinkncollab.in/cli/createBranch", {
58
- branchName: branchName.branchName.trim(),
59
- roomId: roomId,
60
- email: email
76
+ branchName: branchName.trim(),
77
+ roomId,
78
+ email,
61
79
  });
62
80
 
63
81
  if (res.data.success) {
64
- console.log(`✅ Branch '${branchName.branchName}' created successfully!`);
65
- updateBranch(branchName.branchName);
82
+ console.log(`✅ Branch '${branchName}' created successfully!`);
83
+ await updateBranch(branchName);
66
84
  } else {
67
85
  console.log(`❌ Failed to create branch: ${res.data.message}`);
68
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.61",
4
+ "version": "0.0.63",
5
5
  "description": "CLI tool for ThinkNCollab",
6
6
  "main": "index.js",
7
7
  "bin": {