Skip to content

Commit

Permalink
Added git commit js file
Browse files Browse the repository at this point in the history
  • Loading branch information
joonshakya committed Jan 29, 2024
1 parent 37cdb67 commit 084e8d1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ yarn-error.log*
out/

# Joon commit hook
commit.js
outgit/
46 changes: 46 additions & 0 deletions commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { exec, spawn } = require("child_process");
const jExec = async (command) => {
const spawnCommand = command.split(" ")[0];
const spawnArgs = command.split(" ").slice(1);
await new Promise((resolve) => {
let std = spawn(spawnCommand, spawnArgs || [], {
shell: true,
stdio: "inherit",
});
std.on("data", (data) => {
console.log(`stdout: ${data}`);
});
std.on("error", (error) => {
console.log(`error: ${error.message}`);
});
std.on("close", () => {
resolve();
});
});
};

(async () => {
try {
exec("pwd");
} catch (e) {
console.log("Please use Git Bash to run this script");
process.exit();
}

const message = process.argv[2];

if (!message) {
console.log("Please enter a commit message");
} else {
console.log("\npnpm build");
await jExec(`pnpm build`);
console.log("\nCommitting Static HTML...");
await jExec(
`cd out && git init && git remote add static-html https://github.com/joonshakya/CSIT21-Next-Static.git && git add . && git branch -M static && git commit -m "Deploy from local" && git push static-html static --force`
);
console.log("\nCommitting code...");
await jExec(
`git add . && git commit -m "${message} [skip ci]" && git push`
);
}
})();

0 comments on commit 084e8d1

Please sign in to comment.