forked from bpampuch/pdfmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
91 lines (80 loc) · 2.77 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
var gulp = require('gulp');
var webpack = require('webpack-stream');
var gutil = require('gulp-util');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var replace = require('gulp-replace');
var mocha = require('gulp-spawn-mocha');
var jshint = require('gulp-jshint');
var each = require('gulp-each');
var fc2json = require('gulp-file-contents-to-json');
var header = require('gulp-header');
var DEBUG = process.env.NODE_ENV === 'debug',
CI = process.env.CI === 'true';
var banner = '/*! <%= pkg.name %> v<%= pkg.version %>, @license <%= pkg.license %>, @link <%= pkg.homepage %> */\n';
var uglifyOptions = {
compress: {
drop_console: true
},
mangle: {
except: ['HeadTable', 'NameTable', 'CmapTable', 'HheaTable', 'MaxpTable', 'HmtxTable', 'PostTable', 'OS2Table', 'LocaTable', 'GlyfTable']
}
};
gulp.task('default', [/*'lint',*/ 'test', 'build', 'buildFonts']);
gulp.task('build', function () {
var pkg = require('./package.json');
return gulp.src('src/browser-extensions/pdfMake.js')
.pipe(webpack(require('./webpack.config.js'), null, reportWebPackErrors))
.pipe(replace(/\/[*/][@#]\s+sourceMappingURL=((?:(?!\s+\*\/).)*).*\n/g, ''))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('build'))
.pipe(sourcemaps.init())
.pipe(uglify(uglifyOptions))
.pipe(header(banner, {pkg: pkg}))
.pipe(rename({extname: '.min.js'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('build'));
});
function reportWebPackErrors(err, stats) {
if (err) {
throw new gutil.PluginError("webpack", err);
}
gutil.log("[webpack]", stats.toString({
}));
}
gulp.task('test', ['prepareTestEnv'], function (cb) {
return gulp.src(['test-env/tests/**/*.js'])
.pipe(mocha({
debugBrk: DEBUG,
R: CI ? 'spec' : 'nyan'
}));
});
gulp.task('prepareTestEnv', ['copy-src-with-exposed-test-methods', 'copy-tests']);
gulp.task('copy-src-with-exposed-test-methods', function () {
return gulp.src(['src/**/*.js'], {base: './'})
.pipe(replace(/^(\/(\*)*TESTS.*$)/gm, '/$1'))
.pipe(gulp.dest('test-env'));
});
gulp.task('copy-tests', function () {
return gulp.src('tests/**/*.*', {base: './'})
.pipe(gulp.dest('test-env'));
});
gulp.task('lint', function () {
return gulp.src(['./src/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter());
});
gulp.task('buildFonts', function () {
return gulp.src(['./examples/fonts/*.*'])
.pipe(each(function (content, file, callback) {
var newContent = new Buffer(content).toString('base64');
callback(null, newContent);
}, 'buffer'))
.pipe(fc2json('vfs_fonts.js'))
.pipe(each(function (content, file, callback) {
var newContent = 'this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = ' + content + ';';
callback(null, newContent);
}, 'buffer'))
.pipe(gulp.dest('build'));
});