blob: 2cad6d85200287b998cd37b975561b63960ccc31 [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001'use strict';
2
AviZi280f8012017-06-09 02:39:56 +03003let gulp = require('gulp');
4let gulpHelpers = require('gulp-helpers');
5let replace = require('gulp-replace');
6let taskMaker = gulpHelpers.taskMaker(gulp);
7let runSequence = gulpHelpers.framework('run-sequence');
8let i18nTask = require('./tools/gulp/tasks/i18n');
9let prodTask = require('./tools/gulp/tasks/prod');
10let gulpCssUsage = require('gulp-css-usage').default;
11let jsonConfig = {
12 "appContextPath" : "/onboarding"
13};
Michael Landoefa037d2017-02-19 12:57:33 +020014
Michael Landoefa037d2017-02-19 12:57:33 +020015try {
AviZi280f8012017-06-09 02:39:56 +030016 jsonConfig = require('./src/sdc-app/config/config.json');
Michael Landoefa037d2017-02-19 12:57:33 +020017} catch (e) {
AviZi280f8012017-06-09 02:39:56 +030018 console.log('could not load config. using deault value instead');
Michael Landoefa037d2017-02-19 12:57:33 +020019}
20
AviZi280f8012017-06-09 02:39:56 +030021const appName = 'onboarding';
22const dist = 'dist';
23
24const path = {
25 jetty: './webapp-onboarding/WEB-INF/jetty-web.xml',
26 appinf: './webapp-onboarding/**/*.*',
27 appinf_output: dist + '/webapp-onboarding',
28 locales: dist + '/i18n/',
29 output: dist,
30 json: './src/**/*.json',
31 index: './src/index.html',
32 heat: './src/heat.html',
33 scss: './resources/scss/**/*.scss',
34 css: dist + '/css',
35 svgSrc: './resources/images/svg/*.svg',
36 svg: dist + '/resources/images/svg',
37 war: [dist + '/index.html', dist + '/punch-outs_en.js', dist + '/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '/**/*(config.json|locale.json)', 'tools/gulp/deployment/**', dist + '/webapp-onboarding/**'],
38 heatWar: [dist + '/heat.html', dist + '/heat-validation_en.js', dist + '/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '/**/*(config.json|locale.json)', 'webapp-heat-validation/**'],
39 wardest: dist,
40 storybookFonts: './.storybook/fonts/*',
41 storybookDist: './.storybook-dist',
42 storybookResources: './.storybook/resources/onboarding/resources/images/svg',
43 storybookDistResources: './.storybook-dist/onboarding/resources/images/svg'
44};
45
46taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
47taskMaker.defineTask('copy', {taskName: 'copy-json', src: path.json, dest: path.output, changed: {extension: '.json'}});
48taskMaker.defineTask('copy', {taskName: 'copy-index.html', src: path.index, dest: path.output, rename: 'index.html'});
49taskMaker.defineTask('copy', {taskName: 'copy-heat.html', src: path.heat, dest: path.output, rename: 'heat.html'});
50taskMaker.defineTask('copy', {taskName: 'copy-svg', src: path.svgSrc, dest: path.svg});
51//TODO: delete this task after gulp-css-usage support for SCSS files
52taskMaker.defineTask('sass', {taskName: 'sass', src: path.scss, dest: path.css, config: {outputStyle: 'compressed'}});
53taskMaker.defineTask('compress', {taskName: 'compress-war', src: path.war, filename: appName + '.war', dest: path.wardest});
54taskMaker.defineTask('compress', {taskName: 'compress-heat-war', src: path.heatWar, filename: 'heat-validation.war', dest: path.wardest});
55taskMaker.defineTask('watch', {taskName: 'watch-stuff', src: [path.json, path.index, path.heat], tasks: ['copy-stuff']});
56taskMaker.defineTask('copy', {taskName: 'copy-storybook-fonts', src: path.storybookFonts, dest: path.storybookDist});
57taskMaker.defineTask('copy', {taskName: 'copy-storybook-resources', src: path.svgSrc, dest: path.storybookResources});
58taskMaker.defineTask('copy', {taskName: 'copy-storybook-resources-prod', src: path.svgSrc, dest: path.storybookDistResources});
59
60gulp.task('app-context', function(){
61 gulp.src([path.appinf])
62 .pipe(gulp.dest(path.appinf_output))
63 .on('end', function () {
64 gulp.src([path.jetty])
65 .pipe(replace(/<Set name="contextPath">.*<\/Set>/g, '<Set name="contextPath">'+jsonConfig.appContextPath+'</Set>'))
66 .pipe(gulp.dest(path.appinf_output + '/WEB-INF'));
67 })
Michael Landoefa037d2017-02-19 12:57:33 +020068});
69
AviZi280f8012017-06-09 02:39:56 +030070gulp.task('copy-stuff', callback => runSequence(['copy-json', 'copy-index.html', 'copy-heat.html', 'copy-svg', 'app-context'], callback));
71
72gulp.task('i18n', () =>
73 i18nTask({outputPath: path.output, localesPath: path.locales, lang: 'en'}).catch(err => {
74 console.log('i18n Task : Error! ', err);
75 throw err;
76 })
77);
78
79gulp.task('dev', callback => runSequence('clean', ['i18n', 'copy-stuff'], callback));
80gulp.task('build', callback => runSequence('clean', ['copy-stuff', 'i18n'], 'prod', ['compress-war', 'compress-heat-war'], callback));
Michael Landoefa037d2017-02-19 12:57:33 +020081
82gulp.task('default', ['dev']);
83
AviZi280f8012017-06-09 02:39:56 +030084gulp.task('prod', () => prodTask({outDir: path.output})
85 .catch(err => {
86 if (err && err.stack) {
87 console.error(err, err.stack);
Michael Landoefa037d2017-02-19 12:57:33 +020088 }
AviZi280f8012017-06-09 02:39:56 +030089 throw new Error('Webpack build FAILED');
Michael Landoefa037d2017-02-19 12:57:33 +020090 })
AviZi280f8012017-06-09 02:39:56 +030091);
92
93
94gulp.task('gulp-css-usage', () => {
95 return gulp.src('src/**/*.jsx').pipe(gulpCssUsage({css: path.css + '/style.css', babylon: ['objectRestSpread']}));
Michael Landoefa037d2017-02-19 12:57:33 +020096});
97
AviZi280f8012017-06-09 02:39:56 +030098gulp.task('css-usage', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020099 runSequence('sass', 'gulp-css-usage');
100});
101