erratic-gate/deploy.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

const { publish } = require('gh-pages')
const { exec } = require('child_process')
2019-06-02 22:06:25 +02:00
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
const message = `${mFlag >= 0 ? args[mFlag + 1] : 'automated update'}`
2019-05-27 19:29:29 +02:00
console.log('Deploying...')
2019-05-27 19:29:29 +02:00
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) rej(err)
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 () => {
2019-05-27 19:49:10 +02:00
try {
if (!args.includes('--skipBuild') && !args.includes('-sb')) {
await run('npm run build')
}
if (!args.includes('--skipGit') && !args.includes('-sg')) {
await run('git add .')
await run(`git commit -m " ${message} "`)
await run('git push origin master')
}
2019-05-27 19:49:10 +02:00
await new Promise((res, rej) => {
console.log('🏃 Updating github pages')
2019-06-02 22:06:25 +02:00
//@ts-ignore
publish('dist', err => {
if (err) rej(err)
2019-05-27 19:49:10 +02:00
console.log(`😄 Succesfully published to github pages`)
res(true)
})
})
} catch (err) {
2019-05-27 19:49:10 +02:00
console.log(`😭 Something went wrong: ${err}`)
}
})()