forked from dwmkerr/angular-modal-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (88 loc) · 3.12 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
var gulp = require('gulp');
var path = require('path');
var open = require('gulp-open');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var express = require('express');
var connectLivereload = require('connect-livereload');
var opn = require('opn');
var karma = require('karma').server;
var header = require('gulp-header');
// Copies bower dependencies into the samples/vendor folder.
gulp.task('vendor', function() {
gulp.src('bower_components/bootstrap/dist/**/*.*')
.pipe(gulp.dest('samples/vendor/bootstrap'));
gulp.src(
[
'bower_components/angular/angular.js',
'bower_components/angular-route/angular-route.js'
])
.pipe(gulp.dest('samples/vendor/angular'));
gulp.src('bower_components/jquery/dist/*.*')
.pipe(gulp.dest('samples/vendor/jquery'));
});
// Builds the js code.
gulp.task('js', function() {
return gulp.src('src/angular-modal-service.js')
.pipe(sourcemaps.init())
.pipe(gulp.dest('./dst'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(header('/*<%= pkg.name %> v<%= pkg.version %> - <%= pkg.homepage %> */\n', {pkg: require('./package.json') } ))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dst'));
});
// Lints the code.
gulp.task('jshint', function() {
return gulp.src(['*.js', 'src/*.js', 'test/**.js', 'samples/**/*.js', '!samples/vendor/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
// Serves the sample app and kicks off livereload.
gulp.task('serve', function() {
// Create the app. Serve the samples and the dist.
var app = express();
app.use(connectLivereload());
app.use(express.static(path.join(__dirname, 'samples')));
app.use(express.static(path.join(__dirname, 'src')));
app.listen(3000);
console.log('Kick off some modals on port 3000!');
});
// Starts the livereload server.
var tinylr;
gulp.task('livereload', function() {
tinylr = require('tiny-lr')();
tinylr.listen(35729);
});
// Notifies livereload of changes detected
function notifyLivereload(event) {
tinylr.changed({
body: {
files: [path.relative(__dirname, event.path)]
}
});
}
// Test the code.
gulp.task('test', function (done) {
karma.start({
configFile: path.join(__dirname, './test/karma.config.js'),
singleRun: true
}, done);
});
// Sets up watchers.
gulp.task('watch', function() {
// When the source file changes, build it and test it. Whenever any JS changes hint it.
gulp.watch(['src/*.js'], ['js']);
gulp.watch(['*.js', 'src/*.js', 'test/**.js', 'samples/**/*.js', '!samples/vendor/**/*.js'], ['jshint']);
// When our source or tests change, build, retest and livereload.
gulp.watch(['src/*.js', 'test/**/*.spec.js'], ['test'], notifyLivereload);
// When our samples change, livereload.
gulp.watch(['samples/**/*.*'], notifyLivereload);
});
// The default task sets up the vendor files, builds, serves and watches.
gulp.task('default', ['vendor', 'js', 'serve', 'livereload', 'watch'], function() {
opn('http://localhost:3000');
});