-
Notifications
You must be signed in to change notification settings - Fork 77
/
gulpfile.js
49 lines (43 loc) · 1.53 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
'use strict';
var fs = require('fs');
var gulp = require('gulp');
var gulpPlugins = {
concat: require('gulp-concat'),
rename: require('gulp-rename'),
replace: require('gulp-replace'),
uglify: require('gulp-uglify'),
wrap: require('gulp-wrap')
};
var log = require('fancy-log');
var license = require('uglify-save-license');
var pkg = require('./package.json');
function bundleTask() {
var USE_STRICT_PATTERN = /(['"]use strict['"];?\n?)/g;
var REQUIRE_PATTERN = /((?:var |,)[^=]+=\s*require\([^\)]+\);?\n?)/g;
var EXPORT_PATTERN = /((?:module\.)?exports\s*=\s*[^,;]+;?\n?)/g;
var files = [
'./src/maxSafeInteger.js',
'./src/isFinite.js',
'./src/isSafeNumber.js',
'./src/makeOrdinal.js',
'./src/toOrdinal.js',
'./src/toWords.js',
'./src/toWordsOrdinal.js'
];
return gulp.src(files)
.on('error', log.error)
.pipe(gulpPlugins.wrap({ src: 'wrapEach.tmpl' }))
.pipe(gulpPlugins.replace(USE_STRICT_PATTERN, ''))
.pipe(gulpPlugins.replace(REQUIRE_PATTERN, ''))
.pipe(gulpPlugins.replace(EXPORT_PATTERN, ''))
.pipe(gulpPlugins.concat('numberToWords.js'))
.pipe(gulpPlugins.wrap({ src: 'wrapBundle.tmpl' }, pkg, { variable: 'data' }))
.pipe(gulp.dest('./'))
// Minified version
.pipe(gulpPlugins.uglify({ output: { comments: license } }))
.pipe(gulpPlugins.rename('numberToWords.min.js'))
.pipe(gulp.dest('./'));
}
module.exports = {
build: gulp.parallel(bundleTask)
};