jvcs 1.7.2 → 1.7.4
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/controllers/status.js +33 -33
- package/package.json +2 -2
package/controllers/status.js
CHANGED
|
@@ -23,32 +23,32 @@ function hashfile(filepath) {
|
|
|
23
23
|
const data = fs.readFileSync(filepath)
|
|
24
24
|
return crypto.createHash("sha256").update(data).digest("hex")
|
|
25
25
|
}
|
|
26
|
-
catch(error) {
|
|
26
|
+
catch (error) {
|
|
27
27
|
// return null
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
function getAllFiles(dir, rootDir=dir, collected=[]) {
|
|
32
|
+
function getAllFiles(dir, rootDir = dir, collected = []) {
|
|
33
33
|
|
|
34
34
|
if (!fs.existsSync(dir)) return collected;
|
|
35
35
|
|
|
36
|
-
const entries = fs.readdirSync(dir,{withFileTypes:true})
|
|
36
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
37
37
|
|
|
38
|
-
for(const entry of entries) {
|
|
39
|
-
const fullPath = path.join(dir,entry.name)
|
|
40
|
-
const rel = normalizeRel(path.relative(rootDir,fullPath))
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
const fullPath = path.join(dir, entry.name)
|
|
40
|
+
const rel = normalizeRel(path.relative(rootDir, fullPath))
|
|
41
41
|
|
|
42
|
-
if(entry.isDirectory() && (entry.name === ".jvcs" || entry.name === "node_modules"))
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if(entry.isFile() && (entry.name === "meta.json" || entry.name === "jvcs_hashcode.json"))
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if(entry.isFile()) {
|
|
42
|
+
if (entry.isDirectory() && (entry.name === ".jvcs" || entry.name === "node_modules"))
|
|
43
|
+
continue;
|
|
44
|
+
|
|
45
|
+
if (entry.isFile() && (entry.name === "meta.json" || entry.name === "jvcs_hashcode.json"))
|
|
46
|
+
continue;
|
|
47
|
+
|
|
48
|
+
if (entry.isFile()) {
|
|
49
49
|
collected.push(rel);
|
|
50
50
|
}
|
|
51
|
-
else if(entry.isDirectory()) {
|
|
51
|
+
else if (entry.isDirectory()) {
|
|
52
52
|
getAllFiles(fullPath, rootDir, collected);
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -59,30 +59,30 @@ function getAllFiles(dir, rootDir=dir, collected=[]) {
|
|
|
59
59
|
|
|
60
60
|
async function statusCmd() {
|
|
61
61
|
|
|
62
|
-
if(!checkGlobalConfig()) {
|
|
62
|
+
if (!checkGlobalConfig()) {
|
|
63
63
|
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
64
64
|
console.log(chalk.green("jvcs --help for help"));
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
const configData = getGlobalConfig();
|
|
69
|
-
if(!configData) {
|
|
69
|
+
if (!configData) {
|
|
70
70
|
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
if(!checkforjvcs()) {
|
|
74
|
+
if (!checkforjvcs()) {
|
|
75
75
|
console.log(chalk.red("Repository is not initialized or is deleted."));
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const cwd = process.cwd()
|
|
80
|
-
const jvcsDir = path.join(cwd,".jvcs")
|
|
81
|
-
const commitDir = path.join(jvcsDir,"commits")
|
|
82
|
-
const stagingDir = path.join(jvcsDir,"staging")
|
|
80
|
+
const jvcsDir = path.join(cwd, ".jvcs")
|
|
81
|
+
const commitDir = path.join(jvcsDir, "commits")
|
|
82
|
+
const stagingDir = path.join(jvcsDir, "staging")
|
|
83
83
|
const headFile = path.join(jvcsDir, "HEAD");
|
|
84
84
|
|
|
85
|
-
if(!fs.existsSync(jvcsDir)) {
|
|
85
|
+
if (!fs.existsSync(jvcsDir)) {
|
|
86
86
|
console.log(chalk.red("No repository exists. Please create one using 'jvcs init'"))
|
|
87
87
|
return
|
|
88
88
|
}
|
|
@@ -91,9 +91,9 @@ async function statusCmd() {
|
|
|
91
91
|
const cwdFiles = getAllFiles(cwd, cwd, []);
|
|
92
92
|
const stagedFiles = fs.existsSync(stagingDir) ? getAllFiles(stagingDir, stagingDir, []).map(f => normalizeRel(f)) : [];
|
|
93
93
|
let commitedFiles = []
|
|
94
|
-
if(fs.existsSync(commitDir)) {
|
|
94
|
+
if (fs.existsSync(commitDir)) {
|
|
95
95
|
const commits = fs.readdirSync(commitDir)
|
|
96
|
-
if(commits.length > 0) {
|
|
96
|
+
if (commits.length > 0) {
|
|
97
97
|
const lastCommit = `${fs.readFileSync(headFile, "utf-8").trim()}`;
|
|
98
98
|
const commitPath = path.join(commitDir, lastCommit);
|
|
99
99
|
commitedFiles = getAllFiles(commitPath, commitPath, []).map(f => normalizeRel(f))
|
|
@@ -111,12 +111,12 @@ async function statusCmd() {
|
|
|
111
111
|
const toBeCommitted = stagedFiles.filter(f => !committedSet.has(f));
|
|
112
112
|
|
|
113
113
|
// Changes not staged for commit: present in staging and in cwd, but changed in cwd compared to staged copy
|
|
114
|
-
const modified = stagedFiles.filter((file)=> {
|
|
115
|
-
const cwdFilePath = path.join(process.cwd(),file)
|
|
116
|
-
const stagedFilePath = path.join(stagingDir,file)
|
|
117
|
-
|
|
118
|
-
if(!fs.existsSync(cwdFilePath) || !fs.existsSync(stagedFilePath))
|
|
119
|
-
|
|
114
|
+
const modified = stagedFiles.filter((file) => {
|
|
115
|
+
const cwdFilePath = path.join(process.cwd(), file)
|
|
116
|
+
const stagedFilePath = path.join(stagingDir, file)
|
|
117
|
+
|
|
118
|
+
if (!fs.existsSync(cwdFilePath) || !fs.existsSync(stagedFilePath))
|
|
119
|
+
return false
|
|
120
120
|
|
|
121
121
|
const cwdHash = hashfile(cwdFilePath)
|
|
122
122
|
const stagingHash = hashfile(stagedFilePath)
|
|
@@ -129,7 +129,7 @@ async function statusCmd() {
|
|
|
129
129
|
console.log(chalk.bold.blue(`\nOn branch: main (default)`));
|
|
130
130
|
|
|
131
131
|
console.log(chalk.bold.green("\nChanges to be committed (files that are staged but not commited):"));
|
|
132
|
-
if(toBeCommitted.length > 0) {
|
|
132
|
+
if (toBeCommitted.length > 0) {
|
|
133
133
|
toBeCommitted.forEach(f => console.log(chalk.green(`\t${f}`)));
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
@@ -137,15 +137,15 @@ async function statusCmd() {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
console.log(chalk.bold.yellow("\nChanges not staged for commit (files that are modified after adding to staging area):"));
|
|
140
|
-
if(modified.length > 0) {
|
|
140
|
+
if (modified.length > 0) {
|
|
141
141
|
modified.forEach(f => console.log(chalk.yellow(`\t${f}`)));
|
|
142
|
-
}
|
|
142
|
+
}
|
|
143
143
|
else {
|
|
144
144
|
console.log(chalk.gray("\tNo modified files detected"));
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
console.log(chalk.bold.red("\nUntracked files (files that are not staged or commited):"));
|
|
148
|
-
if(untracked.length > 0) {
|
|
148
|
+
if (untracked.length > 0) {
|
|
149
149
|
untracked.forEach(f => console.log(chalk.red(`\t${f}`)));
|
|
150
150
|
}
|
|
151
151
|
else {
|