-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
91 lines (77 loc) · 2.29 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
'use strict';
/* jshint node: true */
var fs = require('fs');
var KarmaServer = require('karma').Server;
var browserify = require('browserify');
var babelify = require('babelify');
var minifyCSS = require('gulp-minify-css');
var less = require('gulp-less');
var gulp = require('gulp');
var header = require('gulp-header');
var rename = require('gulp-rename');
var jshint = require('gulp-jshint');
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');
var config = {
pkg : require('./package.json'),
banner:
'/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.homepage %>\n' +
' * Version: <%= pkg.version %> - <%= timestamp %>\n' +
' * License: <%= pkg.license %>\n' +
' */\n\n\n'
};
gulp.task('jshint', function() {
return gulp.src(['src/**.js']).pipe(jshint());
});
gulp.task('scripts', ['jshint'], function() {
return browserify('src/index.js', {debug: true, standalone: 'JSONSchemaView'})
.transform(babelify.configure({compact: false}))
.bundle()
.on('error', logError)
.pipe(connect.reload())
.pipe(fs.createWriteStream('dist/bundle.js'));
});
gulp.task('uglify', ['scripts'], function() {
gulp.src('dist/bundle.js')
.pipe(uglify())
.pipe(rename({basename: 'bundle.min'}))
.pipe(gulp.dest('dist'));
});
gulp.task('styles', function() {
return gulp.src('src/style.less')
.pipe(less())
.on('error', logError)
.pipe(header(config.banner, {
timestamp: (new Date()).toISOString(), pkg: config.pkg
}))
.pipe(gulp.dest('dist'))
.pipe(minifyCSS())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist'))
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch(['src/style.less'], ['styles']);
gulp.watch(['src/*.js'], ['scripts']);
});
gulp.task('connect', function() {
connect.server({
root: __dirname,
open: 'demo',
livereload: true
});
});
gulp.task('test', function(done) {
var argv = require('minimist')(process.argv.slice(2));
new KarmaServer({
configFile: __dirname + '/test/karma.conf.js',
singleRun: argv.singleRun
}, done).start();
});
gulp.task('serve', ['watch', 'connect']);
gulp.task('default', ['styles', 'uglify']);
function logError(err) {
console.log('Error :\n' + err.message);
}