jvcs 1.4.0 → 1.4.1

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.
Files changed (2) hide show
  1. package/controllers/add.js +35 -4
  2. package/package.json +3 -2
@@ -4,13 +4,30 @@ const fssync = require("fs")
4
4
  const chalk = require("chalk")
5
5
  const fs = require("fs").promises
6
6
  const crypto = require("crypto")
7
+ const { minimatch } = require("minimatch")
8
+
7
9
 
8
10
  async function getFileHash(filepath) {
9
11
  const buffer = await fs.readFile(filepath)
10
12
  return crypto.createHash("sha256").update(buffer).digest("hex")
11
13
  }
12
14
 
13
- async function hashDirectoryRecursive(dir,hashData) {
15
+ // load .jvcsignore file
16
+ async function loadIgnorePatterns() {
17
+
18
+ const ignorePath = path.join(process.cwd(), ".jvcsignore")
19
+ if(!fssync.existsSync(ignorePath)) return []
20
+
21
+ return content.split("\n").map(line => line && !line.startsWith("#"))
22
+ }
23
+
24
+ function isIgnored(relativePath, ignorePatterns) {
25
+ return ignorePatterns.some(pattern =>
26
+ minimatch(relativePath, pattern, { dot: true })
27
+ )
28
+ }
29
+
30
+ async function hashDirectoryRecursive(dir,hashData,ignorePatterns) {
14
31
 
15
32
  const entries = await fs.readdir(dir, {withFileTypes: true})
16
33
 
@@ -19,6 +36,11 @@ async function hashDirectoryRecursive(dir,hashData) {
19
36
  const fullPath = path.join(dir,entry.name)
20
37
  const relativePath = path.relative(process.cwd(),fullPath)
21
38
 
39
+ if(isIgnored(relativePath, ignorePatterns)) {
40
+ console.log(chalk.gray(`skipped "${relativePath}" as it is present in .jvcsignore`))
41
+ continue
42
+ }
43
+
22
44
  if(entry.isFile()) {
23
45
  const hash = await getFileHash(fullPath)
24
46
  hashData[relativePath] = {
@@ -27,7 +49,7 @@ async function hashDirectoryRecursive(dir,hashData) {
27
49
  }
28
50
  }
29
51
  else if(entry.isDirectory()) {
30
- await hashDirectoryRecursive(fullPath,hashData)
52
+ await hashDirectoryRecursive(fullPath,hashData,ignorePatterns)
31
53
  }
32
54
  }
33
55
  }
@@ -71,10 +93,13 @@ async function addCmd(paths) {
71
93
  hashData = JSON.parse(await fs.readFile(hashPath,"utf-8"))
72
94
  }
73
95
 
96
+ // load ignore patterns
97
+ const ignorePatterns = await loadIgnorePatterns()
98
+
74
99
  let targets = []
75
100
  if(paths.length === 1 && paths[0] === ".") {
76
- targets = await fs.readdir(process.cwd(),{withFileTypes: true})
77
- targets = targets.filter((target)=> target.name !== ".jvcs" && target.name !== "node_modules").map((item)=> path.resolve(process.cwd(),item.name))
101
+ let rootEntries = await fs.readdir(process.cwd(),{withFileTypes: true})
102
+ targets = rootEntries.filter((target)=> target.name !== ".jvcs").map((item)=> path.resolve(process.cwd(), item.name))
78
103
  }
79
104
  else {
80
105
  targets = paths.map((p)=> path.resolve(process.cwd(),p))
@@ -90,6 +115,12 @@ async function addCmd(paths) {
90
115
  continue
91
116
  }
92
117
 
118
+ const relative = path.relative(process.cwd(), target)
119
+ if(isIgnored(relative, ignorePatterns)) {
120
+ console.log(chalk.gray(`skipped "${relative}" as it is present in .jvcsignore`))
121
+ continue
122
+ }
123
+
93
124
  const destination = path.join(staging,path.relative(process.cwd(),target))
94
125
  await fs.mkdir(path.dirname(destination), {recursive: true})
95
126
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "jvcs",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "bin": {
5
- "jvcs": "./index.js"
5
+ "jvcs": "index.js"
6
6
  },
7
7
  "keywords": [],
8
8
  "author": "",
@@ -12,6 +12,7 @@
12
12
  "dotenv": "^17.2.3",
13
13
  "googleapis": "^164.1.0",
14
14
  "inquirer": "^8.2.7",
15
+ "minimatch": "^10.2.4",
15
16
  "uuid": "^13.0.0",
16
17
  "validator": "^13.15.20",
17
18
  "yargs": "^18.0.0"