-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgulpfile.js
88 lines (75 loc) · 2.36 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
/**
* Package Dependencies
*/
var concat = require('gulp-concat')
, del = require('del')
, header = require('gulp-header')
, gulp = require('gulp')
, templateCache = require('gulp-angular-templatecache')
, rename = require('gulp-rename')
, uglify = require('gulp-uglifyjs')
, util = require('util')
, eslint = require('gulp-eslint');
/**
* Local Dependencies
*/
var pkg = require('./package.json');
var banner = ['/**'
, ' * # <%= pkg.name %>'
, ' * ## <%= pkg.description %>'
, ' *'
, ' * @version v<%= pkg.version %>'
, ' * @link <%= pkg.repository.url %>'
, ' * @license <%= pkg.license %>'
, ' * @author <%= pkg.author %>'
, ' */'
, ''
, ''].join('\n');
var filename = util.format('%s.js', pkg.name)
, dest = 'dist/' + filename;
gulp.task('build', ['uglify']);
gulp.task('default', ['uglify']);
gulp.task('clean', function(done) {
del('./dist', done);
});
gulp.task('concat', [ 'templatecache' ], function() {
return gulp.src(['./src/module.js', './src/**/*.js'])
.pipe(concat(filename))
.pipe(gulp.dest('./dist'));
});
gulp.task('header', [ 'concat' ], function() {
return gulp.src('./dist/*.js')
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest('./dist'));
});
gulp.task('uglify', [ 'header' ], function() {
return gulp.src('./dist/*.js')
.pipe(uglify(dest.replace(/\.js$/, '.min.js')))
.pipe(gulp.dest('./'));
});
gulp.task('templatecache', [ 'clean' ], function() {
var TEMPLATE_HEADER = '(function(angular) {"use strict"; angular.module("<%= module %>"<%= standalone %>).run(["$templateCache", function($templateCache) {'
, TEMPLATE_FOOTER = '}]);})(window.angular);';
return gulp.src('src/tmpl/**/*.html')
.pipe(templateCache({
root: 'angular-elastic-builder',
module: 'angular-elastic-builder',
templateHeader: TEMPLATE_HEADER,
templateFooter: TEMPLATE_FOOTER,
}))
.pipe(rename('ElasticBuilderTemplates.js'))
.pipe(gulp.dest('src/tmpl'));
});
gulp.task('lint', function() {
return gulp.src([
'src/**/**.js',
'!src/tmpl/ElasticBuilderTemplates.js',
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('watch', [ 'templatecache', 'build' ], function() {
gulp.watch('src/tmpl/**/*.html', [ 'templatecache', 'build' ]);
gulp.watch(['src/**/**.js','!src/tmpl/ElasticBuilderTemplates.js'], [ 'build' ]);
});