codehub-ghx-cli 1.0.4 → 1.0.5

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.
Binary file
Binary file
@@ -47,7 +47,7 @@ async function commitRepo(message) {
47
47
  );
48
48
  }
49
49
 
50
- await axios.put(`http://localhost:3000/repo/update/${repoId}`, {
50
+ await axios.put(`https://codehub-backend-jj4b.onrender.com/repo/update/${repoId}`, {
51
51
  message:message,
52
52
  });
53
53
 
package/commands/push.js CHANGED
@@ -1,26 +1,24 @@
1
1
 
2
2
 
3
- // ghx-cli/commands/push.js
4
3
  const fs = require("fs").promises;
5
4
  const fssync = require("fs");
6
5
  const path = require("path");
7
6
  const axios = require("axios");
8
7
  const mongoose = require('mongoose');
9
8
  const { s3, s3_BUCKET } = require("../config/aws-config");
10
- const PushLog = require('../../models/pushModel');
9
+ // const PushLog = require('../../models/pushModel');
11
10
  require('dotenv').config;
12
11
 
13
12
 
14
- async function connectDB(){
15
- const mongoURI = process.env.MONGODB_URI;
16
- mongoose.connect(mongoURI)
17
- .then(()=>console.log("push date saved"))
18
- .catch((err)=>console.error("Unable to connect",err));
19
- }
13
+ // async function connectDB(){
14
+ // const mongoURI = process.env.MONGODB_URI;
15
+ // mongoose.connect(mongoURI)
16
+ // .then(()=>console.log("push date saved"))
17
+ // .catch((err)=>console.error("Unable to connect",err));
18
+ // }
20
19
 
21
20
 
22
21
 
23
- // uploadRecursive:
24
22
 
25
23
  async function uploadRecursive(localPath, baseDir, commitId, collectedFiles) {
26
24
 
@@ -52,12 +50,12 @@ async function uploadRecursive(localPath, baseDir, commitId, collectedFiles) {
52
50
  const relative = path.relative(baseDir, localPath).replace(/\\/g, "/");
53
51
 
54
52
  const cleanPath = relative.replace(/\\/g, "/");
55
- // const s3Key = `commits/${commitId}/${relative}`; // canonical S3 key and DB path
53
+ // const s3Key = `commits/${commitId}/${relative}`;
56
54
  const s3Key = `repo/${commitId}/${cleanPath}`;
57
55
  const fileIdPath = cleanPath;
58
56
  const fileContent = await fs.readFile(localPath);
59
57
 
60
- // upload to S3 under canonical key
58
+
61
59
  await s3.upload({
62
60
  Bucket: s3_BUCKET,
63
61
  Key: s3Key,
@@ -65,25 +63,25 @@ async function uploadRecursive(localPath, baseDir, commitId, collectedFiles) {
65
63
  }).promise();
66
64
 
67
65
  const filename = path.basename(localPath);
68
- const folder = path.dirname(relative).replace(/\\/g, "/"); // relative folder inside commit
66
+ const folder = path.dirname(relative).replace(/\\/g, "/");
69
67
 
70
68
  collectedFiles.push({
71
69
  // filename,
72
70
  // commit: commitId,
73
- // // path: s3Key, // canonical path saved to DB
71
+ // // path: s3Key, //
74
72
  // // folder: folder === "." ? "" : folder,
75
73
  // // isFolder: false
76
- // path: cleanPath, // <-- canonical
74
+ // path: cleanPath, //
77
75
  // folder: folder === "." ? "" : folder,
78
- // fullS3Path: s3Key, // <-- actual file stored in S3
76
+ // fullS3Path: s3Key, //
79
77
  // fullPath: cleanPath,
80
78
  // isFolder: false
81
79
  filename,
82
80
  commit: commitId,
83
- path: s3Key, // <--- ALWAYS THIS
81
+ path: s3Key,
84
82
  folder: folder === "." ? "" : folder,
85
- fullS3Path: s3Key, // <--- ALWAYS THIS
86
- fullPath: s3Key, // <--- ALWAYS THIS
83
+ fullS3Path: s3Key,
84
+ fullPath: s3Key,
87
85
  isFolder: false
88
86
  });
89
87
  }
@@ -99,7 +97,7 @@ async function pushRepo() {
99
97
  const repoId = config.repoId;
100
98
 
101
99
  if (!repoId) {
102
- console.log(" repoId missing in .codehub/config.json");
100
+ console.log(" repoId missing in .codehub/config.json");
103
101
  return;
104
102
  }
105
103
 
@@ -107,7 +105,7 @@ async function pushRepo() {
107
105
  const commitDirs = await fs.readdir(commitsPath);
108
106
 
109
107
  if (commitDirs.length === 0) {
110
- console.log(" No commits to push");
108
+ console.log(" No commits to push");
111
109
  return;
112
110
  }
113
111
 
@@ -122,41 +120,39 @@ async function pushRepo() {
122
120
 
123
121
 
124
122
 
125
-
126
- // Fetch existing repo content so we can merge (and dedupe)
127
- const dbRes = await axios.get(`http://localhost:3000/repo/id/${repoId}`);
128
- // backend returns array; first element is repo object
123
+ const dbRes = await axios.get(`https://codehub-backend-jj4b.onrender.com/repo/id/${repoId}`);
124
+
129
125
  const existing = (dbRes.data && dbRes.data[0] && dbRes.data[0].content) || [];
130
126
 
131
- // map existing by path for fast overwrite
127
+
132
128
  const contentMap = {};
133
129
  existing.forEach(f => {
134
130
  if (!f || !f.path) return;
135
131
  contentMap[f.path] = f;
136
132
  });
137
133
 
138
- // const commitDirs = await fs.readdir(commitsPath);
134
+
139
135
  let newFiles = [];
140
136
 
141
137
  for (const commitId of commitDirs) {
142
138
  const commitFolder = path.join(commitsPath, commitId);
143
139
 
144
- // commitFolder may contain files/folders
140
+ // commitFolder
145
141
  await uploadRecursive(
146
142
  commitFolder,
147
- commitFolder, // baseDir
143
+ commitFolder,
148
144
  commitId,
149
145
  newFiles
150
146
  );
151
147
  }
152
148
 
153
- // merge/overwrite: newFiles wins
149
+
154
150
  for (const f of newFiles) {
155
151
 
156
152
  for (const existingPath in contentMap) {
157
153
  const old = contentMap[existingPath];
158
154
 
159
- // compare logical location (folder + filename)
155
+
160
156
  if (old.filename === f.filename && old.folder === f.folder) {
161
157
  delete contentMap[existingPath];
162
158
  }
@@ -171,8 +167,8 @@ async function pushRepo() {
171
167
 
172
168
  const finalFiles = Object.values(contentMap);
173
169
 
174
- // push finalFiles to backend (replace content)
175
- await axios.put(`http://localhost:3000/repo/update/${repoId}`, {
170
+ // push
171
+ await axios.put(`https://codehub-backend-jj4b.onrender.com/repo/update/${repoId}`, {
176
172
  content: finalFiles,
177
173
  message: commitMessage,
178
174
  description: ""
@@ -181,20 +177,29 @@ async function pushRepo() {
181
177
 
182
178
  await fs.rm(commitsPath, { recursive: true, force: true });
183
179
  await fs.mkdir(commitsPath);
184
- await connectDB();
180
+ // await connectDB();
185
181
 
186
182
 
187
- console.log(" Push complete!");
183
+ console.log(" Push complete!");
188
184
  // console.log("Using repoId:", repoId);
189
185
 
190
- await PushLog.create({
191
- repoId: repoId,
192
- pushedAt: new Date()
193
- });
186
+ try {
187
+ await axios.post('https://codehub-backend-jj4b.onrender.com/push-log', {
188
+ repoId: repoId,
189
+ pushedAt: new Date()
190
+ });
191
+ console.log("Push log saved to backend");
192
+ } catch (err) {
193
+ console.error("Failed to save push log:", err.message);
194
+ }
195
+ // await PushLog.create({
196
+ // repoId: repoId,
197
+ // pushedAt: new Date()
198
+ // });
194
199
 
195
200
  process.exit(0);
196
201
  } catch (err) {
197
- console.error(" Push error:", err);
202
+ console.error(" Push error:", err);
198
203
  process.exit(1);
199
204
  }
200
205
  }
@@ -1,33 +1,4 @@
1
- // const fs = require("fs");
2
- // const path = require('path');
3
- // const { promisify } = require("util");
4
- // // const {s3, s3_BUCKET} = require('../config/aws-config');
5
- // const {s3, s3_BUCKET} = require('../config/aws-config');
6
1
 
7
- // const readdir = promisify(fs.readdir);
8
- // const copyFile = promisify(fs.copyFile);
9
-
10
-
11
- // async function revertRepo(commitID) {
12
- // const repopath = path.resolve(process.cwd(), ".codehub");
13
- // const commitsPath = path.join(repopath, "commits");
14
-
15
-
16
- // try {
17
- // const commitDir = path.join(commitsPath, commitID);
18
- // const files = await readdir(commitDir);
19
- // const parentDir = path.resolve(repopath, "..");
20
-
21
- // for(const file of files){
22
- // await copyFile(path.join(commitDir, file), path.join(parentDir, file));
23
- // }
24
- // console.log(`Commit ${commitID} reverted successfully!`);
25
- // } catch (err) {
26
- // console.error("Unable to revert:", err);
27
- // }
28
- // }
29
-
30
- // module.exports = {revertRepo};
31
2
 
32
3
  const fs = require("fs").promises;
33
4
  const fssync = require("fs");
@@ -55,7 +26,7 @@ async function revertRepo(commitID) {
55
26
  const commitsPath = path.join(repoPath, "commits");
56
27
  const commitFolder = path.join(commitsPath, commitID);
57
28
 
58
- // Ensure that commit exists
29
+
59
30
  if (!fssync.existsSync(commitFolder)) {
60
31
  console.log(`❌ Commit "${commitID}" not found.`);
61
32
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codehub-ghx-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,6 +17,7 @@
17
17
  "axios": "^1.13.2",
18
18
  "codehub-ghx-cli": "^1.0.3",
19
19
  "dotenv": "^17.2.3",
20
+ "mongoose": "^9.0.2",
20
21
  "path": "^0.12.7",
21
22
  "uuid": "^13.0.0",
22
23
  "yargs": "^18.0.0"