Commit 3d03ae981efbc5d27fb3e57b0a7be2e06dc4e218
1 parent
192accea06
Exists in
master
gulp
Showing
1 changed file
with
19 additions
and
1 deletions
Show diff stats
gulpfile.js
1 | const templateCache = require('gulp-angular-templatecache'); | 1 | const templateCache = require('gulp-angular-templatecache'); |
2 | const clean = require('gulp-clean'); | 2 | const clean = require('gulp-clean'); |
3 | const concat = require('gulp-concat'); | 3 | const concat = require('gulp-concat'); |
4 | const htmlmin = require('gulp-htmlmin'); | 4 | const htmlmin = require('gulp-htmlmin'); |
5 | const rename = require('gulp-rename'); | 5 | const rename = require('gulp-rename'); |
6 | const uglify = require('gulp-uglify'); | 6 | const uglify = require('gulp-uglify'); |
7 | const gulp = require('gulp'); | 7 | const gulp = require('gulp'); |
8 | const pump = require('pump'); | 8 | const pump = require('pump'); |
9 | const jshint = require('gulp-jshint'); | 9 | const jshint = require('gulp-jshint'); |
10 | const replace = require('gulp-replace'); | 10 | const replace = require('gulp-replace'); |
11 | const connect = require('gulp-connect'); | 11 | const connect = require('gulp-connect'); |
12 | const header = require('gulp-header'); | ||
13 | const footer = require('gulp-footer'); | ||
14 | const gulpSequence = require('gulp-sequence'); | ||
12 | 15 | ||
13 | var paths = { | 16 | var paths = { |
14 | srcJS: 'src/js/*.js', | 17 | srcJS: 'src/js/*.js', |
15 | srcViews: 'src/views/*.html', | 18 | srcViews: 'src/views/*.html', |
16 | specs: 'spec/*.js', | 19 | specs: 'spec/*.js', |
17 | tmp: 'tmp', | 20 | tmp: 'tmp', |
18 | dist: 'dist/' | 21 | dist: 'dist/' |
19 | }; | 22 | }; |
20 | 23 | ||
24 | gulp.task('uglify', gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app')); | ||
25 | |||
21 | gulp.task('templates', ['clean'], function() { | 26 | gulp.task('templates', ['clean'], function() { |
22 | return pump( | 27 | return pump( |
23 | [ | 28 | [ |
24 | gulp.src(paths.srcViews), | 29 | gulp.src(paths.srcViews), |
25 | htmlmin(), | 30 | htmlmin(), |
26 | templateCache('views.js', { | 31 | templateCache('views.js', { |
27 | module: 'focaCrearRemito', | 32 | module: 'focaCrearRemito', |
28 | root: '' | 33 | root: '' |
29 | }), | 34 | }), |
30 | gulp.dest(paths.tmp) | 35 | gulp.dest(paths.tmp) |
31 | ] | 36 | ] |
32 | ); | 37 | ); |
33 | }); | 38 | }); |
34 | 39 | ||
35 | gulp.task('uglify', ['templates'], function() { | 40 | gulp.task('uglify-app', function() { |
36 | return pump( | 41 | return pump( |
37 | [ | 42 | [ |
38 | gulp.src([ | 43 | gulp.src([ |
39 | paths.srcJS, | 44 | paths.srcJS, |
40 | 'tmp/views.js' | 45 | 'tmp/views.js' |
41 | ]), | 46 | ]), |
42 | concat('foca-crear-remito.js'), | 47 | concat('foca-crear-remito.js'), |
43 | replace('src/views/', ''), | 48 | replace('src/views/', ''), |
44 | gulp.dest(paths.tmp), | 49 | gulp.dest(paths.tmp), |
45 | rename('foca-crear-remito.min.js'), | 50 | rename('foca-crear-remito.min.js'), |
46 | uglify(), | 51 | uglify(), |
47 | gulp.dest(paths.dist) | 52 | gulp.dest(paths.dist) |
48 | ] | 53 | ] |
49 | ); | 54 | ); |
50 | }); | 55 | }); |
51 | 56 | ||
57 | gulp.task('uglify-spec', function() { | ||
58 | return pump( | ||
59 | [ | ||
60 | gulp.src(paths.specs), | ||
61 | concat('foca-crear-remito.spec.js'), | ||
62 | replace('src/views/', ''), | ||
63 | header("describe('Módulo foca-crear-remito', function() { \n"), | ||
64 | footer("});"), | ||
65 | gulp.dest(paths.dist) | ||
66 | ] | ||
67 | ); | ||
68 | }); | ||
69 | |||
52 | gulp.task('clean', function() { | 70 | gulp.task('clean', function() { |
53 | return gulp.src(['tmp', 'dist'], {read: false}) | 71 | return gulp.src(['tmp', 'dist'], {read: false}) |
54 | .pipe(clean()); | 72 | .pipe(clean()); |
55 | }); | 73 | }); |
56 | 74 | ||
57 | gulp.task('pre-commit', function() { | 75 | gulp.task('pre-commit', function() { |
58 | return pump( | 76 | return pump( |
59 | [ | 77 | [ |
60 | gulp.src([paths.srcJS, paths.specs]), | 78 | gulp.src([paths.srcJS, paths.specs]), |
61 | jshint('.jshintrc'), | 79 | jshint('.jshintrc'), |
62 | jshint.reporter('default'), | 80 | jshint.reporter('default'), |
63 | jshint.reporter('fail') | 81 | jshint.reporter('fail') |
64 | ] | 82 | ] |
65 | ); | 83 | ); |
66 | 84 | ||
67 | gulp.start('uglify'); | 85 | gulp.start('uglify'); |
68 | }); | 86 | }); |
69 | 87 | ||
70 | gulp.task('webserver', function() { | 88 | gulp.task('webserver', function() { |
71 | pump [ | 89 | pump [ |
72 | connect.server({port: 3300, host: '0.0.0.0'}) | 90 | connect.server({port: 3300, host: '0.0.0.0'}) |
73 | ] | 91 | ] |
74 | }); | 92 | }); |
75 | 93 | ||
76 | gulp.task('clean-post-install', function() { | 94 | gulp.task('clean-post-install', function() { |
77 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | 95 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
78 | 'index.html'], {read: false}) | 96 | 'index.html'], {read: false}) |
79 | .pipe(clean()); | 97 | .pipe(clean()); |
80 | }); | 98 | }); |
81 | 99 | ||
82 | gulp.task('default', ['webserver']); | 100 | gulp.task('default', ['webserver']); |
83 | 101 | ||
84 | gulp.task('watch', function() { | 102 | gulp.task('watch', function() { |
85 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); | 103 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); |
86 | }); | 104 | }); |
87 | 105 | ||
88 | gulp.task('copy', ['uglify'], function() { | 106 | gulp.task('copy', ['uglify'], function() { |
89 | return gulp.src('dist/*.js') | 107 | return gulp.src('dist/*.js') |
90 | .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-remito/dist/')); | 108 | .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-crear-remito/dist/')); |
91 | }); | 109 | }); |
92 | 110 | ||
93 | gulp.task('watchAndCopy', function() { | 111 | gulp.task('watchAndCopy', function() { |
94 | return gulp.watch([paths.srcJS, paths.srcViews], ['copy']); | 112 | return gulp.watch([paths.srcJS, paths.srcViews], ['copy']); |
95 | }); | 113 | }); |
96 | 114 |