timestring/Gulpfile.js

92 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-04-30 12:37:57 +02:00
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
scope: 'devDependencies'
});
2015-04-30 18:03:33 +02:00
2015-05-01 18:31:25 +02:00
var browserify = require('browserify');
2015-04-30 18:03:33 +02:00
var del = require('del');
2015-05-01 18:31:25 +02:00
var runSequence = require('run-sequence');
var source = require('vinyl-source-stream');
2015-04-30 12:37:57 +02:00
2015-04-30 18:03:33 +02:00
gulp.task('static-analysis:lint', function () {
2015-05-05 10:05:13 +02:00
gulp.src('./src/**/*.js')
2015-04-30 12:37:57 +02:00
.pipe($.jshint('.jshintrc'))
.pipe($.jshint.reporter('jshint-stylish'));
});
2015-04-30 18:03:33 +02:00
gulp.task('static-analysis:cs', function () {
2015-05-05 10:05:13 +02:00
return gulp.src('./src/**/*.js')
2015-04-30 12:37:57 +02:00
.pipe($.jscs());
});
gulp.task('test', function () {
2015-05-05 10:05:13 +02:00
return gulp.src('./test/timestring.js', { read: false })
2015-04-30 12:37:57 +02:00
.pipe($.mocha());
});
2015-04-30 18:03:33 +02:00
gulp.task('build:clean', function (callback) {
2015-05-05 10:05:13 +02:00
del(['./build/**/*'], callback);
2015-04-30 18:03:33 +02:00
});
2015-05-01 18:31:25 +02:00
gulp.task('build:transpile', function () {
2015-05-05 10:05:13 +02:00
return gulp.src(['./src/Timestring.js', './src/String.parseTime.js'])
2015-05-01 18:31:25 +02:00
.pipe($.sourcemaps.init())
2015-05-02 23:38:39 +02:00
.pipe($.concat('timestring.js'))
2015-05-01 18:31:25 +02:00
.pipe($.babel())
.pipe($.sourcemaps.write())
2015-05-05 10:05:13 +02:00
.pipe(gulp.dest('./build'));
2015-04-30 18:03:33 +02:00
});
2015-05-01 18:31:25 +02:00
gulp.task('build:lib', function () {
2015-05-05 10:05:13 +02:00
return gulp.src('./build/timestring.js')
.pipe(gulp.dest('./dist/lib'));
2015-05-01 18:31:25 +02:00
});
gulp.task('build:browserify', function() {
return browserify('./build/timestring.js', { standalone: 'Timestring', debug: true })
.bundle()
.on('error', function(e){
console.log(e.message);
this.emit('end');
})
.pipe(source('timestring.js'))
2015-04-30 18:03:33 +02:00
.pipe(gulp.dest('dist'));
});
gulp.task('build:minify', function () {
2015-05-05 11:31:15 +02:00
return gulp.src('./dist/timestring.js')
.pipe($.sourcemaps.init({ loadMaps: true }))
2015-04-30 12:37:57 +02:00
.pipe($.uglify())
.pipe($.rename({
extname: '.min.js'
}))
2015-05-05 11:31:15 +02:00
.pipe($.sourcemaps.write())
2015-04-30 12:37:57 +02:00
.pipe(gulp.dest('dist'));
});
gulp.task('build', function (callback) {
runSequence(
2015-05-01 18:31:25 +02:00
['static-analysis:lint', 'static-analysis:cs'],
2015-04-30 18:03:33 +02:00
'build:clean',
2015-05-01 18:31:25 +02:00
'build:transpile',
'test',
['build:lib', 'build:browserify'],
2015-04-30 18:03:33 +02:00
'build:minify',
2015-04-30 12:37:57 +02:00
callback
);
});
2015-04-30 18:03:33 +02:00
gulp.task('sa', ['static-analysis:lint', 'static-analysis:cs']);
2015-05-01 18:31:25 +02:00
gulp.task('ci', function (callback) {
runSequence(
['static-analysis:lint', 'static-analysis:cs'],
'build:clean',
'build:transpile',
'test'
);
});
2015-04-30 12:37:57 +02:00
gulp.task('default', ['build']);