forked from pimcore/pimcore-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
139 lines (124 loc) · 4.02 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
var cssnano = require('cssnano'),
gulp = require('gulp'),
less = require('gulp-less'),
rename = require('gulp-rename'),
plumber = require('gulp-plumber'),
postcss = require('gulp-postcss'),
stylelint = require('gulp-stylelint'),
concat = require('gulp-concat'),
babel = require('gulp-babel'),
uglify = require('gulp-uglifyes');
var styles = {
'pimcore-core': {
source: "themes/pimcore/less/pimcore-core.less",
dest: "themes/pimcore/css/"
},
'pimcore-generic': {
source: "themes/pimcore/less/pimcore-generic.less",
dest: "themes/pimcore/css/"
}
};
var scripts = {
pimcore: {
filename: "pimcore.js",
sources: [
"vendor/daux/daux.io/themes/daux/js/jquery-1.11.3.min.js",
"vendor/daux/daux.io/themes/daux/js/highlight.pack.js",
"themes/pimcore/js/source/pimcore_code_section.js",
"themes/pimcore/js/source/pimcore_video.js",
"themes/pimcore/js/source/pimcore_image_lightbox.js",
"themes/pimcore/js/source/pimcore.js",
"vendor/daux/daux.io/themes/daux/js/daux.js"
],
dest: "themes/pimcore/js/build/"
}
};
var stylelintRules = {
"indentation": 4,
"selector-list-comma-newline-after": "always-multi-line",
"selector-max-id": 0,
// Autoprefixer
"at-rule-no-vendor-prefix": true,
"media-feature-name-no-vendor-prefix": true,
// "property-no-vendor-prefix": false,
"selector-no-vendor-prefix": true,
"value-no-vendor-prefix": true
};
var cssnanoOptions = {
safe: true, // Disable dangerous optimisations
filterPlugins: false, // This does very weird stuff
autoprefixer: {
add: true, // Add needed prefixes
remove: true // Remove unnecessary prefixes
}
};
function createCSSTask(source, dest) {
return function () {
return gulp.src(source)
.pipe(plumber())
.pipe(less())
.pipe(postcss([cssnano(cssnanoOptions)]))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(dest));
}
}
function createScriptTask(filename, sources, destination) {
return function () {
return gulp.src(sources)
.pipe(plumber())
.pipe(concat(filename))
.pipe(gulp.dest(destination))
.pipe(uglify({
mangle: false,
ecma: 6
}))
// .pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(destination));
}
}
gulp.task('lint-css', function () {
return gulp
.src(['themes/**/less/**/*.less', '!themes/**/vendor/**/*.less'])
.pipe(stylelint({
failAfterError: true,
config: {
extends: 'stylelint-config-standard',
rules: stylelintRules
},
syntax: 'less',
reporters: [{
formatter: 'string',
console: true
}],
debug: true
}));
});
var style_tasks = [];
for (var style in styles) {
if (styles.hasOwnProperty(style)) {
gulp.task('style_' + style, createCSSTask(styles[style].source, styles[style].dest));
style_tasks.push('style_' + style);
}
}
style_tasks.push('lint-css');
var script_tasks = [];
for (var script in scripts) {
if (scripts.hasOwnProperty(script)) {
gulp.task('script_' + script, createScriptTask(
scripts[script].filename,
scripts[script].sources,
scripts[script].dest
));
script_tasks.push('script_' + script);
}
}
gulp.task("styles", gulp.series(style_tasks));
gulp.task("scripts", gulp.series(script_tasks));
gulp.task('default', gulp.series(['scripts', 'styles']));
gulp.task('watch', function () {
// Watch .less files
gulp.watch('themes/**/less/**/*.less', { ignoreInitial: false }, gulp.series(['styles']));
// Watch .js files
gulp.watch('themes/**/js/source/**/*.js', { ignoreInitial: false }, gulp.series(['scripts']));
});