Removed edit attribute code
[aai/sparky-fe.git] / gulpfile.js
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 'use strict';
22
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');
33
34 let appName = 'aai';
35 let dist = 'dist/';
36
37 let path = {
38         output: dist,
39         aaiOutput: dist + '/aai/',
40         assets: './resources/**/*.{css,png,svg,eot,ttf,woff,woff2,otf}',
41         json: './src/**/*.json',
42         aaiIndex: './src/index.html',
43         scss: './resources/scss/**/*.scss',
44         aaiCss: dist + '/css',
45         war: [dist + '**/*.html', dist + '**/*.js', dist + '**/*.{css,png,svg,eot,ttf,woff,woff2,otf}', dist + '**/*.json', 'webapp/**'],
46         bundleSrc:[dist + '**/*.map'],
47         wardest: dist
48 };
49
50 taskMaker.defineTask('clean', {taskName: 'clean', src: path.output});
51 taskMaker.defineTask('copy', {taskName: 'copy-aai-index.html', src: path.aaiIndex, dest: path.output, rename: 'index.html'});
52 taskMaker.defineTask('copy', {taskName: 'copy-map-file', src: path.bundleSrc, dest: path.output, rename: 'mappingFile'});
53 taskMaker.defineTask('clean', {taskName: 'clean-map-file', src: path.bundleSrc});
54 /** Uncomment the loine below to generate a .war file with a local build */
55 // taskMaker.defineTask('compress', {taskName: 'compress-war', src: path.war, filename: appName + '.war', dest: path.wardest})
56
57 gulp.task('copy-dev-stuff', callback => {
58         return runSequence(['copy-aai-index.html'], callback);
59 });
60
61 gulp.task('copy-stuff', callback => {
62         return runSequence(['copy-aai-index.html'], callback);
63 });
64
65 gulp.task('dev', callback => {
66         return runSequence('clean', 'copy-dev-stuff', 'webpack-dev-server', callback);
67 });
68
69 // Production build
70 gulp.task('build', callback => {
71         return runSequence('clean', ['copy-stuff'], 'prod', 'copy-map-file', 'clean-map-file', callback);
72         /** Uncomment the loine below to generate a .war file with a local build */
73         //return runSequence('clean', ['copy-stuff'], 'prod', 'compress-war', callback);
74 });
75
76
77 gulp.task('default', ['dev']);
78
79 gulp.task('prod', () => {
80
81         return new Promise((resolve, reject)=> {
82                 // configure webpack for production
83                 let webpackProductionConfig = webpackConfig;
84                 webpack(webpackProductionConfig, function (err, stats) {
85                         console.log('[webpack:build]', stats.toString());
86                         if (err || stats.hasErrors()) {
87                                 console.log('bundleJS : Failure!!');
88                                 reject();
89                         }
90                         else {
91                                 console.log('bundleJS : Done');
92                                 resolve();
93                         }
94                 });
95         });
96
97 });
98
99 gulp.task('webpack-dev-server', () => {
100         let myConfig = Object.create(devWebpackConfig);
101
102         // Start a webpack-dev-server
103         let server = new WebpackDevServer(webpack(myConfig), myConfig.devServer);
104         server.listen(myConfig.devServer.port, '0.0.0.0', err => {
105                 if (err) {
106                         throw new Error('webpack-dev-server' + err);
107                 }
108         });
109 });