jvcs 1.2.0 → 1.2.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 (38) hide show
  1. package/controllers/clone.js +2 -2
  2. package/package.json +1 -1
  3. package/readme.md +42 -0
  4. package/.jvcs/HEAD +0 -1
  5. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/add.js +0 -122
  6. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/begin.js +0 -201
  7. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/clone.js +0 -138
  8. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/commit.js +0 -83
  9. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/driveUtility.js +0 -56
  10. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/init.js +0 -60
  11. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/log.js +0 -99
  12. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/login.js +0 -33
  13. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/push.js +0 -165
  14. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/revert.js +0 -208
  15. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/signup.js +0 -28
  16. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/status.js +0 -160
  17. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/unstage.js +0 -104
  18. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/utility.js +0 -29
  19. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/controllers/verifyOtp.js +0 -55
  20. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/jvcs_hashcode.json +0 -62
  21. package/.jvcs/commits/cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3/meta.json +0 -7
  22. package/.jvcs/config.json +0 -9
  23. package/.jvcs/staging/controllers/add.js +0 -122
  24. package/.jvcs/staging/controllers/begin.js +0 -201
  25. package/.jvcs/staging/controllers/clone.js +0 -138
  26. package/.jvcs/staging/controllers/commit.js +0 -83
  27. package/.jvcs/staging/controllers/driveUtility.js +0 -56
  28. package/.jvcs/staging/controllers/init.js +0 -60
  29. package/.jvcs/staging/controllers/log.js +0 -99
  30. package/.jvcs/staging/controllers/login.js +0 -33
  31. package/.jvcs/staging/controllers/push.js +0 -165
  32. package/.jvcs/staging/controllers/revert.js +0 -208
  33. package/.jvcs/staging/controllers/signup.js +0 -28
  34. package/.jvcs/staging/controllers/status.js +0 -160
  35. package/.jvcs/staging/controllers/unstage.js +0 -104
  36. package/.jvcs/staging/controllers/utility.js +0 -29
  37. package/.jvcs/staging/controllers/verifyOtp.js +0 -55
  38. package/.jvcs/staging/jvcs_hashcode.json +0 -62
