jvcs 1.3.8 → 1.3.9
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.
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const chalk = require("chalk");
|
|
4
|
+
const { checkGlobalConfig, getGlobalConfig } = require("./utility");
|
|
5
|
+
const { getDriveClient } = require("../config/drive-config");
|
|
6
|
+
const drive = getDriveClient()
|
|
7
|
+
|
|
8
|
+
async function findFolderIdByName(name,parentId=null) {
|
|
9
|
+
|
|
10
|
+
const safeName = name.replace(/'/g, "\\'");
|
|
11
|
+
let q = `(name='${safeName}') and (mimeType='application/vnd.google-apps.folder') and (trashed=false)`;
|
|
12
|
+
if (parentId) q = `('${parentId}' in parents) and ` + q
|
|
13
|
+
|
|
14
|
+
console.log("Executing Drive Query:", q); // DEBUG
|
|
15
|
+
|
|
16
|
+
const res = await drive.files.list({
|
|
17
|
+
q,
|
|
18
|
+
fields: "files(id, name, mimeType)",
|
|
19
|
+
spaces: "drive",
|
|
20
|
+
includeItemsFromAllDrives: true,
|
|
21
|
+
supportsAllDrives: true
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const files = (res.data && res.data.files) || [];
|
|
25
|
+
console.log("Search result:", files); // DEBUG
|
|
26
|
+
if (files.length === 0) return null;
|
|
27
|
+
return files[0].id;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function downloadFolderFromDrive(folderId, destPath) {
|
|
31
|
+
try {
|
|
32
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
33
|
+
|
|
34
|
+
const res = await drive.files.list({
|
|
35
|
+
q: `'${folderId}' in parents and trashed=false`,
|
|
36
|
+
fields: "files(id, name, mimeType)",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const files = res.data.files;
|
|
40
|
+
if(!files.length) return;
|
|
41
|
+
|
|
42
|
+
for(const file of files) {
|
|
43
|
+
|
|
44
|
+
if(file.name === "jvcs_hashcode.json" || file.name === "meta.json")
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
const filePath = path.join(destPath, file.name);
|
|
48
|
+
|
|
49
|
+
if(file.mimeType === "application/vnd.google-apps.folder") {
|
|
50
|
+
// create folder locally
|
|
51
|
+
if(!fs.existsSync(filePath)) fs.mkdirSync(filePath);
|
|
52
|
+
await downloadFolderFromDrive(file.id, filePath);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
56
|
+
const dest = fs.createWriteStream(filePath);
|
|
57
|
+
const resFile = await drive.files.get(
|
|
58
|
+
{ fileId: file.id, alt: "media" },
|
|
59
|
+
{ responseType: "stream" }
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
await new Promise((resolve,reject)=> {
|
|
63
|
+
resFile.data.on("end", resolve)
|
|
64
|
+
.on("error",reject)
|
|
65
|
+
.pipe(dest)
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log(chalk.gray(`Downloaded: ${file.name}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.log(chalk.red("Error downloading folder: " + err.message));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async function getVisibilityAndLatestCommit(username,reponame,configData) {
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
|
|
82
|
+
const response = await fetch("https://version-control-system-mebn.onrender.com/cloneRepo", {
|
|
83
|
+
method:"POST",
|
|
84
|
+
headers: {
|
|
85
|
+
'Content-Type':"application/json"
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify({username,reponame,token:configData.token})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const data = await response.json()
|
|
91
|
+
return data
|
|
92
|
+
}
|
|
93
|
+
catch(error) {
|
|
94
|
+
console.log(chalk.red(error || error.message))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function cloneCmd(username,reponame) {
|
|
99
|
+
|
|
100
|
+
if(!username || !reponame) {
|
|
101
|
+
console.log(chalk.red("Path is not provided properly"))
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if(!checkGlobalConfig()) {
|
|
106
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
107
|
+
console.log(chalk.green("jvcs --help for help"));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const configData = getGlobalConfig();
|
|
112
|
+
if(!configData) {
|
|
113
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(username,reponame)
|
|
118
|
+
|
|
119
|
+
const response = await getVisibilityAndLatestCommit(username,reponame,configData)
|
|
120
|
+
if(response.status === false) {
|
|
121
|
+
console.log(chalk.red(`${response.message}`))
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const latestCommit = response.commitId
|
|
126
|
+
// find the repo from drive GithubClone/username/reponame/commit_lastestCommit
|
|
127
|
+
|
|
128
|
+
const rootFolder = await findFolderIdByName("GithubClone")
|
|
129
|
+
if(!rootFolder) throw new Error("Root folder not found on cloud.");
|
|
130
|
+
|
|
131
|
+
const userFolder = await findFolderIdByName(username, rootFolder);
|
|
132
|
+
if (!userFolder) throw new Error(`User folder '${username}' not found.`);
|
|
133
|
+
|
|
134
|
+
console.log("\nListing folders under user:", username);
|
|
135
|
+
|
|
136
|
+
const list = await drive.files.list({
|
|
137
|
+
q: `'${userFolder}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
138
|
+
fields: "files(id, name)"
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
console.log("Folders inside user folder:", list.data.files);
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const repoFolder = await findFolderIdByName(reponame, userFolder);
|
|
145
|
+
if (!repoFolder) throw new Error(`Repository folder '${reponame}' not found.`);
|
|
146
|
+
|
|
147
|
+
const commitFolder = await findFolderIdByName(`commit_${latestCommit}`, repoFolder);
|
|
148
|
+
if (!commitFolder) throw new Error(`Commit folder 'commit_${latestCommit}' not found.`);
|
|
149
|
+
|
|
150
|
+
console.log(chalk.green(`Found repository, downloading...`));
|
|
151
|
+
|
|
152
|
+
const destPath = path.join(process.cwd(), reponame);
|
|
153
|
+
if(fs.existsSync(destPath)) {
|
|
154
|
+
console.log(chalk.red(`Destination '${reponame}' already exists. Remove or rename it and retry.`));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await downloadFolderFromDrive(commitFolder, destPath);
|
|
159
|
+
|
|
160
|
+
console.log(chalk.green(`Repository cloned successfully into ./${reponame}`));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = cloneCmd
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const chalk = require("chalk");
|
|
4
|
+
const { checkGlobalConfig, getGlobalConfig } = require("./utility");
|
|
5
|
+
const { getDriveClient } = require("../config/drive-config");
|
|
6
|
+
const drive = getDriveClient()
|
|
7
|
+
|
|
8
|
+
async function findFolderIdByName(name,parentId=null) {
|
|
9
|
+
|
|
10
|
+
const safeName = name.replace(/'/g, "\\'");
|
|
11
|
+
let q = `(name='${safeName}') and (mimeType='application/vnd.google-apps.folder') and (trashed=false)`;
|
|
12
|
+
if (parentId) q = `('${parentId}' in parents) and ` + q
|
|
13
|
+
|
|
14
|
+
console.log("Executing Drive Query:", q); // DEBUG
|
|
15
|
+
|
|
16
|
+
const res = await drive.files.list({
|
|
17
|
+
q,
|
|
18
|
+
fields: "files(id, name, mimeType)",
|
|
19
|
+
spaces: "drive",
|
|
20
|
+
includeItemsFromAllDrives: true,
|
|
21
|
+
supportsAllDrives: true
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const files = (res.data && res.data.files) || [];
|
|
25
|
+
console.log("Search result:", files); // DEBUG
|
|
26
|
+
if (files.length === 0) return null;
|
|
27
|
+
return files[0].id;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function downloadFolderFromDrive(folderId, destPath) {
|
|
31
|
+
try {
|
|
32
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
33
|
+
|
|
34
|
+
const res = await drive.files.list({
|
|
35
|
+
q: `'${folderId}' in parents and trashed=false`,
|
|
36
|
+
fields: "files(id, name, mimeType)",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const files = res.data.files;
|
|
40
|
+
if(!files.length) return;
|
|
41
|
+
|
|
42
|
+
for(const file of files) {
|
|
43
|
+
|
|
44
|
+
if(file.name === "jvcs_hashcode.json" || file.name === "meta.json")
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
const filePath = path.join(destPath, file.name);
|
|
48
|
+
|
|
49
|
+
if(file.mimeType === "application/vnd.google-apps.folder") {
|
|
50
|
+
// create folder locally
|
|
51
|
+
if(!fs.existsSync(filePath)) fs.mkdirSync(filePath);
|
|
52
|
+
await downloadFolderFromDrive(file.id, filePath);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
56
|
+
const dest = fs.createWriteStream(filePath);
|
|
57
|
+
const resFile = await drive.files.get(
|
|
58
|
+
{ fileId: file.id, alt: "media" },
|
|
59
|
+
{ responseType: "stream" }
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
await new Promise((resolve,reject)=> {
|
|
63
|
+
resFile.data.on("end", resolve)
|
|
64
|
+
.on("error",reject)
|
|
65
|
+
.pipe(dest)
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log(chalk.gray(`Downloaded: ${file.name}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.log(chalk.red("Error downloading folder: " + err.message));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async function getVisibilityAndLatestCommit(username,reponame,configData) {
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
|
|
82
|
+
const response = await fetch("https://version-control-system-mebn.onrender.com/cloneRepo", {
|
|
83
|
+
method:"POST",
|
|
84
|
+
headers: {
|
|
85
|
+
'Content-Type':"application/json"
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify({username,reponame,token:configData.token})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const data = await response.json()
|
|
91
|
+
return data
|
|
92
|
+
}
|
|
93
|
+
catch(error) {
|
|
94
|
+
console.log(chalk.red(error || error.message))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function cloneCmd(username,reponame) {
|
|
99
|
+
|
|
100
|
+
if(!username || !reponame) {
|
|
101
|
+
console.log(chalk.red("Path is not provided properly"))
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if(!checkGlobalConfig()) {
|
|
106
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
107
|
+
console.log(chalk.green("jvcs --help for help"));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const configData = getGlobalConfig();
|
|
112
|
+
if(!configData) {
|
|
113
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(username,reponame)
|
|
118
|
+
|
|
119
|
+
const response = await getVisibilityAndLatestCommit(username,reponame,configData)
|
|
120
|
+
if(response.status === false) {
|
|
121
|
+
console.log(chalk.red(`${response.message}`))
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const latestCommit = response.commitId
|
|
126
|
+
// find the repo from drive GithubClone/username/reponame/commit_lastestCommit
|
|
127
|
+
|
|
128
|
+
const rootFolder = await findFolderIdByName("GithubClone")
|
|
129
|
+
if(!rootFolder) throw new Error("Root folder not found on cloud.");
|
|
130
|
+
|
|
131
|
+
const userFolder = await findFolderIdByName(username, rootFolder);
|
|
132
|
+
if (!userFolder) throw new Error(`User folder '${username}' not found.`);
|
|
133
|
+
|
|
134
|
+
console.log("\nListing folders under user:", username);
|
|
135
|
+
|
|
136
|
+
const list = await drive.files.list({
|
|
137
|
+
q: `'${userFolder}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
138
|
+
fields: "files(id, name)"
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
console.log("Folders inside user folder:", list.data.files);
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const repoFolder = await findFolderIdByName(reponame, userFolder);
|
|
145
|
+
if (!repoFolder) throw new Error(`Repository folder '${reponame}' not found.`);
|
|
146
|
+
|
|
147
|
+
const commitFolder = await findFolderIdByName(`commit_${latestCommit}`, repoFolder);
|
|
148
|
+
if (!commitFolder) throw new Error(`Commit folder 'commit_${latestCommit}' not found.`);
|
|
149
|
+
|
|
150
|
+
console.log(chalk.green(`Found repository, downloading...`));
|
|
151
|
+
|
|
152
|
+
const destPath = path.join(process.cwd(), reponame);
|
|
153
|
+
if(fs.existsSync(destPath)) {
|
|
154
|
+
console.log(chalk.red(`Destination '${reponame}' already exists. Remove or rename it and retry.`));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await downloadFolderFromDrive(commitFolder, destPath);
|
|
159
|
+
|
|
160
|
+
console.log(chalk.green(`Repository cloned successfully into ./${reponame}`));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = cloneCmd
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const chalk = require("chalk");
|
|
4
|
+
const { checkGlobalConfig, getGlobalConfig } = require("./utility");
|
|
5
|
+
const { getDriveClient } = require("../config/drive-config");
|
|
6
|
+
const drive = getDriveClient()
|
|
7
|
+
|
|
8
|
+
async function findFolderIdByName(name,parentId=null) {
|
|
9
|
+
|
|
10
|
+
const safeName = name.replace(/'/g, "\\'");
|
|
11
|
+
let q = `(name='${safeName}') and (mimeType='application/vnd.google-apps.folder') and (trashed=false)`;
|
|
12
|
+
if (parentId) q = `('${parentId}' in parents) and ` + q
|
|
13
|
+
|
|
14
|
+
console.log("Executing Drive Query:", q); // DEBUG
|
|
15
|
+
|
|
16
|
+
const res = await drive.files.list({
|
|
17
|
+
q,
|
|
18
|
+
fields: "files(id, name, mimeType)",
|
|
19
|
+
spaces: "drive",
|
|
20
|
+
includeItemsFromAllDrives: true,
|
|
21
|
+
supportsAllDrives: true
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const files = (res.data && res.data.files) || [];
|
|
25
|
+
console.log("Search result:", files); // DEBUG
|
|
26
|
+
if (files.length === 0) return null;
|
|
27
|
+
return files[0].id;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function downloadFolderFromDrive(folderId, destPath) {
|
|
31
|
+
try {
|
|
32
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
33
|
+
|
|
34
|
+
const res = await drive.files.list({
|
|
35
|
+
q: `'${folderId}' in parents and trashed=false`,
|
|
36
|
+
fields: "files(id, name, mimeType)",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const files = res.data.files;
|
|
40
|
+
if(!files.length) return;
|
|
41
|
+
|
|
42
|
+
for(const file of files) {
|
|
43
|
+
|
|
44
|
+
if(file.name === "jvcs_hashcode.json" || file.name === "meta.json")
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
const filePath = path.join(destPath, file.name);
|
|
48
|
+
|
|
49
|
+
if(file.mimeType === "application/vnd.google-apps.folder") {
|
|
50
|
+
// create folder locally
|
|
51
|
+
if(!fs.existsSync(filePath)) fs.mkdirSync(filePath);
|
|
52
|
+
await downloadFolderFromDrive(file.id, filePath);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
56
|
+
const dest = fs.createWriteStream(filePath);
|
|
57
|
+
const resFile = await drive.files.get(
|
|
58
|
+
{ fileId: file.id, alt: "media" },
|
|
59
|
+
{ responseType: "stream" }
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
await new Promise((resolve,reject)=> {
|
|
63
|
+
resFile.data.on("end", resolve)
|
|
64
|
+
.on("error",reject)
|
|
65
|
+
.pipe(dest)
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log(chalk.gray(`Downloaded: ${file.name}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.log(chalk.red("Error downloading folder: " + err.message));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async function getVisibilityAndLatestCommit(username,reponame,configData) {
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
|
|
82
|
+
const response = await fetch("https://version-control-system-mebn.onrender.com/cloneRepo", {
|
|
83
|
+
method:"POST",
|
|
84
|
+
headers: {
|
|
85
|
+
'Content-Type':"application/json"
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify({username,reponame,token:configData.token})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const data = await response.json()
|
|
91
|
+
return data
|
|
92
|
+
}
|
|
93
|
+
catch(error) {
|
|
94
|
+
console.log(chalk.red(error || error.message))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function cloneCmd(username,reponame) {
|
|
99
|
+
|
|
100
|
+
if(!username || !reponame) {
|
|
101
|
+
console.log(chalk.red("Path is not provided properly"))
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if(!checkGlobalConfig()) {
|
|
106
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
107
|
+
console.log(chalk.green("jvcs --help for help"));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const configData = getGlobalConfig();
|
|
112
|
+
if(!configData) {
|
|
113
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(username,reponame)
|
|
118
|
+
|
|
119
|
+
const response = await getVisibilityAndLatestCommit(username,reponame,configData)
|
|
120
|
+
if(response.status === false) {
|
|
121
|
+
console.log(chalk.red(`${response.message}`))
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const latestCommit = response.commitId
|
|
126
|
+
// find the repo from drive GithubClone/username/reponame/commit_lastestCommit
|
|
127
|
+
|
|
128
|
+
const rootFolder = await findFolderIdByName("GithubClone")
|
|
129
|
+
if(!rootFolder) throw new Error("Root folder not found on cloud.");
|
|
130
|
+
|
|
131
|
+
const userFolder = await findFolderIdByName(username, rootFolder);
|
|
132
|
+
if (!userFolder) throw new Error(`User folder '${username}' not found.`);
|
|
133
|
+
|
|
134
|
+
console.log("\nListing folders under user:", username);
|
|
135
|
+
|
|
136
|
+
const list = await drive.files.list({
|
|
137
|
+
q: `'${userFolder}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
138
|
+
fields: "files(id, name)"
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
console.log("Folders inside user folder:", list.data.files);
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const repoFolder = await findFolderIdByName(reponame, userFolder);
|
|
145
|
+
if (!repoFolder) throw new Error(`Repository folder '${reponame}' not found.`);
|
|
146
|
+
|
|
147
|
+
const commitFolder = await findFolderIdByName(`commit_${latestCommit}`, repoFolder);
|
|
148
|
+
if (!commitFolder) throw new Error(`Commit folder 'commit_${latestCommit}' not found.`);
|
|
149
|
+
|
|
150
|
+
console.log(chalk.green(`Found repository, downloading...`));
|
|
151
|
+
|
|
152
|
+
const destPath = path.join(process.cwd(), reponame);
|
|
153
|
+
if(fs.existsSync(destPath)) {
|
|
154
|
+
console.log(chalk.red(`Destination '${reponame}' already exists. Remove or rename it and retry.`));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await downloadFolderFromDrive(commitFolder, destPath);
|
|
159
|
+
|
|
160
|
+
console.log(chalk.green(`Repository cloned successfully into ./${reponame}`));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports = cloneCmd
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jvcs",
|
|
3
|
+
"version": "1.3.9",
|
|
4
|
+
"bin": {
|
|
5
|
+
"jvcs": "./index.js"
|
|
6
|
+
},
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"chalk": "^4.1.2",
|
|
12
|
+
"dotenv": "^17.2.3",
|
|
13
|
+
"googleapis": "^164.1.0",
|
|
14
|
+
"inquirer": "^8.2.7",
|
|
15
|
+
"uuid": "^13.0.0",
|
|
16
|
+
"validator": "^13.15.20",
|
|
17
|
+
"yargs": "^18.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/controllers/clone.js
CHANGED
|
@@ -131,6 +131,16 @@ async function cloneCmd(username,reponame) {
|
|
|
131
131
|
const userFolder = await findFolderIdByName(username, rootFolder);
|
|
132
132
|
if (!userFolder) throw new Error(`User folder '${username}' not found.`);
|
|
133
133
|
|
|
134
|
+
console.log("\nListing folders under user:", username);
|
|
135
|
+
|
|
136
|
+
const list = await drive.files.list({
|
|
137
|
+
q: `'${userFolder}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
138
|
+
fields: "files(id, name)"
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
console.log("Folders inside user folder:", list.data.files);
|
|
142
|
+
|
|
143
|
+
|
|
134
144
|
const repoFolder = await findFolderIdByName(reponame, userFolder);
|
|
135
145
|
if (!repoFolder) throw new Error(`Repository folder '${reponame}' not found.`);
|
|
136
146
|
|