forked from OpenShare/openshare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
76 lines (69 loc) · 1.89 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var gulp = require('gulp'),
browserify = require('browserify'),
babel = require('gulp-babel'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
uglify = require('gulp-uglify'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
util = require('gulp-util'),
gulpif = require('gulp-if'),
fs = require('fs'),
prompt = require('gulp-prompt'),
needsPrompt = false,
filename = '.vhost';
function _startBrowserSync() {
// read vhost file here
fs.readFile(filename, 'utf8', function(err, data) {
if (err) throw err;
// start a browsersync session using the data of gulp/.vhost
browserSync({
proxy: data
});
});
}
function _watchFiles() {
gulp.watch('src/**/*.js', ['compile']).on('change', reload);
}
gulp.task('compile', ['compile-js', 'compile-test']);
gulp.task('compile-js', function() {
return browserify('src/browser.js')
.bundle()
.pipe(source('open-share.js'))
.pipe(buffer())
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
gulp.task('compile-test', function() {
return browserify('src/test.js')
.bundle()
.pipe(source('test.js'))
.pipe(buffer())
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
gulp.task('watch', function() {
// does our vhost exist
// check if gulp/.vhost has been created
fs.exists(filename, function(exists) {
if (!exists) {
// prompt
needsPrompt = true;
gulp.src('gulpfile.js')
.pipe(prompt.prompt({
name: 'vhost',
message: 'Please enter your vhost name'
}, function(res) {
fs.writeFile(filename, res.vhost);
console.log('Virtual Host Set: ' + res.vhost);
_startBrowserSync();
_watchFiles();
}));
} else {
_startBrowserSync();
_watchFiles();
}
});
});