2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
25 var localPath = require('path');
26 var gulp = require('gulp');
27 var gulpHelpers = require('gulp-helpers');
28 var taskMaker = gulpHelpers.taskMaker(gulp);
29 var runSequence = gulpHelpers.framework('run-sequence');
30 var gulpCssUsage = require('gulp-css-usage').default;
31 var webpack = require('webpack');
32 var WebpackDevServer = require('webpack-dev-server');
33 var devWebpackConfig = require('./webpack.devConfig.js');
34 var webpackConfig = require('./webpack.config');
41 aaiOutput: dist + '/aai/',
42 saOutput: dist + '/editAttributes/',
43 assets: './resources/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}',
44 json: './src/**/*.json',
45 aaiIndex: './src/index.html',
46 saIndex: './src/editAttributes/index.html',
47 scss: './resources/scss/**/*.scss',
48 aaiCss: dist + '/css',
49 saCss: dist + '/editAttributes/css',
50 war: [dist + '**/*.html', dist + '**/*.js', dist + '**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '**/*.json', 'webapp/**'],
54 taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
55 taskMaker.defineTask('copy', {taskName: 'copy-aai-index.html', src: path.aaiIndex, dest: path.output, rename: 'index.html'});
56 taskMaker.defineTask('copy', {taskName: 'copy-sa-index.html', src: path.saIndex, dest: path.saOutput, rename: 'index.html'});
57 /** Uncomment the loine below to generate a .war file with a local build */
58 // taskMaker.defineTask('compress', {taskName: 'compress-war', src: path.war, filename: appName + '.war', dest: path.wardest})
60 gulp.task('copy-dev-stuff', callback => {
61 return runSequence(['copy-aai-index.html', 'copy-sa-index.html'], callback);
64 gulp.task('copy-stuff', callback => {
65 return runSequence(['copy-aai-index.html', 'copy-sa-index.html'], callback);
68 gulp.task('dev', callback => {
69 return runSequence('clean', 'copy-dev-stuff', 'webpack-dev-server', callback);
73 gulp.task('build', callback => {
74 return runSequence('clean', ['copy-stuff'], 'prod', callback);
75 /** Uncomment the loine below to generate a .war file with a local build */
76 //return runSequence('clean', ['copy-stuff'], 'prod', 'compress-war', callback);
80 gulp.task('default', ['dev']);
82 gulp.task('prod', () => {
84 return new Promise((resolve, reject)=> {
85 // configure webpack for production
86 let webpackProductionConfig = Object.create(webpackConfig);
88 for (let name in webpackProductionConfig.entry) {
89 webpackProductionConfig.entry[name] = webpackProductionConfig.entry[name].filter(path => !path.startsWith('webpack'));
92 webpackProductionConfig.cache = true;
93 webpackProductionConfig.output = {
94 path: localPath.join(__dirname, 'dist'),
95 publicPath: '/services/aai/webapp/',
98 webpackProductionConfig.resolveLoader = {
99 root: [localPath.resolve('.')],
101 'config-json-loader': 'tools/webpack/config-json-loader/index.js'
105 // remove source maps
106 webpackProductionConfig.devtool = undefined;
107 webpackProductionConfig.module.preLoaders = webpackProductionConfig.module.preLoaders.filter(preLoader => preLoader.loader != 'source-map-loader');
108 webpackProductionConfig.module.loaders.forEach(loader => {
109 if (loader.loaders && loader.loaders[0] === 'style') {
110 loader.loaders = loader.loaders.map(loaderName => loaderName.replace('?sourceMap', ''));
114 webpackProductionConfig.module.loaders.push({test: /config.json$/, loaders: ['config-json-loader']});
115 webpackProductionConfig.eslint = {
116 configFile: './.eslintrc',
119 webpackProductionConfig.plugins = [
120 new webpack.DefinePlugin({
122 // This has effect on the react lib size
123 'NODE_ENV': JSON.stringify('production')
128 new webpack.optimize.DedupePlugin(),
129 new webpack.optimize.UglifyJsPlugin()
132 // run production build
133 webpack(webpackProductionConfig, function (err, stats) {
134 console.log('[webpack:build]', stats.toString());
135 if (err || stats.hasErrors()) {
136 console.log('bundleJS : Failure!!');
140 console.log('bundleJS : Done');
149 gulp.task('webpack-dev-server', () => {
150 let myConfig = Object.create(devWebpackConfig);
152 // Start a webpack-dev-server
153 let server = new WebpackDevServer(webpack(myConfig), myConfig.devServer);
154 server.listen(myConfig.devServer.port, '0.0.0.0', err => {
156 throw new Error('webpack-dev-server' + err);