3 let gulp = require('gulp');
5 let replace = require('gulp-replace');
6 let del = require('del');
7 let zip = require('gulp-zip');
8 let gulpSass = require('gulp-sass');
9 let runSequence = require('run-sequence');
10 let gulpCssUsage = require('gulp-css-usage').default;
11 let prodTask = require('./tools/gulp/tasks/prod');
12 let i18nTask = require('./tools/gulp/tasks/i18n.js');
15 "appContextPath" : "/onboarding"
19 jsonConfig = require('./src/sdc-app/config/config.json');
21 console.log('could not load config. using default value instead');
24 const appName = 'onboarding';
29 json: './src/**/*.json',
30 index: './src/index.html',
31 heat: './src/heat.html',
32 scss: './resources/scss/**/*.scss',
33 i18nBundles: './src/nfvo-utils/i18n/*.json',
34 svgSrc: './resources/images/svg/*.svg',
35 appinf: './webapp-onboarding/**/*.*',
36 jetty: './webapp-onboarding/WEB-INF/jetty-web.xml',
37 healthCheckInput: './external-resources/healthcheck/healthcheck',
42 // svg: dist + '/resources/images/svg',
43 appinf_output: dist + '/webapp-onboarding',
44 healthCheckOutput: dist + '/v1.0',
46 war: [dist + '/index.html', dist + '/punch-outs*.js', dist + '/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '/**/*(config.json)', dist + '/webapp-onboarding/**', dist + '/**/*(healthcheck)'],
47 heatWar: [dist + '/heat.html', dist + '/heat-validation_en.js', dist + '/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '/**/*(config.json)', 'webapp-heat-validation/**'],
50 storybookFonts: './.storybook/fonts/*',
51 storybookDist: './.storybook-dist',
52 //storybookResources: './.storybook/resources/onboarding/resources/images/svg',
53 //storybookDistResources: './.storybook-dist/onboarding/resources/images/svg'
55 // cleans up the output directory
57 gulp.task('clean', callback => {
58 return del([path.output], callback);
60 // copies for all relevant files to the output directory'
62 gulp.task('copy-json', () => {
64 .pipe(gulp.dest(path.output));
67 gulp.task('copy-index.html', () => {
69 .pipe(gulp.dest(path.output));
72 gulp.task('copy-heat.html', () => {
74 .pipe(gulp.dest(path.output));
77 gulp.task('copy-storybook-fonts', () => {
78 gulp.src(path.storybookFonts)
79 .pipe(gulp.dest(path.storybookDist));
82 // used for compressing war files
87 gulp.task('compress-war', ()=> {
89 .pipe(zip(appName + '.war'))
90 .pipe(gulp.dest(path.wardest));
93 gulp.task('compress-heat-war', ()=> {
94 gulp.src(path.heatWar)
95 .pipe(zip('heat-validation.war'))
96 .pipe(gulp.dest(path.wardest));
99 //TODO: delete this task after gulp-css-usage support for SCSS files
100 gulp.task('sass', () => {
101 return gulp.src(path.scss)
102 .pipe(gulpSass({outputStyle: 'compressed'}).on('error', gulpSass.logError))
103 .pipe(gulp.dest(path.css));
108 // copy the healthcheck file and replace the version with command line argument
109 gulp.task('healthcheck', function(){
110 let args = process.argv;
111 let versionArg = args.find(arg => arg.startsWith('--version'));
112 let version = versionArg && versionArg.slice(versionArg.indexOf('=') + 1);
114 gulp.src(path.healthCheckInput)
115 .pipe(replace('{VERSION}', version))
116 .pipe(gulp.dest(path.healthCheckOutput));
120 // update the app-context for the web-xml file to the value from the config
121 gulp.task('app-context', function(){
122 gulp.src([path.appinf])
123 .pipe(gulp.dest(path.appinf_output))
124 .on('end', function () {
125 gulp.src([path.jetty])
126 .pipe(replace(/<Set name="contextPath">.*<\/Set>/g, '<Set name="contextPath">'+jsonConfig.appContextPath+'</Set>'))
127 .pipe(gulp.dest(path.appinf_output + '/WEB-INF'));
130 // aggregates all copy tasks
131 gulp.task('copy-stuff', callback => runSequence(['copy-json', 'copy-index.html', 'copy-heat.html', 'app-context'], callback));
133 // minimum build for dev
134 gulp.task('dev', callback => runSequence('clean', 'copy-stuff', callback));
135 // build procedure for war file
136 gulp.task('build', callback => runSequence('clean', 'copy-stuff', 'healthcheck', 'prod', ['compress-war', 'compress-heat-war'], callback));
137 // default build is set to 'dev'
138 gulp.task('default', ['dev']);
139 // creating the webpack tasks for the production build
140 gulp.task('prod', () => prodTask({outDir: path.output, i18nBundles : path.i18nBundles})
142 if (err && err.stack) {
143 console.error(err, err.stack);
145 throw new Error('Webpack build FAILED');
150 * T O O L S . N O T P A R T O F B U I L D
153 // this is used to manually run on the sass files to check which classes are never used. not run as part of build.
154 // can be run as npm task
155 gulp.task('gulp-css-usage', () => {
156 return gulp.src('src/**/*.jsx').pipe(gulpCssUsage({css: path.css + '/style.css', babylon: ['objectRestSpread']}));
159 gulp.task('css-usage', () => {
160 runSequence('sass', 'gulp-css-usage');
164 gulp.task('static-keys-bundle', () => i18nTask({outDir: path.output, srcDir: path.srcDir})
166 throw new Error('static-keys-bundle FAILED');
170 gulp.task('static-keys-bundle-with-report', () => i18nTask({outDir: path.output, srcDir: path.srcDir, i18nBundles : path.i18nBundles })
172 throw new Error('static-keys-bundle FAILED');