-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
136 lines (128 loc) · 4.69 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
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/switchtemplate.js',
'source/js/mgr/helper/combo.js',
'source/js/mgr/helper/util.js',
'source/js/mgr/widgets/home.panel.js',
'source/js/mgr/widgets/setting.grid.js',
'source/js/mgr/widgets/settings.panel.js',
'source/js/mgr/sections/home.js'
])
.pipe(concat('switchtemplate.min.js'))
.pipe(uglify())
.pipe(header(banner + '\n', {pkg: pkg}))
.pipe(gulp.dest('assets/components/switchtemplate/js/mgr/'))
};
gulp.task('scripts', gulp.series(scriptsMgr));
const sassMgr = function () {
return gulp.src([
'source/sass/mgr/switchtemplate.scss'
])
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
autoprefixer()
]))
.pipe(gulp.dest('source/css/mgr/'))
.pipe(concat('switchtemplate.css'))
.pipe(postcss([
cssnano({
preset: ['default', {
discardComments: {
removeAll: true
}
}]
})
]))
.pipe(rename({
suffix: '.min'
}))
.pipe(footer('\n' + banner, {pkg: pkg}))
.pipe(gulp.dest('assets/components/switchtemplate/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/switchtemplate/img/'));
};
gulp.task('images', gulp.series(imagesMgr));
const bumpCopyright = function () {
return gulp.src([
'core/components/switchtemplate/model/switchtemplate/switchtemplate.class.php',
'core/components/switchtemplate/src/SwitchTemplate.php',
], {base: './'})
.pipe(replace(/Copyright 2014(-\d{4})? by/g, 'Copyright ' + (year > 2014 ? '2014-' : '') + year + ' by'))
.pipe(gulp.dest('.'));
};
const bumpVersion = function () {
return gulp.src([
'core/components/switchtemplate/src/SwitchTemplate.php',
], {base: './'})
.pipe(replace(/version = '\d+\.\d+\.\d+[-a-z0-9]*'/ig, 'version = \'' + pkg.version + '\''))
.pipe(gulp.dest('.'));
};
const bumpHomepanel = function () {
return gulp.src([
'source/js/mgr/widgets/home.panel.js'
], {base: './'})
.pipe(replace(/© 2014(-\d{4})?/g, '© ' + (year > 2014 ? '2014-' : '') + year))
.pipe(gulp.dest('.'));
};
const bumpDocs = function () {
return gulp.src([
'mkdocs.yml',
], {base: './'})
.pipe(replace(/© 2014(-\d{4})?/g, '© ' + (year > 2014 ? '2014-' : '') + 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, bumpHomepanel, 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'));