-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
122 lines (105 loc) · 3.65 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
/**
* @author Bilal Cinarli
*/
'use strict';
var gulp = require('gulp'),
pkg = require('./package.json'),
isTravis = process.env.TRAVIS || false,
// utils
header = require('gulp-header'),
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
notify = require('gulp-notify'),
// sass
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
// lint
jshint = require('gulp-jshint'),
csslint = require('gulp-csslint'),
// testing
mochaPhantomJs = require('gulp-mocha-phantomjs');
var paths = {
lib : 'lib/',
dist : 'dist/',
test : 'test/',
examples: 'examples/'
};
var banner = [
'/*! UX Rocket Clear \n' +
' * <%= pkg.description %> \n' +
' * @author <%= pkg.author %> \n' +
'<% pkg.contributors.forEach(function(contributor) { %>' +
' * <%= contributor.name %> <<%=contributor.email %>> (<%=contributor.url %>)\n' +
'<% }) %>' +
' * @version <%= pkg.version %> \n' +
' * @build <%= date %> \n' +
' */\n'
].join('');
var tasks = {
mocha: function() {
return gulp.src(paths.test + 'index.html')
.pipe(mochaPhantomJs());
},
sass: function() {
return gulp.src(paths.lib + '**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}))
.pipe(autoprefixer({
browsers: ['last 3 versions']
}))
.pipe(rename('uxrocket.clear.css'))
.pipe(gulp.dest(paths.dist))
.pipe(sass({
outputStyle: 'compressed'
})).on('error', notify.onError('Error: <%= error.message %>'))
.pipe(autoprefixer({
browsers: ['last 3 versions']
}))
.pipe(rename('uxrocket.clear.min.css'))
.pipe(header(banner, {pkg: pkg, date: now()}))
.pipe(sourcemaps.write('./'))
.pipe(notify('Sass styles completed'))
.pipe(gulp.dest(paths.dist));
},
csslint: function() {
return gulp.src(paths.dist + 'uxrocket.clear.css')
.pipe(csslint())
.pipe(csslint.reporter());
},
lint: function() {
return gulp.src(paths.lib + '**/*.js')
.pipe(jshint()).on('error', notify.onError('Error: <%= error.message %>'))
.pipe(jshint.reporter('default'))
.pipe(notify('JSHint completed'));
},
scripts: function() {
return gulp.src(paths.lib + '**/*.js')
.pipe(sourcemaps.init())
.pipe(rename('uxrocket.clear.js'))
.pipe(gulp.dest(paths.dist))
.pipe(uglify()).on('error', notify.onError('Error: <%= error.message %>'))
.pipe(header(banner, {pkg: pkg, date: now()}))
.pipe(rename('uxrocket.clear.min.js'))
.pipe(sourcemaps.write('./'))
.pipe(notify('Script file uglified'))
.pipe(gulp.dest(paths.dist));
}
};
var now = function() {
var d = new Date();
return d.getFullYear() + '-' + (d.getMonth() < 10 ? '0' + d.getMonth() : d.getMonth()) + '-' + (d.getDay() < 10 ? '0' + d.getDay() : d.getDay());
};
gulp.task('sass', tasks.sass);
gulp.task('csslint', tasks.csslint);
gulp.task('lint', tasks.lint);
gulp.task('scripts', tasks.scripts);
gulp.task('mocha', tasks.mocha);
gulp.task('watch', ['csslint', 'sass', 'lint', 'scripts', 'mocha'], function() {
gulp.watch(paths.lib + '**/*.scss', ['sass']);
gulp.watch(paths.dist + '**/*.css', ['csslint']);
gulp.watch(paths.lib + '**/*.js', ['lint', 'scripts', 'mocha']);
});
gulp.task('default', ['watch']);