Skip to content

Instantly share code, notes, and snippets.

@jsmithdev
Created May 22, 2017 01:07
Show Gist options
  • Save jsmithdev/e48721addf954a4fd5cf8dbe5d4d82cf to your computer and use it in GitHub Desktop.
Save jsmithdev/e48721addf954a4fd5cf8dbe5d4d82cf to your computer and use it in GitHub Desktop.
Sync a Firebase App + Functions with Gulp automatically.
'use strict';
const gulp = require('gulp')
,watch = require('gulp-watch')
,dir = '/home/ubuntu/workspace/app'
,fnDir = '/home/ubuntu/workspace/functions'
,version = 'prod'
,useVersion = false
,comando = "firebase deploy "
,comandoParams = " -P " +version+ " "
,comandOnlyFnc = " --only functions "
,log = msg => console.log(msg)
,info = () => {
log('Watching Firebase App in ' + dir)
log('Watching Firebase Functions in ' + fnDir)
}
,write = (data) => {
for (let i = 0; i < data.history.length; i++) {
let archiveLocal = data.history[i]
,valid = true
;
if (archiveLocal.indexOf('/.') >= 0) {
valid = false; //ignore .git, .ssh, etc
}
if (valid) {
let exec = require('child_process').exec
,offset = -4.0//EST
,clientDate = new Date()
,utc = clientDate.getTime() + (clientDate.getTimezoneOffset() * 60000)
;
let serverDate = new Date(utc + (3600000 * offset));
if (useVersion) {
console.log(comando,' ',comandoParams,' ',archiveLocal,' - ',data.event, ' @ ',serverDate.toLocaleString())
exec(comando + ' ' + comandoParams)
}
else {
console.log(comando,' ',archiveLocal,' - ',data.event,' @ ',serverDate.toLocaleString())
exec(comando)
}
}
}
}
;
info();
gulp.task('default', ['syncFirebaseApp','syncFirebaseFuncs']);
gulp.task('syncFirebaseApp', () => watch(dir, (data) => write(data)));
gulp.task('syncFirebaseFuncs', () => watch(fnDir, (data) => write(data)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment