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 +9 -8
- package/commands/pull.js +19 -5
- package/core/config.js +46 -5
- package/core/workerPool.js +5 -2
- package/package.json +1 -1
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
|
|
8
|
+
const absolutePath = path.resolve(repoPath);
|
|
9
|
+
const gitDir = path.join(absolutePath, ".git");
|
|
9
10
|
|
|
10
|
-
if (!fs.existsSync(
|
|
11
|
-
console.log("Path does not exist:",
|
|
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:",
|
|
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(
|
|
23
|
-
console.log("⚠ Repo already added:",
|
|
23
|
+
if (config.repos.includes(absolutePath)) {
|
|
24
|
+
console.log("⚠ Repo already added:", absolutePath);
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
config.repos.push(
|
|
28
|
+
config.repos.push(absolutePath);
|
|
28
29
|
|
|
29
30
|
saveConfig(config);
|
|
30
31
|
|
|
31
|
-
console.log("✅ Added repo:",
|
|
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(`❌ ${
|
|
14
|
+
console.log(`❌ ${name}`);
|
|
11
15
|
console.log(stderr || err.message);
|
|
12
16
|
return reject(err);
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
console.log(`✔ ${
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
package/core/workerPool.js
CHANGED