blob: 4888bdf9a8c54d2817f9dc665fd87ab83f815291 [file] [log] [blame]
Matteo Scandoloa5d03d52016-07-21 11:35:46 -07001/*eslint-env node */
2
3(function () {
4 'use strict';
5
6 const gulp = require('gulp');
7 const uglify = require('gulp-uglify');
8 const concat = require('gulp-concat');
9 const ngAnnotate = require('gulp-ng-annotate');
10 const angularFilesort = require('gulp-angular-filesort');
11 const del = require('del');
12 const babel = require('gulp-babel');
13 const sourcemaps = require('gulp-sourcemaps');
14 const rename = require('gulp-rename');
15 const sass = require('gulp-sass');
16
17 module.exports = function(options){
18
19 // delete previous builded file
20 gulp.task('cleanLib', function(){
21 return del(
22 [
23 `${options.ngXosVendor}/ngXosHelpers.min.js`,
24 `${options.ngXosVendor}/xosUiComponents.js`,
25 `${options.ngXosVendor}/ngXos.css`
26 ],
27 {force: true}
28 );
29 });
30
31 gulp.task('style', function(){
32 return gulp.src(`${options.xosHelperSource}styles/main.scss`)
33 .pipe(sourcemaps.init())
34 .pipe(sass().on('error', sass.logError))
35 .pipe(rename('xosNgLib.css'))
36 .pipe(sourcemaps.write())
37 .pipe(gulp.dest(options.ngXosStyles));
38 });
39
40 // transpile js with sourceMaps
41 gulp.task('babel', function(){
42 return gulp.src(options.xosHelperSource + '**/*.js')
43 .pipe(babel({
44 presets: ['es2015']
45 }))
46 .pipe(gulp.dest(options.xosHelperTmp));
47 });
48
49 // build
50 gulp.task('helpers', ['cleanLib', 'babel', 'style'], function(){
51 return gulp.src([options.xosHelperTmp + '**/*.js'])
52 .pipe(angularFilesort())
53 .pipe(concat('ngXosHelpers.min.js'))
54 .pipe(ngAnnotate())
55 .pipe(uglify())
56 .pipe(gulp.dest(options.ngXosVendor));
57 });
58
59 // build Dev (no minify, sourcemaps), for development purposes
60 // gulp.task('helpersDev', ['babelDev'], function(){
61 // return gulp.src([options.xosHelperTmp + '**/*.js'])
62 // .pipe(angularFilesort())
63 // .pipe(concat('ngXosHelpers.js'))
64 // .pipe(ngAnnotate())
65 // .pipe(gulp.dest(options.ngXosVendor));
66 // });
67
68 // concat only UI Components (for free use)
69 gulp.task('uiLibrary', function(){
70 return gulp.src([
71 options.xosHelperTmp + '**/*.js',
72 !options.xosHelperTmp + 'services/rest/*.js'
73 ])
74 .pipe(angularFilesort())
75 .pipe(concat('xosUiComponents.js'))
76 .pipe(ngAnnotate())
77 .pipe(gulp.dest(options.ngXosVendor));
78 });
79
80 gulp.task('dev', function(){
81 gulp.watch(`${options.xosHelperSource}**/*.scss`, ['style']);
82 gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']);
83 });
84 };
85})();