This repository has been archived by the owner on Oct 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathgulpfile.js
121 lines (98 loc) · 3.03 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
'use strict';
var gulp = require('gulp');
var templateCache = require('gulp-angular-templatecache');
var runSequence = require('run-sequence');
var minifyCss = require('gulp-minify-css');
var changed = require('gulp-changed');
var connect = require('gulp-connect');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var jscs = require('gulp-jscs');
var childProcess = require('child_process');
var wiredep = require('wiredep').stream;
var merge = require('merge-stream');
var del = require('del');
var GLOBS = {
assets: '{demo/index.html,src/*.{html,css,js}}'
};
function execute(command, callback) {
childProcess.exec(command, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callback(err);
});
}
function executeTask(command) {
return function(callback) {
execute(command, callback);
};
}
gulp.task('browserify', executeTask('grunt browserify'));
gulp.task('deploy', executeTask('sh demo/gh-pages.sh'));
gulp.task('test', executeTask('node_modules/karma/bin/karma start test/karma.conf.js'));
gulp.task('server:connect', function() {
connect.server({
livereload: true,
fallback: 'demo/index.html',
host: 'localhost',
port: 8080,
root: ['demo/', '.']
});
});
gulp.task('server:reload', function() {
return gulp.src(GLOBS.assets)
.pipe(changed(GLOBS.assets))
.pipe(connect.reload());
});
gulp.task('refresh', function(callback) {
runSequence('build', 'server:reload', callback);
});
gulp.task('lint', function() {
return gulp.src('{src/*.js,test/*.js,*.js}')
.pipe(jscs())
.pipe(jscs.reporter());
});
gulp.task('build:css', function() {
return gulp.src('src/bc-phone-number.css')
.pipe(gulp.dest('dist/css/'))
.pipe(minifyCss())
.pipe(rename('bc-phone-number.min.css'))
.pipe(gulp.dest('dist/css/'));
});
gulp.task('uglify', function() {
return gulp.src('dist/js/bc-phone-number.js')
.pipe(uglify())
.pipe(rename('bc-phone-number.min.js'))
.pipe(gulp.dest('dist/js/'));
});
gulp.task('wiredep', function() {
var index = gulp.src('demo/index.html')
.pipe(wiredep({ignorePath: '../'}))
.pipe(gulp.dest('demo/'));
var test = gulp.src('test/karma.conf.js')
.pipe(wiredep({devDependencies: true}))
.pipe(gulp.dest('test/'));
return merge(index, test);
});
gulp.task('inline-templates', function() {
return gulp.src('src/*.html')
.pipe(templateCache({
standalone: true,
module: 'bcPhoneNumberTemplates',
root: 'bc-phone-number'
}))
.pipe(gulp.dest('build/js/'));
});
gulp.task('watch', function() {
gulp.watch([GLOBS.assets], ['refresh']);
});
gulp.task('clean', function() {
return del(['build/']);
});
gulp.task('build', function(callback) {
runSequence(['inline-templates', 'wiredep', 'build:css', 'lint'], 'browserify', 'uglify', 'clean', callback);
});
gulp.task('default', function(callback) {
runSequence('build', 'server:connect', 'watch', callback);
});