/
gulpfile.js
100 lines (87 loc) · 2.83 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var gulp = require('gulp'),
traceur = require('gulp-traceur'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
watch = require('gulp-watch'),
livereload = require('gulp-livereload'),
plumber = require('gulp-plumber'),
del = require('del'),
runSequence = require('run-sequence'),
ngConstant = require('gulp-ng-constant'),
less = require('gulp-less'),
concat = require('gulp-concat'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer');
gulp.task('clean', function (cb) {
del(['dist/**/*'], cb);
});
gulp.task('copy_bower_libs', function(){
return gulp.src('./bower_components/**/*', {base: './bower_components'})
.pipe(gulp.dest('dist/lib'))
.pipe(livereload());
});
gulp.task('copy_libs', function(){
return gulp.src('./lib/*.js')
.pipe(traceur())
.pipe(gulp.dest('dist/lib'))
.pipe(livereload());
});
gulp.task('copy_html', function(){
return gulp.src('./app/**/*.html')
.pipe(gulp.dest('dist'))
.pipe(livereload());
});
gulp.task('copy_traceur_runtime', function(){
return gulp.src('./node_modules/traceur/bin/**/*.js')
.pipe(gulp.dest('dist/lib/traceur'))
.pipe(livereload());
});
gulp.task('traceur', ['build_config'], function() {
return gulp.src(['!app/**/*Spec.js', 'app/**/*.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(traceur())
.pipe(concat('app.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/js'))
.pipe(livereload());
});
gulp.task('copy_css', function () {
gulp.src(['app/**/*.less'])
.pipe(less())
.pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
.pipe(concat('app.css'))
.pipe(gulp.dest('dist'))
.pipe(livereload());
});
gulp.task('build_config', function(){
return gulp.src('config.json')
.pipe(ngConstant({
constants: {
apiUrl: process.env.API_URL || 'http://localhost:3000/api',
mqttConfig: {
host: process.env.MQTT_HOST || '127.0.0.1',
port: process.env.MQTT_PORT || '9001'
}
}
})).pipe(gulp.dest('./app/js/components/config'))
});
gulp.task('watch', function () {
livereload.listen();
watch('./app/**/*.js', function () {
gulp.start('traceur');
});
watch('./app/**/*.less', function () {
gulp.start('copy_css');
});
watch('./app/**/*.html', function () {
gulp.start('copy_html');
});
watch('./bower_components/**/*', function () {
gulp.start('copy_libs');
});
});
gulp.task('default', function(cb){
runSequence('clean', ['traceur', 'copy_bower_libs', 'copy_html', 'copy_traceur_runtime', 'copy_libs', 'copy_css']);
cb();
});