namastejs
Version:
A spiritual greeting from your JavaScript code. Because every function deserves a 'Namaste š'
43 lines (34 loc) ⢠1.34 kB
JavaScript
const { execSync } = require("child_process");
function parseArgs(args) {
const result = {};
args.forEach(arg => {
const [key, value] = arg.split("=");
if (key.startsWith("--") && value) {
result[key.replace("--", "")] = value;
}
});
return result;
}
function updateCLI(rawArgs) {
const args = parseArgs(rawArgs);
const myBranch = args.my;
const fromBranch = args.from;
if (!myBranch || !fromBranch) {
console.log("ā Please provide both --my and --from branches.");
console.log("Usage: npx namastejs update --my=your-branch --from=source-branch");
return;
}
try {
console.clear();
console.log(`š Switching to '${fromBranch}' and pulling latest...`);
execSync(`git checkout ${fromBranch}`, { stdio: "inherit" });
execSync(`git pull origin ${fromBranch}`, { stdio: "inherit" });
console.log(`\nš Switching to '${myBranch}' and merging '${fromBranch}'...`);
execSync(`git checkout ${myBranch}`, { stdio: "inherit" });
execSync(`git merge ${fromBranch}`, { stdio: "inherit" });
console.log(`\nā
Update complete. '${fromBranch}' merged into '${myBranch}'. Namaste š`);
} catch (err) {
console.error("ā Something went wrong during the Git process.");
}
}
module.exports = { updateCLI };