codehub-ghx-cli 1.0.4 → 1.0.6
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/codehub-ghx-cli-1.0.4.tgz +0 -0
- package/codehub-ghx-cli-1.0.5.tgz +0 -0
- package/codehub-ghx-cli-1.0.6.tgz +0 -0
- package/commands/commit.js +1 -1
- package/commands/push.js +70 -46
- package/commands/revert.js +1 -30
- package/package.json +2 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/commands/commit.js
CHANGED
package/commands/push.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
async function uploadRecursive(localPath, baseDir, commitId, collectedFiles) {
|
|
23
|
+
async function uploadRecursive(localPath, baseDir, commitId, collectedFiles, repoId) {
|
|
26
24
|
|
|
27
25
|
const relative = path.relative(baseDir, localPath).replace(/\\/g, "/");
|
|
28
26
|
|
|
@@ -52,38 +50,57 @@ 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}`;
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
const fileBase64 = fileContent.toString("base64");
|
|
61
|
+
|
|
62
|
+
await axios.post(
|
|
63
|
+
"https://codehub-backend-jj4b.onrender.com/push/upload",
|
|
64
|
+
{
|
|
65
|
+
repoId, // ✅ use actual repoId
|
|
66
|
+
s3Key,
|
|
67
|
+
content: fileBase64,
|
|
68
|
+
filename: path.basename(localPath),
|
|
69
|
+
folder: path.dirname(relative).replace(/\\/g, "/") === "." ? "" : path.dirname(relative).replace(/\\/g, "/"),
|
|
70
|
+
isFolder: false
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// await s3.upload({
|
|
79
|
+
// Bucket: s3_BUCKET,
|
|
80
|
+
// Key: s3Key,
|
|
81
|
+
// Body: fileContent
|
|
82
|
+
// }).promise();
|
|
66
83
|
|
|
67
84
|
const filename = path.basename(localPath);
|
|
68
|
-
const folder = path.dirname(relative).replace(/\\/g, "/");
|
|
85
|
+
const folder = path.dirname(relative).replace(/\\/g, "/");
|
|
69
86
|
|
|
70
87
|
collectedFiles.push({
|
|
71
88
|
// filename,
|
|
72
89
|
// commit: commitId,
|
|
73
|
-
// // path: s3Key, //
|
|
90
|
+
// // path: s3Key, //
|
|
74
91
|
// // folder: folder === "." ? "" : folder,
|
|
75
92
|
// // isFolder: false
|
|
76
|
-
// path: cleanPath, //
|
|
93
|
+
// path: cleanPath, //
|
|
77
94
|
// folder: folder === "." ? "" : folder,
|
|
78
|
-
// fullS3Path: s3Key, //
|
|
95
|
+
// fullS3Path: s3Key, //
|
|
79
96
|
// fullPath: cleanPath,
|
|
80
97
|
// isFolder: false
|
|
81
98
|
filename,
|
|
82
99
|
commit: commitId,
|
|
83
|
-
path: s3Key,
|
|
100
|
+
path: s3Key,
|
|
84
101
|
folder: folder === "." ? "" : folder,
|
|
85
|
-
fullS3Path: s3Key,
|
|
86
|
-
fullPath: s3Key,
|
|
102
|
+
fullS3Path: s3Key,
|
|
103
|
+
fullPath: s3Key,
|
|
87
104
|
isFolder: false
|
|
88
105
|
});
|
|
89
106
|
}
|
|
@@ -99,7 +116,7 @@ async function pushRepo() {
|
|
|
99
116
|
const repoId = config.repoId;
|
|
100
117
|
|
|
101
118
|
if (!repoId) {
|
|
102
|
-
console.log("
|
|
119
|
+
console.log(" repoId missing in .codehub/config.json");
|
|
103
120
|
return;
|
|
104
121
|
}
|
|
105
122
|
|
|
@@ -107,7 +124,7 @@ async function pushRepo() {
|
|
|
107
124
|
const commitDirs = await fs.readdir(commitsPath);
|
|
108
125
|
|
|
109
126
|
if (commitDirs.length === 0) {
|
|
110
|
-
console.log("
|
|
127
|
+
console.log(" No commits to push");
|
|
111
128
|
return;
|
|
112
129
|
}
|
|
113
130
|
|
|
@@ -122,41 +139,39 @@ async function pushRepo() {
|
|
|
122
139
|
|
|
123
140
|
|
|
124
141
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const dbRes = await axios.get(`http://localhost:3000/repo/id/${repoId}`);
|
|
128
|
-
// backend returns array; first element is repo object
|
|
142
|
+
const dbRes = await axios.get(`https://codehub-backend-jj4b.onrender.com/repo/id/${repoId}`);
|
|
143
|
+
|
|
129
144
|
const existing = (dbRes.data && dbRes.data[0] && dbRes.data[0].content) || [];
|
|
130
145
|
|
|
131
|
-
|
|
146
|
+
|
|
132
147
|
const contentMap = {};
|
|
133
148
|
existing.forEach(f => {
|
|
134
149
|
if (!f || !f.path) return;
|
|
135
150
|
contentMap[f.path] = f;
|
|
136
151
|
});
|
|
137
152
|
|
|
138
|
-
|
|
153
|
+
|
|
139
154
|
let newFiles = [];
|
|
140
155
|
|
|
141
156
|
for (const commitId of commitDirs) {
|
|
142
157
|
const commitFolder = path.join(commitsPath, commitId);
|
|
143
158
|
|
|
144
|
-
// commitFolder
|
|
159
|
+
// commitFolder
|
|
145
160
|
await uploadRecursive(
|
|
146
161
|
commitFolder,
|
|
147
|
-
commitFolder,
|
|
162
|
+
commitFolder,
|
|
148
163
|
commitId,
|
|
149
|
-
newFiles
|
|
164
|
+
newFiles,repoId,
|
|
150
165
|
);
|
|
151
166
|
}
|
|
152
167
|
|
|
153
|
-
|
|
168
|
+
|
|
154
169
|
for (const f of newFiles) {
|
|
155
170
|
|
|
156
171
|
for (const existingPath in contentMap) {
|
|
157
172
|
const old = contentMap[existingPath];
|
|
158
173
|
|
|
159
|
-
|
|
174
|
+
|
|
160
175
|
if (old.filename === f.filename && old.folder === f.folder) {
|
|
161
176
|
delete contentMap[existingPath];
|
|
162
177
|
}
|
|
@@ -171,8 +186,8 @@ async function pushRepo() {
|
|
|
171
186
|
|
|
172
187
|
const finalFiles = Object.values(contentMap);
|
|
173
188
|
|
|
174
|
-
// push
|
|
175
|
-
await axios.put(`
|
|
189
|
+
// push
|
|
190
|
+
await axios.put(`https://codehub-backend-jj4b.onrender.com/repo/update/${repoId}`, {
|
|
176
191
|
content: finalFiles,
|
|
177
192
|
message: commitMessage,
|
|
178
193
|
description: ""
|
|
@@ -181,20 +196,29 @@ async function pushRepo() {
|
|
|
181
196
|
|
|
182
197
|
await fs.rm(commitsPath, { recursive: true, force: true });
|
|
183
198
|
await fs.mkdir(commitsPath);
|
|
184
|
-
await connectDB();
|
|
199
|
+
// await connectDB();
|
|
185
200
|
|
|
186
201
|
|
|
187
|
-
console.log("
|
|
202
|
+
console.log(" Push complete!");
|
|
188
203
|
// console.log("Using repoId:", repoId);
|
|
189
204
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
205
|
+
try {
|
|
206
|
+
await axios.post('https://codehub-backend-jj4b.onrender.com/push-log', {
|
|
207
|
+
repoId: repoId,
|
|
208
|
+
pushedAt: new Date()
|
|
209
|
+
});
|
|
210
|
+
console.log("Push log saved to backend");
|
|
211
|
+
} catch (err) {
|
|
212
|
+
console.error("Failed to save push log:", err.message);
|
|
213
|
+
}
|
|
214
|
+
// await PushLog.create({
|
|
215
|
+
// repoId: repoId,
|
|
216
|
+
// pushedAt: new Date()
|
|
217
|
+
// });
|
|
194
218
|
|
|
195
219
|
process.exit(0);
|
|
196
220
|
} catch (err) {
|
|
197
|
-
console.error("
|
|
221
|
+
console.error(" Push error:", err);
|
|
198
222
|
process.exit(1);
|
|
199
223
|
}
|
|
200
224
|
}
|
package/commands/revert.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "1.0.6",
|
|
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"
|