buildsight-collector 1.0.2 → 1.0.3
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/index.js +69 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5,6 +5,65 @@ import chalk from "chalk";
|
|
|
5
5
|
import ora from "ora";
|
|
6
6
|
import simpleGit from "simple-git";
|
|
7
7
|
import { spawn } from 'child_process';
|
|
8
|
+
import os from "os";
|
|
9
|
+
import { execSync } from "child_process";
|
|
10
|
+
|
|
11
|
+
function getCurrentCron() {
|
|
12
|
+
try {
|
|
13
|
+
return execSync("crontab -l").toString();
|
|
14
|
+
} catch {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function detectOS() {
|
|
20
|
+
const platform = os.platform();
|
|
21
|
+
|
|
22
|
+
if (platform === "linux") return "linux";
|
|
23
|
+
if (platform === "darwin") return "mac";
|
|
24
|
+
if (platform === "win32") return "windows";
|
|
25
|
+
|
|
26
|
+
return "unknown";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function setupAutomaticRun(token, intervalMinutes) {
|
|
30
|
+
const platform = detectOS();
|
|
31
|
+
const cronLine = `*/${intervalMinutes} * * * * npx buildsight-collector ${token}`;
|
|
32
|
+
|
|
33
|
+
console.log(chalk.cyan("\n⚙ Configuração de execução automática detectada."));
|
|
34
|
+
|
|
35
|
+
if (platform === "linux" || platform === "mac") {
|
|
36
|
+
console.log(chalk.gray("➡ Sistema detected: Linux/Mac"));
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const current = getCurrentCron();
|
|
40
|
+
if (current.includes(cronLine)) {
|
|
41
|
+
console.log(chalk.yellow("⚠ Cron já configurada anteriormente."));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
execSync(`(crontab -l 2>/dev/null; echo "${cronLine}") | crontab -`);
|
|
46
|
+
|
|
47
|
+
console.log(chalk.green("✓ Cron adicionada com sucesso!"));
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.log(chalk.red("❌ Falha ao configurar cron:", err.message));
|
|
50
|
+
}
|
|
51
|
+
} else if (platform === "windows") {
|
|
52
|
+
console.log(chalk.gray("➡ Sistema detected: Windows"));
|
|
53
|
+
|
|
54
|
+
const taskName = "BuildSightCollector";
|
|
55
|
+
const taskCmd = `schtasks /Create /SC MINUTE /MO ${intervalMinutes} /TN "${taskName}" /TR "npx buildsight-collector ${token}" /F`;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
execSync(taskCmd);
|
|
59
|
+
console.log(chalk.green("✓ Tarefa agendada criada com sucesso!"));
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.log(chalk.red("❌ Falha ao criar tarefa agendada:", err.message));
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
console.log(chalk.red("❌ Sistema operacional não suportado para execução automática."));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
8
67
|
|
|
9
68
|
const spinner = ora();
|
|
10
69
|
|
|
@@ -36,9 +95,17 @@ async function main() {
|
|
|
36
95
|
process.exit(0);
|
|
37
96
|
}
|
|
38
97
|
|
|
39
|
-
|
|
98
|
+
const paths = data?.data || [];
|
|
99
|
+
const autoRunEnabled = data?.autoRunEnabled ?? false;
|
|
100
|
+
const intervalMinutes = data?.intervalMinutes ?? 15;
|
|
101
|
+
|
|
102
|
+
if (autoRunEnabled) {
|
|
103
|
+
await setupAutomaticRun(token, intervalMinutes);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
spinner.succeed(`Foram encontrados ${paths.length} paths.`);
|
|
40
107
|
|
|
41
|
-
for (const repo of
|
|
108
|
+
for (const repo of paths) {
|
|
42
109
|
console.log(chalk.blue(`\n📂 Processando repositório:`), chalk.white(repo.name));
|
|
43
110
|
const git = simpleGit(repo.path);
|
|
44
111
|
const DAYS_RANGE = repo.periodDays || 1;
|