forked from alanpich/tvImagePlus
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
gulpfile.js
140 lines (132 loc) · 4.96 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
const gulp = require('gulp'),
autoprefixer = require('autoprefixer'),
composer = require('gulp-uglify/composer'),
concat = require('gulp-concat'),
cssnano = require('cssnano'),
footer = require('gulp-footer'),
format = require('date-format'),
header = require('@fomantic/gulp-header'),
postcss = require('gulp-postcss'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
sass = require('gulp-sass')(require('sass')),
uglifyjs = require('uglify-js'),
uglify = composer(uglifyjs, console),
pkg = require('./_build/config.json');
const banner = '/*!\n' +
' * <%= pkg.name %> - <%= pkg.description %>\n' +
' * Version: <%= pkg.version %>\n' +
' * Build date: ' + format("yyyy-MM-dd", new Date()) + '\n' +
' */';
const year = new Date().getFullYear();
let phpversion;
let modxversion;
pkg.dependencies.forEach(function (dependency, index) {
switch (pkg.dependencies[index].name) {
case 'php':
phpversion = pkg.dependencies[index].version.replace(/>=/, '');
break;
case 'modx':
modxversion = pkg.dependencies[index].version.replace(/>=/, '');
break;
}
});
const scriptsMgr = function () {
return gulp.src([
'source/js/mgr/imageplus.js',
'source/js/mgr/imageplus.panel.input.js',
'source/js/mgr/imageplus.window.editor.js',
'source/js/mgr/imageplus.migx_renderer.js',
'source/js/mgr/tools/JSON2.js',
'node_modules/jquery/dist/jquery.slim.min.js',
'source/vendor/jcrop/js/jquery.Jcrop.min.js',
'source/js/mgr/imageplus.jquery.imagecrop.js',
'source/js/mgr/imageplus.grid.js'
])
.pipe(concat('imageplus.min.js'))
.pipe(uglify())
.pipe(header(banner + '\n', {pkg: pkg}))
.pipe(gulp.dest('assets/components/imageplus/js/mgr/'))
};
gulp.task('scripts', gulp.series(scriptsMgr));
const sassMgr = function () {
return gulp.src([
'source/sass/mgr/imageplus.scss'
])
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
autoprefixer()
]))
.pipe(gulp.dest('source/css/mgr/'))
.pipe(concat('imageplus.css'))
.pipe(postcss([
cssnano({
preset: ['default', {
discardComments: {
removeAll: true
}
}]
})
]))
.pipe(rename({
suffix: '.min'
}))
.pipe(footer('\n' + banner, {pkg: pkg}))
.pipe(gulp.dest('assets/components/imageplus/css/mgr/'))
};
gulp.task('sass', gulp.series(sassMgr));
const imagesMgr = function () {
return gulp.src('./source/img/**/*.+(png|jpg|gif|svg)', {encoding: false})
.pipe(gulp.dest('assets/components/imageplus/img/'));
};
gulp.task('images', gulp.series(imagesMgr));
const bumpCopyright = function () {
return gulp.src([
'core/components/imageplus/model/imageplus/imageplus.class.php',
'core/components/imageplus/src/ImagePlus.php'
], {base: './'})
.pipe(replace(/Copyright 2015(-\d{4})? by/g, 'Copyright ' + (year > 2015 ? '2015-' : '') + year + ' by'))
.pipe(replace(/(@copyright .*?) 2015(-\d{4})?/g, '$1 ' + (year > 2015 ? '2015-' : '') + year))
.pipe(gulp.dest('.'));
};
const bumpVersion = function () {
return gulp.src([
'core/components/imageplus/src/ImagePlus.php'
], {base: './'})
.pipe(replace(/version = '\d+\.\d+\.\d+[-a-z0-9]*'/ig, 'version = \'' + pkg.version + '\''))
.pipe(gulp.dest('.'));
};
const bumpOptions = function () {
return gulp.src([
'core/components/imageplus/elements/tv/input/tpl/imageplus.options.tpl',
'core/components/imageplus/elements/tv/output/tpl/imageplus.options.tpl'
], {base: './'})
.pipe(replace(/© 2015(-\d{4})?/g, '© ' + (year > 2015 ? '2015-' : '') + year))
.pipe(gulp.dest('.'));
};
const bumpDocs = function () {
return gulp.src([
'mkdocs.yml',
], {base: './'})
.pipe(replace(/© 2015(-\d{4})?/g, '© ' + (year > 2015 ? '2015-' : '') + year))
.pipe(gulp.dest('.'));
};
const bumpRequirements = function () {
return gulp.src([
'docs/index.md',
], {base: './'})
.pipe(replace(/[*-] MODX Revolution \d.\d.*/g, '* MODX Revolution ' + modxversion + '+'))
.pipe(replace(/[*-] PHP (v)?\d.\d.*/g, '* PHP ' + phpversion + '+'))
.pipe(gulp.dest('.'));
};
gulp.task('bump', gulp.series(bumpCopyright, bumpVersion, bumpOptions, bumpDocs, bumpRequirements));
gulp.task('watch', function () {
// Watch .js files
gulp.watch(['./source/js/**/*.js'], gulp.series('scripts'));
// Watch .scss files
gulp.watch(['./source/sass/**/*.scss'], gulp.series('sass'));
// Watch *.(png|jpg|gif|svg) files
gulp.watch(['./source/img/**/*.(png|jpg|gif|svg)'], gulp.series('images'));
});
// Default Task
gulp.task('default', gulp.series('bump', 'scripts', 'sass', 'images'));