erratic-gate/deploy.ts

53 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-06-02 22:06:25 +02:00
const { publish } = require("gh-pages")
const { exec } = require("child_process")
const { random } = require("random-emoji")
// const { publish } = require("gh-pages")
2019-05-27 19:49:10 +02:00
const args = process.argv.splice(2)
2019-05-27 20:07:48 +02:00
const randomEmoji = () => random({ count: 1 })[0].character
2019-05-27 19:55:30 +02:00
const mFlag = ((args.indexOf("--message") + 1) || (args.indexOf("-m") + 1)) - 1
const message = `${randomEmoji()} ${(mFlag >= 0) ? args[mFlag + 1] : "automated update"} ${randomEmoji()}`
2019-05-27 19:29:29 +02:00
console.log("Deploying...");
2019-05-27 19:49:10 +02:00
const run = (command: string): Promise<string> => {
return new Promise((res, rej) => {
console.log(`🏃 Running: '${command}'`)
2019-06-02 22:06:25 +02:00
//@ts-ignore
2019-05-27 19:49:10 +02:00
exec(command, (err, stdout, stderr) => {
if (err != null)
2019-05-27 19:29:29 +02:00
rej(err)
2019-05-27 19:49:10 +02:00
else if (typeof (stderr) != "string")
rej(new Error(stderr))
else
res(stdout)
2019-05-27 19:29:29 +02:00
})
})
2019-05-27 19:49:10 +02:00
}
2019-05-27 19:49:10 +02:00
(async () => {
try {
if (!args.includes("--skipBuild") && !args.includes("-sb"))
await run("npm run build")
await run("git add .")
2019-05-27 20:16:38 +02:00
await run(`git commit -m " ${message} "`)
2019-05-27 19:49:10 +02:00
await run("git push origin master")
await new Promise((res, rej) => {
2019-05-27 19:50:03 +02:00
console.log("🏃 Updating github pages")
2019-06-02 22:06:25 +02:00
//@ts-ignore
2019-05-27 19:49:10 +02:00
publish("dist", (err) => {
if (err)
rej(err)
console.log(`😄 Succesfully published to github pages`)
res(true)
})
})
}
catch (err) {
console.log(`😭 Something went wrong: ${err}`)
}
2019-05-27 19:29:29 +02:00
})()