3 let gulp = require('gulp');
4 let gulpHelpers = require('gulp-helpers');
5 let replace = require('gulp-replace');
6 let taskMaker = gulpHelpers.taskMaker(gulp);
7 let runSequence = gulpHelpers.framework('run-sequence');
8 let i18nTask = require('./tools/gulp/tasks/i18n');
9 let prodTask = require('./tools/gulp/tasks/prod');
10 let gulpCssUsage = require('gulp-css-usage').default;
12 "appContextPath" : "/onboarding"
16 jsonConfig = require('./src/sdc-app/config/config.json');
18 console.log('could not load config. using deault value instead');
21 const appName = 'onboarding';
25 jetty: './webapp-onboarding/WEB-INF/jetty-web.xml',
26 appinf: './webapp-onboarding/**/*.*',
27 appinf_output: dist + '/webapp-onboarding',
28 locales: dist + '/i18n/',
30 json: './src/**/*.json',
31 index: './src/index.html',
32 heat: './src/heat.html',
33 scss: './resources/scss/**/*.scss',
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/**'],
40 storybookFonts: './.storybook/fonts/*',
41 storybookDist: './.storybook-dist',
42 storybookResources: './.storybook/resources/onboarding/resources/images/svg',
43 storybookDistResources: './.storybook-dist/onboarding/resources/images/svg'
46 taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
47 taskMaker.defineTask('copy', {taskName: 'copy-json', src: path.json, dest: path.output, changed: {extension: '.json'}});
48 taskMaker.defineTask('copy', {taskName: 'copy-index.html', src: path.index, dest: path.output, rename: 'index.html'});
49 taskMaker.defineTask('copy', {taskName: 'copy-heat.html', src: path.heat, dest: path.output, rename: 'heat.html'});
50 taskMaker.defineTask('copy', {taskName: 'copy-svg', src: path.svgSrc, dest: path.svg});
51 //TODO: delete this task after gulp-css-usage support for SCSS files
52 taskMaker.defineTask('sass', {taskName: 'sass', src: path.scss, dest: path.css, config: {outputStyle: 'compressed'}});
53 taskMaker.defineTask('compress', {taskName: 'compress-war', src: path.war, filename: appName + '.war', dest: path.wardest});
54 taskMaker.defineTask('compress', {taskName: 'compress-heat-war', src: path.heatWar, filename: 'heat-validation.war', dest: path.wardest});
55 taskMaker.defineTask('watch', {taskName: 'watch-stuff', src: [path.json, path.index, path.heat], tasks: ['copy-stuff']});
56 taskMaker.defineTask('copy', {taskName: 'copy-storybook-fonts', src: path.storybookFonts, dest: path.storybookDist});
57 taskMaker.defineTask('copy', {taskName: 'copy-storybook-resources', src: path.svgSrc, dest: path.storybookResources});
58 taskMaker.defineTask('copy', {taskName: 'copy-storybook-resources-prod', src: path.svgSrc, dest: path.storybookDistResources});
60 gulp.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'));
70 gulp.task('copy-stuff', callback => runSequence(['copy-json', 'copy-index.html', 'copy-heat.html', 'copy-svg', 'app-context'], callback));
72 gulp.task('i18n', () =>
73 i18nTask({outputPath: path.output, localesPath: path.locales, lang: 'en'}).catch(err => {
74 console.log('i18n Task : Error! ', err);
79 gulp.task('dev', callback => runSequence('clean', ['i18n', 'copy-stuff'], callback));
80 gulp.task('build', callback => runSequence('clean', ['copy-stuff', 'i18n'], 'prod', ['compress-war', 'compress-heat-war'], callback));
82 gulp.task('default', ['dev']);
84 gulp.task('prod', () => prodTask({outDir: path.output})
86 if (err && err.stack) {
87 console.error(err, err.stack);
89 throw new Error('Webpack build FAILED');
94 gulp.task('gulp-css-usage', () => {
95 return gulp.src('src/**/*.jsx').pipe(gulpCssUsage({css: path.css + '/style.css', babylon: ['objectRestSpread']}));
98 gulp.task('css-usage', () => {
99 runSequence('sass', 'gulp-css-usage');