Created
September 17, 2019 09:03
-
-
Save quantonganh/ee8ee0e2c9576acdcbfc56fd627ad07e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gulp = require('gulp'), | |
util = require('gulp-util'), | |
notifier = require('node-notifier'), | |
child = require('child_process'), | |
os = require('os'), | |
path = require('path'); | |
var server = 'null' | |
function build() { | |
var build = child.spawn('go', ['install']); | |
build.stdout.on('data', (data) => { | |
console.log(`stdout: ${data}`); | |
}); | |
build.stderr.on('data', (data) => { | |
console.error(`stderr: ${data}`); | |
}); | |
return build; | |
} | |
function spawn(done) { | |
if (server && server != 'null') { | |
server.kill(); | |
} | |
var path_folder = process.cwd().split(path.sep) | |
var length = path_folder.length | |
var app = path_folder[length - parseInt(1)]; | |
if (os.platform() == 'win32') { | |
server = child.spawn(app + '.exe') | |
} else { | |
server = child.spawn(app) | |
} | |
server.stdout.on('data', (data) => { | |
console.log(`stdout: ${data}`); | |
}); | |
server.stderr.on('data', (data) => { | |
console.log(`stderr: ${data}`); | |
}); | |
done(); | |
} | |
const serve = gulp.series(build, spawn) | |
function watch(done) { | |
gulp.watch(['*.go', '**/*.go'], serve); | |
done(); | |
} | |
exports.serve = serve | |
exports.watch = watch | |
exports.default = gulp.parallel(serve, watch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment