forked from straker/css-style-guide-audit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
71 lines (60 loc) · 2.32 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
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat-util');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var size = require('gulp-size');
var karma = require('karma').server;
var autoprefixer = require('gulp-autoprefixer');
function swallowError(error) {
this.emit('end');
}
gulp.task('lint', function() {
return gulp.src('src/*.js')
.pipe(jshint())
.pipe(jshint.reporter( 'jshint-stylish' ));
});
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
}, done);
});
gulp.task('scripts', function() {
// auto-prefix test css files
gulp.src('test/css/*.css')
.pipe(autoprefixer())
.pipe(gulp.dest('test/css'));
// index.test.js is used in the test code to have access to all private function/variables
// index.js is the unminified output
// index.min.js is what's hosted on Dropbox and is used by the bookmarklet script
gulp.src(['src/core.js', 'node_modules/specificity/specificity.js', 'src/*.js', '!src/run.js', '!src/bookmarkletCore.js'])
.pipe(concat('index.test.js'))
.pipe(gulp.dest('.'))
.pipe(rename('index.js'))
.pipe(concat.header('(function(window, document) {\n\'use strict\';\n'))
.pipe(concat.footer('\n\n})(window, document);'))
.pipe(size())
.pipe(gulp.dest('.'))
.pipe(rename('index.min.js'))
// prevent IIFE from starting with !, which breaks bookmarklet return value
.pipe(uglify({compress: {negate_iife: false}}))
.pipe(size())
.pipe(gulp.dest('.'))
// create the bookmarklet code
return gulp.src(['src/bookmarkletCore.js', 'src/run.js'])
.pipe(concat('bookmarklet.js'))
.pipe(concat.header('(function(document) {\n\'use strict\';\n'))
.pipe(concat.footer('\n\n})(document);'))
// prevent IIFE from starting with !, which breaks bookmarklet return value
.pipe(uglify({compress: {negate_iife: false}}))
.pipe(concat.header('javascript:'))
.pipe(gulp.dest('.'));
// return;
// index.run.js includes the run script for running the code
// return gulp.src(['src/core.js', 'node_modules/specificity/specificity.js', 'src/*.js'])
// .pipe(concat('index.js'))
});
gulp.task('watch', function() {
gulp.watch('src/*.js', ['lint', 'scripts']);
});
gulp.task('default', ['lint', 'scripts', 'test', 'watch']);