/
gulpfile.js
110 lines (90 loc) · 3.37 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rev = require('gulp-rev');
var htmlreplace = require('gulp-html-replace');
var runSequence = require('run-sequence');
var vinylPaths = require('vinyl-paths');
var del = require('del');
var mainBowerFiles = require('main-bower-files');
var gulpFilter = require('gulp-filter');
var ngAnnotate = require('gulp-ng-annotate');
var through = require('through2');
var fs = require('fs');
var rmOrig = function() {
return through.obj(function(file, enc, cb) {
if (file.revOrigPath) {
fs.unlink(file.revOrigPath, function(err) {
// TODO: emit an error if err
});
}
this.push(file); // Pass file when you're done
return cb() // notify through2 you're done
});
};
// bootsrap-modal only
gulp.task('scripts', function() {
return gulp.src('public_html/javascripts/*.js')
.pipe(ngAnnotate())
.pipe(concat('notewithmeapplication.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/public_html/javascripts'))
})
gulp.task('revision', function(){
return gulp.src('dist/public_html/javascripts/*.js')
.pipe(rev())
.pipe(gulp.dest('dist/public_html/javascripts'))
.pipe(rmOrig())
.pipe(rev.manifest())
.pipe(gulp.dest('dist/public_html/javascripts'))
})
gulp.task('copy-nodejs', function(){
return gulp.src(['node_modules', 'app.js','run.sh'])
.pipe(gulp.dest('dist'))
})
gulp.task('copy-resources', function(){
return gulp.src(['public_html/**/', '!public_html/javascripts/**', '!public_html/bower_components/', '!public_html/bower_components/**'])
.pipe(gulp.dest('dist/public_html'))
})
gulp.task('replace-min', function(){
return gulp.src('dist/public_html/index.html')
.pipe(htmlreplace({
'js': 'javascripts/'+require('./dist/public_html/javascripts/rev-manifest.json')['nwm.min.js']
}))
.pipe(gulp.dest('dist/public_html'))
})
gulp.task('concat-vendor', function(){
var jsFilter = gulpFilter(['*.js']);
return gulp.src(mainBowerFiles({
paths: {
bowerDirectory: 'public_html/bower_components',
bowerJson: 'bower.json'
}
}
))
.pipe(jsFilter)
.pipe(concat('vendor.min.js'))
.pipe(jsFilter.restore())
.pipe(gulp.dest('dist/public_html/javascripts'))
})
gulp.task('scripts-concat', function() {
return gulp.src(['dist/public_html/javascripts/vendor.min.js','dist/public_html/javascripts/notewithmeapplication.min.js'])
.pipe(concat('nwm.min.js'))
.pipe(gulp.dest('dist/public_html/javascripts'))
})
gulp.task('clean', function() {
return gulp.src('dist')
.pipe(vinylPaths(del))
});
gulp.task('clean-tmp-files', function() {
return gulp.src(['dist/public_html/javascripts/notewithmeapplication.min.js', 'dist/public_html/javascripts/vendor.min.js'])
.pipe(vinylPaths(del))
});
gulp.task('clean-tmp-files', function() {
return gulp.src(['dist/public_html/javascripts/notewithmeapplication.min.js', 'dist/public_html/javascripts/vendor.min.js'])
.pipe(vinylPaths(del))
});
gulp.task('build', function(){
return runSequence('clean', 'scripts', 'copy-resources','copy-nodejs', 'concat-vendor','scripts-concat', 'clean-tmp-files', 'revision','replace-min');
})
gulp.task('default',['build']);