blob: f26f1698f4cffa798ab1c9a6545a541c6cf6c6b2 [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/*eslint-env node */
2/*global require: true, module: true */
3
4'use strict';
5
Andrew Geissler7d6e6292018-05-24 12:06:58 -07006var options = require('../gulp-options.js'), gulp = require('gulp'),
Iftekharul Islam99d199f2017-03-24 15:28:25 -05007
8 // Base dependencies
Andrew Geissler7d6e6292018-05-24 12:06:58 -07009 clean = require('gulp-clean'), rename = require('gulp-rename'),
Iftekharul Islam99d199f2017-03-24 15:28:25 -050010 util = require('gulp-util'),
11
12 // Angular gulp dependencies
13 ngTemplateCache = require('gulp-angular-templatecache'),
14 ngAnnotate = require('gulp-ng-annotate'),
15 ngConstant = require('gulp-ng-constant'),
16
17 // Classical gulp dependencies
Andrew Geissler7d6e6292018-05-24 12:06:58 -070018 stripDebug = require('gulp-strip-debug'), uglify = require('gulp-uglify'),
19 sass = require('gulp-sass'), cleanCss = require('gulp-clean-css'),
20 rev = require('gulp-rev'), revReplace = require('gulp-rev-replace'),
21 gulpIf = require('gulp-if'), useref = require('gulp-useref'),
Iftekharul Islam99d199f2017-03-24 15:28:25 -050022 jsoncombine = require('gulp-jsoncombine'),
23 htmlParser = require('gulp-htmlparser');
24
25
Andrew Geissler7d6e6292018-05-24 12:06:58 -070026var runSequence = require('run-sequence'), es = require('event-stream');
Iftekharul Islam99d199f2017-03-24 15:28:25 -050027
Andrew Geissler7d6e6292018-05-24 12:06:58 -070028gulp.task('webapp:clean', function() {
29 return gulp
30 .src(
31 [options.targetFolderPath + '/webapp', options.dirname + '/.temp'],
32 {'read': false})
33 .pipe(clean({'force': true}));
Iftekharul Islam99d199f2017-03-24 15:28:25 -050034});
35
Andrew Geissler7d6e6292018-05-24 12:06:58 -070036gulp.task('webapp:sasscompile', function() {
37 return gulp.src('app/styles/index.scss')
38 .pipe(sass.sync().on('error', util.log))
39 .pipe(gulp.dest(options.srcFolderPath + '/styles'));
Iftekharul Islam99d199f2017-03-24 15:28:25 -050040});
41
42// ----- To .temp from app
Andrew Geissler7d6e6292018-05-24 12:06:58 -070043gulp.task('webapp:copyjs', function() {
44 return gulp.src(options.srcFolderPath + '/**/*.js')
45 .pipe(ngAnnotate()) // Check angular dependencies injection
46 .pipe(stripDebug()) // Remove all logs
47 .pipe(uglify({'mangle': false}))
48 .pipe(gulp.dest(options.dirname + '/.temp'));
Iftekharul Islam99d199f2017-03-24 15:28:25 -050049});
50
Andrew Geissler7d6e6292018-05-24 12:06:58 -070051gulp.task('webapp:copyothers', function() {
52 return gulp
53 .src(
54 ['**/*', '!**/*.js', '!**/*.css', '!**/*.scss'],
55 {'cwd': options.srcFolderPath}) // All except JS files
56 .pipe(gulp.dest(options.tempFolderPath));
Iftekharul Islam99d199f2017-03-24 15:28:25 -050057});
58
Andrew Geissler7d6e6292018-05-24 12:06:58 -070059gulp.task('webapp:copycss', function() {
60 return gulp.src('app/styles/index.css')
61 .pipe(cleanCss())
62 .pipe(gulp.dest(options.tempFolderPath + '/styles'));
Iftekharul Islam99d199f2017-03-24 15:28:25 -050063});
64
Iftekharul Islam99d199f2017-03-24 15:28:25 -050065// ----- To target/webapp from .temp and bower_components
Andrew Geissler7d6e6292018-05-24 12:06:58 -070066gulp.task('webapp:template', function() {
67 return gulp
68 .src([
69 options.srcFolderPath + '/**/*.html',
70 '!' + options.srcFolderPath + '/index.html'
71 ])
72 .pipe(ngTemplateCache(
73 'templates.js', {'module': 'app.templates', 'standalone': true}))
74 .pipe(gulp.dest(options.tempFolderPath));
Iftekharul Islam99d199f2017-03-24 15:28:25 -050075});
76
Andrew Geissler7d6e6292018-05-24 12:06:58 -070077gulp.task('webapp:useref', function() {
78 var tasks = ['index.html'].map(function(indexPage) {
79 var assets = useref.assets({});
Iftekharul Islam99d199f2017-03-24 15:28:25 -050080
Andrew Geissler7d6e6292018-05-24 12:06:58 -070081 return gulp.src(options.tempFolderPath + '/' + indexPage)
82 .pipe(assets)
83 .pipe(assets.restore())
84 .pipe(useref())
85 .pipe(revReplace()) // Force useref to apply the 'rev' method
Iftekharul Islam99d199f2017-03-24 15:28:25 -050086 .pipe(gulp.dest(options.targetFolderPath + '/webapp'));
Andrew Geissler7d6e6292018-05-24 12:06:58 -070087 });
88
89 return es.concat.apply(null, tasks);
Iftekharul Islam99d199f2017-03-24 15:28:25 -050090});
91
Andrew Geissler7d6e6292018-05-24 12:06:58 -070092gulp.task('webapp:copyresources', function() {
93 return gulp
94 .src(
95 ['**/*.*', '!**/*.js', '!**/*.css', '!**/*.html', '!**/*.log'],
96 {'cwd': options.tempFolderPath})
97 .pipe(gulp.dest(options.targetFolderPath + '/webapp'));
98});
99
100module.exports = function(callback) {
101 return runSequence(
102 'webapp:clean', 'webapp:sasscompile',
103 ['webapp:copyjs', 'webapp:copycss', 'webapp:copyothers'],
Gunnar Mills2b9a0d92018-07-11 15:10:08 -0500104 ['webapp:template'], ['webapp:useref'], ['webapp:copyresources'],
105 callback);
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500106};