|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var path = require('path'); |
| 4 | +var gulp = require('gulp'); |
| 5 | +var conf = require('./conf'); |
| 6 | + |
| 7 | +var $ = require('gulp-load-plugins')({ |
| 8 | + pattern: ['gulp-*', 'main-bower-files', 'uglify-save-license', 'del'] |
| 9 | +}); |
| 10 | + |
| 11 | +gulp.task('partials', function () { |
| 12 | + return gulp.src([ |
| 13 | + path.join(conf.paths.src, '/app/**/*.html'), |
| 14 | + path.join(conf.paths.tmp, '/serve/app/**/*.html') |
| 15 | + ]) |
| 16 | + .pipe($.minifyHtml({ |
| 17 | + empty: true, |
| 18 | + spare: true, |
| 19 | + quotes: true |
| 20 | + })) |
| 21 | + .pipe($.angularTemplatecache('templateCacheHtml.js', { |
| 22 | + module: 'hyperdeckUi', |
| 23 | + root: 'app' |
| 24 | + })) |
| 25 | + .pipe(gulp.dest(conf.paths.tmp + '/partials/')); |
| 26 | +}); |
| 27 | + |
| 28 | +gulp.task('html', ['inject', 'partials'], function () { |
| 29 | + var partialsInjectFile = gulp.src(path.join(conf.paths.tmp, '/partials/templateCacheHtml.js'), { read: false }); |
| 30 | + var partialsInjectOptions = { |
| 31 | + starttag: '<!-- inject:partials -->', |
| 32 | + ignorePath: path.join(conf.paths.tmp, '/partials'), |
| 33 | + addRootSlash: false |
| 34 | + }; |
| 35 | + |
| 36 | + var htmlFilter = $.filter('*.html'); |
| 37 | + var jsFilter = $.filter('**/*.js'); |
| 38 | + var cssFilter = $.filter('**/*.css'); |
| 39 | + var assets; |
| 40 | + |
| 41 | + return gulp.src(path.join(conf.paths.tmp, '/serve/*.html')) |
| 42 | + .pipe($.inject(partialsInjectFile, partialsInjectOptions)) |
| 43 | + .pipe(assets = $.useref.assets()) |
| 44 | + .pipe($.rev()) |
| 45 | + .pipe(jsFilter) |
| 46 | + .pipe($.ngAnnotate()) |
| 47 | + .pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify')) |
| 48 | + .pipe(jsFilter.restore()) |
| 49 | + .pipe(cssFilter) |
| 50 | + .pipe($.replace('../../bower_components/bootstrap/fonts/', '../fonts/')) |
| 51 | + .pipe($.csso()) |
| 52 | + .pipe(cssFilter.restore()) |
| 53 | + .pipe(assets.restore()) |
| 54 | + .pipe($.useref()) |
| 55 | + .pipe($.revReplace()) |
| 56 | + .pipe(htmlFilter) |
| 57 | + .pipe($.minifyHtml({ |
| 58 | + empty: true, |
| 59 | + spare: true, |
| 60 | + quotes: true, |
| 61 | + conditionals: true |
| 62 | + })) |
| 63 | + .pipe(htmlFilter.restore()) |
| 64 | + .pipe(gulp.dest(path.join(conf.paths.dist, '/'))) |
| 65 | + .pipe($.size({ title: path.join(conf.paths.dist, '/'), showFiles: true })); |
| 66 | +}); |
| 67 | + |
| 68 | +// Only applies for fonts from bower dependencies |
| 69 | +// Custom fonts are handled by the "other" task |
| 70 | +gulp.task('fonts', function () { |
| 71 | + return gulp.src($.mainBowerFiles()) |
| 72 | + .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) |
| 73 | + .pipe($.flatten()) |
| 74 | + .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/'))); |
| 75 | +}); |
| 76 | + |
| 77 | +gulp.task('other', function () { |
| 78 | + var fileFilter = $.filter(function (file) { |
| 79 | + return file.stat.isFile(); |
| 80 | + }); |
| 81 | + |
| 82 | + return gulp.src([ |
| 83 | + path.join(conf.paths.src, '/**/*'), |
| 84 | + path.join('!' + conf.paths.src, '/**/*.{html,css,js,less}') |
| 85 | + ]) |
| 86 | + .pipe(fileFilter) |
| 87 | + .pipe(gulp.dest(path.join(conf.paths.dist, '/'))); |
| 88 | +}); |
| 89 | + |
| 90 | +gulp.task('clean', function (done) { |
| 91 | + $.del([path.join(conf.paths.dist, '/'), path.join(conf.paths.tmp, '/')], done); |
| 92 | +}); |
| 93 | + |
| 94 | +gulp.task('build', ['html', 'fonts', 'other']); |
0 commit comments