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/push.js
CHANGED
|
@@ -1,135 +1,145 @@
|
|
|
1
|
-
const fs = require("fs")
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
6
|
-
const
|
|
7
|
-
const { checkInitialization, checkRepoExists, getCLIConfig } = require("./utils");
|
|
8
|
-
|
|
9
|
-
async function pushCmd(reponame) {
|
|
10
|
-
try {
|
|
11
|
-
if (!checkInitialization()) return;
|
|
12
|
-
if (!checkRepoExists(reponame)) return;
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const chalk = require("chalk")
|
|
4
|
+
const { drive } = require("../config/drive-config")
|
|
5
|
+
const { getGlobalConfig, checkGlobalConfig, checkforjvcs } = require("./utility")
|
|
6
|
+
const getDirectoryStructure = require("./driveUtility")
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
const commitFolder = path.join(repoPath, "commits");
|
|
8
|
+
async function uploadFile(localFile, parentId) {
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
if (!config) return console.log(chalk.red("Could not read CLI configuration."));
|
|
10
|
+
try {
|
|
19
11
|
|
|
20
|
-
|
|
12
|
+
const fileName = path.basename(localFile)
|
|
13
|
+
const fileMetaData = {
|
|
14
|
+
name: fileName,
|
|
15
|
+
parents: [parentId]
|
|
16
|
+
}
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
console.log(chalk.yellow("⚠ No commits to push."));
|
|
26
|
-
return;
|
|
18
|
+
const media = {
|
|
19
|
+
mimeType: "application/octet-stream",
|
|
20
|
+
body: fs.createReadStream(localFile),
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
const res = await drive.files.create({
|
|
24
|
+
resource: fileMetaData,
|
|
25
|
+
media,
|
|
26
|
+
fields: "id"
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
console.log(chalk.gray(` ↳ Uploaded: ${fileName}`));
|
|
30
|
+
return res.data.id;
|
|
31
|
+
}
|
|
32
|
+
catch(error) {
|
|
33
|
+
console.log(chalk.red(`Failed to upload ${filePath}: ${err.message}`));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function uploadDirectory(localDir, parentId) {
|
|
38
|
+
|
|
39
|
+
const entries = fs.readdirSync(localDir, {withFileTypes: true})
|
|
40
|
+
|
|
41
|
+
for(const entry of entries) {
|
|
42
|
+
|
|
43
|
+
const entryPath = path.join(localDir,entry.name)
|
|
44
|
+
|
|
45
|
+
if(entry.isDirectory()) {
|
|
46
|
+
const folderMeta = {
|
|
47
|
+
name: entry.name,
|
|
48
|
+
mimeType: "application/vnd.google-apps.folder",
|
|
49
|
+
parents: [parentId],
|
|
50
|
+
}
|
|
35
51
|
|
|
36
|
-
if (userFolderRes.data.files.length) {
|
|
37
|
-
userFolderId = userFolderRes.data.files[0].id;
|
|
38
|
-
} else {
|
|
39
52
|
const folder = await drive.files.create({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
console.log(chalk.green(`Created user folder in Drive.`));
|
|
53
|
+
resource: folderMeta,
|
|
54
|
+
fields: "id"
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
await uploadDirectory(entryPath,folder.data.id)
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await uploadFile(entryPath,parentId)
|
|
49
61
|
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
50
64
|
|
|
51
|
-
|
|
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
|
-
});
|
|
65
|
+
async function pushCmd() {
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
console.log(chalk.green(
|
|
67
|
+
try {
|
|
68
|
+
|
|
69
|
+
if(!checkGlobalConfig()) {
|
|
70
|
+
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
71
|
+
console.log(chalk.green("jvcs --help for help"))
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let configData = getGlobalConfig()
|
|
76
|
+
|
|
77
|
+
if(!configData) {
|
|
78
|
+
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
79
|
+
console.log(chalk.green("jvcs --help for help"))
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if(!checkforjvcs()) {
|
|
84
|
+
console.log(chalk.red("Repository is not initialized or is deleted. Please create it."))
|
|
85
|
+
return
|
|
71
86
|
}
|
|
87
|
+
|
|
88
|
+
const cwd = process.cwd()
|
|
89
|
+
const jvcsDir = path.join(cwd,".jvcs")
|
|
90
|
+
const commitDir = path.join(jvcsDir,"commits")
|
|
91
|
+
const reponame = path.basename(process.cwd())
|
|
92
|
+
|
|
93
|
+
if(!fs.existsSync(commitDir)) {
|
|
94
|
+
console.log(chalk.yellow("No commits to push"))
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// storing the name of commit folders
|
|
99
|
+
const commitFolders = fs.readdirSync(commitDir, {withFileTypes: true}).filter((e)=> e.isDirectory()).map((e)=> e.name)
|
|
100
|
+
if(commitFolders.length === 0) {
|
|
101
|
+
console.log(chalk.yellow('No commits to push'))
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log(chalk.blue("Pushing commits of ",reponame," to cloud storage..."))
|
|
72
106
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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.`));
|
|
107
|
+
for(const commitId of commitFolders) {
|
|
108
|
+
|
|
109
|
+
const commitFolder = path.join(commitDir,commitId)
|
|
110
|
+
const metaPath = path.join(commitFolder,"meta.json")
|
|
111
|
+
|
|
112
|
+
if(!fs.existsSync(metaPath)) {
|
|
113
|
+
console.log(chalk.yellow(`Skipping ${commitId} (no meta.json found)`));
|
|
84
114
|
continue;
|
|
85
115
|
}
|
|
86
116
|
|
|
87
|
-
const
|
|
117
|
+
const metaData = JSON.parse(fs.readFileSync(metaPath,"utf-8"))
|
|
118
|
+
const { author, message, timeStamp } = metaData;
|
|
88
119
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
fields: "id, name"
|
|
96
|
-
});
|
|
97
|
-
const commitFolderId = commitFolderRes.data.id;
|
|
120
|
+
console.log(chalk.green(`\n Uploading commit:`));
|
|
121
|
+
console.log(chalk.gray(` id: ${commitId}`));
|
|
122
|
+
console.log(chalk.gray(` message: ${message}`));
|
|
123
|
+
console.log(chalk.gray(` author: ${author}`));
|
|
124
|
+
console.log(chalk.gray(` time: ${timeStamp}`));
|
|
98
125
|
|
|
99
|
-
await
|
|
126
|
+
const { commitFolderId : driveCommitId , commitAlreadyExists } = await getDirectoryStructure(configData.username,reponame,commitId)
|
|
127
|
+
|
|
128
|
+
if (commitAlreadyExists) {
|
|
129
|
+
console.log(chalk.yellow(`Skipping ${commitId} (already uploaded)`));
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
100
132
|
|
|
101
|
-
|
|
133
|
+
await uploadDirectory(commitFolder,driveCommitId)
|
|
134
|
+
console.log(chalk.green(`Commit ${commitId} uploaded successfully!`));
|
|
102
135
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
console.log(chalk.red("Error in pushCmd:"), error.message);
|
|
136
|
+
|
|
137
|
+
console.log(chalk.bold.green("\nAll commits pushed successfully!"));
|
|
106
138
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
}
|
|
139
|
+
catch(error) {
|
|
140
|
+
console.log(chalk.red.bold("\nPush Failed"));
|
|
141
|
+
console.error(chalk.red(error.stack || error.message || error));
|
|
132
142
|
}
|
|
133
143
|
}
|
|
134
144
|
|
|
135
|
-
module.exports = pushCmd
|
|
145
|
+
module.exports = pushCmd
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const yargs = require("yargs");
|
|
4
4
|
const { hideBin } = require("yargs/helpers");
|
|
@@ -11,7 +11,9 @@ const initCmd = require("./controllers/init")
|
|
|
11
11
|
const addCmd = require("./controllers/add")
|
|
12
12
|
const commitCmd = require("./controllers/commit")
|
|
13
13
|
const unstageCmd = require("./controllers/unstage")
|
|
14
|
-
const logCmd = require("./controllers/log")
|
|
14
|
+
const logCmd = require("./controllers/log");
|
|
15
|
+
const pushCmd = require("./controllers/push");
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
yargs(hideBin(process.argv))
|
|
17
19
|
.scriptName("jvcs")
|
|
@@ -126,6 +128,19 @@ yargs(hideBin(process.argv))
|
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
)
|
|
131
|
+
.command(
|
|
132
|
+
"push",
|
|
133
|
+
"Push all the commits to remote",
|
|
134
|
+
{},
|
|
135
|
+
async ()=> {
|
|
136
|
+
try {
|
|
137
|
+
await pushCmd()
|
|
138
|
+
}
|
|
139
|
+
catch(error) {
|
|
140
|
+
console.log(chalk.red(error))
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
)
|
|
129
144
|
.demandCommand(1, chalk.yellow("You need at least one command"))
|
|
130
145
|
.help()
|
|
131
146
|
.parse();
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility")
|
|
2
|
-
const path = require("path")
|
|
3
|
-
const fssync = require("fs")
|
|
4
|
-
const chalk = require("chalk")
|
|
5
|
-
const fs = require("fs").promises
|
|
6
|
-
const crypto = require("crypto")
|
|
7
|
-
|
|
8
|
-
async function getFileHash(filepath) {
|
|
9
|
-
const buffer = await fs.readFile(filepath)
|
|
10
|
-
return crypto.createHash("sha256").update(buffer).digest("hex")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async function hashDirectoryRecursive(dir,hashData) {
|
|
14
|
-
|
|
15
|
-
const entries = await fs.readdir(dir, {withFileTypes: true})
|
|
16
|
-
console.log(entries)
|
|
17
|
-
|
|
18
|
-
for(const entry of entries) {
|
|
19
|
-
|
|
20
|
-
const fullPath = path.join(dir,entry.name)
|
|
21
|
-
const relativePath = path.relative(process.cwd(),fullPath)
|
|
22
|
-
|
|
23
|
-
if(entry.isFile()) {
|
|
24
|
-
const hash = await getFileHash(fullPath)
|
|
25
|
-
hashData[relativePath] = {
|
|
26
|
-
hash,
|
|
27
|
-
time: new Date().toISOString(),
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else if(entry.isDirectory()) {
|
|
31
|
-
await hashDirectoryRecursive(fullPath,hashData)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function addCmd(paths) {
|
|
37
|
-
|
|
38
|
-
if(!paths || paths.length === 0) {
|
|
39
|
-
console.log(chalk.yellow("Please specify files or folders to add."));
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if(!checkGlobalConfig()) {
|
|
44
|
-
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
45
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let configData = getGlobalConfig()
|
|
50
|
-
|
|
51
|
-
if(!configData) {
|
|
52
|
-
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
53
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if(!checkforjvcs()) {
|
|
58
|
-
console.log(chalk.red("Repository is not initialized or is deleted. Please create it."))
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const repoPath = path.join(process.cwd(),".jvcs")
|
|
63
|
-
const staging = path.join(repoPath,"staging")
|
|
64
|
-
|
|
65
|
-
if(!fssync.existsSync(staging))
|
|
66
|
-
fssync.mkdirSync(staging, {recursive: true})
|
|
67
|
-
|
|
68
|
-
const hashPath = path.join(staging,"jvcs_hashcode.json")
|
|
69
|
-
let hashData = {}
|
|
70
|
-
|
|
71
|
-
if(fssync.existsSync(hashPath)) {
|
|
72
|
-
hashData = JSON.parse(await fs.readFile(hashPath,"utf-8"))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let targets = []
|
|
76
|
-
if(paths.length === 1 && paths[0] === ".") {
|
|
77
|
-
targets = await fs.readdir(process.cwd(),{withFileTypes: true})
|
|
78
|
-
targets = targets.filter((target)=> target.name !== ".jvcs").map((item)=> path.resolve(process.cwd(),item.name))
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
targets = paths.map((p)=> path.resolve(process.cwd(),p))
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// copying the files and folders to staging area
|
|
85
|
-
for(const target of targets) {
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
|
|
89
|
-
if(!fssync.existsSync(target)) {
|
|
90
|
-
console.log(chalk.red(`Path not found: ${target}`))
|
|
91
|
-
continue
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const destination = path.join(staging,path.relative(process.cwd(),target))
|
|
95
|
-
await fs.mkdir(path.dirname(destination), {recursive: true})
|
|
96
|
-
|
|
97
|
-
const stats = await fs.stat(target)
|
|
98
|
-
|
|
99
|
-
if(stats.isFile()) {
|
|
100
|
-
await fs.copyFile(target,destination)
|
|
101
|
-
const hash = await getFileHash(target)
|
|
102
|
-
hashData[path.relative(process.cwd(),target)] = {
|
|
103
|
-
hash,
|
|
104
|
-
time: new Date().toISOString(),
|
|
105
|
-
}
|
|
106
|
-
console.log(chalk.green(`Added file: ${path.relative(process.cwd(), target)}`));
|
|
107
|
-
}
|
|
108
|
-
else if(stats.isDirectory()) {
|
|
109
|
-
await fs.cp(target,destination,{recursive: true})
|
|
110
|
-
await hashDirectoryRecursive(target,hashData)
|
|
111
|
-
console.log(chalk.cyan(`Added folder: ${path.relative(process.cwd(), target)}`));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
catch(error) {
|
|
115
|
-
console.log(chalk.red(`Unexpected error: ${error.message}`));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
await fs.writeFile(hashPath, JSON.stringify(hashData, null, 2));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
module.exports = addCmd
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
const inquirer = require("inquirer");
|
|
2
|
-
const chalk = require("chalk");
|
|
3
|
-
const validator = require("validator");
|
|
4
|
-
const signup = require("./signup")
|
|
5
|
-
const login = require("./login")
|
|
6
|
-
const path = require("path")
|
|
7
|
-
const fs = require("fs")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async function beginCmd() {
|
|
12
|
-
|
|
13
|
-
const config = path.join(require("os").homedir(),".jvcs","config.json")
|
|
14
|
-
let isInitialized = false
|
|
15
|
-
let configData = null
|
|
16
|
-
if(fs.existsSync(config)) {
|
|
17
|
-
isInitialized = true
|
|
18
|
-
configData = JSON.parse(fs.readFileSync(config,"utf-8"))
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (isInitialized) {
|
|
22
|
-
console.log(chalk.green(`You are already logged in as ${configData.username} (${configData.email})`))
|
|
23
|
-
console.log(chalk.yellow(`[1] Continue \n[2] Logout \nChoose an option (1/2) : `))
|
|
24
|
-
|
|
25
|
-
const answer = await inquirer.prompt([
|
|
26
|
-
{
|
|
27
|
-
type: 'input',
|
|
28
|
-
name: 'choice',
|
|
29
|
-
validate: function (input) {
|
|
30
|
-
if (input === "1" || input === "2")
|
|
31
|
-
return true
|
|
32
|
-
|
|
33
|
-
return "Please enter 1 or 2"
|
|
34
|
-
},
|
|
35
|
-
filter: function (input) {
|
|
36
|
-
return input.trim()
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
])
|
|
40
|
-
|
|
41
|
-
console.log(`Your choice was ${answer.choice}`)
|
|
42
|
-
if (answer.choice === "1") {
|
|
43
|
-
console.log(chalk.green("Continuing as current user..."))
|
|
44
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
console.log(chalk.green("logging out..."))
|
|
48
|
-
fs.unlinkSync(config)
|
|
49
|
-
console.log(chalk.green("Logged out Successfully"))
|
|
50
|
-
console.log(chalk.green("Please login or signup again (jvcs begin) to use version control system"))
|
|
51
|
-
console.log(chalk.green("jvcs --help for help"))
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
58
|
-
console.log(chalk.yellow(`[1] Signup \n[2] login \nChoose an option (1/2) : `))
|
|
59
|
-
|
|
60
|
-
const answer = await inquirer.prompt([
|
|
61
|
-
{
|
|
62
|
-
type: 'input',
|
|
63
|
-
name: 'choice',
|
|
64
|
-
validate: function (input) {
|
|
65
|
-
|
|
66
|
-
if (input === "1" || input === "2")
|
|
67
|
-
return true
|
|
68
|
-
|
|
69
|
-
return "Please enter 1 or 2"
|
|
70
|
-
},
|
|
71
|
-
filter: function (input) {
|
|
72
|
-
return input.trim(); // optional: remove whitespace
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
])
|
|
76
|
-
|
|
77
|
-
if (answer.choice === "1") {
|
|
78
|
-
|
|
79
|
-
const signupData = await inquirer.prompt([
|
|
80
|
-
{
|
|
81
|
-
type: 'input',
|
|
82
|
-
name: 'username',
|
|
83
|
-
filter: function (input) {
|
|
84
|
-
return input.trim()
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
type: 'input',
|
|
89
|
-
name: 'email',
|
|
90
|
-
validate: function (input) {
|
|
91
|
-
// validate email
|
|
92
|
-
if (validator.isEmail(input))
|
|
93
|
-
return true
|
|
94
|
-
|
|
95
|
-
return "Please enter an valid email"
|
|
96
|
-
},
|
|
97
|
-
filter: function (input) {
|
|
98
|
-
return input.trim()
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
type: 'password',
|
|
103
|
-
name: 'password',
|
|
104
|
-
validate: function (input) {
|
|
105
|
-
// validate password
|
|
106
|
-
if (validator.isStrongPassword(input, {
|
|
107
|
-
minLength: 8,
|
|
108
|
-
maxLength: 20,
|
|
109
|
-
minLowercase: 1,
|
|
110
|
-
minUppercase: 1,
|
|
111
|
-
minNumbers: 1,
|
|
112
|
-
minSymbols: 1,
|
|
113
|
-
}))
|
|
114
|
-
return true
|
|
115
|
-
|
|
116
|
-
return "Please enter a strong password"
|
|
117
|
-
},
|
|
118
|
-
filter: function (input) {
|
|
119
|
-
return input.trim()
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
type: 'password',
|
|
124
|
-
name: 'confirmPassword',
|
|
125
|
-
validate: function (input, answers) {
|
|
126
|
-
if (answers.password !== input)
|
|
127
|
-
return "password must be same as above"
|
|
128
|
-
|
|
129
|
-
return true
|
|
130
|
-
},
|
|
131
|
-
filter: function (input) {
|
|
132
|
-
return input.trim()
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
])
|
|
136
|
-
|
|
137
|
-
try {
|
|
138
|
-
await signup(signupData)
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
console.log(chalk.red(error))
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
|
|
146
|
-
const loginData = await inquirer.prompt([
|
|
147
|
-
{
|
|
148
|
-
type: 'input',
|
|
149
|
-
name: 'username',
|
|
150
|
-
filter: function (input) {
|
|
151
|
-
return input.trim()
|
|
152
|
-
},
|
|
153
|
-
validate: function (input) {
|
|
154
|
-
if (input === "")
|
|
155
|
-
return "email cannot be empty"
|
|
156
|
-
|
|
157
|
-
return true
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
type: 'input',
|
|
162
|
-
name: 'email',
|
|
163
|
-
filter: function (input) {
|
|
164
|
-
return input.trim()
|
|
165
|
-
},
|
|
166
|
-
validate: function (input) {
|
|
167
|
-
if (!validator.isEmail(input))
|
|
168
|
-
return "email is not valid"
|
|
169
|
-
|
|
170
|
-
if (input === "")
|
|
171
|
-
return "email cannot be empty"
|
|
172
|
-
|
|
173
|
-
return true
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
type: 'password',
|
|
178
|
-
name: 'password',
|
|
179
|
-
filter: function (input) {
|
|
180
|
-
return input.trim()
|
|
181
|
-
},
|
|
182
|
-
validate: function (input) {
|
|
183
|
-
|
|
184
|
-
if (input === "")
|
|
185
|
-
return "password cannot be empty"
|
|
186
|
-
|
|
187
|
-
return true
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
])
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
await login(loginData)
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
console.log(chalk.red(error))
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
module.exports = beginCmd
|