2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
23 var localPath = require('path');
24 var gulp = require('gulp');
25 var gulpHelpers = require('gulp-helpers');
26 var taskMaker = gulpHelpers.taskMaker(gulp);
27 var runSequence = gulpHelpers.framework('run-sequence');
28 var gulpCssUsage = require('gulp-css-usage').default;
29 var webpack = require('webpack');
30 var WebpackDevServer = require('webpack-dev-server');
31 var devWebpackConfig = require('./webpack.devConfig.js');
32 var webpackConfig = require('./webpack.config');
39 aaiOutput: dist + '/aai/',
40 saOutput: dist + '/editAttributes/',
41 assets: './resources/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}',
42 json: './src/**/*.json',
43 aaiIndex: './src/index.html',
44 saIndex: './src/editAttributes/index.html',
45 scss: './resources/scss/**/*.scss',
46 aaiCss: dist + '/css',
47 saCss: dist + '/editAttributes/css',
48 war: [dist + '**/*.html', dist + '**/*.js', dist + '**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '**/*.json', 'webapp/**'],
52 taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
53 taskMaker.defineTask('copy', {taskName: 'copy-aai-index.html', src: path.aaiIndex, dest: path.output, rename: 'index.html'});
54 taskMaker.defineTask('copy', {taskName: 'copy-sa-index.html', src: path.saIndex, dest: path.saOutput, rename: 'index.html'});
55 /** Uncomment the loine below to generate a .war file with a local build */
56 // taskMaker.defineTask('compress', {taskName: 'compress-war', src: path.war, filename: appName + '.war', dest: path.wardest})
58 gulp.task('copy-dev-stuff', callback => {
59 return runSequence(['copy-aai-index.html', 'copy-sa-index.html'], callback);
62 gulp.task('copy-stuff', callback => {
63 return runSequence(['copy-aai-index.html', 'copy-sa-index.html'], callback);
66 gulp.task('dev', callback => {
67 return runSequence('clean', 'copy-dev-stuff', 'webpack-dev-server', callback);
71 gulp.task('build', callback => {
72 return runSequence('clean', ['copy-stuff'], 'prod', callback);
73 /** Uncomment the loine below to generate a .war file with a local build */
74 //return runSequence('clean', ['copy-stuff'], 'prod', 'compress-war', callback);
78 gulp.task('default', ['dev']);
80 gulp.task('prod', () => {
82 return new Promise((resolve, reject)=> {
83 // configure webpack for production
84 let webpackProductionConfig = Object.create(webpackConfig);
86 for (let name in webpackProductionConfig.entry) {
87 webpackProductionConfig.entry[name] = webpackProductionConfig.entry[name].filter(path => !path.startsWith('webpack'));
90 webpackProductionConfig.cache = true;
91 webpackProductionConfig.output = {
92 path: localPath.join(__dirname, 'dist'),
93 publicPath: '/services/aai/webapp/',
96 webpackProductionConfig.resolveLoader = {
97 root: [localPath.resolve('.')],
99 'config-json-loader': 'tools/webpack/config-json-loader/index.js'
103 // remove source maps
104 webpackProductionConfig.devtool = undefined;
105 webpackProductionConfig.module.preLoaders = webpackProductionConfig.module.preLoaders.filter(preLoader => preLoader.loader != 'source-map-loader');
106 webpackProductionConfig.module.loaders.forEach(loader => {
107 if (loader.loaders && loader.loaders[0] === 'style') {
108 loader.loaders = loader.loaders.map(loaderName => loaderName.replace('?sourceMap', ''));
112 webpackProductionConfig.module.loaders.push({test: /config.json$/, loaders: ['config-json-loader']});
113 webpackProductionConfig.eslint = {
114 configFile: './.eslintrc',
117 webpackProductionConfig.plugins = [
118 new webpack.DefinePlugin({
120 // This has effect on the react lib size
121 'NODE_ENV': JSON.stringify('production')
126 new webpack.optimize.DedupePlugin(),
127 new webpack.optimize.UglifyJsPlugin()
130 // run production build
131 webpack(webpackProductionConfig, function (err, stats) {
132 console.log('[webpack:build]', stats.toString());
133 if (err || stats.hasErrors()) {
134 console.log('bundleJS : Failure!!');
138 console.log('bundleJS : Done');
147 gulp.task('webpack-dev-server', () => {
148 let myConfig = Object.create(devWebpackConfig);
150 // Start a webpack-dev-server
151 let server = new WebpackDevServer(webpack(myConfig), myConfig.devServer);
152 server.listen(myConfig.devServer.port, '0.0.0.0', err => {
154 throw new Error('webpack-dev-server' + err);