forked from Athou/commafeed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
115 lines (98 loc) · 4.29 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
var gulp = require('gulp');
var rev = require('gulp-rev');
var revReplace = require('gulp-rev-replace');
var minifyCSS = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var filter = require('gulp-filter');
var connect = require('gulp-connect');
var modRewrite = require('connect-modrewrite');
var sass = require('gulp-sass');
var useref = require('gulp-useref');
var templateCache = require('gulp-angular-templatecache');
var SRC_DIR = 'src/main/app/';
var TEMP_DIR = 'target/gulp/'
var BUILD_DIR = 'target/classes/assets/';
gulp.task('images', function() {
return gulp.src(SRC_DIR + 'images/**/*').pipe(gulp.dest(BUILD_DIR + 'images'));
});
gulp.task('i18n', function() {
return gulp.src(SRC_DIR + 'i18n/**/*.js').pipe(gulp.dest(BUILD_DIR + 'i18n'));
});
gulp.task('resources', function() {
var favicons_png = SRC_DIR + '*.png';
var favicons_ico = SRC_DIR + '*.ico';
var favicons_svg = SRC_DIR + '*.svg';
var manifest = SRC_DIR + 'manifest.json';
return gulp.src([favicons_png, favicons_ico, favicons_svg, manifest]).pipe(gulp.dest(BUILD_DIR));
});
gulp.task('sass', function() {
return gulp.src(SRC_DIR + 'sass/app.scss').pipe(sass()).pipe(gulp.dest(TEMP_DIR + 'css'));
});
gulp.task('fonts', function() {
var font_awesome = SRC_DIR + 'lib/font-awesome/font/fontawesome-webfont.*';
var zocial = SRC_DIR + 'lib/zocial-less/css/zocial-regular-*';
var readabilicons = SRC_DIR + 'lib/readabilicons/webfont/fonts/readabilicons-*';
return gulp.src([font_awesome, zocial, readabilicons]).pipe(gulp.dest(BUILD_DIR + 'font'));
});
gulp.task('select2', function() {
var gif = SRC_DIR + 'lib/select2/*.gif';
var png = SRC_DIR + 'lib/select2/*.png';
return gulp.src([gif, png]).pipe(gulp.dest(BUILD_DIR + 'css'));
});
gulp.task('swagger-ui', function() {
var index_html = SRC_DIR + 'api/index.html';
var swagger_json = 'target/swagger/swagger.json';
var lib = SRC_DIR + 'lib/swagger-ui/dist/**/*';
return gulp.src([lib, index_html, swagger_json]).pipe(gulp.dest(BUILD_DIR + 'api'));
});
gulp.task('template-cache', function() {
var options = {
module : 'commafeed.services',
root : 'templates/'
};
return gulp.src(SRC_DIR + 'templates/**/*.html').pipe(templateCache(options)).pipe(gulp.dest(TEMP_DIR + 'js'));
});
gulp.task('build-dev', ['images', 'i18n', 'resources', 'sass', 'fonts', 'select2', 'swagger-ui', 'template-cache'], function() {
var assets = useref.assets({
searchPath : [SRC_DIR, TEMP_DIR]
});
var jsFilter = filter("**/*.js");
var cssFilter = filter("**/*.css");
return gulp.src([SRC_DIR + 'index.html', TEMP_DIR + 'app.css']).pipe(assets).pipe(rev()).pipe(assets.restore()).pipe(useref()).pipe(
revReplace()).pipe(gulp.dest(BUILD_DIR)).pipe(connect.reload());
});
gulp.task('build', ['images', 'i18n', 'resources', 'sass', 'fonts', 'select2', 'swagger-ui', 'template-cache'], function() {
var assets = useref.assets({
searchPath : [SRC_DIR, TEMP_DIR]
});
var jsFilter = filter("**/*.js");
var cssFilter = filter("**/*.css");
return gulp.src([SRC_DIR + 'index.html', TEMP_DIR + 'app.css']).pipe(assets)
.pipe(cssFilter).pipe(minifyCSS()).pipe(cssFilter.restore())
.pipe(jsFilter).pipe(uglify()).pipe(jsFilter.restore())
.pipe(rev()).pipe(assets.restore()).pipe(useref()).pipe(revReplace()).pipe(gulp.dest(BUILD_DIR));
});
gulp.task('watch', function() {
gulp.watch(SRC_DIR + 'sass/**/*.scss', ['build-dev']);
gulp.watch(SRC_DIR + 'js/**/*.js', ['build-dev']);
gulp.watch(SRC_DIR + 'i18n/**/*.js', ['build-dev']);
gulp.watch(SRC_DIR + 'templates/**/*.html', ['build-dev']);
});
gulp.task('serve', function() {
connect.server({
root : BUILD_DIR,
port : 8082,
livereload : true,
middleware : function() {
var api = '^/api/(.*)$ http://localhost:8083/rest/$1 [P]';
var rest = '^/rest/(.*)$ http://localhost:8083/rest/$1 [P]';
var next = '^/next(.*)$ http://localhost:8083/next$1 [P]';
var logout = '^/logout$ http://localhost:8083/logout [P]';
var custom_css = '^/custom_css.css$ http://localhost:8083/custom_css.css [P]';
var analytics = '^/analytics.js http://localhost:8083/analytics.js [P]';
return [modRewrite([rest, next, logout, custom_css, analytics])];
}
});
});
gulp.task('dev', ['build-dev', 'watch', 'serve']);
gulp.task('default', ['build']);