/
gulpfile.js
131 lines (115 loc) · 3.4 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'use strict';
var fs = require('fs')
, gulp = require('gulp')
, karma = require('karma').server
, concat = require('gulp-concat')
, jshint = require('gulp-jshint')
, header = require('gulp-header')
, rename = require('gulp-rename')
, es = require('event-stream')
, del = require('del')
, uglify = require('gulp-uglify')
, minifyHtml = require('gulp-minify-html')
, minifyCSS = require('gulp-minify-css')
, sass = require('gulp-sass')
, templateCache = require('gulp-angular-templatecache')
, gutil = require('gulp-util')
, plumber = require('gulp-plumber')
, order = require("gulp-order")
, harp = require('harp')
, cp = require('child_process')
, browserSync = require('browser-sync')
, reload = browserSync.reload;
var config = {
pkg : JSON.parse(fs.readFileSync('./package.json')),
banner:
'/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.homepage %>\n' +
' * Author: <%= pkg.author %>\n' +
' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
' * License: <%= pkg.license %>\n' +
' */\n\n\n'
};
gulp.task('watch', function () {
gulp.watch(['./index.html'], function(){
reload('index.html', { stream: true });
});
gulp.watch(['./src/styles/*.sass'], ['styles'], function(){
reload('ng-input.css', { stream: true });
});
gulp.watch(['./src/**/*.js', './**/*.html'], ['scripts']);
});
gulp.task('clean', function(cb) {
del(['dist/**'], cb);
});
gulp.task('scripts', function() {
function buildTemplates() {
return gulp.src('src/ng-input.html')
.pipe(minifyHtml({
empty: true
, spare: true
, quotes: true
}))
.pipe(templateCache({ module: 'ngInput' }));
}
function buildDistJS(){
return gulp.src('src/ng-input.js')
.pipe(plumber({
errorHandler: handleError
}))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
}
es.merge(buildDistJS(), buildTemplates())
.pipe(plumber({
errorHandler: handleError
}))
.pipe(concat('ng-input.js'))
.pipe(header(config.banner, {
timestamp: (new Date()).toISOString(), pkg: config.pkg
}))
.pipe(gulp.dest('dist'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify({preserveComments: 'some'}))
.pipe(gulp.dest('./dist'));
});
gulp.task('styles', function() {
return gulp.src('src/styles/ng-input.sass')
.pipe(sass())
.pipe(header(config.banner, {
timestamp: (new Date()).toISOString(), pkg: config.pkg
}))
.pipe(gulp.dest('dist/css'))
.pipe(minifyCSS())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('open', function() {
harp.server(__dirname, {
port: 9000
}, function() {
browserSync({
proxy: "localhost:9000"
, open: false
});
});
});
gulp.task('jshint-test', function(){
return gulp.src('./test/**/*.js').pipe(jshint());
});
gulp.task('karma', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
, singleRun: true
}, done);
});
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
gulp.task('build', ['clean', 'scripts', 'styles']);
gulp.task('serve', ['open', 'watch']);
gulp.task('default', ['build', 'test']);
gulp.task('test', ['jshint-test', 'karma']);