jvcs 1.0.0
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 -0
- package/.jvcs/HEAD +1 -0
- package/.jvcs/commits/292abee1-42ea-4ddf-b590-be7c98abaf45/jvcs_hashcode.json +1 -0
- package/.jvcs/commits/292abee1-42ea-4ddf-b590-be7c98abaf45/meta.json +7 -0
- package/.jvcs/commits/302af5ea-5789-4ee9-98fe-eab9308b2e27/jvcs_hashcode.json +1 -0
- package/.jvcs/commits/302af5ea-5789-4ee9-98fe-eab9308b2e27/meta.json +7 -0
- package/.jvcs/commits/376d44d4-c595-429e-b711-ae6ec7c9ef74/jvcs_hashcode.json +1 -0
- package/.jvcs/commits/376d44d4-c595-429e-b711-ae6ec7c9ef74/meta.json +7 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/add.js +122 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/begin.js +201 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/commit.js +82 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/init.js +60 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/login.js +33 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/pull.js +98 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/push.js +135 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/revert.js +110 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/signup.js +28 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/unstage.js +96 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/utility.js +28 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/controllers/verifyOtp.js +55 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/jvcs_hashcode.json +50 -0
- package/.jvcs/commits/484ac37d-c1a9-4ddd-8796-6e3facda1e11/meta.json +7 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/add.js +122 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/begin.js +201 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/commit.js +82 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/init.js +60 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/login.js +33 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/pull.js +98 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/push.js +135 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/revert.js +110 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/signup.js +28 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/unstage.js +96 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/utility.js +28 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/controllers/verifyOtp.js +55 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/jvcs_hashcode.json +50 -0
- package/.jvcs/commits/c3f6ff7a-13bd-4697-a80e-041f7dae8a09/meta.json +7 -0
- package/.jvcs/commits/c7aa89bd-5016-4f21-8979-02e3c0a2c8ee/jvcs_hashcode.json +1 -0
- package/.jvcs/commits/c7aa89bd-5016-4f21-8979-02e3c0a2c8ee/meta.json +7 -0
- package/.jvcs/config.json +9 -0
- package/.jvcs/staging/jvcs_hashcode.json +1 -0
- package/config/drive-config.js +25 -0
- package/controllers/add.js +122 -0
- package/controllers/begin.js +201 -0
- package/controllers/commit.js +82 -0
- package/controllers/init.js +60 -0
- package/controllers/log.js +99 -0
- package/controllers/login.js +33 -0
- package/controllers/pull.js +98 -0
- package/controllers/push.js +135 -0
- package/controllers/revert.js +110 -0
- package/controllers/signup.js +28 -0
- package/controllers/unstage.js +96 -0
- package/controllers/utility.js +28 -0
- package/controllers/verifyOtp.js +55 -0
- package/index.js +131 -0
- package/package.json +21 -0
|
@@ -0,0 +1,135 @@
|
|
|
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 saveData = require("../controllers/saveData");
|
|
7
|
+
const { checkInitialization, checkRepoExists, getCLIConfig } = require("./utils");
|
|
8
|
+
|
|
9
|
+
async function pushCmd(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
|
+
|
|
17
|
+
const config = await getCLIConfig();
|
|
18
|
+
if (!config) return console.log(chalk.red("Could not read CLI configuration."));
|
|
19
|
+
|
|
20
|
+
console.log(chalk.blue("Pushing commits for user:"), chalk.green(config.username));
|
|
21
|
+
|
|
22
|
+
// Check commits locally
|
|
23
|
+
const commitDirs = await fsPromises.readdir(commitFolder);
|
|
24
|
+
if (!commitDirs.length) {
|
|
25
|
+
console.log(chalk.yellow("⚠ No commits to push."));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Ensure user folder exists in Google Drive
|
|
30
|
+
let userFolderId;
|
|
31
|
+
const userFolderRes = await drive.files.list({
|
|
32
|
+
q: `name='${config.username}' and '1ahuoMCN_Ls5kGF2KPUGLbRZb9kGVMe0V' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
33
|
+
fields: "files(id, name)"
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (userFolderRes.data.files.length) {
|
|
37
|
+
userFolderId = userFolderRes.data.files[0].id;
|
|
38
|
+
} else {
|
|
39
|
+
const folder = await drive.files.create({
|
|
40
|
+
requestBody: {
|
|
41
|
+
name: config.username,
|
|
42
|
+
mimeType: "application/vnd.google-apps.folder",
|
|
43
|
+
parents: ["1ahuoMCN_Ls5kGF2KPUGLbRZb9kGVMe0V"]
|
|
44
|
+
},
|
|
45
|
+
fields: "id, name"
|
|
46
|
+
});
|
|
47
|
+
userFolderId = folder.data.id;
|
|
48
|
+
console.log(chalk.green(`Created user folder in Drive.`));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Ensure repo folder exists
|
|
52
|
+
let repoFolderId;
|
|
53
|
+
const repoFolderRes = await drive.files.list({
|
|
54
|
+
q: `name='${reponame}' and '${userFolderId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
55
|
+
fields: "files(id, name)"
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (repoFolderRes.data.files.length) {
|
|
59
|
+
repoFolderId = repoFolderRes.data.files[0].id;
|
|
60
|
+
} else {
|
|
61
|
+
const folder = await drive.files.create({
|
|
62
|
+
requestBody: {
|
|
63
|
+
name: reponame,
|
|
64
|
+
mimeType: "application/vnd.google-apps.folder",
|
|
65
|
+
parents: [userFolderId]
|
|
66
|
+
},
|
|
67
|
+
fields: "id, name"
|
|
68
|
+
});
|
|
69
|
+
repoFolderId = folder.data.id;
|
|
70
|
+
console.log(chalk.green(`Created repo folder '${reponame}' in Drive.`));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// List existing commits in Drive
|
|
74
|
+
const driveCommitsRes = await drive.files.list({
|
|
75
|
+
q: `'${repoFolderId}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
76
|
+
fields: "files(name, id)"
|
|
77
|
+
});
|
|
78
|
+
const driveCommitNames = driveCommitsRes.data.files.map(f => f.name);
|
|
79
|
+
|
|
80
|
+
// Upload commits
|
|
81
|
+
for (const commitDir of commitDirs) {
|
|
82
|
+
if (driveCommitNames.includes(commitDir)) {
|
|
83
|
+
console.log(chalk.yellow(`Commit '${commitDir}' already exists on Drive, skipping.`));
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const folderPath = path.join(commitFolder, commitDir);
|
|
88
|
+
|
|
89
|
+
const commitFolderRes = await drive.files.create({
|
|
90
|
+
requestBody: {
|
|
91
|
+
name: commitDir,
|
|
92
|
+
mimeType: "application/vnd.google-apps.folder",
|
|
93
|
+
parents: [repoFolderId]
|
|
94
|
+
},
|
|
95
|
+
fields: "id, name"
|
|
96
|
+
});
|
|
97
|
+
const commitFolderId = commitFolderRes.data.id;
|
|
98
|
+
|
|
99
|
+
await uploadFolder(folderPath, commitFolderId);
|
|
100
|
+
|
|
101
|
+
console.log(chalk.green(`Commit '${commitDir}' pushed successfully.`));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
} catch(error) {
|
|
105
|
+
console.log(chalk.red("Error in pushCmd:"), error.message);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Helper to recursively upload folder to Drive
|
|
110
|
+
async function uploadFolder(folderPath, parentId) {
|
|
111
|
+
const items = await fsPromises.readdir(folderPath);
|
|
112
|
+
for (const item of items) {
|
|
113
|
+
const fullPath = path.join(folderPath, item);
|
|
114
|
+
const stats = await fsPromises.stat(fullPath);
|
|
115
|
+
if (stats.isDirectory()) {
|
|
116
|
+
const folder = await drive.files.create({
|
|
117
|
+
requestBody: {
|
|
118
|
+
name: item,
|
|
119
|
+
mimeType: "application/vnd.google-apps.folder",
|
|
120
|
+
parents: [parentId]
|
|
121
|
+
},
|
|
122
|
+
fields: "id, name"
|
|
123
|
+
});
|
|
124
|
+
await uploadFolder(fullPath, folder.data.id);
|
|
125
|
+
} else {
|
|
126
|
+
await drive.files.create({
|
|
127
|
+
requestBody: { name: item, parents: [parentId] },
|
|
128
|
+
media: { body: fs.createReadStream(fullPath) },
|
|
129
|
+
fields: "id, name"
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = pushCmd;
|
|
@@ -0,0 +1,110 @@
|
|
|
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;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const chalk = require("chalk")
|
|
2
|
+
const verifyOtp = require("./verifyOtp")
|
|
3
|
+
async function signup(signupData) {
|
|
4
|
+
|
|
5
|
+
const response = await fetch("http://localhost:3000/signup", {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json'
|
|
9
|
+
},
|
|
10
|
+
credentials: "include",
|
|
11
|
+
body: JSON.stringify(signupData)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const data = await response.json()
|
|
15
|
+
|
|
16
|
+
if(data.status === true) {
|
|
17
|
+
console.log(chalk.green(data.message))
|
|
18
|
+
await verifyOtp(signupData)
|
|
19
|
+
}
|
|
20
|
+
else if(data.status == "user") {
|
|
21
|
+
console.log(chalk.yellow(data.message))
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(data.message)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = signup
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const fs = require("fs").promises;
|
|
2
|
+
const fssync = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility");
|
|
6
|
+
|
|
7
|
+
function removeHashesForFolder(hashData,folderPath) {
|
|
8
|
+
|
|
9
|
+
for(const key of Object.keys(hashData)) {
|
|
10
|
+
if(key.startsWith(folderPath+path.sep)) {
|
|
11
|
+
delete hashData[key]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function unstageCmd(paths) {
|
|
17
|
+
|
|
18
|
+
if(!paths || paths.length === 0) {
|
|
19
|
+
console.log(chalk.yellow("Please specify files or folders to unstage."));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if(!checkGlobalConfig()) {
|
|
24
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
25
|
+
console.log(chalk.green("jvcs --help for help"));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const configData = getGlobalConfig();
|
|
30
|
+
if(!configData) {
|
|
31
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if(!checkforjvcs()) {
|
|
36
|
+
console.log(chalk.red("Repository is not initialized or is deleted."));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const repoPath = path.join(process.cwd(), ".jvcs");
|
|
41
|
+
const stagingPath = path.join(repoPath, "staging");
|
|
42
|
+
const hashPath = path.join(stagingPath, "jvcs_hashcode.json");
|
|
43
|
+
|
|
44
|
+
if(!fssync.existsSync(stagingPath)) {
|
|
45
|
+
console.log(chalk.yellow("Nothing is staged yet."));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const stagedItems = fssync.readdirSync(stagingPath).filter((item)=> item !== "jvcs_hashcode.json")
|
|
50
|
+
if(stagedItems.length === 0) {
|
|
51
|
+
console.log(chalk.yellow("Staging area is empty. Nothing to unstage."));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let hashData = {};
|
|
56
|
+
if(fssync.existsSync(hashPath)) {
|
|
57
|
+
hashData = JSON.parse(await fs.readFile(hashPath, "utf-8"));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if(paths.length === 1 && paths[0] === ".") {
|
|
61
|
+
await fs.rm(stagingPath, {recursive: true, force: true})
|
|
62
|
+
await fs.mkdir(stagingPath, {recursive: true})
|
|
63
|
+
console.log(chalk.cyan("Unstaged all files and folders."));
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const targets = paths.map((p) => path.resolve(process.cwd(), p));
|
|
68
|
+
|
|
69
|
+
for(const target of targets) {
|
|
70
|
+
|
|
71
|
+
const stagedTarget = path.join(stagingPath, path.relative(process.cwd(),target))
|
|
72
|
+
|
|
73
|
+
if(!fssync.existsSync(stagedTarget)) {
|
|
74
|
+
console.log(chalk.yellow(`Not found in staging: ${path.relative(process.cwd(), target)}`));
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const stats = await fs.stat(stagedTarget);
|
|
79
|
+
|
|
80
|
+
if(stats.isDirectory()) {
|
|
81
|
+
await fs.rm(stagedTarget, {recursive: true, force: true})
|
|
82
|
+
removeHashesForFolder(hashData,path.relative(process.cwd(),target))
|
|
83
|
+
console.log(chalk.cyan(`Unstaged folder: ${path.relative(process.cwd(), target)}`));
|
|
84
|
+
}
|
|
85
|
+
else if(stats.isFile()) {
|
|
86
|
+
await fs.rm(stagedTarget)
|
|
87
|
+
delete hashData[path.relative(process.cwd(),target)]
|
|
88
|
+
console.log(chalk.green(`Unstaged file: ${path.relative(process.cwd(), target)}`));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
await fs.writeFile(hashPath, JSON.stringify(hashData, null, 2));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = unstageCmd
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
|
|
4
|
+
const config = path.join(require("os").homedir(),".jvcs","config.json")
|
|
5
|
+
|
|
6
|
+
function checkGlobalConfig() {
|
|
7
|
+
return fs.existsSync(config)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getGlobalConfig() {
|
|
11
|
+
if(checkGlobalConfig()) {
|
|
12
|
+
const configData = JSON.parse(fs.readFileSync(config,"utf-8"))
|
|
13
|
+
return configData
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function checkforjvcs() {
|
|
20
|
+
const jvcsPath = path.join(process.cwd(),".jvcs")
|
|
21
|
+
return fs.existsSync(jvcsPath)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
checkGlobalConfig,
|
|
26
|
+
getGlobalConfig,
|
|
27
|
+
checkforjvcs
|
|
28
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const inquirer = require("inquirer");
|
|
2
|
+
const fs = require("fs")
|
|
3
|
+
const path = require("path")
|
|
4
|
+
const chalk = require("chalk")
|
|
5
|
+
|
|
6
|
+
async function verifyOtp(signupData) {
|
|
7
|
+
|
|
8
|
+
const otp = await inquirer.prompt([
|
|
9
|
+
{
|
|
10
|
+
type: 'password',
|
|
11
|
+
name: 'otp',
|
|
12
|
+
validate: function(input) {
|
|
13
|
+
if(input.length !== 6)
|
|
14
|
+
return "OTP must be of 6 length"
|
|
15
|
+
|
|
16
|
+
return true
|
|
17
|
+
},
|
|
18
|
+
filter: function(input) {
|
|
19
|
+
return input.trim()
|
|
20
|
+
},
|
|
21
|
+
mask: '*',
|
|
22
|
+
}
|
|
23
|
+
])
|
|
24
|
+
|
|
25
|
+
console.log(`otp is : ${otp.otp}`)
|
|
26
|
+
const response = await fetch("http://localhost:3000/verifyEmail", {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: { 'Content-Type': 'application/json' },
|
|
29
|
+
credentials: "include",
|
|
30
|
+
body: JSON.stringify({email:signupData.email,otp:otp.otp,cli:true})
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
|
|
35
|
+
if (data.status === true) {
|
|
36
|
+
console.log(chalk.green(data.message))
|
|
37
|
+
|
|
38
|
+
const dirPath = path.join(require("os").homedir(), ".jvcs");
|
|
39
|
+
if (!fs.existsSync(dirPath)) {
|
|
40
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const configPath = path.join(dirPath, "config.json");
|
|
44
|
+
fs.writeFileSync(configPath,JSON.stringify({email: signupData.email,username: signupData.username,token: data.token},null,2));
|
|
45
|
+
}
|
|
46
|
+
else if(data.status === "user") {
|
|
47
|
+
console.log(chalk.yellow(data.message))
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error(data.message)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = verifyOtp
|
package/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const yargs = require("yargs");
|
|
4
|
+
const { hideBin } = require("yargs/helpers");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const dotenv = require("dotenv")
|
|
7
|
+
dotenv.config()
|
|
8
|
+
|
|
9
|
+
const beginCmd = require("./controllers/begin")
|
|
10
|
+
const initCmd = require("./controllers/init")
|
|
11
|
+
const addCmd = require("./controllers/add")
|
|
12
|
+
const commitCmd = require("./controllers/commit")
|
|
13
|
+
const unstageCmd = require("./controllers/unstage")
|
|
14
|
+
const logCmd = require("./controllers/log")
|
|
15
|
+
|
|
16
|
+
yargs(hideBin(process.argv))
|
|
17
|
+
.scriptName("jvcs")
|
|
18
|
+
.command(
|
|
19
|
+
"begin",
|
|
20
|
+
chalk.blue("Initialize the Version Control System (login/signup).\n"),
|
|
21
|
+
{},
|
|
22
|
+
async () => {
|
|
23
|
+
try {
|
|
24
|
+
await beginCmd()
|
|
25
|
+
}
|
|
26
|
+
catch(error) {
|
|
27
|
+
console.log(chalk.red(error))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
.command(
|
|
32
|
+
"init",
|
|
33
|
+
chalk.blue("Create an empty repository.\n"),
|
|
34
|
+
{},
|
|
35
|
+
async () => {
|
|
36
|
+
try {
|
|
37
|
+
await initCmd()
|
|
38
|
+
}
|
|
39
|
+
catch(error) {
|
|
40
|
+
console.log(chalk.red(error))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
.command(
|
|
45
|
+
"add <paths...>",
|
|
46
|
+
chalk.blue(
|
|
47
|
+
`Add files or folders to the staging area.
|
|
48
|
+
|
|
49
|
+
Command | Description
|
|
50
|
+
---------------------------------|-------------------
|
|
51
|
+
jvcs add . | all files/folders
|
|
52
|
+
jvcs add <file1> <file2> | multiple files
|
|
53
|
+
jvcs add <folder1> <folder2> | multiple folders
|
|
54
|
+
jvcs add <file> <folder> | files and folders\n`
|
|
55
|
+
),
|
|
56
|
+
(yargs)=> {
|
|
57
|
+
return yargs.positional("paths", {
|
|
58
|
+
type: 'string',
|
|
59
|
+
describe: 'Files and folders to stage'
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
async (argv) => {
|
|
63
|
+
try {
|
|
64
|
+
await addCmd(argv.paths)
|
|
65
|
+
}
|
|
66
|
+
catch(error) {
|
|
67
|
+
console.log(chalk.red(error))
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
.command(
|
|
72
|
+
"commit <message>",
|
|
73
|
+
chalk.blue("Commit all the files/folders inside staging area\n"),
|
|
74
|
+
(yargs)=> {
|
|
75
|
+
return yargs.positional("message", {
|
|
76
|
+
type: 'string',
|
|
77
|
+
describe: 'Some message with your commit'
|
|
78
|
+
})
|
|
79
|
+
},
|
|
80
|
+
async (argv)=> {
|
|
81
|
+
try {
|
|
82
|
+
await commitCmd(argv.message)
|
|
83
|
+
}
|
|
84
|
+
catch(error) {
|
|
85
|
+
console.log(chalk.red(error))
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
.command(
|
|
90
|
+
"unstage <paths...>",
|
|
91
|
+
chalk.blue(`
|
|
92
|
+
Remove files and folders from staging area
|
|
93
|
+
|
|
94
|
+
Command | Description
|
|
95
|
+
---------------------------------|-------------------
|
|
96
|
+
jvcs unstage . | all files/folders
|
|
97
|
+
jvcs unstage <file1> <file2> | multiple files
|
|
98
|
+
jvcs unstage <folder1> <folder2> | multiple folders
|
|
99
|
+
jvcs unstage <file> <folder> | files and folders\n
|
|
100
|
+
`),
|
|
101
|
+
(yargs)=> {
|
|
102
|
+
return yargs.positional("paths", {
|
|
103
|
+
type: 'string',
|
|
104
|
+
describe: 'Files and folders to unstage'
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
async (argv)=> {
|
|
108
|
+
try {
|
|
109
|
+
await unstageCmd(argv.paths)
|
|
110
|
+
}
|
|
111
|
+
catch(error) {
|
|
112
|
+
console.log(chalk.red(error))
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
.command(
|
|
117
|
+
"log",
|
|
118
|
+
"show details of all commits",
|
|
119
|
+
{},
|
|
120
|
+
async ()=> {
|
|
121
|
+
try {
|
|
122
|
+
await logCmd()
|
|
123
|
+
}
|
|
124
|
+
catch(error) {
|
|
125
|
+
console.log(chalk.red(error))
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
.demandCommand(1, chalk.yellow("You need at least one command"))
|
|
130
|
+
.help()
|
|
131
|
+
.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jvcs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"bin": {
|
|
5
|
+
"jvcs": "./index.js"
|
|
6
|
+
},
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"description": "",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"chalk": "^4.1.2",
|
|
13
|
+
"crypto": "^1.0.1",
|
|
14
|
+
"dotenv": "^17.2.3",
|
|
15
|
+
"googleapis": "^164.1.0",
|
|
16
|
+
"inquirer": "^8.2.7",
|
|
17
|
+
"uuid": "^13.0.0",
|
|
18
|
+
"validator": "^13.15.20",
|
|
19
|
+
"yargs": "^18.0.0"
|
|
20
|
+
}
|
|
21
|
+
}
|