jvcs 1.1.1 → 1.1.3
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/config/drive-config.js +33 -42
- package/controllers/driveUtility.js +2 -1
- package/controllers/push.js +2 -1
- package/controllers/revert.js +9 -1
- package/package.json +1 -1
package/config/drive-config.js
CHANGED
|
@@ -1,44 +1,35 @@
|
|
|
1
1
|
const { google } = require("googleapis");
|
|
2
|
-
const dotenv = require("dotenv")
|
|
3
|
-
const fs = require("fs")
|
|
4
|
-
const path = require("path")
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
const dotenv = require("dotenv");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
|
|
8
|
+
dotenv.config();
|
|
9
|
+
|
|
10
|
+
const credDir = path.join(os.homedir(), ".jvcs");
|
|
11
|
+
const credFile = path.join(credDir, "config.json");
|
|
12
|
+
|
|
13
|
+
function getDriveClient() {
|
|
14
|
+
|
|
15
|
+
if(!fs.existsSync(credFile)) {
|
|
16
|
+
console.log(chalk.red("No credentials found. Please login/signup."));
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const data = JSON.parse(fs.readFileSync(credFile, "utf-8"));
|
|
21
|
+
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, REFRESH_TOKEN } = data;
|
|
22
|
+
|
|
23
|
+
if(!CLIENT_ID || !CLIENT_SECRET || !REFRESH_TOKEN) {
|
|
24
|
+
console.log(chalk.red("Incomplete credentials in ~/.jvcs/config.json"));
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const oauth2client = new google.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
|
|
29
|
+
oauth2client.setCredentials({ refresh_token: REFRESH_TOKEN });
|
|
30
|
+
|
|
31
|
+
const drive = google.drive({ version: "v3", auth: oauth2client });
|
|
32
|
+
return drive;
|
|
18
33
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// Replace these with your own credentials from Google Cloud Console
|
|
22
|
-
const CLIENT_ID = data.CLIENT_ID
|
|
23
|
-
const CLIENT_SECRET = data.CLIENT_SECRET
|
|
24
|
-
const REDIRECT_URI = data.REDIRECT_URI
|
|
25
|
-
|
|
26
|
-
// Your generated refresh token from OAuth Playground or your OAuth flow
|
|
27
|
-
const REFRESH_TOKEN = data.REFRESH_TOKEN
|
|
28
|
-
console.log(REFRESH_TOKEN)
|
|
29
|
-
const oauth2client = new google.auth.OAuth2(
|
|
30
|
-
CLIENT_ID,
|
|
31
|
-
CLIENT_SECRET,
|
|
32
|
-
REDIRECT_URI
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// hello
|
|
37
|
-
oauth2client.setCredentials({ refresh_token: REFRESH_TOKEN });
|
|
38
|
-
|
|
39
|
-
const drive = google.drive({
|
|
40
|
-
version: 'v3',
|
|
41
|
-
auth: oauth2client
|
|
42
|
-
});
|
|
43
|
-
//hello
|
|
44
|
-
module.exports = { drive };
|
|
34
|
+
|
|
35
|
+
module.exports = { getDriveClient };
|
package/controllers/push.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const fs = require("fs")
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const chalk = require("chalk")
|
|
4
|
-
const {
|
|
4
|
+
const { getDriveClient } = require("../config/drive-config");
|
|
5
|
+
const drive = getDriveClient()
|
|
5
6
|
const { getGlobalConfig, checkGlobalConfig, checkforjvcs } = require("./utility")
|
|
6
7
|
const getDirectoryStructure = require("./driveUtility")
|
|
7
8
|
const handleDbForRepo = require("../apicall/handleDbForRepo")
|
package/controllers/revert.js
CHANGED
|
@@ -2,7 +2,8 @@ const fs = require("fs");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const chalk = require("chalk");
|
|
4
4
|
const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility");
|
|
5
|
-
const
|
|
5
|
+
const { getDriveClient } = require("../config/drive-config");
|
|
6
|
+
|
|
6
7
|
|
|
7
8
|
function copyDir(targetCommitFolder, destDir=process.cwd()) {
|
|
8
9
|
|
|
@@ -73,6 +74,13 @@ function deleteLocalCommits(commitDir,Ids) {
|
|
|
73
74
|
|
|
74
75
|
async function deleteCommitsFromDrive(ids) {
|
|
75
76
|
|
|
77
|
+
const drive = getDriveClient();
|
|
78
|
+
|
|
79
|
+
if (!drive) {
|
|
80
|
+
console.log(chalk.red("Drive client not initialized. Please re-authenticate."));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
76
84
|
let folderName = null
|
|
77
85
|
try {
|
|
78
86
|
for(const id of ids) {
|