-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
124 lines (116 loc) · 4.18 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
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 scriptsWeb = function () {
return gulp.src([
'source/js/rememberthis.js'
])
.pipe(concat('rememberthis.min.js'))
.pipe(uglify())
.pipe(header(banner + '\n', {pkg: pkg}))
.pipe(gulp.dest('assets/components/rememberthis/js/'))
};
gulp.task('scripts', gulp.series(scriptsWeb));
const sassWeb = function () {
return gulp.src([
'source/sass/rememberthis.scss'
])
.pipe(gulp.dest('assets/components/rememberthis/scss/'))
.pipe(concat('rememberthis.scss'))
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
autoprefixer()
]))
.pipe(gulp.dest('assets/components/rememberthis/css/'))
.pipe(concat('rememberthis.css'))
.pipe(postcss([
cssnano({
preset: ['default', {
discardComments: {
removeAll: true
}
}]
})
]))
.pipe(rename({
suffix: '.min'
}))
.pipe(footer('\n' + banner, {pkg: pkg}))
};
gulp.task('sass', gulp.series(sassWeb));
const imagesWeb = function () {
return gulp.src('./source/img/**/*.+(png|jpg|gif|svg)', {encoding: false})
.pipe(gulp.dest('assets/components/rememberthis/img/'));
};
gulp.task('images', gulp.series(imagesWeb));
const bumpCopyright = function () {
return gulp.src([
'core/components/rememberthis/model/rememberthis/rememberthis.class.php',
'core/components/rememberthis/src/RememberThis.php'
], {base: './'})
.pipe(replace(/Copyright 2008(-\d{4})? by/g, 'Copyright ' + (year > 2008 ? '2008-' : '') + year + ' by'))
.pipe(gulp.dest('.'));
};
const bumpVersion = function () {
return gulp.src([
'core/components/rememberthis/src/RememberThis.php'
], {base: './'})
.pipe(replace(/version = '\d+\.\d+\.\d+[-a-z0-9]*'/ig, 'version = \'' + pkg.version + '\''))
.pipe(gulp.dest('.'));
};
const bumpDocs = function () {
return gulp.src([
'mkdocs.yml',
], {base: './'})
.pipe(replace(/© 2008(-\d{4})?/g, '© ' + (year > 2008 ? '2008-' : '') + 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, 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'));