-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37cdb67
commit 084e8d1
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,4 @@ yarn-error.log* | |
out/ | ||
|
||
# Joon commit hook | ||
commit.js | ||
outgit/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
); | ||
} | ||
})(); |