forked from dockwa/simple-react-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
98 lines (89 loc) · 2.59 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
/********* 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 HEADER_COMMENT = '// Simple React Validator v1.2.2 | Created By Dockwa | MIT License | 2017 - Present\n';
var gutil = require('gulp-util');
gulp.task('build', function() {
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/'));
});
gulp.task('build-locales', function() {
gulp.src('./src/locale/*')
.pipe(babel())
.pipe(umd({
exports: function(file) {
return capitalizeFilename(file, false);
},
namespace: function(file) {
return `SimpleReactValidatorLocale${capitalizeFilename(file, true)}`;
},
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/'));
});
gulp.task('watch', function() {
gulp.watch(['src/*'], ['build', 'build-locales']);
});
gulp.task('dist', ['build', 'build-locales']);
function capitalizeFilename(file, pascalCase) {
return camelCase(path.basename(file.path, '.js'), {pascalCase: pascalCase});
}