self-updater
Version:
Automatic GitHub/GitLab-based updater for PM2 or Docker services
51 lines (50 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const config_1 = require("./config");
const watcher_1 = require("./watcher");
const updater_1 = require("./updater");
const program = new commander_1.Command();
program
.command("init")
.description("Initialize configuration")
.requiredOption("-r, --repo <url>", "GitHub/GitLab Repository URL")
.option("-b, --branch <branch>", "Branch", "main")
.requiredOption("-p, --path <path>", "Local path of the project")
.requiredOption("-t, --type <pm2|docker>", "Service Typ")
.requiredOption("-n, --name <service>", "Service Name")
.option("-i, --interval <seconds>", "Check-Intervall", "60")
.action((options) => {
const config = {
repoUrl: options.repo,
branch: options.branch,
localPath: options.path,
serviceType: options.type,
serviceName: options.name,
checkInterval: parseInt(options.interval, 10),
};
(0, config_1.saveConfig)(config);
console.log("✅ Configuration saved!");
});
program
.command("start")
.description("Start the updater")
.action(async () => {
const config = (0, config_1.loadConfig)();
let lastCommit = await (0, watcher_1.getLatestCommit)(config.repoUrl, config.branch);
console.log(`🔍 Watching ${config.repoUrl} [${config.branch}]...`);
setInterval(async () => {
try {
const latest = await (0, watcher_1.getLatestCommit)(config.repoUrl, config.branch);
if (latest !== lastCommit) {
console.log("📥 New commit found → Update and Restart!");
await (0, updater_1.updateAndRestart)(config);
lastCommit = latest;
}
}
catch (e) {
console.error("Error during check:", e);
}
}, config.checkInterval * 1000);
});
program.parse(process.argv);