-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
127 lines (112 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var gulp = require('gulp'),
gulpFilter = require('gulp-filter'),
gulpIf = require('gulp-if'),
artoo = require('gulp-artoo'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
rename = require('gulp-rename'),
webserver = require('gulp-webserver'),
concat = require('gulp-concat'),
replace = require('gulp-replace'),
uglify = require('gulp-uglify'),
order = require("gulp-order"),
debug = require('gulp-debug'),
fs = require('fs');
// Files to aggregate
var files = [
'./templates/*.tpl',
'./stylesheets/*.scss',
'./stylesheets/*.css',
'./src/*.js'
];
function htmlBuild(mode) {
return gulp.src('src/bookmarklet.html')
.pipe(replace('{{bookmarklet}}', function(s) {
var script = fs.readFileSync('build/hear2view.bookmark.' + mode + '.js', 'utf8');
return 'javascript:' + encodeURIComponent(script);
}))
.pipe(rename('bookmarklet.' + mode + '.html'))
.pipe(gulp.dest('./build'));
}
gulp.task('html:prod', ['bookmark.dev', 'bookmark.prod'], function() {
return htmlBuild('prod');
});
gulp.task('html:dev', ['bookmark.dev', 'bookmark.prod'], function() {
return htmlBuild('dev');
});
gulp.task('readme', ['bookmark.dev', 'bookmark.prod'], function() {
return gulp.src('src/bookmarklet.html')
.pipe(replace('{{bookmarklet}}', function(s) {
var script = fs.readFileSync('build/hear2view.bookmark.prod.js', 'utf8');
return 'javascript:' + encodeURIComponent(script);
}))
.pipe(rename('index.html'))
.pipe(gulp.dest('./'));
});
gulp.task('html', ['html:prod', 'html:dev', 'readme']);
// Build
function preBuild() {
var tplFilter = gulpFilter('**/*.tpl', {restore: true});
var scssFilter = gulpFilter('**/*.scss', {restore: true});
var cssFilter = gulpFilter('**/*.css', {restore: true});
return gulp.src(files)
.pipe(tplFilter)
.pipe(artoo.template())
.pipe(tplFilter.restore)
.pipe(scssFilter)
.pipe(gulpIf('*.scss', sass()))
.pipe(scssFilter.restore)
.pipe(cssFilter)
.pipe(gulpIf('*.css', autoprefixer()))
.pipe(gulpIf('*.css', artoo.stylesheet()))
.pipe(cssFilter.restore)
.pipe(order(['**/*.css', 'src/*.js']))
.pipe(concat('hear2view.concat.js'));
}
gulp.task('compile', function() {
return preBuild()
.pipe(gulp.dest('./build'));
});
gulp.task('build', ['compile', 'html']);
// Bookmarklets
gulp.task('bookmark.dev', function() {
return artoo.blank('hear2view.bookmark.dev.js')
.pipe(artoo({
random: true,
loadingText: null,
settings: {
reExec: false,
scriptUrl: 'http://localhost/hv/HV-Dev/Accessibility/Hear2View/build/hear2view.concat.js',
env: 'dev'
}
}))
.pipe(gulp.dest('./build'));
});
gulp.task('bookmark.prod', function() {
return preBuild()
.pipe(uglify())
.pipe(rename('hear2view.bookmark.prod.js'))
.pipe(artoo({
settings: {
reExec: false
}
}))
.pipe(gulp.dest('./build'));
});
// Watch
gulp.task('watch', function() {
gulp.watch(files, ['compile']);
});
// Server
gulp.task('serve', function() {
gulp.src('./')
.pipe(webserver({
directoryListing: true,
port: 8000,
https: true
}));
});
// Macro tasks
gulp.task('work', ['build', 'watch', 'serve']);
gulp.task('bookmarklets', ['bookmark.dev', 'bookmark.prod']);
gulp.task('default', ['build', 'bookmark.dev', 'bookmark.prod']);