Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 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; |
| 11 | let jsonConfig = { |
| 12 | "appContextPath" : "/onboarding" |
| 13 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 14 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | try { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 16 | jsonConfig = require('./src/sdc-app/config/config.json'); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | } catch (e) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 18 | console.log('could not load config. using deault value instead'); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | } |
| 20 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 21 | const appName = 'onboarding'; |
| 22 | const dist = 'dist'; |
| 23 | |
| 24 | const 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 | |
| 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}); |
| 59 | |
| 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')); |
| 67 | }) |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 68 | }); |
| 69 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 70 | gulp.task('copy-stuff', callback => runSequence(['copy-json', 'copy-index.html', 'copy-heat.html', 'copy-svg', 'app-context'], callback)); |
| 71 | |
| 72 | gulp.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 | |
| 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)); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | |
| 82 | gulp.task('default', ['dev']); |
| 83 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 84 | gulp.task('prod', () => prodTask({outDir: path.output}) |
| 85 | .catch(err => { |
| 86 | if (err && err.stack) { |
| 87 | console.error(err, err.stack); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 88 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 89 | throw new Error('Webpack build FAILED'); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 90 | }) |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 91 | ); |
| 92 | |
| 93 | |
| 94 | gulp.task('gulp-css-usage', () => { |
| 95 | return gulp.src('src/**/*.jsx').pipe(gulpCssUsage({css: path.css + '/style.css', babylon: ['objectRestSpread']})); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 96 | }); |
| 97 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 98 | gulp.task('css-usage', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 99 | runSequence('sass', 'gulp-css-usage'); |
| 100 | }); |
| 101 | |