-
Notifications
You must be signed in to change notification settings - Fork 329
/
gulpfile.js
142 lines (128 loc) · 2.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
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
'use strict';
/*eslint no-console: 0*/
/*eslint no-process-env: 0*/
const path = require('path');
const gulp = require('gulp'),
mergeStream = require('merge-stream'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
loadPlugins = require('gulp-load-plugins');
const plugins = loadPlugins({
config: path.join(__dirname, 'package.json')
});
const pkg = require('./package.json');
const header = [
'/**',
' * <%= pkg.name %>',
' * <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''
].join('\n');
exports.build = gulp.series(buildDependencies, build);
exports.default = gulp.series(build, function() {
gulp.watch('src/**/*.js', build);
});
exports.serve = gulp.series(build, function(done) {
var server = require('./server');
const PORT = process.env.PORT || 9090;
server.listen(PORT, function() {
console.log(`Server running in port ${PORT}`);
done();
});
});
function buildDependencies() {
return browserify()
.require('string-mask', {
expose: 'string-mask'
})
.require('date-fns/format', {
expose: 'date-fns/format'
})
.require('date-fns/parse', {
expose: 'date-fns/parse'
})
.require('date-fns/isValid', {
expose: 'date-fns/isValid'
})
.require('br-validations', {
expose: 'br-validations'
})
.bundle()
.pipe(source('angular-input-masks-dependencies.js'))
.pipe(buffer())
.pipe(gulp.dest('./releases/'))
.pipe(plugins.uglify())
.pipe(
plugins.rename({
extname: '.min.js'
})
)
.pipe(gulp.dest('./releases/'));
}
function build() {
var files = [
{
fileName: 'angular-input-masks.js',
debug: false,
bundleExternal: false
},
{
fileName: 'angular-input-masks.br.js',
debug: false,
bundleExternal: false
},
{
fileName: 'angular-input-masks.ch.js',
debug: false,
bundleExternal: false
},
{
fileName: 'angular-input-masks.fr.js',
debug: false,
bundleExternal: false
},
{
fileName: 'angular-input-masks.us.js',
debug: false,
bundleExternal: false
},
{
fileName: 'angular-input-masks.js',
outputFileName: 'angular-input-masks-standalone.js',
debug: false,
bundleExternal: true
},
{
fileName: 'angular-input-masks.js',
outputFileName: 'angular-input-masks-debug.js',
debug: true,
bundleExternal: true
}
];
var tasks = files.map(function(entry) {
return browserify({
entries: entry.fileName,
detectGlobals: false,
basedir: './src/',
debug: entry.debug,
bundleExternal: entry.bundleExternal
})
.bundle()
.pipe(source(entry.outputFileName || entry.fileName))
.pipe(buffer())
.pipe(plugins.header(header, { pkg: pkg }))
.pipe(gulp.dest('./releases/'))
.pipe(plugins.uglify())
.pipe(
plugins.rename({
extname: '.min.js'
})
)
.pipe(gulp.dest('./releases/'));
});
return mergeStream(tasks);
}