This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.babel.js
96 lines (86 loc) · 2.51 KB
/
gulpfile.babel.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
import pkg from './package.json';
import gulp from 'gulp';
import eslint from 'gulp-eslint';
import uglify from 'gulp-uglify';
import header from 'gulp-header';
import rename from 'gulp-rename';
import sourcemaps from 'gulp-sourcemaps';
import browserify from 'browserify';
import babelify from 'babelify';
import del from 'del';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import { Server } from 'karma';
const banner = `/*! ${pkg.name} v${pkg.version} | ${pkg.homepage} */\n`;
const config = {
name: 'isStlyeSupported',
files: './src/**/*.js',
entryFile: './src/is-style-supported.js',
outputFile: 'is-style-supported.js',
outputDir: './dist/',
specs: './test/*.js'
};
const karmaConfig = {
basePath: __dirname,
frameworks: ['browserify', 'mocha', 'chai', 'sinon', 'source-map-support'],
files: [config.specs],
preprocessors: {[config.specs]: ['browserify']},
browserify: {
debug: true,
transform: [
['babelify', {plugins: ['istanbul']}]
]
},
coverageReporter: {
type: 'html',
dir: './test/coverage/'
},
browsers: ['ChromeHeadless'],
autoWatch: false,
singleRun: true
};
gulp.task('clean', () => {
return del.sync([config.outputDir]);
});
gulp.task('build', ['clean'], () => {
return browserify(config.entryFile, {debug: true, standalone: config.name})
.transform(babelify)
.bundle()
.pipe(source(config.outputFile))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(header(banner, {pkg}))
.pipe(gulp.dest(config.outputDir))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(header(banner, {pkg}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.outputDir));
});
gulp.task('lint', () => {
return gulp.src(['./gulpfile.babel.js', config.files, config.specs])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('test', () => {
karmaConfig.reporters = ['mocha'];
new Server(karmaConfig, (code) => {
process.exit(code);
}).start();
});
gulp.task('coverage', () => {
karmaConfig.reporters = ['mocha', 'coverage'];
new Server(karmaConfig, (code) => {
process.exit(code);
}).start();
});
gulp.task('watch', () => {
gulp.watch(['./gulpfile.babel.js', config.files, config.specs], ['lint', 'test']);
});
gulp.task('default', [
'lint',
'coverage',
'build',
'watch'
]);