jvcs 1.6.7 → 1.6.9

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.
@@ -14,12 +14,14 @@ async function getFileHash(filepath) {
14
14
 
15
15
  // load .jvcsignore file
16
16
  async function loadIgnorePatterns() {
17
-
18
17
  const ignorePath = path.join(process.cwd(), ".jvcsignore")
19
18
  if(!fssync.existsSync(ignorePath)) return []
20
19
 
21
20
  const content = await fs.readFile(ignorePath, "utf-8")
22
- return content.split("\n").map(line => line.trim()).filter(line => line.length > 0 && !line.startsWith("#"))
21
+ return content
22
+ .split(/[\n,]+/)
23
+ .map(line => line.trim())
24
+ .filter(line => line.length > 0 && !line.startsWith("#"))
23
25
  }
24
26
 
25
27
  function isIgnored(relativePath, ignorePatterns = []) {
@@ -28,94 +30,94 @@ function isIgnored(relativePath, ignorePatterns = []) {
28
30
  )
29
31
  }
30
32
 
31
- async function hashDirectoryRecursive(dir,hashData,ignorePatterns) {
33
+ async function hashDirectoryRecursive(dir, hashData, ignorePatterns) {
32
34
 
33
- const entries = await fs.readdir(dir, {withFileTypes: true})
35
+ const entries = await fs.readdir(dir, { withFileTypes: true })
34
36
 
35
- for(const entry of entries) {
37
+ for (const entry of entries) {
36
38
 
37
- const fullPath = path.join(dir,entry.name)
38
- const relativePath = path.relative(process.cwd(),fullPath)
39
+ const fullPath = path.join(dir, entry.name)
40
+ const relativePath = path.relative(process.cwd(), fullPath)
39
41
 
40
- if(isIgnored(relativePath, ignorePatterns)) {
42
+ if (isIgnored(relativePath, ignorePatterns)) {
41
43
  console.log(chalk.gray(`skipped "${relativePath}" as it is present in .jvcsignore`))
42
44
  continue
43
45
  }
44
46
 
45
- if(entry.isFile()) {
47
+ if (entry.isFile()) {
46
48
  const hash = await getFileHash(fullPath)
47
49
  hashData[relativePath] = {
48
50
  hash,
49
51
  time: new Date().toISOString(),
50
52
  }
51
53
  }
52
- else if(entry.isDirectory()) {
53
- await hashDirectoryRecursive(fullPath,hashData,ignorePatterns)
54
+ else if (entry.isDirectory()) {
55
+ await hashDirectoryRecursive(fullPath, hashData, ignorePatterns)
54
56
  }
55
57
  }
56
58
  }
57
59
 
58
60
  async function addCmd(paths) {
59
-
60
- if(!paths || paths.length === 0) {
61
+
62
+ if (!paths || paths.length === 0) {
61
63
  console.log(chalk.yellow("Please specify files or folders to add."));
62
64
  return
63
- }
65
+ }
64
66
 
65
- if(!checkGlobalConfig()) {
67
+ if (!checkGlobalConfig()) {
66
68
  console.log(chalk.red("No existing session found. Please login or signup."))
67
69
  console.log(chalk.green("jvcs --help for help"))
68
70
  return
69
71
  }
70
-
72
+
71
73
  let configData = getGlobalConfig()
72
-
73
- if(!configData) {
74
+
75
+ if (!configData) {
74
76
  console.log(chalk.red("No existing session found. Please login or signup."))
75
77
  console.log(chalk.green("jvcs --help for help"))
76
78
  return
77
79
  }
78
80
 
79
- if(!checkforjvcs()) {
81
+ if (!checkforjvcs()) {
80
82
  console.log(chalk.red("Repository is not initialized or is deleted. Please create it."))
81
83
  return
82
84
  }
83
85
 
84
- const repoPath = path.join(process.cwd(),".jvcs")
85
- const staging = path.join(repoPath,"staging")
86
+ const repoPath = path.join(process.cwd(), ".jvcs")
87
+ const staging = path.join(repoPath, "staging")
86
88
 
87
- if(!fssync.existsSync(staging))
88
- fssync.mkdirSync(staging, {recursive: true})
89
+ if (!fssync.existsSync(staging))
90
+ fssync.mkdirSync(staging, { recursive: true })
89
91
 
90
- const hashPath = path.join(staging,"jvcs_hashcode.json")
92
+ const hashPath = path.join(staging, "jvcs_hashcode.json")
91
93
  let hashData = {}
92
94
 
93
- if(fssync.existsSync(hashPath)) {
94
- hashData = JSON.parse(await fs.readFile(hashPath,"utf-8"))
95
+ if (fssync.existsSync(hashPath)) {
96
+ hashData = JSON.parse(await fs.readFile(hashPath, "utf-8"))
95
97
  }
96
98
 
97
99
  // load ignore patterns
98
100
  const ignorePatterns = await loadIgnorePatterns()
99
101
 
100
102
  let targets = []
101
- if(paths.length === 1 && paths[0] === ".") {
102
- let rootEntries = await fs.readdir(process.cwd(),{withFileTypes: true})
103
- targets = rootEntries.filter((target)=> target.name !== ".jvcs" && target.name !== ".jvcsignore").map((item)=> path.resolve(process.cwd(), item.name))
103
+ if (paths.length === 1 && paths[0] === ".") {
104
+ let rootEntries = await fs.readdir(process.cwd(), { withFileTypes: true })
105
+ targets = rootEntries.filter((target) => target.name !== ".jvcs" && target.name !== ".jvcsignore").map((item) => path.resolve(process.cwd(), item.name))
104
106
  }
105
107
  else {
106
- targets = paths.map((p)=> path.resolve(process.cwd(),p))
108
+ targets = paths.map((p) => path.resolve(process.cwd(), p))
107
109
  }
108
110
 
109
111
  // copying the files and folders to staging area
110
- for(const target of targets) {
112
+ for (const target of targets) {
111
113
 
112
114
  try {
113
115
 
114
- if(!fssync.existsSync(target)) {
116
+ if (!fssync.existsSync(target)) {
115
117
  console.log(chalk.red(`Path not found: ${target}`))
116
118
  continue
117
119
  }
118
-
120
+
119
121
  const relative = path.relative(process.cwd(), target)
120
122
  if (relative === ".jvcs" || relative.startsWith(".jvcs" + path.sep)) {
121
123
  console.log(chalk.red(`Cannot add internal repository folder ".jvcs"`))
@@ -127,32 +129,32 @@ async function addCmd(paths) {
127
129
  continue
128
130
  }
129
131
 
130
- if(isIgnored(relative, ignorePatterns)) {
132
+ if (isIgnored(relative, ignorePatterns)) {
131
133
  console.log(chalk.gray(`skipped "${relative}" as it is present in .jvcsignore`))
132
134
  continue
133
135
  }
134
136
 
135
- const destination = path.join(staging,path.relative(process.cwd(),target))
136
- await fs.mkdir(path.dirname(destination), {recursive: true})
137
-
137
+ const destination = path.join(staging, path.relative(process.cwd(), target))
138
+ await fs.mkdir(path.dirname(destination), { recursive: true })
139
+
138
140
  const stats = await fs.stat(target)
139
-
140
- if(stats.isFile()) {
141
- await fs.copyFile(target,destination)
141
+
142
+ if (stats.isFile()) {
143
+ await fs.copyFile(target, destination)
142
144
  const hash = await getFileHash(target)
143
- hashData[path.relative(process.cwd(),target)] = {
145
+ hashData[path.relative(process.cwd(), target)] = {
144
146
  hash,
145
147
  time: new Date().toISOString(),
146
148
  }
147
149
  console.log(chalk.green(`Added file: ${path.relative(process.cwd(), target)}`));
148
150
  }
149
- else if(stats.isDirectory()) {
150
- await fs.cp(target,destination,{recursive: true})
151
- await hashDirectoryRecursive(target,hashData,ignorePatterns)
151
+ else if (stats.isDirectory()) {
152
+ await fs.cp(target, destination, { recursive: true })
153
+ await hashDirectoryRecursive(target, hashData, ignorePatterns)
152
154
  console.log(chalk.cyan(`Added folder: ${path.relative(process.cwd(), target)}`));
153
155
  }
154
156
  }
155
- catch(error) {
157
+ catch (error) {
156
158
  console.log(chalk.red(`Unexpected error: ${error.message}`));
157
159
  }
158
160
  }
@@ -135,11 +135,6 @@ async function cloneCmd(username,reponame) {
135
135
  console.log(chalk.green(`Found repository, downloading...`));
136
136
 
137
137
  const destPath = path.join(process.cwd(), reponame);
138
- if(fs.existsSync(destPath)) {
139
- console.log(chalk.red(`Destination '${reponame}' already exists. Remove or rename it and retry.`));
140
- return;
141
- }
142
-
143
138
  await downloadFolderFromDrive(commitFolder, destPath);
144
139
 
145
140
  console.log(chalk.green(`Repository cloned successfully into ./${reponame}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jvcs",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "bin": {
5
5
  "jvcs": "index.js"
6
6
  },