forked from night/betterttv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
52 lines (46 loc) · 2.13 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
var fs = require('fs'),
gulp = require('gulp'),
jade = require('gulp-jade'),
wrap = require('gulp-wrap-commonjs'),
header = require('gulp-header'),
footer = require('gulp-footer'),
rename = require('gulp-rename'),
concat = require('gulp-concat');
gulp.task('templates', function () {
return gulp.src(['src/templates/*.jade'])
.pipe(jade({client: true, globals: ['$', 'window', 'bttv', 'Twitch']}))
.pipe(rename({suffix: '-template'})) // avoid filename clashes
.pipe(footer(';module.exports=template;'))
.pipe(gulp.dest('build/templates/'));
});
var commonJsRequireDefinition = fs.readFileSync('node_modules/commonjs-require/commonjs-require.js').toString();
var jadeDefinition = fs.readFileSync('node_modules/gulp-jade/node_modules/jade/runtime.js').toString();
var license = fs.readFileSync('license.txt').toString();
gulp.task('scripts', ['templates'], function () {
// if we want .coffee, we can compile them to build/*.js
// and include them here
gulp.src(['src/**/*.js', 'build/templates/*.js'])
.pipe(wrap({pathModifier: commonjsPath}))
.pipe(concat('betterttv.js'))
.pipe(header('(function (bttv) { \n'))
.pipe(header(jadeDefinition))
.pipe(header(commonJsRequireDefinition))
.pipe(header(license+'\n'))
.pipe(footer("\n\
require('main'); \n\
}(window.BetterTTV = window.BetterTTV || {}));"))
.pipe(gulp.dest(__dirname));
});
gulp.task('watch', ['default'], function () {
gulp.watch('src/**/*', ['default']);
});
gulp.task('default', ['scripts']);
function commonjsPath(path) {
return path.toLowerCase() // lowercase so that on windows, C:/ is c:/
.replace(__dirname.toLowerCase(), '') // remove __dirname *before* normalizing
.replace(/\\/g, '/') // normalize path for windows/unix
.replace(/(\-template)?\.js$/, '') // drop extension and remove -template suffix
.replace(/.*\/src/, '').replace(/.*\/build/, '') // remove directory from path
.replace(/^\//, '') // drop leading / if it exists
;
}