forked from bpampuch/pdfmake
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Gruntfile.js
140 lines (129 loc) · 3.41 KB
/
Gruntfile.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
module.exports = function(grunt) {
grunt.initConfig({
replace: {
// expose a couple of methods so they can be unit-tested
exposeTestMethods: {
src: ['src/*.js'],
overwrite: true,
replacements: [{
from: /^(\/(\*)*TESTS.*$)/gm,
to: '/$1'
}]
},
// hide private methods
hideTestMethods: {
src: ['src/*.js'],
overwrite: true,
replacements: [{
from: /^(\/(\/(\*)*TESTS.*$))/gm,
to: '$2'
}]
},
// updates pdfkit for client-side-support
fixPdfKit: {
src: ['node_modules/pdfkit/js/document.js', 'node_modules/pdfkit/js/mixins/fonts.js', 'node_modules/pdfkit/js/font/table.js', 'node_modules/pdfkit/package.json'],
overwrite: true,
replacements: [{
from: /^(\s*mixin = function\()(name)(\) {.*)$/mg,
to: '$1$2, methods$3'
}, {
from: /^(.*require.*\.\/mixins\/'.*$)/mg,
to: '//'
}, {
from: /^(\s*mixin\('([a-zA-Z]*)')(\);)/mg,
to: '$1, require(\'./mixins/$2.js\')$3'
}, {
from: 'return this.font(\'Helvetica\');',
to: ''
},
{
from: /"browserify": {[^}]*},/mg,
to: ''
},
/* IE workaround for no constructor.name */
{
from: 'this.constructor.name.replace',
to: '(this.constructor.name || this.constructor.toString().match(/function (.{1,})\\(/)[1]).replace'
}]
}
},
mochacov: {
test: {
options: {
reporter: '<%= (grunt.option("cc") ? "html-cov" : "spec") %>',
}
},
options: {
files: 'tests',
recursive: true,
'check-leaks': true
}
},
jsdoc: {
dist: {
src: ['src/*.js'],
options: {
destination: 'doc',
a: 'true'
}
}
},
jshint: {
all: [ 'src/**/*.js' ]
},
browserify: {
build: {
options: {
require: ['./src/browser-extensions/virtual-fs.js:fs', './src/browser-extensions/pdfMake.js:pdfMake'],
browserifyOptions: {
standalone: 'pdfMake'
}
}
}
},
dump_dir: {
fonts: {
options: {
pre: 'window.pdfMake = window.pdfMake || {}; window.pdfMake.vfs = ',
rootPath: 'examples/fonts/'
},
files: {
'build/vfs_fonts.js': ['examples/fonts/*' ]
}
}
},
uglify: {
build: {
options: {
sourceMap: true,
compress: {
drop_console: true
},
mangle: {
except: ['HeadTable', 'NameTable', 'CmapTable', 'HheaTable', 'MaxpTable', 'HmtxTable', 'PostTable', 'OS2Table', 'LocaTable', 'GlyfTable']
}
},
files: {
'build/pdfmake.min.js': ['build/pdfmake.js']
}
}
}
});
grunt.loadNpmTasks('grunt-mocha-cov');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-dump-dir');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('test', [ 'replace:fixPdfKit', 'replace:exposeTestMethods', 'jshint', 'mochacov', 'replace:hideTestMethods' ]);
grunt.registerTask('fixVfsFonts', 'Adds semicolon to the end of vfs_fonts.js', function () {
var file = grunt.file.read('build/vfs_fonts.js');
file += ";";
grunt.file.write('build/vfs_fonts.js', file);
});
grunt.registerTask('buildFonts', [ 'dump_dir', 'fixVfsFonts' ]);
grunt.registerTask('build', [ 'replace:fixPdfKit', 'browserify', 'uglify', 'buildFonts' ]);
grunt.registerTask('default', [ 'test', 'build' ]);
};