|
1 |
| - var gulp = require('gulp'); |
2 |
| - var Server = require('karma').Server; |
3 |
| - var browserSync = require('browser-sync').create(); |
4 |
| - var usemin = require('gulp-usemin'), |
5 |
| - cssnano = require('gulp-cssnano'), |
6 |
| - rev = require('gulp-rev'), |
7 |
| - htmlmin = require('gulp-htmlmin'), |
8 |
| - sourcemaps = require('gulp-sourcemaps'), |
9 |
| - ngAnnotate = require('gulp-ng-annotate'), |
10 |
| - uglify = require('gulp-uglify'), |
11 |
| - prefix = require('gulp-autoprefixer'), |
12 |
| - flatten = require('gulp-flatten'), |
13 |
| - del = require('del'), |
14 |
| - runSequence = require('run-sequence'); |
| 1 | +var gulp = require('gulp'); |
| 2 | +var gutil = require('gulp-util'); |
| 3 | +var Server = require('karma').Server; |
| 4 | +var browserSync = require('browser-sync').create(); |
| 5 | +var usemin = require('gulp-usemin'), |
| 6 | + cssnano = require('gulp-cssnano'), |
| 7 | + rev = require('gulp-rev'), |
| 8 | + htmlmin = require('gulp-htmlmin'), |
| 9 | + sourcemaps = require('gulp-sourcemaps'), |
| 10 | + ngAnnotate = require('gulp-ng-annotate'), |
| 11 | + uglify = require('gulp-uglify'), |
| 12 | + prefix = require('gulp-autoprefixer'), |
| 13 | + flatten = require('gulp-flatten'), |
| 14 | + del = require('del'), |
| 15 | + runSequence = require('run-sequence'); |
15 | 16 |
|
16 |
| - var config = { |
17 |
| - app: 'src/main/webapp/', |
18 |
| - dist: 'src/main/webapp/dist/' |
19 |
| - }; |
| 17 | +var config = { |
| 18 | + app: 'src/main/webapp/', |
| 19 | + dist: 'src/main/webapp/dist/' |
| 20 | +}; |
20 | 21 |
|
21 |
| - /** |
22 |
| - * Run test once and exit |
23 |
| - */ |
24 |
| - gulp.task('test', function (done) { |
25 |
| - new Server({ |
26 |
| - configFile: __dirname + '/src/test/javascript/karma.conf.js', |
27 |
| - singleRun: true |
28 |
| - }, done).start(); |
29 |
| - }); |
| 22 | +/** |
| 23 | + * Run test once and exit |
| 24 | + */ |
| 25 | +gulp.task('test', function (done) { |
| 26 | + new Server({ |
| 27 | + configFile: __dirname + '/src/test/javascript/karma.conf.js', |
| 28 | + singleRun: true |
| 29 | + }).on('browser_error', function (browser, err) { |
| 30 | + gutil.log('Karma Run Failed: ' + err.message); |
| 31 | + throw err; |
| 32 | + }).on('run_complete', function (browsers, results) { |
| 33 | + if (results.failed) { |
| 34 | + throw new Error('Karma: Tests Failed'); |
| 35 | + } |
| 36 | + gutil.log('Karma Run Complete: No Failures'); |
| 37 | + done(); |
| 38 | + }).start(); |
| 39 | +}); |
30 | 40 |
|
31 |
| - /** |
32 |
| - * Run test once and watch changing |
33 |
| - */ |
34 |
| - gulp.task('test-watch', function (done) { |
35 |
| - new Server({ |
36 |
| - configFile: __dirname +'/src/test/javascript/karma.conf.js', |
37 |
| - singleRun: false |
38 |
| - }, done).start(); |
39 |
| - }); |
| 41 | +/** |
| 42 | + * Run test once and watch changing |
| 43 | + */ |
| 44 | +gulp.task('test-watch', function (done) { |
| 45 | + new Server({ |
| 46 | + configFile: __dirname + '/src/test/javascript/karma.conf.js', |
| 47 | + singleRun: false |
| 48 | + }, done).start(); |
| 49 | +}); |
40 | 50 |
|
41 |
| - /** |
42 |
| - * Run a static server and reload changing file |
43 |
| - */ |
44 |
| - gulp.task('serve', function () { |
45 |
| - browserSync.init({ |
46 |
| - server: __dirname + '/src/main/webapp' |
47 |
| - }); |
48 |
| - gulp.watch(__dirname + '/src/main/webapp/*').on('change', browserSync.reload); |
| 51 | +/** |
| 52 | + * Run a static server and reload changing file |
| 53 | + */ |
| 54 | +gulp.task('serve', function () { |
| 55 | + browserSync.init({ |
| 56 | + server: __dirname + '/src/main/webapp' |
49 | 57 | });
|
| 58 | + gulp.watch(__dirname + '/src/main/webapp/*').on('change', browserSync.reload); |
| 59 | +}); |
50 | 60 |
|
51 | 61 |
|
52 |
| - /** |
53 |
| - * build the front app for prod env |
54 |
| - */ |
55 |
| - gulp.task('build', function (cb) { |
56 |
| - runSequence('clean', 'usemin', 'copy-fonts', 'copy-images', cb); |
57 |
| - }); |
| 62 | +/** |
| 63 | + * build the front app for prod env |
| 64 | + */ |
| 65 | +gulp.task('build', function (cb) { |
| 66 | + runSequence('clean', 'usemin', 'copy-fonts', 'copy-images', cb); |
| 67 | +}); |
58 | 68 |
|
59 |
| - gulp.task('styles', [], function () { |
60 |
| - return gulp.src(config.app + 'assets/css/**/*.css') |
61 |
| - .pipe(browserSync.reload({stream: true})); |
62 |
| - }); |
| 69 | +gulp.task('styles', [], function () { |
| 70 | + return gulp.src(config.app + 'assets/css/**/*.css') |
| 71 | + .pipe(browserSync.reload({stream: true})); |
| 72 | +}); |
63 | 73 |
|
64 |
| - /** |
65 |
| - * copy bootstrap font into assets/fonts |
66 |
| - */ |
67 |
| - gulp.task('copy-fonts', function () { |
68 |
| - return gulp.src([ |
69 |
| - config.app + 'bower_components/bootstrap/fonts/*.*', |
70 |
| - config.app + 'bower_components/font-awesome/fonts/*.*']) |
71 |
| - .pipe(flatten()) |
72 |
| - .pipe(gulp.dest(config.dist + 'assets/fonts/')); |
73 |
| - }); |
| 74 | +/** |
| 75 | + * copy bootstrap font into assets/fonts |
| 76 | + */ |
| 77 | +gulp.task('copy-fonts', function () { |
| 78 | + return gulp.src([ |
| 79 | + config.app + 'bower_components/bootstrap/fonts/*.*', |
| 80 | + config.app + 'bower_components/font-awesome/fonts/*.*']) |
| 81 | + .pipe(flatten()) |
| 82 | + .pipe(gulp.dest(config.dist + 'assets/fonts/')); |
| 83 | +}); |
74 | 84 |
|
75 |
| - /** |
76 |
| - * copy images |
77 |
| - */ |
78 |
| - gulp.task('copy-images', function () { |
79 |
| - return gulp.src(config.app + 'assets/images/**') |
80 |
| - .pipe(gulp.dest(config.dist + 'assets/images')); |
81 |
| - }); |
| 85 | +/** |
| 86 | + * copy images |
| 87 | + */ |
| 88 | +gulp.task('copy-images', function () { |
| 89 | + return gulp.src(config.app + 'assets/images/**') |
| 90 | + .pipe(gulp.dest(config.dist + 'assets/images')); |
| 91 | +}); |
82 | 92 |
|
83 | 93 |
|
84 |
| - /** |
85 |
| - * remove the old dist directory |
86 |
| - */ |
87 |
| - gulp.task('clean', function () { |
88 |
| - return del([config.dist]); |
89 |
| - }); |
| 94 | +/** |
| 95 | + * remove the old dist directory |
| 96 | + */ |
| 97 | +gulp.task('clean', function () { |
| 98 | + return del([config.dist]); |
| 99 | +}); |
90 | 100 |
|
91 |
| - /** |
92 |
| - * minify css and js |
93 |
| - */ |
94 |
| - gulp.task('usemin', ['styles'], function () { |
95 |
| - return gulp.src([config.app + '**/*.html', '!' + config.app + '@(dist|bower_components)/**/*.html']) |
96 |
| - .pipe(usemin({ |
97 |
| - css: [ |
98 |
| - prefix, |
99 |
| - 'concat', |
100 |
| - cssnano, |
101 |
| - rev |
102 |
| - ], |
103 |
| - html: [ |
104 |
| - htmlmin.bind(htmlmin, {collapseWhitespace: true}) |
105 |
| - ], |
106 |
| - js: [ |
107 |
| - sourcemaps.init, |
108 |
| - ngAnnotate, |
109 |
| - 'concat', |
110 |
| - uglify.bind(uglify, {mangle: false}), |
111 |
| - rev, |
112 |
| - sourcemaps.write.bind(sourcemaps.write, '.') |
113 |
| - ] |
114 |
| - })) |
115 |
| - .pipe(gulp.dest(config.dist)); |
116 |
| - }); |
| 101 | +/** |
| 102 | + * minify css and js |
| 103 | + */ |
| 104 | +gulp.task('usemin', ['styles'], function () { |
| 105 | + return gulp.src([config.app + '**/*.html', '!' + config.app + '@(dist|bower_components)/**/*.html']) |
| 106 | + .pipe(usemin({ |
| 107 | + css: [ |
| 108 | + prefix, |
| 109 | + 'concat', |
| 110 | + cssnano, |
| 111 | + rev |
| 112 | + ], |
| 113 | + html: [ |
| 114 | + htmlmin.bind(htmlmin, {collapseWhitespace: true}) |
| 115 | + ], |
| 116 | + js: [ |
| 117 | + sourcemaps.init, |
| 118 | + ngAnnotate, |
| 119 | + 'concat', |
| 120 | + uglify.bind(uglify, {mangle: false}), |
| 121 | + rev, |
| 122 | + sourcemaps.write.bind(sourcemaps.write, '.') |
| 123 | + ] |
| 124 | + })) |
| 125 | + .pipe(gulp.dest(config.dist)); |
| 126 | +}); |
0 commit comments