-
Notifications
You must be signed in to change notification settings - Fork 77
/
gulpfile.js
104 lines (94 loc) · 2.63 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
/********* to run gulp script *********
$ npm run gulp dist
or to watch files
$ npm run gulp watch
**************************************/
// include plug-ins
var gulp = require('gulp');
var umd = require('gulp-umd');
var inject = require('gulp-inject-string')
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var babel = require('gulp-babel');
var path = require('path');
var camelCase = require('camelcase');
var gutil = require('gulp-util');
var HEADER_COMMENT = '// Simple React Validator v1.6.2 | Created By Dockwa | MIT License | 2017 - Present\n';
function build() {
return gulp.src('./src/simple-react-validator.js')
.pipe(babel())
.pipe(umd({
exports: function() {
return 'SimpleReactValidator';
},
namespace: function() {
return 'SimpleReactValidator';
},
dependencies: function() {
return [
{
name: 'react',
amd: 'react',
cjs: 'react',
global: 'React',
param: 'React'
}
]
}
}))
.pipe(inject.prepend(HEADER_COMMENT))
.pipe(gulp.dest('./dist/'))
// minify
.pipe(uglify().on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString());
this.emit('end');
}))
.pipe(inject.prepend(HEADER_COMMENT))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./dist/'));
}
function buildLocales() {
return gulp.src('./src/locale/*')
.pipe(babel())
.pipe(umd({
exports: function(file) {
return 'null';
},
namespace: function(file) {
return `SimpleReactValidatorLocale${capitalizeFilename(file)}`;
},
dependencies: function() {
return [
{
name: 'simple-react-validator',
amd: 'simple-react-validator',
cjs: 'simple-react-validator',
global: 'SimpleReactValidator',
param: 'SimpleReactValidator'
}
]
}
}))
.pipe(inject.prepend(HEADER_COMMENT))
.pipe(gulp.dest('./dist/locale/'))
// minify
.pipe(uglify().on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString());
this.emit('end');
}))
.pipe(inject.prepend(HEADER_COMMENT))
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./dist/locale/min/'));
}
function watch() {
gulp.watch('src/*', build);
gulp.watch('src/*', buildLocales);
}
var dist = gulp.series(build, buildLocales)
exports.build = build;
exports.buildLocales = buildLocales;
exports.watch = watch;
exports.dist = dist;
function capitalizeFilename(file) {
return camelCase(path.basename(file.path, '.js'), {pascalCase: true});
}