thinkncollab-cli 0.0.16 → 0.0.19

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/.ignoretnc CHANGED
@@ -1,2 +1,2 @@
1
1
  /node_modules
2
-
2
+ .vscode
package/bin/index.js CHANGED
@@ -13,6 +13,9 @@ const VERSION_FILE = path.join(process.cwd(), ".tncversions");
13
13
  const BASE_URL = "http://localhost:3001/rooms";
14
14
  const CWD = process.cwd();
15
15
 
16
+
17
+
18
+
16
19
  /** ------------------ LOGIN ------------------ **/
17
20
  async function login() {
18
21
  const answers = await inquirer.prompt([
@@ -221,6 +224,13 @@ async function uploadTree(fileTree, folderHex, roomId, token, email, parentPath
221
224
  /** ------------------ PUSH FUNCTION ------------------ **/
222
225
  async function push(roomId, targetPath) {
223
226
  const { token, email } = readToken();
227
+ const tncMetaPath = path.join(process.cwd(), ".tnc", ".tncmeta.json");
228
+ if (!fs.existsSync(tncMetaPath)) {
229
+ console.error("❌ Project not initialized. Run 'tnc init' first.");
230
+ process.exit(1);
231
+ }
232
+ const meta = JSON.parse(fs.readFileSync(tncMetaPath, "utf-8"));
233
+ const projectId = meta.projectId;
224
234
  const stats = fs.statSync(targetPath);
225
235
  const rootFolder = stats.isDirectory() ? targetPath : path.dirname(targetPath);
226
236
  const ignoreList = loadIgnore(rootFolder);
@@ -258,7 +268,7 @@ async function push(roomId, targetPath) {
258
268
  console.log("🗂️ Sending metadata to backend...");
259
269
  await axios.post(
260
270
  `${BASE_URL}/${roomId}/upload`,
261
- { folderId: folderHex, content: uploadedTree, uploadedBy: email },
271
+ { folderId: folderHex, content: uploadedTree, uploadedBy: email, projectId },
262
272
  { headers: { authorization: `Bearer ${token}`, email } }
263
273
  );
264
274
 
@@ -281,38 +291,42 @@ async function push(roomId, targetPath) {
281
291
  }
282
292
 
283
293
  /** ------------------ CLI HANDLER ------------------ **/
284
- const args = process.argv.slice(2);
285
-
286
- switch (args[0]) {
287
- case "login":
288
- login();
289
- break;
290
-
291
- case "logout":
292
- logout();
293
- break;
294
-
295
- case "push": {
296
- const roomIndex = args.indexOf("--room");
297
- if (roomIndex === -1 || !args[roomIndex + 1] || !args[roomIndex + 2]) {
298
- console.error("Usage: tnc push --room <roomId> <file-or-folder-path>");
299
- process.exit(1);
294
+ async function main() {
295
+ const args = process.argv.slice(2);
296
+
297
+ switch (args[0]) {
298
+ case "login":
299
+ await login();
300
+ break;
301
+
302
+ case "logout":
303
+ await logout();
304
+ break;
305
+
306
+ case "push": {
307
+ const roomIndex = args.indexOf("--room");
308
+ if (roomIndex === -1 || !args[roomIndex + 1] || !args[roomIndex + 2]) {
309
+ console.error("Usage: tnc push --room <roomId> <file-or-folder-path>");
310
+ process.exit(1);
311
+ }
312
+ const roomId = args[roomIndex + 1];
313
+ const targetPath = args[roomIndex + 2];
314
+ await push(roomId, targetPath);
315
+ break;
300
316
  }
301
- const roomId = args[roomIndex + 1];
302
- const targetPath = args[roomIndex + 2];
303
- push(roomId, targetPath);
304
- break;
305
- }
306
- case "init" :{
307
- await projectInit();
308
- break;
309
- }
310
317
 
311
- default:
312
- console.log("✅ TNC CLI ready!");
313
- console.log("Commands:");
314
- console.log(" tnc login");
315
- console.log(" tnc-cli init")
316
- console.log(" tnc push --room <roomId> <path>");
317
- console.log(" tnc logout");
318
+ case "init":
319
+ await projectInit();
320
+ break;
321
+
322
+ default:
323
+ console.log(" TNC CLI ready!");
324
+ console.log("Commands:");
325
+ console.log(" tnc-cli login");
326
+ console.log(" tnc-cli init");
327
+ console.log(" tnc-cli push --room <roomId> <path>");
328
+ console.log(" tnc-cli logout");
329
+ }
318
330
  }
331
+
332
+ main().catch(err => console.error(err));
package/commands/init.js CHANGED
@@ -2,47 +2,56 @@ import fs from "fs";
2
2
  import os from "os";
3
3
  import path from "path";
4
4
  import inquirer from "inquirer";
5
- import axios from "axios";
6
- import { builtinModules } from "module";
7
- const CWD = process.cwd();
8
-
9
- async function projectInit() {
5
+ import axios from "axios";
10
6
 
7
+ const CWD = process.cwd();
11
8
 
12
- const answer = await inquirer.prompt([
13
- {type: "input", name: "projectName", message: "Enter Project Name:"},
9
+ async function projectInit() {
10
+ const answer = await inquirer.prompt([
11
+ { type: "input", name: "projectName", message: "Enter Project Name:" }
12
+ ]);
14
13
 
14
+ const HomeDir = os.homedir();
15
+ const tncrcPath = path.join(HomeDir, ".tncrc");
15
16
 
16
- ]);
17
+ if (!fs.existsSync(tncrcPath)) {
18
+ console.error("❌ You are not logged in. Run 'tnc login' first.");
19
+ process.exit(1);
20
+ }
17
21
 
18
- const HomeDir = os.homedir();
19
- const data = fs.readFileSync(path.join(HomeDir, ".tncrc"));
20
- const currentUser = JSON.parse(data).email;
21
- // let us make the a .tncmeta.json file for keeping track of branch info
22
- //.tncmeta.json should be in the a separate folder at the root of the project
22
+ const data = fs.readFileSync(tncrcPath, "utf-8");
23
+ const currentUser = JSON.parse(data).email;
23
24
 
24
- const response = await axios.post("http://localhost:3001/cli/init", {
25
- projectName : answer.projectName,
25
+ // Initialize project via backend
26
+ const response = await axios.post("http://localhost:3001/cli/init", {
27
+ projectName: answer.projectName,
26
28
  owner: currentUser
27
- })
28
- const projectId = response.data.project._id;
29
-
30
- const tncFolder = fs.mkdirSync(path.join(CWD, ".tnc"), { recursive: true });
31
-
32
- const metaFilePath = path.join(tncFolder, ".tncmeta.json");
33
-
34
- fs.writeFileSync(metaFilePath, JSON.stringify({"projectId": projectId,
35
- "projectName": answer.projectName,
36
- "currentBranch": "main",
37
- "lastCommit": null,
38
- "files": {},
39
- },
40
- null,
41
- 2
42
- )
43
- );
44
- console.log("✅ Project initialized successfully!");
45
-
29
+ });
30
+
31
+ const projectId = response.data.project._id;
32
+
33
+ // Ensure .tnc folder exists at project root
34
+ const tncFolderPath = path.join(CWD, ".tnc");
35
+ if (!fs.existsSync(tncFolderPath)) fs.mkdirSync(tncFolderPath, { recursive: true });
36
+
37
+ // Write metadata file
38
+ const metaFilePath = path.join(tncFolderPath, ".tncmeta.json");
39
+ fs.writeFileSync(
40
+ metaFilePath,
41
+ JSON.stringify(
42
+ {
43
+ projectId,
44
+ projectName: answer.projectName,
45
+ currentBranch: "main",
46
+ lastCommit: null,
47
+ files: {}
48
+ },
49
+ null,
50
+ 2
51
+ )
52
+ );
53
+
54
+ console.log("✅ Project initialized successfully!");
46
55
  }
47
56
 
48
- export default projectInit;
57
+ export default projectInit;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "thinkncollab-cli",
3
3
  "author": "Raman Singh",
4
- "version": "0.0.16",
4
+ "version": "0.0.19",
5
5
  "description": "CLI tool for ThinkNCollab",
6
6
  "main": "index.js",
7
7
  "bin": {