UNPKG

auxy

Version:

Automation github deployment

69 lines (52 loc) β€’ 1.75 kB
#!/usr/bin/env node const simpleGit = require("simple-git"); const git = simpleGit(); const args = process.argv.slice(2); const inputType = args[0]; const msgParts = args.slice(1); process.removeAllListeners("warning"); const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); (async () => { let type = inputType; if (type === "major") type = "feat: Major Changes\n\nBREAKING CHANGE"; try { console.log("πŸ”„ Fetching & pulling..."); await git.fetch(); await git.pull(); const status = await git.status(); const changedFiles = status.files.map((f) => f.path); if (changedFiles.length === 0) { console.log("βœ… There is no changes to commit!"); return; } console.log("βž• Adding all files..."); await git.add("./*"); // Auto detect type if (!type) { let hasMajor = changedFiles.some( (f) => f.startsWith("routes/") || f.startsWith("auth/") || f === "app.js" ); let hasMinor = changedFiles.includes("firebase.js"); type = hasMajor ? "feat: Major Changes\n\nBREAKING CHANGE" : hasMinor ? "feat" : "fix"; } let commitMsg = msgParts.join(" ").trim(); const fallbackMsg = changedFiles.join(", "); const finalMessage = `${type}: ${commitMsg || fallbackMsg}`; console.log(`βœ… Comitting: "${finalMessage}"`); await git.commit(finalMessage); await git.push(); console.log("⏸️ Prepare to get latest changes..."); await sleep(5000); // in ms console.log("πŸ”„ Fetching & pulling latest changes..."); await git.fetch(); await git.pull(); console.log("πŸš€ Done!"); } catch (err) { console.error("❌ Error:", err.message); } })();