buildsight-collector 1.0.1 → 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.
Files changed (3) hide show
  1. package/README.md +1 -21
  2. package/index.js +69 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -26,25 +26,5 @@ Parâmetros
26
26
 
27
27
  - <token>: token de autenticação gerado pela API do BuildSight.
28
28
 
29
- Publicação no npm
30
-
31
- 1. Verifique o `name` em `package.json` e confirme que está disponível no npm (se já estiver em uso, escolha um nome distinto ou um scope como `@seu-usuario/buildsight-collector`).
32
- 2. Faça login no npm:
33
-
34
- ```bash
35
- npm login
36
- ```
37
-
38
- 3. Publicar (público):
39
-
40
- ```bash
41
- npm publish --access public
42
- ```
43
-
44
- Se usar um scoped package e quiser publicação pública, precisa `--access public`.
45
-
46
- Observações
47
-
48
- - Substitua `author` e `repository.url` em `package.json` pelos seus valores reais antes de publicar.
49
- - Este pacote já inclui o `bin` apontando para `index.js`, que tem shebang para execução como CLI.
29
+ Requisitos
50
30
  - Node.js mínimo sugerido: 14+.
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
- spinner.succeed(`Foram encontrados ${data.data.length} paths.`);
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 data.data) {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buildsight-collector",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "CLI do BuildSight para coleta automatizada de commits e métricas de repositórios.",
5
5
  "main": "index.js",
6
6
  "bin": {