2019-07-11 19:51:14 +02:00
|
|
|
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
|
|
|
|
2019-07-11 19:51:14 +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
|
|
|
|
2019-07-11 19:51:14 +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) => {
|
2019-07-11 19:51:14 +02:00
|
|
|
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
|
|
|
}
|
2019-07-11 19:51:14 +02:00
|
|
|
;(async () => {
|
2019-05-27 19:49:10 +02:00
|
|
|
try {
|
2019-07-25 23:07:02 +02:00
|
|
|
if (!args.includes('--skipBuild') && !args.includes('-sb')) {
|
2019-07-11 19:51:14 +02:00
|
|
|
await run('npm run build')
|
2019-07-25 23:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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) => {
|
2019-07-11 19:51:14 +02:00
|
|
|
console.log('🏃 Updating github pages')
|
2019-06-02 22:06:25 +02:00
|
|
|
//@ts-ignore
|
2019-07-11 19:51:14 +02:00
|
|
|
publish('dist', err => {
|
|
|
|
if (err) rej(err)
|
2019-05-27 19:49:10 +02:00
|
|
|
|
|
|
|
console.log(`😄 Succesfully published to github pages`)
|
|
|
|
res(true)
|
|
|
|
})
|
|
|
|
})
|
2019-07-11 19:51:14 +02:00
|
|
|
} catch (err) {
|
2019-05-27 19:49:10 +02:00
|
|
|
console.log(`😭 Something went wrong: ${err}`)
|
|
|
|
}
|
2019-07-11 19:51:14 +02:00
|
|
|
})()
|