forked from zswang/csst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (64 loc) · 1.62 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
/*jshint globalstrict: true*/
/*global require*/
'use strict';
var gulp = require('gulp');
var util = require('util');
var jdists = require('gulp-jdists');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var connect = require('gulp-connect');
var open = require('gulp-open');
gulp.task('build', function() {
return gulp.src(['src/csst.js'])
.pipe(jdists({
trigger: 'release'
}))
.pipe(gulp.dest('./'))
.pipe(uglify())
.pipe(rename('csst.min.js'))
.pipe(gulp.dest('./'));
});
gulp.task('buildDev', function() {
return gulp.src(['src/csst.js'])
.pipe(jdists({
trigger: 'debug'
}))
.pipe(gulp.dest('./'));
});
var debugPort = 8111;
function debugAddress() {
var net = require('os').networkInterfaces();
var result;
Object.keys(net).some(function(key) {
return net[key].some(function(item) {
if (!item.internal && item.family === 'IPv4') {
result = item.address;
return true;
}
});
});
return result;
}
gulp.task('connect', function() {
require('./example/app');
connect.server({
root: './',
port: debugPort,
livereload: true
});
});
gulp.task('html', function() {
gulp.src('./example/*.html')
.pipe(connect.reload());
});
gulp.task('open', function() {
gulp.src(__filename)
.pipe(open({
uri: util.format('http://%s:%s/example/index.html', debugAddress(), debugPort)
}));
});
gulp.task('watch', function() {
gulp.watch(['src/*.js', 'example/*.html'], ['buildDev', 'html']);
});
gulp.task('debug', ['buildDev', 'html', 'connect', 'open', 'watch']);
gulp.task('default', ['build']);