jvcs 1.4.0 → 1.4.2

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 +36 -4
  2. package/package.json +3 -2
@@ -4,13 +4,31 @@ 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
+ const content = await fs.readFile(ignorePath, "utf-8")
22
+ return content.split("\n").map(line => line && !line.startsWith("#"))
23
+ }
24
+
25
+ function isIgnored(relativePath, ignorePatterns) {
26
+ return ignorePatterns.some(pattern =>
27
+ minimatch(relativePath, pattern, { dot: true })
28
+ )
29
+ }
30
+
31
+ async function hashDirectoryRecursive(dir,hashData,ignorePatterns) {
14
32
 
15
33
  const entries = await fs.readdir(dir, {withFileTypes: true})
16
34
 
@@ -19,6 +37,11 @@ async function hashDirectoryRecursive(dir,hashData) {
19
37
  const fullPath = path.join(dir,entry.name)
20
38
  const relativePath = path.relative(process.cwd(),fullPath)
21
39
 
40
+ if(isIgnored(relativePath, ignorePatterns)) {
41
+ console.log(chalk.gray(`skipped "${relativePath}" as it is present in .jvcsignore`))
42
+ continue
43
+ }
44
+
22
45
  if(entry.isFile()) {
23
46
  const hash = await getFileHash(fullPath)
24
47
  hashData[relativePath] = {
@@ -27,7 +50,7 @@ async function hashDirectoryRecursive(dir,hashData) {
27
50
  }
28
51
  }
29
52
  else if(entry.isDirectory()) {
30
- await hashDirectoryRecursive(fullPath,hashData)
53
+ await hashDirectoryRecursive(fullPath,hashData,ignorePatterns)
31
54
  }
32
55
  }
33
56
  }
@@ -71,10 +94,13 @@ async function addCmd(paths) {
71
94
  hashData = JSON.parse(await fs.readFile(hashPath,"utf-8"))
72
95
  }
73
96
 
97
+ // load ignore patterns
98
+ const ignorePatterns = await loadIgnorePatterns()
99
+
74
100
  let targets = []
75
101
  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))
102
+ let rootEntries = await fs.readdir(process.cwd(),{withFileTypes: true})
103
+ targets = rootEntries.filter((target)=> target.name !== ".jvcs").map((item)=> path.resolve(process.cwd(), item.name))
78
104
  }
79
105
  else {
80
106
  targets = paths.map((p)=> path.resolve(process.cwd(),p))
@@ -90,6 +116,12 @@ async function addCmd(paths) {
90
116
  continue
91
117
  }
92
118
 
119
+ const relative = path.relative(process.cwd(), target)
120
+ if(isIgnored(relative, ignorePatterns)) {
121
+ console.log(chalk.gray(`skipped "${relative}" as it is present in .jvcsignore`))
122
+ continue
123
+ }
124
+
93
125
  const destination = path.join(staging,path.relative(process.cwd(),target))
94
126
  await fs.mkdir(path.dirname(destination), {recursive: true})
95
127
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "jvcs",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
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"