jvcs 1.0.1 → 1.0.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/.env +4 -4
- package/.jvcs/HEAD +1 -1
- package/.jvcs/commits/3a1169c8-ec67-4ce5-8024-ab4f08d7b609/index.js +146 -0
- package/.jvcs/commits/3a1169c8-ec67-4ce5-8024-ab4f08d7b609/jvcs_hashcode.json +6 -0
- package/.jvcs/commits/3a1169c8-ec67-4ce5-8024-ab4f08d7b609/meta.json +7 -0
- package/.jvcs/commits/c362f97f-997b-499a-bb45-9e67f298f61e/index.js +146 -0
- package/.jvcs/commits/c362f97f-997b-499a-bb45-9e67f298f61e/jvcs_hashcode.json +6 -0
- package/.jvcs/commits/c362f97f-997b-499a-bb45-9e67f298f61e/meta.json +7 -0
- package/.jvcs/config.json +1 -1
- package/.jvcs/staging/index.js +146 -0
- package/.jvcs/staging/jvcs_hashcode.json +6 -1
- package/controllers/driveUtility.js +56 -0
- package/controllers/push.js +121 -111
- package/index.js +17 -2
- package/package.json +1 -1
- package/.jvcs/commits/292abee1-42ea-4ddf-b590-be7c98abaf45/jvcs_hashcode.json +0 -1
- package/.jvcs/commits/292abee1-42ea-4ddf-b590-be7c98abaf45/meta.json +0 -7
- package/.jvcs/commits/302af5ea-5789-4ee9-98fe-eab9308b2e27/jvcs_hashcode.json +0 -1
- package/.jvcs/commits/302af5ea-5789-4ee9-98fe-eab9308b2e27/meta.json +0 -7
- package/.jvcs/commits/376d44d4-c595-429e-b711-ae6ec7c9ef74/jvcs_hashcode.json +0 -1
- package/.jvcs/commits/376d44d4-c595-429e-b711-ae6ec7c9ef74/meta.json +0 -7
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/add.js +0 -122
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/begin.js +0 -201
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/commit.js +0 -82
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/init.js +0 -60
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/login.js +0 -33
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/pull.js +0 -98
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/push.js +0 -135
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/revert.js +0 -110
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/signup.js +0 -28
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/unstage.js +0 -96
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/utility.js +0 -28
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/verifyOtp.js +0 -55
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/jvcs_hashcode.json +0 -50
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/meta.json +0 -7
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/add.js +0 -122
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/begin.js +0 -201
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/commit.js +0 -82
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/init.js +0 -60
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/login.js +0 -33
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/pull.js +0 -98
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/push.js +0 -135
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/revert.js +0 -110
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/signup.js +0 -28
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/unstage.js +0 -96
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/utility.js +0 -28
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/verifyOtp.js +0 -55
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/jvcs_hashcode.json +0 -50
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/meta.json +0 -7
- package/.jvcs/commits/c7aa89bd-5016-4f21-8979-02e3c0a2c8ee/jvcs_hashcode.json +0 -1
- package/.jvcs/commits/c7aa89bd-5016-4f21-8979-02e3c0a2c8ee/meta.json +0 -7
- package/controllers/pull.js +0 -98
- package/controllers/revert.js +0 -110
package/controllers/pull.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const fsPromises = require("fs").promises;
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const chalk = require("chalk");
|
|
5
|
-
const { drive } = require("../config/drive-config");
|
|
6
|
-
const { checkInitialization, checkRepoExists, getCLIConfig } = require("./utils");
|
|
7
|
-
|
|
8
|
-
async function pullCmd(reponame) {
|
|
9
|
-
try {
|
|
10
|
-
if (!checkInitialization()) return;
|
|
11
|
-
if (!checkRepoExists(reponame)) return;
|
|
12
|
-
|
|
13
|
-
const repoPath = path.join(process.cwd(), `.${reponame}`);
|
|
14
|
-
const commitFolder = path.join(repoPath, "commits");
|
|
15
|
-
if (!fs.existsSync(commitFolder)) fs.mkdirSync(commitFolder, { recursive: true });
|
|
16
|
-
|
|
17
|
-
const config = await getCLIConfig();
|
|
18
|
-
if (!config) return console.log(chalk.red("Could not read CLI configuration."));
|
|
19
|
-
|
|
20
|
-
console.log(chalk.blue("Pulling commits for user:"), chalk.green(config.username));
|
|
21
|
-
|
|
22
|
-
// 1️⃣ Find user folder in Drive
|
|
23
|
-
const userFolderRes = await drive.files.list({
|
|
24
|
-
q: `name='${config.username}' and '1ahuoMCN_Ls5kGF2KPUGLbRZb9kGVMe0V' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
25
|
-
fields: "files(id, name)"
|
|
26
|
-
});
|
|
27
|
-
if (!userFolderRes.data.files.length) {
|
|
28
|
-
console.log(chalk.yellow("⚠ No user folder found on Drive."));
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const userFolderId = userFolderRes.data.files[0].id;
|
|
32
|
-
|
|
33
|
-
// 2️⃣ Find repo folder in Drive
|
|
34
|
-
const repoFolderRes = await drive.files.list({
|
|
35
|
-
q: `name='${reponame}' and '${userFolderId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
36
|
-
fields: "files(id, name)"
|
|
37
|
-
});
|
|
38
|
-
if (!repoFolderRes.data.files.length) {
|
|
39
|
-
console.log(chalk.yellow(`⚠ Repository '${reponame}' not found on Drive.`));
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const repoFolderId = repoFolderRes.data.files[0].id;
|
|
43
|
-
|
|
44
|
-
// 3️⃣ Get commit folders in Drive
|
|
45
|
-
const driveCommitsRes = await drive.files.list({
|
|
46
|
-
q: `'${repoFolderId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
47
|
-
fields: "files(name, id)"
|
|
48
|
-
});
|
|
49
|
-
const driveCommits = driveCommitsRes.data.files;
|
|
50
|
-
if (!driveCommits.length) {
|
|
51
|
-
console.log(chalk.yellow("⚠ No commits found on Drive."));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 4️⃣ Get local commit folders
|
|
56
|
-
const localCommits = await fsPromises.readdir(commitFolder);
|
|
57
|
-
|
|
58
|
-
// 5️⃣ Download only missing commits
|
|
59
|
-
for (const commit of driveCommits) {
|
|
60
|
-
if (localCommits.includes(commit.name)) {
|
|
61
|
-
console.log(chalk.gray(`✔ Commit '${commit.name}' already exists locally.`));
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const localCommitPath = path.join(commitFolder, commit.name);
|
|
65
|
-
await fsPromises.mkdir(localCommitPath, { recursive: true });
|
|
66
|
-
await downloadFolder(commit.id, localCommitPath);
|
|
67
|
-
console.log(chalk.green(`⬇ Pulled new commit '${commit.name}' successfully.`));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
console.log(chalk.blue("Pull complete! Local repo is now up to date."));
|
|
71
|
-
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.log(chalk.red("Error in pullCmd:"), error.message);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Recursive folder download helper
|
|
78
|
-
async function downloadFolder(folderId, destPath) {
|
|
79
|
-
const res = await drive.files.list({
|
|
80
|
-
q: `'${folderId}' in parents and trashed=false`,
|
|
81
|
-
fields: "files(id, name, mimeType)"
|
|
82
|
-
});
|
|
83
|
-
for (const file of res.data.files) {
|
|
84
|
-
const localPath = path.join(destPath, file.name);
|
|
85
|
-
if (file.mimeType === "application/vnd.google-apps.folder") {
|
|
86
|
-
await fsPromises.mkdir(localPath, { recursive: true });
|
|
87
|
-
await downloadFolder(file.id, localPath);
|
|
88
|
-
} else {
|
|
89
|
-
const dest = fs.createWriteStream(localPath);
|
|
90
|
-
await drive.files.get({ fileId: file.id, alt: "media" }, { responseType: "stream" })
|
|
91
|
-
.then(res => new Promise((resolve, reject) => {
|
|
92
|
-
res.data.on("end", resolve).on("error", reject).pipe(dest);
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
module.exports = pullCmd;
|
package/controllers/revert.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const fsPromises = require("fs").promises;
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const { v4: uuidv4 } = require("uuid");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const { drive } = require("../config/drive-config");
|
|
7
|
-
const { checkInitialization, checkRepoExists, getCLIConfig } = require("./utils");
|
|
8
|
-
|
|
9
|
-
async function revertCmd(commitId, reponame) {
|
|
10
|
-
try {
|
|
11
|
-
if (!checkInitialization()) return;
|
|
12
|
-
if (!checkRepoExists(reponame)) return;
|
|
13
|
-
|
|
14
|
-
const repoPath = path.join(process.cwd(), `.${reponame}`);
|
|
15
|
-
const commitFolder = path.join(repoPath, "commits");
|
|
16
|
-
if (!fs.existsSync(commitFolder)) fs.mkdirSync(commitFolder, { recursive: true });
|
|
17
|
-
|
|
18
|
-
const config = await getCLIConfig();
|
|
19
|
-
if (!config) return console.log(chalk.red("Could not read CLI configuration."));
|
|
20
|
-
|
|
21
|
-
// 1️⃣ Get user folder
|
|
22
|
-
const userFolderRes = await drive.files.list({
|
|
23
|
-
q: `name='${config.username}' and '1ahuoMCN_Ls5kGF2KPUGLbRZb9kGVMe0V' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
24
|
-
fields: "files(id, name)"
|
|
25
|
-
});
|
|
26
|
-
if (!userFolderRes.data.files.length) return console.log(chalk.red("User folder not found on Drive."));
|
|
27
|
-
const userFolderId = userFolderRes.data.files[0].id;
|
|
28
|
-
|
|
29
|
-
// 2️⃣ Get repo folder
|
|
30
|
-
const repoFolderRes = await drive.files.list({
|
|
31
|
-
q: `name='${reponame}' and '${userFolderId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
32
|
-
fields: "files(id, name)"
|
|
33
|
-
});
|
|
34
|
-
if (!repoFolderRes.data.files.length) return console.log(chalk.red("Repo folder not found on Drive."));
|
|
35
|
-
const repoFolderId = repoFolderRes.data.files[0].id;
|
|
36
|
-
|
|
37
|
-
// 3️⃣ Get commit folder
|
|
38
|
-
const commitRes = await drive.files.list({
|
|
39
|
-
q: `name='${commitId}' and '${repoFolderId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
40
|
-
fields: "files(id, name)"
|
|
41
|
-
});
|
|
42
|
-
if (!commitRes.data.files.length) return console.log(chalk.red(`Commit '${commitId}' not found on Drive.`));
|
|
43
|
-
const driveCommitId = commitRes.data.files[0].id;
|
|
44
|
-
|
|
45
|
-
// 4️⃣ Create new revert commit folder locally
|
|
46
|
-
const newCommitId = `revert_${commitId}_${uuidv4()}`;
|
|
47
|
-
const newCommitPath = path.join(commitFolder, newCommitId);
|
|
48
|
-
await fsPromises.mkdir(newCommitPath, { recursive: true });
|
|
49
|
-
|
|
50
|
-
// 5️⃣ Recursively download commit files from Drive
|
|
51
|
-
await downloadFolderFromDrive(driveCommitId, newCommitPath);
|
|
52
|
-
|
|
53
|
-
// 6️⃣ Clean working directory (except hidden files)
|
|
54
|
-
const cwd = process.cwd();
|
|
55
|
-
const entries = await fsPromises.readdir(cwd);
|
|
56
|
-
for (const entry of entries) {
|
|
57
|
-
if (entry.startsWith(".")) continue;
|
|
58
|
-
await fsPromises.rm(path.join(cwd, entry), { recursive: true, force: true });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 7️⃣ Copy new revert commit into working directory
|
|
62
|
-
await copyFolderRecursive(newCommitPath, cwd);
|
|
63
|
-
|
|
64
|
-
console.log(chalk.green(`Reverted to commit '${commitId}'. New revert commit: '${newCommitId}'`));
|
|
65
|
-
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.log(chalk.red("Error in revertCmd:"), err.message);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Recursive download helper
|
|
72
|
-
async function downloadFolderFromDrive(folderId, localPath) {
|
|
73
|
-
const res = await drive.files.list({
|
|
74
|
-
q: `'${folderId}' in parents and trashed=false`,
|
|
75
|
-
fields: "files(id, name, mimeType)"
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
for (const file of res.data.files) {
|
|
79
|
-
const filePath = path.join(localPath, file.name);
|
|
80
|
-
if (file.mimeType === "application/vnd.google-apps.folder") {
|
|
81
|
-
await fsPromises.mkdir(filePath, { recursive: true });
|
|
82
|
-
await downloadFolderFromDrive(file.id, filePath);
|
|
83
|
-
} else {
|
|
84
|
-
const destStream = fs.createWriteStream(filePath);
|
|
85
|
-
await new Promise((resolve, reject) => {
|
|
86
|
-
drive.files.get({ fileId: file.id, alt: "media" }, { responseType: "stream" }, (err, response) => {
|
|
87
|
-
if (err) return reject(err);
|
|
88
|
-
response.data.pipe(destStream).on("finish", resolve).on("error", reject);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Recursive copy helper
|
|
96
|
-
async function copyFolderRecursive(src, dest) {
|
|
97
|
-
const entries = await fsPromises.readdir(src, { withFileTypes: true });
|
|
98
|
-
for (const entry of entries) {
|
|
99
|
-
const srcPath = path.join(src, entry.name);
|
|
100
|
-
const destPath = path.join(dest, entry.name);
|
|
101
|
-
if (entry.isDirectory()) {
|
|
102
|
-
await fsPromises.mkdir(destPath, { recursive: true });
|
|
103
|
-
await copyFolderRecursive(srcPath, destPath);
|
|
104
|
-
} else {
|
|
105
|
-
await fsPromises.copyFile(srcPath, destPath);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
module.exports = revertCmd;
|