erratic-gate/deploy.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

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"
const args = process.argv.splice(2)
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 .")
await run('git commit -m "automated update"')
await run("git push origin master")
await new Promise((res, rej) => {
console.log("Updating github pages")
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
})()