@omer-x/buttler 0.1.0 → 0.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/README.md ADDED
File without changes
package/bin/cli.js ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import fs from "node:fs/promises";
4
+ import { dirname, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { Command } from "commander";
7
+ async function checkFile(filePath) {
8
+ try {
9
+ await fs.access(filePath);
10
+ return true;
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ }
16
+ function spawnChildProcess(detached) {
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ const __dirname = dirname(__filename);
19
+ const appPath = resolve(__dirname, "index.js");
20
+ const child = spawn("node", [appPath], {
21
+ detached,
22
+ stdio: detached ? "ignore" : "inherit",
23
+ env: {
24
+ ...process.env,
25
+ PORT: "2083",
26
+ WEBHOOK_SECRET: "buttler",
27
+ },
28
+ });
29
+ if (detached)
30
+ child.unref();
31
+ return child.pid;
32
+ }
33
+ async function start(development) {
34
+ if (development) {
35
+ await stop();
36
+ }
37
+ const pidFilePath = resolve(process.cwd(), "PID");
38
+ const exists = await checkFile(pidFilePath);
39
+ if (exists) {
40
+ return console.warn("the application is already running");
41
+ }
42
+ const pid = spawnChildProcess(!development);
43
+ await fs.writeFile(pidFilePath, `${pid}`, "utf8");
44
+ console.log("the application has started");
45
+ }
46
+ async function stop() {
47
+ const pidFilePath = resolve(process.cwd(), "PID");
48
+ const exists = await checkFile(pidFilePath);
49
+ if (!exists) {
50
+ return console.warn("the application was not running");
51
+ }
52
+ const content = await fs.readFile(pidFilePath, "utf-8");
53
+ const pid = parseInt(content);
54
+ try {
55
+ if (isNaN(pid))
56
+ throw new Error("Invalid PID");
57
+ process.kill(pid);
58
+ console.log("the application is stopped");
59
+ }
60
+ catch {
61
+ console.warn("the application was crashed");
62
+ }
63
+ finally {
64
+ await fs.unlink(pidFilePath);
65
+ }
66
+ }
67
+ async function restart() {
68
+ await stop();
69
+ await start(false);
70
+ }
71
+ const program = new Command();
72
+ program.command("dev").description("starts the application").action(() => start(true));
73
+ program.command("start").description("starts the application").action(() => start(false));
74
+ program.command("stop").description("stops the application").action(stop);
75
+ program.command("restart").description("restarts the application").action(restart);
76
+ program.parse(process.argv);
package/bin/git.js CHANGED
@@ -1,13 +1,13 @@
1
- import nodegit from "@figma/nodegit";
2
- export function cloneRepo(repoUrl, targetPath) {
3
- return nodegit.Clone(repoUrl, targetPath, {
4
- fetchOpts: {
5
- callbacks: {
6
- certificateCheck: () => 0,
7
- credentials: (_url, userName) => {
8
- return nodegit.Credential.sshKeyFromAgent(userName);
9
- },
10
- },
11
- },
1
+ import simpleGit from "simple-git";
2
+ export async function cloneRepo(repoUrl, targetPath) {
3
+ const git = simpleGit({
4
+ baseDir: targetPath,
5
+ binary: "git",
6
+ maxConcurrentProcesses: 6,
7
+ });
8
+ await git.clone(repoUrl, targetPath, {
9
+ "--depth": "1",
10
+ "--single-branch": null,
11
+ "--branch": "main",
12
12
  });
13
13
  }
package/bin/index.js CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  import http from "node:http";
3
2
  import readline from "node:readline";
4
3
  import dotenv from "dotenv";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/buttler",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "automates CI/CD workflows using Docker and GitHub webhooks",
5
5
  "keywords": [
6
6
  "automation",
@@ -31,14 +31,14 @@
31
31
  "license": "MIT",
32
32
  "main": "bin/index.js",
33
33
  "bin": {
34
- "buttler": "./bin/index.js"
34
+ "buttler": "./bin/cli.js"
35
35
  },
36
36
  "files": [
37
37
  "bin/"
38
38
  ],
39
39
  "type": "module",
40
40
  "engines": {
41
- "node": "^20.0.0"
41
+ "node": ">=19.0.0"
42
42
  },
43
43
  "scripts": {
44
44
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -47,10 +47,11 @@
47
47
  "build": "tsc"
48
48
  },
49
49
  "dependencies": {
50
- "@figma/nodegit": "^0.28.0-figma.6",
50
+ "commander": "^12.1.0",
51
51
  "dockerode": "^4.0.2",
52
52
  "dotenv": "^16.4.5",
53
53
  "express": "^4.19.2",
54
+ "simple-git": "^3.25.0",
54
55
  "tar-fs": "^3.0.6"
55
56
  },
56
57
  "devDependencies": {
@@ -58,7 +59,6 @@
58
59
  "@types/dockerode": "^3.3.31",
59
60
  "@types/express": "^4.17.21",
60
61
  "@types/node": "^22.0.0",
61
- "@types/nodegit": "^0.28.7",
62
62
  "@types/tar-fs": "^2.0.4",
63
63
  "eslint": "^8.57.0",
64
64
  "ts-unused-exports": "^10.1.0",