2019-05-27 19:29:29 +02:00
|
|
|
import { publish } from "gh-pages"
|
2019-05-27 19:49:10 +02:00
|
|
|
import { exec } from "child_process"
|
2019-05-27 20:04:32 +02:00
|
|
|
import { random } from "random-emoji"
|
2019-05-27 19:49:10 +02:00
|
|
|
|
|
|
|
const args = process.argv.splice(2)
|
2019-05-27 19:55:30 +02:00
|
|
|
|
|
|
|
const mFlag = ((args.indexOf("--message") + 1) || (args.indexOf("-m") + 1)) - 1
|
2019-05-27 20:04:32 +02:00
|
|
|
const message = `${random({count: 1})} ${(mFlag) ? args[mFlag + 1] : "automated update"} ${random({count: 1})}`
|
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}'`)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
try {
|
|
|
|
if (!args.includes("--skipBuild") && !args.includes("-sb"))
|
|
|
|
await run("npm run build")
|
|
|
|
await run("git add .")
|
2019-05-27 19:56:01 +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-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
|
|
|
})()
|