-
Notifications
You must be signed in to change notification settings - Fork 103
/
gulpfile.js
73 lines (58 loc) · 1.91 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
'use strict';
var fs = require('fs')
, pkg = require('./package.json')
, gulp = require('gulp')
, header = require('gulp-header')
, footer = require('gulp-footer')
, concat = require('gulp-concat')
, uglify = require('gulp-uglify')
, jshint = require('gulp-jshint')
, livereload = require('gulp-livereload')
, sourcemaps = require('gulp-sourcemaps');
var paths = {
vendor: [
"grid.js", "version.js", "detector.js", "formatinf.js",
"errorlevel.js", "bitmat.js", "datablock.js","bmparser.js",
"datamask.js","rsdecoder.js","gf256poly.js", "gf256.js",
"decoder.js", "qrcode.js", "findpat.js", "alignpat.js",
"databr.js"]
.map(function (file) { return 'vendor/' + file; }),
vendorBuild: ['build/qrcode.js'],
src: ['src/qcode-decoder.js']
};
gulp.task('build', ['build:vendor'], function() {
return gulp.src(paths.vendorBuild.concat(paths.src))
.pipe(sourcemaps.init())
.pipe(concat('qcode-decoder.min.js'))
.pipe(uglify({mangle: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('build'));
});
gulp.task('build:vendor', function () {
var vendor = {
header: fs.readFileSync(__dirname + '/vendor/header-umd.js'),
footer: fs.readFileSync(__dirname + '/vendor/footer-umd.js')
};
return gulp.src(paths.vendor)
.pipe(sourcemaps.init())
.pipe(concat('qrcode.js'))
.pipe(header(vendor.header))
.pipe(footer(vendor.footer))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('build'));
});
gulp.task('hint', function () {
return gulp.src('src/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('watch', function () {
var changeHandler = function (){};
if (process.argv[3] === '--livereload')
(livereload.listen(),
changeHandler = livereload.changed);
gulp.watch(paths.src, ['hint', 'build'])
.on('change', changeHandler);
});
gulp.task('default', ['hint', 'build']);