forked from catarse/catarse.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
112 lines (103 loc) · 3.12 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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var concat = require('gulp-concat');
var argv = require('yargs').argv;
var multiEntry = require('rollup-plugin-multi-entry');
var babel = require('rollup-plugin-babel');
var rollup = require('rollup-stream');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var sourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var clean = require('gulp-clean');
var Server = require('karma').Server;
var sources = ['src/c.js', 'src/h.js', 'src/models.js', 'src/root/**/*.js','src/c/**/*.js','src/**/*.js'];
var tests = ['spec/components/**/*.spec.js', 'spec/helpers/**/*.spec.js', 'src/**/*.js'];
var rollupGlobals = {
underscore: '_',
liquidjs: 'Liquid',
moment: 'moment',
mithril: 'm',
jquery: '$',
select: 'select',
CatarseAnalytics: 'CatarseAnalytics',
chartjs: 'Chart',
replaceDiacritics: 'replaceDiacritics',
'mithril-postgrest': 'Postgrest',
'i18n-js': 'I18n'
};
gulp.task('bundle-tests', function(done){
rollup({
input: tests,
sourcemap: true,
format: 'iife',
name: 'catarseSpecs',
plugins: [
babel({
exclude: 'node_modules/**',
}),
multiEntry()
],
globals: rollupGlobals,
external: Object.keys(rollupGlobals)
})
.pipe(source('spec/components/**/*.spec.js', 'spec/helpers/**/*.spec.js', 'src/**/*.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(rename('bundle.spec.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./spec'))
.on('end', done);
});
gulp.task('clean-tests', ['karma'], function() {
gulp.src('spec/bundle.spec.js', {read: false})
.pipe(clean());
});
gulp.task('karma', ['bundle-tests'],function(done) {
new Server({
configFile: __dirname + '/karma.conf.js'
}, done).start();
});
gulp.task('lint', function(){
gulp.src(sources)
.pipe(plumber())
.pipe(jscs())
.pipe(jshint());
});
gulp.task('dist', function(done){
rollup({
input: 'src/c.js',
format: 'iife',
name: 'c',
sourcemap: true,
plugins: [
babel({
exclude: 'node_modules/**',
})
],
globals: rollupGlobals,
external: Object.keys(rollupGlobals)
})
.pipe(source('src/**/*.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write())
.pipe(rename('catarse.js'))
.pipe(gulp.dest('dist'))
.pipe($.if(!argv.q, uglify()))
.pipe(rename('catarse.min.js'))
.pipe(gulp.dest('dist'))
.on('end', done);
});
gulp.task('watch', function(){
(argv.q) ? gulp.watch(sources, ['dist']) :
(argv.notest) ? gulp.watch(sources, ['lint', 'dist']) :
gulp.watch(sources.concat(tests), ['test', 'lint', 'dist']);
});
gulp.task('default', ['watch']);
gulp.task('test', ['bundle-tests', 'karma', 'clean-tests']);
gulp.task('build', ['lint', 'test', 'dist']);