2015-01-16 06:23:40 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var gulp = require('gulp')
|
2015-01-16 06:44:17 +08:00
|
|
|
, browserify = require('browserify')
|
2015-01-16 06:23:40 +08:00
|
|
|
, bump = require('gulp-bump')
|
2015-01-26 02:52:18 +08:00
|
|
|
, connect = require('gulp-connect')
|
2015-01-26 03:19:37 +08:00
|
|
|
, eslint = require('gulp-eslint')
|
2015-01-16 06:23:40 +08:00
|
|
|
, rename = require('gulp-rename')
|
|
|
|
, rimraf = require('gulp-rimraf')
|
|
|
|
, sass = require('gulp-sass')
|
2015-01-16 06:44:17 +08:00
|
|
|
, transform = require('vinyl-transform')
|
2015-01-16 06:23:40 +08:00
|
|
|
, uglify = require('gulp-uglify');
|
|
|
|
|
|
|
|
gulp.task('lint', function () {
|
|
|
|
return gulp.src(['./src/**/*.js', './gulpfile.js'])
|
2015-01-26 03:19:37 +08:00
|
|
|
.pipe(eslint())
|
|
|
|
.pipe(eslint.format())
|
|
|
|
.pipe(eslint.failOnError());
|
2015-01-16 06:23:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('clean:js', function () {
|
2015-01-16 06:44:17 +08:00
|
|
|
return gulp.src('./out/js/perfect-scrollbar.js', {read: false})
|
2015-01-16 06:23:40 +08:00
|
|
|
.pipe(rimraf());
|
|
|
|
});
|
|
|
|
|
2015-01-16 06:44:17 +08:00
|
|
|
gulp.task('clean:js:min', function () {
|
|
|
|
return gulp.src('./out/js/perfect-scrollbar.min.js', {read: false})
|
|
|
|
.pipe(rimraf());
|
|
|
|
});
|
|
|
|
|
|
|
|
function browserified() {
|
|
|
|
return transform(function (filename) {
|
|
|
|
var b = browserify(filename);
|
|
|
|
return b.bundle();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task('js', ['clean:js'], function () {
|
|
|
|
return gulp.src('./src/js/main.js')
|
|
|
|
.pipe(browserified())
|
|
|
|
.pipe(rename('perfect-scrollbar.js'))
|
2015-01-26 02:52:18 +08:00
|
|
|
.pipe(gulp.dest('./out/js'))
|
|
|
|
.pipe(connect.reload());
|
2015-01-16 06:44:17 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('js:min', ['clean:js:min'], function () {
|
|
|
|
return gulp.src('./src/js/main.js')
|
|
|
|
.pipe(browserified())
|
2015-01-16 06:23:40 +08:00
|
|
|
.pipe(uglify())
|
|
|
|
.pipe(rename('perfect-scrollbar.min.js'))
|
2015-01-16 06:44:17 +08:00
|
|
|
.pipe(gulp.dest('./out/js'));
|
2015-01-16 06:23:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('clean:css', function () {
|
2015-01-16 06:44:17 +08:00
|
|
|
return gulp.src('./out/css/perfect-scrollbar.css', {read: false})
|
2015-01-16 06:23:40 +08:00
|
|
|
.pipe(rimraf());
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('clean:css:min', function () {
|
2015-01-16 06:44:17 +08:00
|
|
|
return gulp.src('./out/css/perfect-scrollbar.min.css', {read: false})
|
2015-01-16 06:23:40 +08:00
|
|
|
.pipe(rimraf());
|
|
|
|
});
|
|
|
|
|
2015-01-16 06:44:17 +08:00
|
|
|
gulp.task('sass', ['clean:css'], function () {
|
|
|
|
return gulp.src('./src/css/main.scss')
|
|
|
|
.pipe(sass())
|
|
|
|
.pipe(rename('perfect-scrollbar.css'))
|
2015-01-26 02:52:18 +08:00
|
|
|
.pipe(gulp.dest('./out/css'))
|
|
|
|
.pipe(connect.reload());
|
2015-01-16 06:44:17 +08:00
|
|
|
});
|
|
|
|
|
2015-01-16 06:23:40 +08:00
|
|
|
gulp.task('sass:min', ['clean:css:min'], function () {
|
2015-01-16 06:44:17 +08:00
|
|
|
return gulp.src('./src/css/main.scss')
|
2015-01-16 06:23:40 +08:00
|
|
|
.pipe(sass({outputStyle: 'compressed'}))
|
|
|
|
.pipe(rename('perfect-scrollbar.min.css'))
|
2015-01-16 06:44:17 +08:00
|
|
|
.pipe(gulp.dest('./out/css'));
|
2015-01-16 06:23:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
function bumpType() {
|
|
|
|
if (gulp.env.major) {
|
|
|
|
return 'major';
|
|
|
|
} else if (gulp.env.minor) {
|
|
|
|
return 'minor';
|
|
|
|
} else {
|
|
|
|
return 'patch';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task('bump', function () {
|
|
|
|
gulp.src('./*.json')
|
|
|
|
.pipe(bump({type: bumpType()}))
|
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('release', ['bump', 'build']);
|
|
|
|
|
2015-01-16 06:44:17 +08:00
|
|
|
gulp.task('build', ['js', 'js:min', 'sass', 'sass:min']);
|
2015-01-26 02:52:18 +08:00
|
|
|
|
|
|
|
gulp.task('connect', ['build'], function () {
|
|
|
|
connect.server({
|
|
|
|
root: __dirname,
|
|
|
|
livereload: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch', function () {
|
|
|
|
gulp.watch(['src/js/**/*'], ['js']);
|
|
|
|
gulp.watch(['src/css/**/*'], ['css']);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('serve', ['connect', 'watch']);
|
|
|
|
|
2015-01-16 06:23:40 +08:00
|
|
|
gulp.task('default', ['lint', 'build']);
|