@omer-x/buttler 0.1.0 → 0.1.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/README.md +3 -0
- package/bin/cli.js +72 -0
- package/bin/git.js +1 -1
- package/bin/index.js +0 -1
- package/package.json +5 -4
package/README.md
ADDED
package/bin/cli.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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() {
|
|
34
|
+
const pidFilePath = resolve(process.cwd(), "PID");
|
|
35
|
+
const exists = await checkFile(pidFilePath);
|
|
36
|
+
if (exists) {
|
|
37
|
+
return console.warn("the application is already running");
|
|
38
|
+
}
|
|
39
|
+
const pid = spawnChildProcess(true);
|
|
40
|
+
await fs.writeFile(pidFilePath, `${pid}`, "utf8");
|
|
41
|
+
console.log("the application has started");
|
|
42
|
+
}
|
|
43
|
+
async function stop() {
|
|
44
|
+
const pidFilePath = resolve(process.cwd(), "PID");
|
|
45
|
+
const exists = await checkFile(pidFilePath);
|
|
46
|
+
if (!exists) {
|
|
47
|
+
return console.warn("the application was not running");
|
|
48
|
+
}
|
|
49
|
+
const content = await fs.readFile(pidFilePath, "utf-8");
|
|
50
|
+
const pid = parseInt(content);
|
|
51
|
+
try {
|
|
52
|
+
if (isNaN(pid))
|
|
53
|
+
throw new Error("Invalid PID");
|
|
54
|
+
process.kill(pid);
|
|
55
|
+
console.log("the application is stopped");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
console.warn("the application was crashed");
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
await fs.unlink(pidFilePath);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function restart() {
|
|
65
|
+
await stop();
|
|
66
|
+
await start();
|
|
67
|
+
}
|
|
68
|
+
const program = new Command();
|
|
69
|
+
program.command("start").description("starts the application").action(start);
|
|
70
|
+
program.command("stop").description("stops the application").action(stop);
|
|
71
|
+
program.command("restart").description("restarts the application").action(restart);
|
|
72
|
+
program.parse(process.argv);
|
package/bin/git.js
CHANGED
package/bin/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omer-x/buttler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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/
|
|
34
|
+
"buttler": "./bin/cli.js"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"bin/"
|
|
38
38
|
],
|
|
39
39
|
"type": "module",
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": "^
|
|
41
|
+
"node": "^18.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
|
-
"
|
|
50
|
+
"commander": "^12.1.0",
|
|
51
51
|
"dockerode": "^4.0.2",
|
|
52
52
|
"dotenv": "^16.4.5",
|
|
53
53
|
"express": "^4.19.2",
|
|
54
|
+
"nodegit": "^0.28.0-alpha.28",
|
|
54
55
|
"tar-fs": "^3.0.6"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|