blob: 5ff7d006f036b9c1707b45766e4263f9e8b75c35 [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',
Matteo Scandolo9a8f53c2016-04-22 09:56:48 -070061 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.11.2/lodash.js',
Matteo Scandolo5614b902016-04-14 15:34:12 -070062 `${options.ngXosVendor}ngXosHelpers.js`
63 ],
64 styles: [
65 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css',
Matteo Scandolo717352a2016-04-13 17:23:28 -070066 ],
Matteo Scandolo6a6586e2016-04-14 16:52:13 -070067 html5Mode: false,
Matteo Scandolo717352a2016-04-13 17:23:28 -070068 title: 'XOS Helpers documentation',
69 startPage: '/module',
70 }
71
72 return gulpDocs.sections({
73 module: {
74 glob: [
75 options.xosHelperSource + '*.js',
Matteo Scandolo5614b902016-04-14 15:34:12 -070076 options.xosHelperSource + 'services/*.js',
77 options.xosHelperSource + 'ui_components/**/*.js'
Matteo Scandolo717352a2016-04-13 17:23:28 -070078 ],
79 title: 'Module Documentation',
80 },
81 'rest-api': {
82 glob: [
83 options.xosHelperSource + 'services/rest/*.js'
84 ],
85 api: true,
86 title: 'API Documentation',
87 }
88 }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs'));
Matteo Scandolo45a5c562016-04-13 16:20:13 -070089 });
Matteo Scandolo1dab3e02016-04-14 11:46:30 -070090
Matteo Scandolo5614b902016-04-14 15:34:12 -070091 gulp.task('serveDocs', function(){
92 browserSync.init({
93 server: {
94 baseDir: './docs',
95 routes: {
96 '/xos/core/xoslib/static/js/vendor': options.ngXosVendor
97 }
98 }
99 });
100 });
101
102 gulp.task('docs', ['makeDocs', 'serveDocs'], function(){
103
104 var files = [
105 options.xosHelperSource + '*.js',
106 options.xosHelperSource + 'services/*.js',
107 options.xosHelperSource + 'ui_components/**/*.js'
108 ];
109
110 gulp.watch(files, ['makeDocs']);
111
112 gulp.watch(files, function(){
Matteo Scandolo5614b902016-04-14 15:34:12 -0700113 browserSync.reload();
114 });
115 })
116
Matteo Scandolo1dab3e02016-04-14 11:46:30 -0700117 gulp.task('dev', function(){
118 gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']);
119 });
Matteo Scandolob0238d32015-11-04 16:03:59 +0100120};