jvcs 1.2.0 → 1.2.2
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/controllers/clone.js +2 -2
- package/package.json +1 -1
- package/readme.md +42 -0
- package/.jvcs/HEAD +0 -1
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/add.js +0 -122
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/begin.js +0 -201
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/clone.js +0 -138
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/commit.js +0 -83
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/driveUtility.js +0 -56
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/init.js +0 -60
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/log.js +0 -99
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/login.js +0 -33
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/push.js +0 -165
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/revert.js +0 -208
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/signup.js +0 -28
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/status.js +0 -160
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/unstage.js +0 -104
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/utility.js +0 -29
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/verifyOtp.js +0 -55
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/jvcs_hashcode.json +0 -62
- package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/meta.json +0 -7
- package/.jvcs/config.json +0 -9
- package/.jvcs/staging/controllers/add.js +0 -122
- package/.jvcs/staging/controllers/begin.js +0 -201
- package/.jvcs/staging/controllers/clone.js +0 -138
- package/.jvcs/staging/controllers/commit.js +0 -83
- package/.jvcs/staging/controllers/driveUtility.js +0 -56
- package/.jvcs/staging/controllers/init.js +0 -60
- package/.jvcs/staging/controllers/log.js +0 -99
- package/.jvcs/staging/controllers/login.js +0 -33
- package/.jvcs/staging/controllers/push.js +0 -165
- package/.jvcs/staging/controllers/revert.js +0 -208
- package/.jvcs/staging/controllers/signup.js +0 -28
- package/.jvcs/staging/controllers/status.js +0 -160
- package/.jvcs/staging/controllers/unstage.js +0 -104
- package/.jvcs/staging/controllers/utility.js +0 -29
- package/.jvcs/staging/controllers/verifyOtp.js +0 -55
- package/.jvcs/staging/jvcs_hashcode.json +0 -62
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const fs = require("fs").promises;
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const fssync = require("fs")
|
|
5
|
-
const { getGlobalConfig, checkGlobalConfig } = require("./utility")
|
|
6
|
-
|
|
7
|
-
async function initCmd() {
|
|
8
|
-
|
|
9
|
-
if(!checkGlobalConfig()) {
|
|
10
|
-
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
11
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
let configData = null
|
|
16
|
-
configData = getGlobalConfig()
|
|
17
|
-
|
|
18
|
-
if(!configData) {
|
|
19
|
-
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
20
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// initialize an empty folder with the name of current directory
|
|
25
|
-
const cwd = process.cwd()
|
|
26
|
-
const home = require("os").homedir()
|
|
27
|
-
|
|
28
|
-
if(cwd === home) {
|
|
29
|
-
console.log(chalk.red("Cannot initialize a repository in your home directory."));
|
|
30
|
-
console.log(chalk.yellow("Hint: navigate to a project folder and run 'jvcs init' there."));
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const repoPath = path.join(cwd,".jvcs")
|
|
35
|
-
if(fssync.existsSync(repoPath)) {
|
|
36
|
-
console.log(chalk.yellow("Repository already is initialized."));
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fssync.mkdirSync(repoPath)
|
|
41
|
-
fssync.mkdirSync(path.join(repoPath,"commits"))
|
|
42
|
-
fssync.mkdirSync(path.join(repoPath,"staging"))
|
|
43
|
-
|
|
44
|
-
const config = {
|
|
45
|
-
repoName: path.basename(cwd),
|
|
46
|
-
createdAt: new Date().toISOString(),
|
|
47
|
-
remote: null,
|
|
48
|
-
owner : {
|
|
49
|
-
username: configData.username,
|
|
50
|
-
email: configData.email
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fssync.writeFileSync(path.join(repoPath, "config.json"), JSON.stringify(config, null, 2))
|
|
55
|
-
fssync.writeFileSync(path.join(repoPath, "HEAD"), "");
|
|
56
|
-
|
|
57
|
-
console.log(chalk.green(`Initialized empty JVCS repository`));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
module.exports = initCmd
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const fssync = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility");
|
|
5
|
-
|
|
6
|
-
async function logCmd() {
|
|
7
|
-
|
|
8
|
-
if(!checkGlobalConfig()) {
|
|
9
|
-
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
10
|
-
console.log(chalk.green("jvcs --help for help"));
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const configData = getGlobalConfig();
|
|
15
|
-
if(!configData) {
|
|
16
|
-
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if(!checkforjvcs()) {
|
|
21
|
-
console.log(chalk.red("Repository is not initialized or is deleted."));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const repoPath = path.join(process.cwd(),".jvcs")
|
|
26
|
-
const commitPath = path.join(repoPath,"commits")
|
|
27
|
-
const headPath = path.join(repoPath,"HEAD")
|
|
28
|
-
|
|
29
|
-
if(!fssync.existsSync(headPath)) {
|
|
30
|
-
console.log(chalk.yellow("No commits yet."));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if(!fssync.existsSync(commitPath)) {
|
|
35
|
-
console.log(chalk.yellow("No commits found. Try commiting first"))
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const commitDir = fssync.readdirSync(commitPath)
|
|
40
|
-
if(commitDir.length === 0) {
|
|
41
|
-
console.log(chalk.yellow("No commits found. Try commiting first"))
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const currentHead = fssync.readFileSync(headPath,"utf-8").trim()
|
|
46
|
-
if(!currentHead) {
|
|
47
|
-
console.log(chalk.yellow("HEAD is empty. No commits to display."));
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(chalk.bold.cyan("\n=========================== Commit History ====================\n"));
|
|
52
|
-
|
|
53
|
-
let commitId = currentHead
|
|
54
|
-
const chains = []
|
|
55
|
-
|
|
56
|
-
while(commitId) {
|
|
57
|
-
const commitFolder = path.join(commitPath,commitId)
|
|
58
|
-
const metaPath = path.join(commitFolder,"meta.json")
|
|
59
|
-
|
|
60
|
-
if (!fssync.existsSync(metaPath)) {
|
|
61
|
-
console.log(chalk.red(`Missing metadata for commit: ${commitId}`));
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const metaData = JSON.parse(fssync.readFileSync(metaPath,"utf-8"))
|
|
66
|
-
console.log('\t',chalk.yellow(`commit ${metaData.id}`));
|
|
67
|
-
console.log('\t',chalk.green(`Author:`), metaData.author || "Unknown");
|
|
68
|
-
console.log('\t',chalk.cyan(`Date:`), new Date(metaData.timeStamp).toLocaleString());
|
|
69
|
-
console.log('\t',chalk.white(`\n\t\t${metaData.message}\n`));
|
|
70
|
-
|
|
71
|
-
chains.push(metaData.id)
|
|
72
|
-
commitId = metaData.parentId
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
console.log(chalk.magenta("\n=================Visual Representation for commits==============\n"))
|
|
76
|
-
|
|
77
|
-
console.log(chalk.cyan.bold("\n HEAD"));
|
|
78
|
-
console.log(chalk.cyan(" ↓\n"));
|
|
79
|
-
|
|
80
|
-
let chainLine = "";
|
|
81
|
-
|
|
82
|
-
for (let i = 0; i < chains.length; i++) {
|
|
83
|
-
const id = chains[i].substring(0, 8); // short commit ID
|
|
84
|
-
chainLine += chalk.green(id);
|
|
85
|
-
|
|
86
|
-
if (i !== chains.length - 1) {
|
|
87
|
-
chainLine += chalk.cyan(" → ");
|
|
88
|
-
} else {
|
|
89
|
-
chainLine += chalk.gray(" → NULL");
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
console.log(chainLine);
|
|
94
|
-
console.log();
|
|
95
|
-
|
|
96
|
-
console.log(chalk.bold.cyan("=================================================================\n"));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
module.exports = logCmd
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const path = require("path")
|
|
2
|
-
const chalk = require("chalk")
|
|
3
|
-
const fs = require("fs")
|
|
4
|
-
async function login(loginData) {
|
|
5
|
-
|
|
6
|
-
const response = await fetch("http://localhost:3000/login", {
|
|
7
|
-
method: "POST",
|
|
8
|
-
headers: {
|
|
9
|
-
'Content-Type': 'application/json'
|
|
10
|
-
},
|
|
11
|
-
credentials: "include",
|
|
12
|
-
body: JSON.stringify({email:loginData.email,username:loginData.username,password:loginData.password,cli:true})
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const data = await response.json()
|
|
16
|
-
|
|
17
|
-
if(data.status === true) {
|
|
18
|
-
console.log(chalk.green(data.message))
|
|
19
|
-
|
|
20
|
-
const dirPath = path.join(require("os").homedir(), ".jvcs");
|
|
21
|
-
if (!fs.existsSync(dirPath)) {
|
|
22
|
-
fs.mkdirSync(dirPath, { recursive: true });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const configPath = path.join(dirPath, "config.json");
|
|
26
|
-
fs.writeFileSync(configPath,JSON.stringify({email: loginData.email,username: loginData.username,token: data.token, CLIENT_ID:"835069827989-3spob55ioa2ocudi3mo8u2ni2ecqohh7.apps.googleusercontent.com",CLIENT_SECRET:"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",REDIRECT_URI:"https://developers.google.com/oauthplayground",REFRESH_TOKEN:"1//04dWkzGCpoIgACgYIARAAGAQSNwF-L9IrRV-B67zRcIkhs7USx3vLewtE764bZPv7d5d7hAlH7QThZxj2CQUr5flQIG12Ad64dQI"},null,2));
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
throw new Error(data.message)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = login
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
const fs = require("fs")
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const chalk = require("chalk")
|
|
4
|
-
const { getDriveClient } = require("../config/drive-config")
|
|
5
|
-
const drive = getDriveClient()
|
|
6
|
-
const { getGlobalConfig, checkGlobalConfig, checkforjvcs } = require("./utility")
|
|
7
|
-
const getDirectoryStructure = require("./driveUtility")
|
|
8
|
-
const handleDbForRepo = require("../apicall/handleDbForRepo")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
async function uploadFile(localFile, parentId,data) {
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
|
|
17
|
-
const fileName = path.basename(localFile)
|
|
18
|
-
const fileMetaData = {
|
|
19
|
-
name: fileName,
|
|
20
|
-
parents: [parentId]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const media = {
|
|
24
|
-
mimeType: "application/octet-stream",
|
|
25
|
-
body: fs.createReadStream(localFile),
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const res = await drive.files.create({
|
|
29
|
-
resource: fileMetaData,
|
|
30
|
-
media,
|
|
31
|
-
fields: "id"
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
console.log(chalk.gray(` ↳ Uploaded: ${fileName}`));
|
|
35
|
-
data.files.push({name:fileName,driveId:res.data.id,parentId:parentId,type:"file"})
|
|
36
|
-
return res.data.id;
|
|
37
|
-
}
|
|
38
|
-
catch(error) {
|
|
39
|
-
console.log(chalk.red(`Failed to upload ${filePath}: ${err.message}`));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function uploadDirectory(localDir, parentId,data) {
|
|
44
|
-
|
|
45
|
-
const entries = fs.readdirSync(localDir, {withFileTypes: true})
|
|
46
|
-
|
|
47
|
-
for(const entry of entries) {
|
|
48
|
-
|
|
49
|
-
const entryPath = path.join(localDir,entry.name)
|
|
50
|
-
|
|
51
|
-
if(entry.isDirectory()) {
|
|
52
|
-
const folderMeta = {
|
|
53
|
-
name: entry.name,
|
|
54
|
-
mimeType: "application/vnd.google-apps.folder",
|
|
55
|
-
parents: [parentId],
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const folder = await drive.files.create({
|
|
59
|
-
resource: folderMeta,
|
|
60
|
-
fields: "id"
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
data.files.push({name:entry.name,driveId:folder.data.id,parentId:parentId,type:"folder"})
|
|
64
|
-
await uploadDirectory(entryPath,folder.data.id,data)
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
await uploadFile(entryPath,parentId,data)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function pushCmd() {
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
|
|
76
|
-
let userFolderId,repoFolderId
|
|
77
|
-
|
|
78
|
-
if(!checkGlobalConfig()) {
|
|
79
|
-
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
80
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let configData = getGlobalConfig()
|
|
85
|
-
|
|
86
|
-
if(!configData) {
|
|
87
|
-
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
88
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if(!checkforjvcs()) {
|
|
93
|
-
console.log(chalk.red("Repository is not initialized or is deleted. Please create it."))
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const cwd = process.cwd()
|
|
98
|
-
const jvcsDir = path.join(cwd,".jvcs")
|
|
99
|
-
const commitDir = path.join(jvcsDir,"commits")
|
|
100
|
-
const reponame = path.basename(process.cwd())
|
|
101
|
-
|
|
102
|
-
if(!fs.existsSync(commitDir)) {
|
|
103
|
-
console.log(chalk.yellow("No commits to push"))
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// storing the name of commit folders
|
|
108
|
-
const commitFolders = fs.readdirSync(commitDir, {withFileTypes: true}).filter((e)=> e.isDirectory()).map((e)=> e.name)
|
|
109
|
-
if(commitFolders.length === 0) {
|
|
110
|
-
console.log(chalk.yellow('No commits to push'))
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
console.log(chalk.blue("Pushing commits of ",reponame," to cloud storage..."))
|
|
115
|
-
|
|
116
|
-
const Content = []
|
|
117
|
-
for(const commitId of commitFolders) {
|
|
118
|
-
let data = {}
|
|
119
|
-
data.files = []
|
|
120
|
-
data.uuid = commitId
|
|
121
|
-
const commitFolder = path.join(commitDir,commitId)
|
|
122
|
-
const metaPath = path.join(commitFolder,"meta.json")
|
|
123
|
-
|
|
124
|
-
if(!fs.existsSync(metaPath)) {
|
|
125
|
-
console.log(chalk.yellow(`Skipping ${commitId} (no meta.json found)`));
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const metaData = JSON.parse(fs.readFileSync(metaPath,"utf-8"))
|
|
130
|
-
const { author, message, timeStamp } = metaData;
|
|
131
|
-
|
|
132
|
-
console.log(chalk.green(`\n Uploading commit:`));
|
|
133
|
-
console.log(chalk.gray(` id: ${commitId}`));
|
|
134
|
-
console.log(chalk.gray(` message: ${message}`));
|
|
135
|
-
console.log(chalk.gray(` author: ${author}`));
|
|
136
|
-
console.log(chalk.gray(` time: ${timeStamp}`));
|
|
137
|
-
|
|
138
|
-
const folderStructure = await getDirectoryStructure(configData.username,reponame,commitId)
|
|
139
|
-
const driveCommitId = folderStructure.commitFolderId;
|
|
140
|
-
repoFolderId = folderStructure.repoFolderId;
|
|
141
|
-
userFolderId = folderStructure.userFolderId;
|
|
142
|
-
const commitAlreadyExists = folderStructure.commitAlreadyExists;
|
|
143
|
-
|
|
144
|
-
if (commitAlreadyExists) {
|
|
145
|
-
console.log(chalk.yellow(`Skipping ${commitId} (already uploaded)`));
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
await uploadDirectory(commitFolder,driveCommitId,data)
|
|
150
|
-
console.log(chalk.green(`Commit ${commitId} uploaded successfully!`));
|
|
151
|
-
Content.push(data)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
console.log(chalk.bold.green("\nAll commits pushed successfully!"));
|
|
155
|
-
|
|
156
|
-
// database call for creating/updating an repository
|
|
157
|
-
await handleDbForRepo(reponame,repoFolderId,userFolderId,Content,configData.token)
|
|
158
|
-
}
|
|
159
|
-
catch(error) {
|
|
160
|
-
console.log(chalk.red.bold("\nPush Failed"));
|
|
161
|
-
console.error(chalk.red(error.stack || error.message || error));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
module.exports = pushCmd
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility");
|
|
5
|
-
const { getDriveClient } = require("../config/drive-config");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function copyDir(targetCommitFolder, destDir=process.cwd()) {
|
|
9
|
-
|
|
10
|
-
const entries = fs.readdirSync(targetCommitFolder, {withFileTypes: true})
|
|
11
|
-
|
|
12
|
-
for(const entry of entries) {
|
|
13
|
-
|
|
14
|
-
if (entry.name === ".jvcs") continue;
|
|
15
|
-
|
|
16
|
-
const srcpath = path.join(targetCommitFolder,entry.name)
|
|
17
|
-
const destpath = path.join(destDir,entry.name)
|
|
18
|
-
|
|
19
|
-
if(entry.isDirectory()) {
|
|
20
|
-
fs.mkdirSync(destpath, { recursive: true });
|
|
21
|
-
copyDir(srcpath, destpath);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
if(entry.name !== "meta.json" && entry.name !== "jvcs_hashcode.json")
|
|
25
|
-
fs.copyFileSync(srcpath, destpath);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function cleanCWD() {
|
|
31
|
-
|
|
32
|
-
const cwd = process.cwd()
|
|
33
|
-
const entries = fs.readdirSync(cwd, {withFileTypes: true})
|
|
34
|
-
|
|
35
|
-
for(const entry of entries) {
|
|
36
|
-
if(entry.name === ".jvcs") continue
|
|
37
|
-
const deleteEntry = path.join(cwd,entry.name)
|
|
38
|
-
fs.rmSync(deleteEntry, {recursive: true, force: true})
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function buildCommitMap(commitFolder) {
|
|
43
|
-
|
|
44
|
-
const map = {}
|
|
45
|
-
const dirs = fs.readdirSync(commitFolder)
|
|
46
|
-
for(const dir of dirs) {
|
|
47
|
-
const metaPath = path.join(commitFolder,dir,"meta.json")
|
|
48
|
-
if(fs.existsSync(metaPath)) {
|
|
49
|
-
const data = JSON.parse(fs.readFileSync(metaPath,"utf-8"))
|
|
50
|
-
map[dir] = data.parentId
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return map
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function getCommitsToDelete(commitFolder,currentCommit,targetCommit) {
|
|
58
|
-
|
|
59
|
-
const commitMap = buildCommitMap(commitFolder)
|
|
60
|
-
console.log("Commit Map:", commitMap); // 👈 debug log
|
|
61
|
-
const toDelete = []
|
|
62
|
-
|
|
63
|
-
while(currentCommit && currentCommit !== targetCommit) {
|
|
64
|
-
toDelete.push(currentCommit)
|
|
65
|
-
currentCommit = commitMap[currentCommit] || null
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return toDelete
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function deleteLocalCommits(commitDir,Ids) {
|
|
72
|
-
|
|
73
|
-
for(const id of Ids) {
|
|
74
|
-
const p = path.join(commitDir,id)
|
|
75
|
-
fs.rmSync(p, {recursive: true, force: true})
|
|
76
|
-
console.log(chalk.red(`Deleted local commit ${id}`))
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function deleteCommitsFromDrive(ids) {
|
|
81
|
-
|
|
82
|
-
const drive = getDriveClient();
|
|
83
|
-
|
|
84
|
-
if (!drive) {
|
|
85
|
-
console.log(chalk.red("Drive client not initialized. Please re-authenticate."));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let folderName = null
|
|
90
|
-
try {
|
|
91
|
-
for(const id of ids) {
|
|
92
|
-
folderName = `commit_${id}`
|
|
93
|
-
|
|
94
|
-
const res = await drive.files.list({
|
|
95
|
-
q: `name='${folderName}' and trashed=false`,
|
|
96
|
-
fields: "files(id,name)"
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
if(res.data.files.length > 0) {
|
|
100
|
-
const fileId = res.data.files[0].id;
|
|
101
|
-
await drive.files.delete({fileId})
|
|
102
|
-
console.log(chalk.red(`Deleted folder ${folderName} from remote`));
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
console.log(chalk.gray(`Drive folder ${folderName} not found.`));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch(error) {
|
|
110
|
-
console.log(chalk.red(`Failed to delete ${folderName} from remote: ${error.message}`));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async function deleteCommitsFromDatabase(configData,toDelete,reponame) {
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
|
|
118
|
-
const response = await fetch("http://localhost:3000/deleteCommit", {
|
|
119
|
-
method: "POST",
|
|
120
|
-
headers: {
|
|
121
|
-
'Content-Type': 'application/json'
|
|
122
|
-
},
|
|
123
|
-
body: JSON.stringify({token:configData.token,email:configData.email,username:configData.username,toDelete,reponame})
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const data = await response.json()
|
|
127
|
-
|
|
128
|
-
if(data.status === true) {
|
|
129
|
-
console.log(chalk.green("Removed previous commits from DB"))
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
console.log(chalk.red(data.message))
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
catch(error) {
|
|
136
|
-
console.log(chalk.red(error || error.message))
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function revertCmd(commitId) {
|
|
141
|
-
|
|
142
|
-
if(!checkGlobalConfig()) {
|
|
143
|
-
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
144
|
-
console.log(chalk.green("jvcs --help for help"));
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const configData = getGlobalConfig();
|
|
149
|
-
if(!configData) {
|
|
150
|
-
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if(!checkforjvcs()) {
|
|
155
|
-
console.log(chalk.red("Repository is not initialized or is deleted."));
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// actual implementation
|
|
160
|
-
const cwd = process.cwd()
|
|
161
|
-
const jvcsDir = path.join(cwd,".jvcs")
|
|
162
|
-
const commitFolder = path.join(jvcsDir,"commits")
|
|
163
|
-
const targetCommitFolder = path.join(commitFolder,commitId)
|
|
164
|
-
const headFile = path.join(jvcsDir,"HEAD")
|
|
165
|
-
|
|
166
|
-
if(!fs.existsSync(jvcsDir)) {
|
|
167
|
-
console.log(chalk.red("Repository is not initialized or is deleted."));
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if(!fs.existsSync(commitFolder)) {
|
|
172
|
-
console.log(chalk.red("You have made no commits yet. Revert not possible"))
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if(!fs.existsSync(targetCommitFolder)) {
|
|
177
|
-
console.log(chalk.red("No commit exists with commit Id : ",commitId))
|
|
178
|
-
return
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const currentHead = fs.readFileSync(headFile,"utf-8").trim()
|
|
183
|
-
|
|
184
|
-
if(currentHead === commitId) {
|
|
185
|
-
console.log(chalk.green("HEAD is already at the given commit"))
|
|
186
|
-
return
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// get commits to delete
|
|
190
|
-
const toDelete = getCommitsToDelete(commitFolder,currentHead,commitId)
|
|
191
|
-
|
|
192
|
-
// clear the current working directory except .jvcs
|
|
193
|
-
cleanCWD()
|
|
194
|
-
|
|
195
|
-
// copy the content of commit to cwd
|
|
196
|
-
copyDir(targetCommitFolder)
|
|
197
|
-
|
|
198
|
-
fs.writeFileSync(headFile,commitId,"utf-8")
|
|
199
|
-
console.log(chalk.green(`HEAD moved to ${commitId}`));
|
|
200
|
-
|
|
201
|
-
deleteLocalCommits(commitFolder,toDelete)
|
|
202
|
-
await deleteCommitsFromDrive(toDelete)
|
|
203
|
-
await deleteCommitsFromDatabase(configData,toDelete,path.basename(process.cwd()))
|
|
204
|
-
|
|
205
|
-
console.log(chalk.green(`Successfully reverted to commit ${commitId}`));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
module.exports = revertCmd
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const chalk = require("chalk")
|
|
2
|
-
const verifyOtp = require("./verifyOtp")
|
|
3
|
-
async function signup(signupData) {
|
|
4
|
-
|
|
5
|
-
const response = await fetch("http://localhost:3000/signup", {
|
|
6
|
-
method: "POST",
|
|
7
|
-
headers: {
|
|
8
|
-
'Content-Type': 'application/json'
|
|
9
|
-
},
|
|
10
|
-
credentials: "include",
|
|
11
|
-
body: JSON.stringify(signupData)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const data = await response.json()
|
|
15
|
-
|
|
16
|
-
if(data.status === true) {
|
|
17
|
-
console.log(chalk.green(data.message))
|
|
18
|
-
await verifyOtp(signupData)
|
|
19
|
-
}
|
|
20
|
-
else if(data.status == "user") {
|
|
21
|
-
console.log(chalk.yellow(data.message))
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw new Error(data.message)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = signup
|