Matteo Scandolo | 686547a | 2017-08-08 13:05:25 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | a5d03d5 | 2016-07-21 11:35:46 -0700 | [diff] [blame] | 19 | /*eslint-env node */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
| 24 | const gulp = require('gulp'); |
| 25 | const uglify = require('gulp-uglify'); |
| 26 | const concat = require('gulp-concat'); |
| 27 | const ngAnnotate = require('gulp-ng-annotate'); |
| 28 | const angularFilesort = require('gulp-angular-filesort'); |
| 29 | const del = require('del'); |
| 30 | const babel = require('gulp-babel'); |
| 31 | const sourcemaps = require('gulp-sourcemaps'); |
| 32 | const rename = require('gulp-rename'); |
| 33 | const sass = require('gulp-sass'); |
| 34 | |
| 35 | module.exports = function(options){ |
| 36 | |
| 37 | // delete previous builded file |
| 38 | gulp.task('cleanLib', function(){ |
| 39 | return del( |
| 40 | [ |
| 41 | `${options.ngXosVendor}/ngXosHelpers.min.js`, |
| 42 | `${options.ngXosVendor}/xosUiComponents.js`, |
| 43 | `${options.ngXosVendor}/ngXos.css` |
| 44 | ], |
| 45 | {force: true} |
| 46 | ); |
| 47 | }); |
| 48 | |
| 49 | gulp.task('style', function(){ |
| 50 | return gulp.src(`${options.xosHelperSource}styles/main.scss`) |
| 51 | .pipe(sourcemaps.init()) |
| 52 | .pipe(sass().on('error', sass.logError)) |
| 53 | .pipe(rename('xosNgLib.css')) |
| 54 | .pipe(sourcemaps.write()) |
| 55 | .pipe(gulp.dest(options.ngXosStyles)); |
| 56 | }); |
| 57 | |
| 58 | // transpile js with sourceMaps |
| 59 | gulp.task('babel', function(){ |
| 60 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 61 | .pipe(babel({ |
| 62 | presets: ['es2015'] |
| 63 | })) |
| 64 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 65 | }); |
| 66 | |
| 67 | // build |
| 68 | gulp.task('helpers', ['cleanLib', 'babel', 'style'], function(){ |
| 69 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
| 70 | .pipe(angularFilesort()) |
| 71 | .pipe(concat('ngXosHelpers.min.js')) |
| 72 | .pipe(ngAnnotate()) |
| 73 | .pipe(uglify()) |
| 74 | .pipe(gulp.dest(options.ngXosVendor)); |
| 75 | }); |
| 76 | |
| 77 | // build Dev (no minify, sourcemaps), for development purposes |
| 78 | // gulp.task('helpersDev', ['babelDev'], function(){ |
| 79 | // return gulp.src([options.xosHelperTmp + '**/*.js']) |
| 80 | // .pipe(angularFilesort()) |
| 81 | // .pipe(concat('ngXosHelpers.js')) |
| 82 | // .pipe(ngAnnotate()) |
| 83 | // .pipe(gulp.dest(options.ngXosVendor)); |
| 84 | // }); |
| 85 | |
| 86 | // concat only UI Components (for free use) |
| 87 | gulp.task('uiLibrary', function(){ |
| 88 | return gulp.src([ |
| 89 | options.xosHelperTmp + '**/*.js', |
| 90 | !options.xosHelperTmp + 'services/rest/*.js' |
| 91 | ]) |
| 92 | .pipe(angularFilesort()) |
| 93 | .pipe(concat('xosUiComponents.js')) |
| 94 | .pipe(ngAnnotate()) |
| 95 | .pipe(gulp.dest(options.ngXosVendor)); |
| 96 | }); |
| 97 | |
| 98 | gulp.task('dev', function(){ |
| 99 | gulp.watch(`${options.xosHelperSource}**/*.scss`, ['style']); |
| 100 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 101 | }); |
| 102 | }; |
| 103 | })(); |