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 | (function () { |
| 21 | 'use strict'; |
| 22 | |
| 23 | const gulp = require('gulp'); |
| 24 | const inject = require('gulp-inject'); |
| 25 | const angularFilesort = require('gulp-angular-filesort'); |
| 26 | const wiredep = require('wiredep').stream; |
| 27 | const path = require('path'); |
| 28 | const babel = require('gulp-babel'); |
| 29 | const sourcemaps = require('gulp-sourcemaps'); |
| 30 | const browserSync = require('browser-sync').create(); |
| 31 | module.exports = function(options){ |
| 32 | |
| 33 | console.log(options.xosHelperTmp, path.join(__dirname, `../${options.xosHelperTmp}`)); |
| 34 | |
| 35 | gulp.task('serveDevEnv', ['babelDev', 'wiredep', 'inject', 'injectStyle'], function(){ |
| 36 | browserSync.init({ |
| 37 | server: { |
| 38 | baseDir: ['./dev', './.tmp', './dist'], |
| 39 | // directory: true, |
| 40 | routes: { |
| 41 | '/bower_components': 'bower_components' |
| 42 | }, |
| 43 | } |
| 44 | }); |
| 45 | |
| 46 | gulp.watch([ |
| 47 | './src/**/*.js' |
| 48 | ], ['babelDev']); |
| 49 | |
| 50 | gulp.watch([ |
| 51 | './src/**/*.scss' |
| 52 | ], ['style']); |
| 53 | |
| 54 | gulp.watch([ |
| 55 | './dev/*.html', |
| 56 | './dev/*.js', |
| 57 | './.tmp/**/*.js' |
| 58 | ], function(){ |
| 59 | browserSync.reload(); |
| 60 | }); |
| 61 | }); |
| 62 | |
| 63 | gulp.task('babelDev', function(){ |
| 64 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 65 | .pipe(sourcemaps.init()) |
| 66 | .pipe(babel({ |
| 67 | presets: ['es2015'] |
| 68 | })) |
| 69 | .pipe(sourcemaps.write('./maps')) |
| 70 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 71 | }); |
| 72 | |
| 73 | gulp.task('inject', function(){ |
| 74 | const files = gulp.src([ |
| 75 | `${options.xosHelperTmp}**/*.js` |
| 76 | ]) |
| 77 | .pipe(angularFilesort()) |
| 78 | |
| 79 | return gulp.src('./dev/index.html') |
| 80 | .pipe(inject(files, {ignorePath: ['.tmp/']})) |
| 81 | .pipe(gulp.dest('./dev/')); |
| 82 | }); |
| 83 | |
| 84 | gulp.task('injectStyle', function(){ |
| 85 | const files = gulp.src([ |
| 86 | `${options.ngXosStyles}*.css` |
| 87 | ]) |
| 88 | |
| 89 | return gulp.src('./dev/index.html') |
| 90 | .pipe(inject(files, {ignorePath: ['dist/']})) |
| 91 | .pipe(gulp.dest('./dev/')); |
| 92 | }); |
| 93 | |
| 94 | |
| 95 | // inject bower dependencies with wiredep |
| 96 | gulp.task('wiredep', function () { |
| 97 | return gulp.src('./dev/index.html') |
| 98 | .pipe(wiredep({devDependencies: false})) |
| 99 | .pipe(gulp.dest('./dev')); |
| 100 | }); |
| 101 | }; |
| 102 | })(); |