blob: ee51e3f1f78ec17c9996ed91864c461d0e1d2e1f [file] [log] [blame]
Matteo Scandoloa5d03d52016-07-21 11:35:46 -07001/*eslint-env node */
2(function () {
3 'use strict';
4
5 const gulp = require('gulp');
6 const inject = require('gulp-inject');
7 const angularFilesort = require('gulp-angular-filesort');
8 const wiredep = require('wiredep').stream;
9 const path = require('path');
10 const babel = require('gulp-babel');
11 const sourcemaps = require('gulp-sourcemaps');
12 const browserSync = require('browser-sync').create();
13 module.exports = function(options){
14
15 console.log(options.xosHelperTmp, path.join(__dirname, `../${options.xosHelperTmp}`));
16
17 gulp.task('serveDevEnv', ['babelDev', 'wiredep', 'inject', 'injectStyle'], function(){
18 browserSync.init({
19 server: {
20 baseDir: ['./dev', './.tmp', './dist'],
21 // directory: true,
22 routes: {
23 '/bower_components': 'bower_components'
24 },
25 }
26 });
27
28 gulp.watch([
29 './src/**/*.js'
30 ], ['babelDev']);
31
32 gulp.watch([
33 './src/**/*.scss'
34 ], ['style']);
35
36 gulp.watch([
37 './dev/*.html',
38 './dev/*.js',
39 './.tmp/**/*.js'
40 ], function(){
41 browserSync.reload();
42 });
43 });
44
45 gulp.task('babelDev', function(){
46 return gulp.src(options.xosHelperSource + '**/*.js')
47 .pipe(sourcemaps.init())
48 .pipe(babel({
49 presets: ['es2015']
50 }))
51 .pipe(sourcemaps.write('./maps'))
52 .pipe(gulp.dest(options.xosHelperTmp));
53 });
54
55 gulp.task('inject', function(){
56 const files = gulp.src([
57 `${options.xosHelperTmp}**/*.js`
58 ])
59 .pipe(angularFilesort())
60
61 return gulp.src('./dev/index.html')
62 .pipe(inject(files, {ignorePath: ['.tmp/']}))
63 .pipe(gulp.dest('./dev/'));
64 });
65
66 gulp.task('injectStyle', function(){
67 const files = gulp.src([
68 `${options.ngXosStyles}*.css`
69 ])
70
71 return gulp.src('./dev/index.html')
72 .pipe(inject(files, {ignorePath: ['dist/']}))
73 .pipe(gulp.dest('./dev/'));
74 });
75
76
77 // inject bower dependencies with wiredep
78 gulp.task('wiredep', function () {
79 return gulp.src('./dev/index.html')
80 .pipe(wiredep({devDependencies: false}))
81 .pipe(gulp.dest('./dev'));
82 });
83 };
84})();