thinkncollab-cli 0.0.17 → 0.0.20
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 +56 -44
- package/commands/init.js +44 -35
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -14,13 +14,7 @@ const BASE_URL = "http://localhost:3001/rooms";
|
|
|
14
14
|
const CWD = process.cwd();
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
if (!fs.existsSync(tncMetaPath)) {
|
|
19
|
-
console.error("❌ Project not initialized. Run 'tnc init' first.");
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
const meta = JSON.parse(fs.readFileSync(tncMetaPath, "utf-8"));
|
|
23
|
-
const projectId = meta.projectId;
|
|
17
|
+
|
|
24
18
|
|
|
25
19
|
/** ------------------ LOGIN ------------------ **/
|
|
26
20
|
async function login() {
|
|
@@ -230,6 +224,13 @@ async function uploadTree(fileTree, folderHex, roomId, token, email, parentPath
|
|
|
230
224
|
/** ------------------ PUSH FUNCTION ------------------ **/
|
|
231
225
|
async function push(roomId, targetPath) {
|
|
232
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;
|
|
233
234
|
const stats = fs.statSync(targetPath);
|
|
234
235
|
const rootFolder = stats.isDirectory() ? targetPath : path.dirname(targetPath);
|
|
235
236
|
const ignoreList = loadIgnore(rootFolder);
|
|
@@ -264,12 +265,19 @@ async function push(roomId, targetPath) {
|
|
|
264
265
|
console.log("🚀 Uploading to Cloudinary...");
|
|
265
266
|
const uploadedTree = await uploadTree(contentWithChanges, folderHex, roomId, token, email);
|
|
266
267
|
|
|
267
|
-
console.log("🗂️ Sending metadata
|
|
268
|
+
console.log("🗂️ Sending metadata:", {
|
|
269
|
+
folderId: folderHex,
|
|
270
|
+
content: uploadedTree,
|
|
271
|
+
uploadedBy: email,
|
|
272
|
+
projectId
|
|
273
|
+
});
|
|
274
|
+
|
|
268
275
|
await axios.post(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
276
|
+
`${BASE_URL}/${roomId}/upload`,
|
|
277
|
+
{ folderId: folderHex, content: uploadedTree, uploadedBy: email, projectId },
|
|
278
|
+
{ headers: { authorization: `Bearer ${token}`, email } }
|
|
279
|
+
);
|
|
280
|
+
|
|
273
281
|
|
|
274
282
|
console.log("✅ Upload complete! Metadata stored successfully.");
|
|
275
283
|
|
|
@@ -290,38 +298,42 @@ async function push(roomId, targetPath) {
|
|
|
290
298
|
}
|
|
291
299
|
|
|
292
300
|
/** ------------------ CLI HANDLER ------------------ **/
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
login
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
logout
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
301
|
+
async function main() {
|
|
302
|
+
const args = process.argv.slice(2);
|
|
303
|
+
|
|
304
|
+
switch (args[0]) {
|
|
305
|
+
case "login":
|
|
306
|
+
await login();
|
|
307
|
+
break;
|
|
308
|
+
|
|
309
|
+
case "logout":
|
|
310
|
+
await logout();
|
|
311
|
+
break;
|
|
312
|
+
|
|
313
|
+
case "push": {
|
|
314
|
+
const roomIndex = args.indexOf("--room");
|
|
315
|
+
if (roomIndex === -1 || !args[roomIndex + 1] || !args[roomIndex + 2]) {
|
|
316
|
+
console.error("Usage: tnc push --room <roomId> <file-or-folder-path>");
|
|
317
|
+
process.exit(1);
|
|
318
|
+
}
|
|
319
|
+
const roomId = args[roomIndex + 1];
|
|
320
|
+
const targetPath = args[roomIndex + 2];
|
|
321
|
+
await push(roomId, targetPath);
|
|
322
|
+
break;
|
|
309
323
|
}
|
|
310
|
-
const roomId = args[roomIndex + 1];
|
|
311
|
-
const targetPath = args[roomIndex + 2];
|
|
312
|
-
push(roomId, targetPath);
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
case "init" :{
|
|
316
|
-
await projectInit();
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
324
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
case "init":
|
|
326
|
+
await projectInit();
|
|
327
|
+
break;
|
|
328
|
+
|
|
329
|
+
default:
|
|
330
|
+
console.log("✅ TNC CLI ready!");
|
|
331
|
+
console.log("Commands:");
|
|
332
|
+
console.log(" tnc-cli login");
|
|
333
|
+
console.log(" tnc-cli init");
|
|
334
|
+
console.log(" tnc-cli push --room <roomId> <path>");
|
|
335
|
+
console.log(" tnc-cli logout");
|
|
336
|
+
}
|
|
327
337
|
}
|
|
338
|
+
|
|
339
|
+
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
|
-
|
|
13
|
-
|
|
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
|
|
19
|
-
const
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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;
|