-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·86 lines (78 loc) · 2.23 KB
/
index.js
File metadata and controls
executable file
·86 lines (78 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
import { createRequire } from "module";
import { execSync } from "child_process";
import { fileURLToPath } from "url";
import path from "path";
import fs from "fs";
const require = createRequire(import.meta.url);
const pkg = require("./package.json");
const args = process.argv.slice(2);
if (args.includes('--short') || args.includes('-s')) {
process.env.SCOM_STYLE = 'short';
}
if (args.includes('--adaptive') || args.includes('-a')) {
process.env.SCOM_STYLE = 'adaptive';
}
if (args.includes('--detailed') || args.includes('-d')) {
process.env.SCOM_STYLE = 'detailed';
}
if (args.includes("-v") || args.includes("--version")) {
console.log(pkg.version);
process.exit(0);
}
if (args[0] === "update") {
try {
console.log("Updating sweet-commit globally via npm...");
execSync("npm update -g sweet-commit", { stdio: "inherit" });
process.exit(0);
} catch (err) {
console.error("Update failed:", err.message);
process.exit(1);
}
}
if (args[0] === "setup") {
try {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const setupPath = path.join(__dirname, "src", "setup.js");
if (!fs.existsSync(setupPath)) {
console.error(`Setup script not found at: ${setupPath}`);
process.exit(1);
}
console.log("Running sweet-commit setup...");
execSync(`node "${setupPath}"`, { stdio: "inherit" });
process.exit(0);
} catch (err) {
console.error("Setup failed:", err.message);
process.exit(1);
}
}
if (
args[0] &&
![
"--short",
"-s",
"--adaptive",
"-a",
"--detailed",
"-d",
"-v",
"--version",
"update",
].includes(args[0]) &&
!args[0].startsWith("-")
) {
console.error(`Unknown command: ${args[0]}`);
console.log("\nUsage:");
console.log(" scom --short or -s # Short commit message");
console.log(" scom --adaptive or -a # Adaptive commit message");
console.log(" scom --detailed or -d # Detailed commit message");
console.log(" scom -v or --version");
console.log(" scom update");
process.exit(1);
}
import { main } from "./src/main.js";
main().catch((error) => {
console.error("Unexpected error:", error.message);
process.exit(1);
});