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 gulpCssUsage = require('gulp-css-usage').default;
10 let prodTask = require('./tools/gulp/tasks/prod');
11 let i18nTask = require('./tools/gulp/tasks/i18n.js');
14 "appContextPath" : "/onboarding"
18 jsonConfig = require('./src/sdc-app/config/config.json');
20 console.log('could not load config. using default value instead');
23 const appName = 'onboarding';
28 json: './src/**/*.json',
29 index: './src/index.html',
30 heat: './src/heat.html',
31 scss: './resources/scss/**/*.scss',
32 i18nBundles: './src/nfvo-utils/i18n/*.json',
33 svgSrc: './resources/images/svg/*.svg',
34 appinf: './webapp-onboarding/**/*.*',
35 jetty: './webapp-onboarding/WEB-INF/jetty-web.xml',
40 svg: dist + '/resources/images/svg',
41 appinf_output: dist + '/webapp-onboarding',
43 war: [dist + '/index.html', dist + '/punch-outs*.js', dist + '/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '/**/*(config.json)', dist + '/webapp-onboarding/**'],
44 heatWar: [dist + '/heat.html', dist + '/heat-validation_en.js', dist + '/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '/**/*(config.json)', 'webapp-heat-validation/**'],
47 storybookFonts: './.storybook/fonts/*',
48 storybookDist: './.storybook-dist',
49 storybookResources: './.storybook/resources/onboarding/resources/images/svg',
50 storybookDistResources: './.storybook-dist/onboarding/resources/images/svg'
52 // cleans up the output directory
53 taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
54 // copies for all relevant files to the output directory
55 taskMaker.defineTask('copy', {taskName: 'copy-json', src: path.json, dest: path.output, changed: {extension: '.json'}});
56 taskMaker.defineTask('copy', {taskName: 'copy-index.html', src: path.index, dest: path.output, rename: 'index.html'});
57 taskMaker.defineTask('copy', {taskName: 'copy-heat.html', src: path.heat, dest: path.output, rename: 'heat.html'});
58 taskMaker.defineTask('copy', {taskName: 'copy-svg', src: path.svgSrc, dest: path.svg});
59 taskMaker.defineTask('copy', {taskName: 'copy-storybook-fonts', src: path.storybookFonts, dest: path.storybookDist});
60 taskMaker.defineTask('copy', {taskName: 'copy-storybook-resources', src: path.svgSrc, dest: path.storybookResources});
61 taskMaker.defineTask('copy', {taskName: 'copy-storybook-resources-prod', src: path.svgSrc, dest: path.storybookDistResources});
62 // used for compressing war files
63 taskMaker.defineTask('compress', {taskName: 'compress-war', src: path.war, filename: appName + '.war', dest: path.wardest});
64 taskMaker.defineTask('compress', {taskName: 'compress-heat-war', src: path.heatWar, filename: 'heat-validation.war', dest: path.wardest});
65 // used for watching for changes for test
66 taskMaker.defineTask('watch', {taskName: 'watch-stuff', src: [path.json, path.index, path.heat], tasks: ['copy-stuff']});
69 //TODO: delete this task after gulp-css-usage support for SCSS files
70 taskMaker.defineTask('sass', {taskName: 'sass', src: path.scss, dest: path.css, config: {outputStyle: 'compressed'}});
73 // update the app-context for the web-xml file to the value from the config
74 gulp.task('app-context', function(){
75 gulp.src([path.appinf])
76 .pipe(gulp.dest(path.appinf_output))
77 .on('end', function () {
78 gulp.src([path.jetty])
79 .pipe(replace(/<Set name="contextPath">.*<\/Set>/g, '<Set name="contextPath">'+jsonConfig.appContextPath+'</Set>'))
80 .pipe(gulp.dest(path.appinf_output + '/WEB-INF'));
83 // aggregates all copy tasks
84 gulp.task('copy-stuff', callback => runSequence(['copy-json', 'copy-index.html', 'copy-heat.html', 'copy-svg', 'app-context'], callback));
86 // minimum build for dev
87 gulp.task('dev', callback => runSequence('clean', 'copy-stuff', callback));
88 // build procedure for war file
89 gulp.task('build', callback => runSequence('clean', 'copy-stuff', 'prod', ['compress-war', 'compress-heat-war'], callback));
90 // default build is set to 'dev'
91 gulp.task('default', ['dev']);
92 // creating the webpack tasks for the production build
93 gulp.task('prod', () => prodTask({outDir: path.output, i18nBundles : path.i18nBundles})
95 if (err && err.stack) {
96 console.error(err, err.stack);
98 throw new Error('Webpack build FAILED');
103 * T O O L S . N O T P A R T O F B U I L D
106 // this is used to manually run on the sass files to check which classes are never used. not run as part of build.
107 // can be run as npm task
108 gulp.task('gulp-css-usage', () => {
109 return gulp.src('src/**/*.jsx').pipe(gulpCssUsage({css: path.css + '/style.css', babylon: ['objectRestSpread']}));
112 gulp.task('css-usage', () => {
113 runSequence('sass', 'gulp-css-usage');
117 gulp.task('static-keys-bundle', () => i18nTask({outDir: path.output, srcDir: path.srcDir})
119 throw new Error('static-keys-bundle FAILED');
123 gulp.task('static-keys-bundle-with-report', () => i18nTask({outDir: path.output, srcDir: path.srcDir, i18nBundles : path.i18nBundles })
125 throw new Error('static-keys-bundle FAILED');