jvcs 1.3.7 → 1.3.8

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