blob: a19d85e413010cccbdf72eb1cb71926743f1963c [file] [log] [blame]
Matteo Scandolo2b626742015-11-04 16:03:59 +01001var gulp = require('gulp');
2var uglify = require('gulp-uglify');
Matteo Scandolo57404dc2016-04-13 16:20:13 -07003var concat = require('gulp-concat');
Matteo Scandolo2b626742015-11-04 16:03:59 +01004var ngAnnotate = require('gulp-ng-annotate');
5var angularFilesort = require('gulp-angular-filesort');
Matteo Scandolo57404dc2016-04-13 16:20:13 -07006var gulpDocs = require('gulp-ngdocs');
Matteo Scandolo582cc812016-04-13 17:23:28 -07007var del = require('del');
Matteo Scandolob7a86dc2016-04-14 11:46:30 -07008var babel = require('gulp-babel');
9const sourcemaps = require('gulp-sourcemaps');
Matteo Scandoloaa683dd2016-04-14 15:34:12 -070010var browserSync = require('browser-sync').create();
Matteo Scandolo90ed0642016-04-25 10:11:56 -070011var rename = require('gulp-rename');
12var sass = require('gulp-sass');
Matteo Scandolo2b626742015-11-04 16:03:59 +010013
14module.exports = function(options){
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070015
Matteo Scandolo90ed0642016-04-25 10:11:56 -070016 gulp.task('style', function(){
Matteo Scandolob0280752016-04-25 10:31:22 -070017 return gulp.src(`${options.xosHelperSource}styles/main.scss`)
Matteo Scandolo90ed0642016-04-25 10:11:56 -070018 .pipe(sourcemaps.init())
19 .pipe(sass().on('error', sass.logError))
20 .pipe(rename('xosNgLib.css'))
21 .pipe(sourcemaps.write())
22 .pipe(gulp.dest(options.ngXosStyles));
23 });
24
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070025 // transpile js with sourceMaps
26 gulp.task('babel', function(){
27 return gulp.src(options.xosHelperSource + '**/*.js')
28 .pipe(babel({
29 presets: ['es2015']
30 }))
31 .pipe(gulp.dest(options.xosHelperTmp));
32 });
33
34 gulp.task('babelDev', function(){
35 return gulp.src(options.xosHelperSource + '**/*.js')
36 .pipe(sourcemaps.init())
37 .pipe(babel({
38 presets: ['es2015']
39 }))
40 .pipe(sourcemaps.write('./maps'))
41 .pipe(gulp.dest(options.xosHelperTmp));
42 });
43
44 // build
Matteo Scandolo90ed0642016-04-25 10:11:56 -070045 gulp.task('helpers', ['babel', 'style'], function(){
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070046 return gulp.src([options.xosHelperTmp + '**/*.js'])
Matteo Scandolo2b626742015-11-04 16:03:59 +010047 .pipe(angularFilesort())
48 .pipe(concat('ngXosHelpers.js'))
49 .pipe(ngAnnotate())
50 .pipe(uglify())
51 .pipe(gulp.dest(options.ngXosVendor));
52 });
Matteo Scandolo57404dc2016-04-13 16:20:13 -070053
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070054 // build Dev (no minify, sourcemaps)
55 gulp.task('helpersDev', ['babelDev'], function(){
56 return gulp.src([options.xosHelperTmp + '**/*.js'])
57 .pipe(angularFilesort())
58 .pipe(concat('ngXosHelpers.js'))
59 .pipe(ngAnnotate())
60 .pipe(gulp.dest(options.ngXosVendor));
61 });
62
Matteo Scandolo582cc812016-04-13 17:23:28 -070063 gulp.task('cleanDocs', function(){
Matteo Scandolo582cc812016-04-13 17:23:28 -070064 return del([options.docs + '**/*']);
65 });
66
Matteo Scandoloaa683dd2016-04-14 15:34:12 -070067 gulp.task('makeDocs', ['cleanDocs'], function(){
Matteo Scandolo68df51b2016-05-03 17:07:01 -070068
Matteo Scandolo582cc812016-04-13 17:23:28 -070069 var ngOptions = {
Matteo Scandolo68df51b2016-05-03 17:07:01 -070070 scripts: [].concat([
Matteo Scandolo68df51b2016-05-03 17:07:01 -070071 `./${options.ngXosVendor}ngXosVendor.js`,
Matteo Scandolo88e18462016-04-25 14:24:18 -070072 `./${options.ngXosVendor}ngXosHelpers.js`,
arpiagariu98680a52016-06-14 14:08:45 -070073 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-mocks.js',
Matteo Scandolo68df51b2016-05-03 17:07:01 -070074 ]),
Matteo Scandoloaa683dd2016-04-14 15:34:12 -070075 styles: [
Matteo Scandolo88e18462016-04-25 14:24:18 -070076 `./${options.ngXosStyles}xosNgLib.css`,
Matteo Scandolo199ec002016-04-22 10:53:49 -070077 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css',
Matteo Scandolo582cc812016-04-13 17:23:28 -070078 ],
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070079 html5Mode: false,
Matteo Scandolo582cc812016-04-13 17:23:28 -070080 title: 'XOS Helpers documentation',
81 startPage: '/module',
82 }
83
84 return gulpDocs.sections({
85 module: {
86 glob: [
87 options.xosHelperSource + '*.js',
Matteo Scandolo974c0e42016-05-25 16:02:16 -070088 options.xosHelperSource + 'services/helpers/**/*.js',
Matteo Scandoloaa683dd2016-04-14 15:34:12 -070089 options.xosHelperSource + 'services/*.js',
90 options.xosHelperSource + 'ui_components/**/*.js'
Matteo Scandolo582cc812016-04-13 17:23:28 -070091 ],
92 title: 'Module Documentation',
93 },
94 'rest-api': {
95 glob: [
96 options.xosHelperSource + 'services/rest/*.js'
97 ],
98 api: true,
99 title: 'API Documentation',
100 }
101 }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs'));
Matteo Scandolo57404dc2016-04-13 16:20:13 -0700102 });
Matteo Scandolob7a86dc2016-04-14 11:46:30 -0700103
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700104 gulp.task('serveDocs', function(){
105 browserSync.init({
106 server: {
107 baseDir: './docs',
108 routes: {
Matteo Scandolo88e18462016-04-25 14:24:18 -0700109 '/xos/core/xoslib/static/js/vendor': options.ngXosVendor,
arpiagariu98680a52016-06-14 14:08:45 -0700110 '/xos/core/static': options.ngXosStyles,
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700111 }
112 }
113 });
114 });
115
116 gulp.task('docs', ['makeDocs', 'serveDocs'], function(){
117
118 var files = [
Matteo Scandolo974c0e42016-05-25 16:02:16 -0700119 options.xosHelperSource + '**/*.js'
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700120 ];
121
122 gulp.watch(files, ['makeDocs']);
123
Matteo Scandolob7dac502016-04-28 13:14:08 -0700124 // uncomment to enable autoreload, now it is broken (reload a wrong page)
125 // https://github.com/nikhilmodak/gulp-ngdocs/issues/81
126
127 // gulp.watch(files, function(){
128 // browserSync.reload();
129 // });
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700130 })
131
Matteo Scandolob7a86dc2016-04-14 11:46:30 -0700132 gulp.task('dev', function(){
Matteo Scandolo90ed0642016-04-25 10:11:56 -0700133 gulp.watch(`${options.xosHelperSource}**/*.scss`, ['style']);
Matteo Scandolob7a86dc2016-04-14 11:46:30 -0700134 gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']);
135 });
Matteo Scandolo2b626742015-11-04 16:03:59 +0100136};