@@ -1,160 +0,0 @@
1
- // Untracked files
2
- // Files that exist in your working directory (project folder) but have never been added to staging or committed.
3
-
4
- // Changes to be committed
5
- // Files that are in the staging area (.jvcs/staging) — meaning, you’ve already added them using jvcs add, but haven’t committed yet.
6
-
7
- // Changes not staged for commit
8
- // Files that were already added to staging earlier, but you modified them again in your working directory after staging — i.e., the staged copy and working copy are different.
9
-
10
- const fs = require("fs");
11
- const path = require("path");
12
- const crypto = require("crypto");
13
- const chalk = require("chalk");
14
- const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility");
15
-
16
- // normalize relative path to use forward slashes for consistent comparisons
17
- function normalizeRel(p) {
18
- return p.split(path.sep).join("/")
19
- }
20
-
21
- function hashfile(filepath) {
22
- try {
23
- const data = fs.readFileSync(filepath)
24
- return crypto.createHash("sha256").update(data).digest("hex")
25
- }
26
- catch(error) {
27
- // return null
28
- }
29
- }
30
-
31
-
32
- function getAllFiles(dir, rootDir=dir, collected=[]) {
33
-
34
- if (!fs.existsSync(dir)) return collected;
35
-
36
- const entries = fs.readdirSync(dir,{withFileTypes:true})
37
-
38
- for(const entry of entries) {
39
- const fullPath = path.join(dir,entry.name)
40
- const rel = normalizeRel(path.relative(rootDir,fullPath))
41
-
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
- collected.push(rel);
50
- }
51
- else if(entry.isDirectory()) {
52
- getAllFiles(fullPath, rootDir, collected);
53
- }
54
-
55
- }
56
-
57
- return collected
58
- }
59
-
60
- async function statusCmd() {
61
-
62
- if(!checkGlobalConfig()) {
63
- console.log(chalk.red("No existing session found. Please login or signup."));
64
- console.log(chalk.green("jvcs --help for help"));
65
- return;
66
- }
67
-
68
- const configData = getGlobalConfig();
69
- if(!configData) {
70
- console.log(chalk.red("No existing session found. Please login or signup."));
71
- return;
72
- }
73
-
74
- if(!checkforjvcs()) {
75
- console.log(chalk.red("Repository is not initialized or is deleted."));
76
- return;
77
- }
78
-
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")
83
- const headFile = path.join(jvcsDir, "HEAD");
84
-
85
- if(!fs.existsSync(jvcsDir)) {
86
- console.log(chalk.red("No repository exists. Please create one using 'jvcs init'"))
87
- return
88
- }
89
-
90
- // collect files (all relative to cwd, normalized)
91
- const cwdFiles = getAllFiles(cwd, cwd, []);
92
- const stagedFiles = fs.existsSync(stagingDir) ? getAllFiles(stagingDir, stagingDir, []).map(f => normalizeRel(f)) : [];
93
- let commitedFiles = []
94
- if(fs.existsSync(commitDir)) {
95
- const commits = fs.readdirSync(commitDir)
96
- if(commits.length > 0) {
97
- const lastCommit = `${fs.readFileSync(headFile, "utf-8").trim()}`;
98
- const commitPath = path.join(commitDir, lastCommit);
99
- commitedFiles = getAllFiles(commitPath, commitPath, []).map(f => normalizeRel(f))
100
- }
101
- }
102
-
103
- // use Sets for fast looku
104
- const committedSet = new Set(commitedFiles);
105
- const stagedSet = new Set(stagedFiles);
106
-
107
- // Untracked: present in cwd but not in staging or commits
108
- const untracked = cwdFiles.filter(f => !stagedSet.has(f) && !committedSet.has(f));
109
-
110
- // Changes to be committed: present in staging but not in (any) commits
111
- const toBeCommitted = stagedFiles.filter(f => !committedSet.has(f));
112
-
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
- return false
120
-
121
- const cwdHash = hashfile(cwdFilePath)
122
- const stagingHash = hashfile(stagedFilePath)
123
-
124
- return cwdHash !== stagingHash
125
- })
126
-
127
-
128
- // output
129
- console.log(chalk.bold.blue(`\nOn branch: main (default)`));
130
-
131
- console.log(chalk.bold.green("\nChanges to be committed (files that are staged but not commited):"));
132
- if(toBeCommitted.length > 0) {
133
- toBeCommitted.forEach(f => console.log(chalk.green(`\t${f}`)));
134
- }
135
- else {
136
- console.log(chalk.gray("\tNo changes added to commit"));
137
- }
138
-
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) {
141
- modified.forEach(f => console.log(chalk.yellow(`\t${f}`)));
142
- }
143
- else {
144
- console.log(chalk.gray("\tNo modified files detected"));
145
- }
146
-
147
- console.log(chalk.bold.red("\nUntracked files (files that are not staged or commited):"));
148
- if(untracked.length > 0) {
149
- untracked.forEach(f => console.log(chalk.red(`\t${f}`)));
150
- }
151
- else {
152
- console.log(chalk.gray("\tNo untracked files"));
153
- }
154
-
155
- console.log(chalk.gray("\n(use 'jvcs add <file>' to stage changes)"));
156
- console.log(chalk.gray("(use 'jvcs commit -m \"message\"' to commit changes)"));
157
- console.log(chalk.gray("(use 'jvcs unstage <file>/<folder> to unstage a file/folder')"))
158
- }
159
-
160
- module.exports = statusCmd
@@ -1,104 +0,0 @@
1
- const fs = require("fs").promises;
2
- const fssync = require("fs");
3
- const path = require("path");
4
- const chalk = require("chalk");
5
- const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility");
6
-
7
- function removeHashesForFolder(hashData,folderPath) {
8
-
9
- for(const key of Object.keys(hashData)) {
10
- if(key.startsWith(folderPath+path.sep)) {
11
- delete hashData[key]
12
- }
13
- }
14
- }
15
-
16
- async function unstageCmd(paths) {
17
-
18
- if(!paths || paths.length === 0) {
19
- console.log(chalk.yellow("Please specify files or folders to unstage."));
20
- return;
21
- }
22
-
23
- if(!checkGlobalConfig()) {
24
- console.log(chalk.red("No existing session found. Please login or signup."));
25
- console.log(chalk.green("jvcs --help for help"));
26
- return;
27
- }
28
-
29
- const configData = getGlobalConfig();
30
- if(!configData) {
31
- console.log(chalk.red("No existing session found. Please login or signup."));
32
- return;
33
- }
34
-
35
- if(!checkforjvcs()) {
36
- console.log(chalk.red("Repository is not initialized or is deleted."));
37
- return;
38
- }
39
-
40
- const repoPath = path.join(process.cwd(), ".jvcs");
41
- const stagingPath = path.join(repoPath, "staging");
42
- const hashPath = path.join(stagingPath, "jvcs_hashcode.json");
43
-
44
- if(!fssync.existsSync(stagingPath)) {
45
- console.log(chalk.yellow("Nothing is staged yet."));
46
- return;
47
- }
48
-
49
- const stagedItems = fssync.readdirSync(stagingPath).filter((item)=> item !== "jvcs_hashcode.json")
50
- if(stagedItems.length === 0) {
51
- console.log(chalk.yellow("Staging area is empty. Nothing to unstage."));
52
- return;
53
- }
54
-
55
- let hashData = {};
56
- if(fssync.existsSync(hashPath)) {
57
- hashData = JSON.parse(await fs.readFile(hashPath, "utf-8"));
58
- }
59
-
60
- if(paths.length === 1 && paths[0] === ".") {
61
- await fs.rm(stagingPath, {recursive: true, force: true})
62
- await fs.mkdir(stagingPath, {recursive: true})
63
- console.log(chalk.cyan("Unstaged all files and folders."));
64
- return
65
- }
66
-
67
- const targets = paths.map((p) => path.resolve(process.cwd(), p));
68
-
69
- for(const target of targets) {
70
-
71
- const stagedTarget = path.join(stagingPath, path.relative(process.cwd(),target))
72
-
73
- if(!fssync.existsSync(stagedTarget)) {
74
- console.log(chalk.yellow(`Not found in staging: ${path.relative(process.cwd(), target)}`));
75
- continue;
76
- }
77
-
78
- const stats = await fs.stat(stagedTarget);
79
-
80
- if(stats.isDirectory()) {
81
- await fs.rm(stagedTarget, {recursive: true, force: true})
82
- removeHashesForFolder(hashData,path.relative(process.cwd(),target))
83
- console.log(chalk.cyan(`Unstaged folder: ${path.relative(process.cwd(), target)}`));
84
- }
85
- else if(stats.isFile()) {
86
- await fs.rm(stagedTarget)
87
- delete hashData[path.relative(process.cwd(),target)]
88
- console.log(chalk.green(`Unstaged file: ${path.relative(process.cwd(), target)}`));
89
- }
90
-
91
- }
92
-
93
- if(Object.keys(hashData).length === 0) {
94
- if(fssync.existsSync(hashPath)) {
95
- await fs.rm(hashPath)
96
- }
97
- }
98
- else {
99
- await fs.writeFile(hashPath,JSON.stringify(hashData,null,2))
100
- }
101
-
102
- }
103
-
104
- module.exports = unstageCmd
@@ -1,29 +0,0 @@
1
- const fs = require("fs")
2
- const path = require("path")
3
-
4
- const config = path.join(require("os").homedir(),".jvcs","config.json")
5
-
6
- function checkGlobalConfig() {
7
- return fs.existsSync(config)
8
- }
9
-
10
- function getGlobalConfig() {
11
- if(checkGlobalConfig()) {
12
- const configData = JSON.parse(fs.readFileSync(config,"utf-8"))
13
- if(configData.username && configData.email && configData.token)
14
- return configData
15
- }
16
-
17
- return null
18
- }
19
-
20
- function checkforjvcs() {
21
- const jvcsPath = path.join(process.cwd(),".jvcs")
22
- return fs.existsSync(jvcsPath)
23
- }
24
-
25
- module.exports = {
26
- checkGlobalConfig,
27
- getGlobalConfig,
28
- checkforjvcs
29
- }
@@ -1,55 +0,0 @@
1
- const inquirer = require("inquirer");
2
- const fs = require("fs")
3
- const path = require("path")
4
- const chalk = require("chalk")
5
-
6
- async function verifyOtp(signupData) {
7
-
8
- const otp = await inquirer.prompt([
9
- {
10
- type: 'password',
11
- name: 'otp',
12
- validate: function(input) {
13
- if(input.length !== 6)
14
- return "OTP must be of 6 length"
15
-
16
- return true
17
- },
18
- filter: function(input) {
19
- return input.trim()
20
- },
21
- mask: '*',
22
- }
23
- ])
24
-
25
- console.log(`otp is : ${otp.otp}`)
26
- const response = await fetch("http://localhost:3000/verifyEmail", {
27
- method: "POST",
28
- headers: { 'Content-Type': 'application/json' },
29
- credentials: "include",
30
- body: JSON.stringify({email:signupData.email,otp:otp.otp,cli:true})
31
- });
32
-
33
- const data = await response.json();
34
-
35
- if (data.status === true) {
36
- console.log(chalk.green(data.message))
37
-
38
- const dirPath = path.join(require("os").homedir(), ".jvcs");
39
- if (!fs.existsSync(dirPath)) {
40
- fs.mkdirSync(dirPath, { recursive: true });
41
- }
42
-
43
- const configPath = path.join(dirPath, "config.json");
44
- fs.writeFileSync(configPath,JSON.stringify({email: signupData.email,username: signupData.username,token: data.token, CLIENT_ID:"835069827989-3spob55ioa2ocudi3mo8u2ni2ecqohh7.apps.googleusercontent.com",CLIENT_SECRET:"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",REDIRECT_URI:"https://developers.google.com/oauthplayground",REFRESH_TOKEN:"1//04dWkzGCpoIgACgYIARAAGAQSNwF-L9IrRV-B67zRcIkhs7USx3vLewtE764bZPv7d5d7hAlH7QThZxj2CQUr5flQIG12Ad64dQI"},null,2));
45
- }
46
- else if(data.status === "user") {
47
- console.log(chalk.yellow(data.message))
48
- }
49
- else {
50
- throw new Error(data.message)
51
- }
52
-
53
- }
54
-
55
- module.exports = verifyOtp
@@ -1,62 +0,0 @@
1
- {
2
- "controllers\\add.js": {
3
- "hash": "1acab05c2c549de3100d5f5e8298268ce83a7f3722ea97a1fb9a151403756024",
4
- "time": "2025-10-29T12:53:25.244Z"
5
- },
6
- "controllers\\begin.js": {
7
- "hash": "228ccbb0e8965765aa039b27cd4a6ffaad388b9b09c52fafe8f807b7b568f378",
8
- "time": "2025-10-29T12:53:25.247Z"
9
- },
10
- "controllers\\clone.js": {
11
- "hash": "4c184aa2116c6cccf2d50986d550b3ebbfa41a09ba916be5d165ef955e6fe474",
12
- "time": "2025-10-29T12:53:25.248Z"
13
- },
14
- "controllers\\commit.js": {
15
- "hash": "a4549dba1503666557b945d4013e0e668412721e9d8b5065cc1053b779dce9bc",
16
- "time": "2025-10-29T12:53:25.249Z"
17
- },
18
- "controllers\\driveUtility.js": {
19
- "hash": "7f7b7b4d1aac215e707465a4ba43c0fb7b7567e9ce30269d7b980d4effb57e5b",
20
- "time": "2025-10-29T12:53:25.249Z"
21
- },
22
- "controllers\\init.js": {
23
- "hash": "32343d60e405454a913fddb507749648f9888a9da0d600e521c2c629216d3692",
24
- "time": "2025-10-29T12:53:25.250Z"
25
- },
26
- "controllers\\log.js": {
27
- "hash": "ae40cae361dafd35ccb776ae7ea0abb397f3af47bdb914ffa7ce69207ab1ed46",
28
- "time": "2025-10-29T12:53:25.250Z"
29
- },
30
- "controllers\\login.js": {
31
- "hash": "4b96046c76c0f610651ca71e3ebadf4fd9ca310a0be2e29c373b9c25a35e059c",
32
- "time": "2025-10-29T12:53:25.251Z"
33
- },
34
- "controllers\\push.js": {
35
- "hash": "3c89401eb4ebc695b14271dd5498428364715e50a9f62a2f100d112d0f701a65",
36
- "time": "2025-10-29T12:53:25.251Z"
37
- },
38
- "controllers\\revert.js": {
39
- "hash": "4737f8ca7f3c58c1a83588d0e6a1da97f47f5f323defb9ab11707cbe43aa883b",
40
- "time": "2025-10-29T12:53:25.252Z"
41
- },
42
- "controllers\\signup.js": {
43
- "hash": "67c1f5ad80f8a64e92fd8cd685a06a605831011fd4246256a60e09a6b5d161b8",
44
- "time": "2025-10-29T12:53:25.253Z"
45
- },
46
- "controllers\\status.js": {
47
- "hash": "ca7e71c71824098c805ae4c677801d901259a05ce108025d5847764de9175182",
48
- "time": "2025-10-29T12:53:25.254Z"
49
- },
50
- "controllers\\unstage.js": {
51
- "hash": "32038137ffcb0862d716b14fa966f7ccaa8470188f89353b8356e2e1be9dc00a",
52
- "time": "2025-10-29T12:53:25.254Z"
53
- },
54
- "controllers\\utility.js": {
55
- "hash": "06b49dcf44db91b90d82334c4187eaca13e580c826976343d4c8b3d1deaeb6c7",
56
- "time": "2025-10-29T12:53:25.256Z"
57
- },
58
- "controllers\\verifyOtp.js": {
59
- "hash": "a94ca1ba0018f1ed661ef963b166873319b9f862e51a29c666e62364e56d662f",
60
- "time": "2025-10-29T12:53:25.256Z"
61
- }
62
- }
@@ -1,7 +0,0 @@
1
- {
2
- "author": "jagdish",
3
- "id": "cd2a0ec7-04b8-4ac9-b539-617bb5fea1f3",
4
- "message": "controllers is the main folder",
5
- "timeStamp": "2025-10-29T12:53:44.083Z",
6
- "parentId": null
7
- }
package/.jvcs/config.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "repoName": "backend2",
3
- "createdAt": "2025-10-29T12:52:36.498Z",
4
- "remote": null,
5
- "owner": {
6
- "username": "jagdish",
7
- "email": "pathakjijagdish1@gmail.com"
8
- }
9
- }
@@ -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" && target.name !== "node_modules").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