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.
@@ -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
- dotenv.config()
6
-
7
- const homedir = require("os").homedir()
8
- const credDir = path.join(homedir,".jvcs")
9
- const file = path.join(credDir,"config.json")
10
-
11
- let data = {}
12
-
13
- if(fs.existsSync(file)) {
14
- data = JSON.parse(fs.readFileSync(file, "utf-8"))
15
- }
16
- else {
17
- console.warn("No credentials found. Please login/signup")
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
- console.log(data)
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 };
@@ -1,4 +1,5 @@
1
- const { drive } = require("../config/drive-config");
1
+ const { getDriveClient } = require("../config/drive-config");
2
+ const drive = getDriveClient()
2
3
 
3
4
  async function getDirectoryStructure(username,reponame,commitId) {
4
5
 
@@ -1,7 +1,8 @@
1
1
  const fs = require("fs")
2
2
  const path = require("path")
3
3
  const chalk = require("chalk")
4
- const { drive } = require("../config/drive-config")
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")
@@ -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 drive = require("../config/drive-config")
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jvcs",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "bin": {
5
5
  "jvcs": "./index.js"
6
6
  },