gitfleet 1.1.2 → 1.1.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/commands/add.js CHANGED
@@ -5,28 +5,29 @@ const { loadConfig, saveConfig } = require("../core/config");
5
5
 
6
6
  module.exports = function (repoPath) {
7
7
 
8
- const gitDir = path.join(repoPath, ".git");
8
+ const absolutePath = path.resolve(repoPath);
9
+ const gitDir = path.join(absolutePath, ".git");
9
10
 
10
- if (!fs.existsSync(repoPath)) {
11
- console.log("Path does not exist:", repoPath);
11
+ if (!fs.existsSync(absolutePath)) {
12
+ console.log("Path does not exist:", absolutePath);
12
13
  return;
13
14
  }
14
15
 
15
16
  if (!fs.existsSync(gitDir)) {
16
- console.log("Not a git repository:", repoPath);
17
+ console.log("Not a git repository:", absolutePath);
17
18
  return;
18
19
  }
19
20
 
20
21
  const config = loadConfig();
21
22
 
22
- if (config.repos.includes(repoPath)) {
23
- console.log("⚠ Repo already added:", repoPath);
23
+ if (config.repos.includes(absolutePath)) {
24
+ console.log("⚠ Repo already added:", absolutePath);
24
25
  return;
25
26
  }
26
27
 
27
- config.repos.push(repoPath);
28
+ config.repos.push(absolutePath);
28
29
 
29
30
  saveConfig(config);
30
31
 
31
- console.log("✅ Added repo:", repoPath);
32
+ console.log("✅ Added repo:", absolutePath);
32
33
  };
package/commands/pull.js CHANGED
@@ -1,20 +1,24 @@
1
1
  const { runWorkerPool } = require("../core/workerPool");
2
+ const { loadConfig } = require("../core/config");
2
3
  const { exec } = require("child_process");
4
+ const path = require("path");
3
5
 
4
6
  function runGit(repo, command) {
5
7
  return new Promise((resolve, reject) => {
6
8
 
7
9
  exec(`git -C "${repo}" ${command}`, (err, stdout, stderr) => {
8
10
 
11
+ const name = path.basename(repo);
12
+
9
13
  if (err) {
10
- console.log(`❌ ${repo}`);
14
+ console.log(`❌ ${name}`);
11
15
  console.log(stderr || err.message);
12
16
  return reject(err);
13
17
  }
14
18
 
15
- console.log(`✔ ${repo}`);
19
+ console.log(`✔ ${name}`);
16
20
 
17
- if (stdout.trim()) {
21
+ if (stdout && stdout.trim()) {
18
22
  console.log(stdout.trim());
19
23
  }
20
24
 
@@ -25,11 +29,21 @@ function runGit(repo, command) {
25
29
  });
26
30
  }
27
31
 
28
- async function pullRepos(repos) {
32
+ async function pullRepos() {
33
+
34
+ const config = loadConfig();
35
+ const repos = config.repos || [];
36
+
37
+ if (repos.length === 0) {
38
+ console.log("No repositories configured.");
39
+ return;
40
+ }
41
+
42
+ console.log(`Pulling ${repos.length} repositories...\n`);
29
43
 
30
44
  const results = await runWorkerPool(
31
45
  repos,
32
- (repo) => runGit(repo, "pull"),
46
+ repo => runGit(repo, "pull"),
33
47
  4
34
48
  );
35
49
 
package/core/config.js CHANGED
@@ -1,22 +1,63 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
+ const os = require("os");
4
+
5
+ function findWorkspaceConfig() {
6
+
7
+ let dir = process.cwd();
8
+
9
+ while (dir !== path.parse(dir).root) {
10
+
11
+ const configPath = path.join(dir, ".gitfleet", "config.json");
12
+
13
+ if (fs.existsSync(configPath)) {
14
+ return configPath;
15
+ }
16
+
17
+ dir = path.dirname(dir);
18
+ }
19
+
20
+ return null;
21
+ }
22
+
23
+ function getGlobalConfig() {
24
+
25
+ const globalDir = path.join(os.homedir(), ".gitfleet");
26
+ const globalConfig = path.join(globalDir, "config.json");
27
+
28
+ if (!fs.existsSync(globalDir)) {
29
+ fs.mkdirSync(globalDir, { recursive: true });
30
+ }
31
+
32
+ if (!fs.existsSync(globalConfig)) {
33
+ fs.writeFileSync(globalConfig, JSON.stringify({ repos: [] }, null, 2));
34
+ }
35
+
36
+ return globalConfig;
37
+ }
3
38
 
4
39
  function getConfigPath() {
5
- return path.join(process.cwd(), ".gitfleet", "config.json");
40
+
41
+ const workspace = findWorkspaceConfig();
42
+
43
+ if (workspace) {
44
+ return workspace;
45
+ }
46
+
47
+ return getGlobalConfig();
6
48
  }
7
49
 
8
50
  function loadConfig() {
9
- const configPath = getConfigPath();
10
51
 
11
- if (!fs.existsSync(configPath)) {
12
- return { repos: [] };
13
- }
52
+ const configPath = getConfigPath();
14
53
 
15
54
  return JSON.parse(fs.readFileSync(configPath, "utf-8"));
16
55
  }
17
56
 
18
57
  function saveConfig(config) {
58
+
19
59
  const configPath = getConfigPath();
60
+
20
61
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
21
62
  }
22
63
 
@@ -22,5 +22,8 @@ async function runWorkerPool(items, task, concurrency = os.cpus().length) {
22
22
  })
23
23
  );
24
24
 
25
- return Promise.all(tasks);
26
- }
25
+ return Promise.allSettled(tasks);
26
+ }
27
+
28
+
29
+ module.exports = { runWorkerPool };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitfleet",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"