blob: f046681ae603552d967b5733b0f8cee22ede118b [file] [log] [blame]
Matteo Scandolob0238d32015-11-04 16:03:59 +01001var gulp = require('gulp');
2var uglify = require('gulp-uglify');
Matteo Scandolo45a5c562016-04-13 16:20:13 -07003var concat = require('gulp-concat');
Matteo Scandolob0238d32015-11-04 16:03:59 +01004var ngAnnotate = require('gulp-ng-annotate');
5var angularFilesort = require('gulp-angular-filesort');
Matteo Scandolo45a5c562016-04-13 16:20:13 -07006var gulpDocs = require('gulp-ngdocs');
Matteo Scandolo717352a2016-04-13 17:23:28 -07007var del = require('del');
Matteo Scandolo1dab3e02016-04-14 11:46:30 -07008var babel = require('gulp-babel');
9const sourcemaps = require('gulp-sourcemaps');
Matteo Scandolo5614b902016-04-14 15:34:12 -070010var browserSync = require('browser-sync').create();
Matteo Scandolob0238d32015-11-04 16:03:59 +010011
12module.exports = function(options){
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070013
14 // transpile js with sourceMaps
15 gulp.task('babel', function(){
16 return gulp.src(options.xosHelperSource + '**/*.js')
17 .pipe(babel({
18 presets: ['es2015']
19 }))
20 .pipe(gulp.dest(options.xosHelperTmp));
21 });
22
23 gulp.task('babelDev', function(){
24 return gulp.src(options.xosHelperSource + '**/*.js')
25 .pipe(sourcemaps.init())
26 .pipe(babel({
27 presets: ['es2015']
28 }))
29 .pipe(sourcemaps.write('./maps'))
30 .pipe(gulp.dest(options.xosHelperTmp));
31 });
32
33 // build
34 gulp.task('helpers', ['babel'], function(){
35 return gulp.src([options.xosHelperTmp + '**/*.js'])
Matteo Scandolob0238d32015-11-04 16:03:59 +010036 .pipe(angularFilesort())
37 .pipe(concat('ngXosHelpers.js'))
38 .pipe(ngAnnotate())
39 .pipe(uglify())
40 .pipe(gulp.dest(options.ngXosVendor));
41 });
Matteo Scandolo45a5c562016-04-13 16:20:13 -070042
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070043 // build Dev (no minify, sourcemaps)
44 gulp.task('helpersDev', ['babelDev'], function(){
45 return gulp.src([options.xosHelperTmp + '**/*.js'])
46 .pipe(angularFilesort())
47 .pipe(concat('ngXosHelpers.js'))
48 .pipe(ngAnnotate())
49 .pipe(gulp.dest(options.ngXosVendor));
50 });
51
Matteo Scandolo717352a2016-04-13 17:23:28 -070052 gulp.task('cleanDocs', function(){
Matteo Scandolo717352a2016-04-13 17:23:28 -070053 return del([options.docs + '**/*']);
54 });
55
Matteo Scandolo5614b902016-04-14 15:34:12 -070056 gulp.task('makeDocs', ['cleanDocs'], function(){
Matteo Scandolo717352a2016-04-13 17:23:28 -070057 var ngOptions = {
58 scripts: [
59 'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js',
Matteo Scandolo5614b902016-04-14 15:34:12 -070060 'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.min.js',
61 `${options.ngXosVendor}ngXosHelpers.js`
62 ],
63 styles: [
64 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css',
Matteo Scandolo717352a2016-04-13 17:23:28 -070065 ],
Matteo Scandolo6a6586e2016-04-14 16:52:13 -070066 html5Mode: false,
Matteo Scandolo717352a2016-04-13 17:23:28 -070067 title: 'XOS Helpers documentation',
68 startPage: '/module',
69 }
70
71 return gulpDocs.sections({
72 module: {
73 glob: [
74 options.xosHelperSource + '*.js',
Matteo Scandolo5614b902016-04-14 15:34:12 -070075 options.xosHelperSource + 'services/*.js',
76 options.xosHelperSource + 'ui_components/**/*.js'
Matteo Scandolo717352a2016-04-13 17:23:28 -070077 ],
78 title: 'Module Documentation',
79 },
80 'rest-api': {
81 glob: [
82 options.xosHelperSource + 'services/rest/*.js'
83 ],
84 api: true,
85 title: 'API Documentation',
86 }
87 }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs'));
Matteo Scandolo45a5c562016-04-13 16:20:13 -070088 });
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070089
Matteo Scandolo5614b902016-04-14 15:34:12 -070090 gulp.task('serveDocs', function(){
91 browserSync.init({
92 server: {
93 baseDir: './docs',
94 routes: {
95 '/xos/core/xoslib/static/js/vendor': options.ngXosVendor
96 }
97 }
98 });
99 });
100
101 gulp.task('docs', ['makeDocs', 'serveDocs'], function(){
102
103 var files = [
104 options.xosHelperSource + '*.js',
105 options.xosHelperSource + 'services/*.js',
106 options.xosHelperSource + 'ui_components/**/*.js'
107 ];
108
109 gulp.watch(files, ['makeDocs']);
110
111 gulp.watch(files, function(){
Matteo Scandolo5614b902016-04-14 15:34:12 -0700112 browserSync.reload();
113 });
114 })
115
Matteo Scandolo1dab3e02016-04-14 11:46:30 -0700116 gulp.task('dev', function(){
117 gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']);
118 });
Matteo Scandolob0238d32015-11-04 16:03:59 +0100119};