forked from mwilliamson/mammoth.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
163 lines (144 loc) · 4 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
'use strict'
const browserify = require('browserify')
const uglifyES = require('uglify-es')
const gulp = require('gulp')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const composer = require('gulp-uglify/composer')
const sourcemaps = require('gulp-sourcemaps')
const minify = composer(uglifyES, console)
const jetpack = require('fs-jetpack')
const rename = require('gulp-rename')
const prependLicense = require('browserify-prepend-licenses')
const babelify = require('babelify')
const babel = require('gulp-babel')
const nodeResolve = require('rollup-plugin-node-resolve')
const srcDir = jetpack.cwd('./src')
const libDir = srcDir.cwd('./lib')
const testDir = srcDir.cwd('./test')
const binDir = srcDir.cwd('./bin')
const buildDir = jetpack.cwd('./build')
const libBuildDir = buildDir.cwd('./lib')
const testBuildDir = buildDir.cwd('./test')
const binBuildDir = buildDir.cwd('./bin')
const distDir = jetpack.cwd('./dist')
const bundleName = 'mammoth.browser.js'
const minifiedBundleName = 'mammoth.browser.min.js'
gulp.task('clean-dist', () => {
distDir.dir('.', {empty: true})
})
gulp.task('clean-build', () => {
buildDir.dir('.', {empty: true})
libBuildDir.dir('.', {empty: true})
testBuildDir.dir('.', {empty: true})
binBuildDir.dir('.', {empty: true})
})
gulp.task('build-dist', ['clean-dist'], () => {
// set up the browserify instance on a task basis
const b = browserify({
entries: libDir.path('index.js'),
debug: true,
standalone: 'mammoth'
})
b.plugin(prependLicense)
b.transform('rollupify', {
config: {
external: ['util.promisify', 'jszip', 'lop', 'path-is-absolute', 'sax', 'xmlbuilder'],
plugins: [
nodeResolve({
browser: true,
jsnext: true
})
]
}
})
b.transform(babelify.configure({
presets: [
['@babel/preset-env', {
targets: {
browsers: ['> 1%']
},
useBuiltIns: 'usage'
}]
],
babel: require('@babel/core')
}))
return b.bundle()
.pipe(source(bundleName, buildDir.path()))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(distDir.path()))
})
gulp.task('minify', ['build-dist'], () => {
return gulp.src(distDir.path(bundleName))
.pipe(rename(minifiedBundleName))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(minify({
compress: {
passes: 2,
toplevel: true,
typeofs: false
},
ie8: true,
toplevel: true
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(distDir.path()))
})
gulp.task('pretest', ['build-lib', 'copy-test-assets', 'build-bin'], () => {
return gulp.src(testDir.path('**/*.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(babel({
presets: [
['@babel/preset-env', {
targets: {
node: '4'
},
useBuiltIns: 'usage'
}]
]
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(testBuildDir.path()))
})
gulp.task('copy-test-assets', ['clean-build'], () => {
return gulp.src(testDir.path('test-data/**'))
.pipe(gulp.dest(testBuildDir.path('test-data')))
})
gulp.task('build-lib', ['clean-build'], () => {
return gulp.src(libDir.path('**/*.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(babel({
presets: [
['@babel/preset-env', {
targets: {
node: '4'
},
useBuiltIns: 'usage'
}]
]
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(libBuildDir.path('.')))
})
gulp.task('build-bin', ['clean-build'], () => {
return gulp.src(binDir.path('**/*'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(babel({
presets: [
['@babel/preset-env', {
targets: {
node: '4'
},
useBuiltIns: 'usage'
}]
]
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(binBuildDir.path('.')))
})