forked from civicrm/org.civicrm.shoreditch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
74 lines (64 loc) · 2.27 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
var gulp = require('gulp');
var bulk = require('gulp-sass-bulk-import');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var postcssPrefix = require('postcss-prefix-selector');
var postcssDiscardDuplicates = require('postcss-discard-duplicates');
var stripCssComments = require('gulp-strip-css-comments');
var transformSelectors = require("gulp-transform-selectors");
var civicrmScssRoot = require('civicrm-scssroot')();
var bootstrapNamespace = '#bootstrap-theme';
gulp.task('sass:bootstrap', ['sass:sync'], function () {
return gulp.src('scss/bootstrap/bootstrap.scss')
.pipe(bulk())
.pipe(sass({
outputStyle: 'compressed',
includePaths: civicrmScssRoot.getPath(),
precision: 10
}).on('error', sass.logError))
.pipe(stripCssComments({ preserve: false }))
.pipe(postcss([postcssPrefix({
prefix: bootstrapNamespace + ' ',
exclude: [/^html/, /^body/, /\.ta-hidden-input/]
})]))
.pipe(transformSelectors(namespaceRootElements, { splitOnCommas: true }))
.pipe(gulp.dest('css/'));
});
gulp.task('sass:civicrm', ['sass:sync'], function () {
return gulp.src('scss/civicrm/custom-civicrm.scss')
.pipe(bulk())
.pipe(sass({
outputStyle: 'compressed',
includePaths: civicrmScssRoot.getPath(),
precision: 10
}).on('error', sass.logError))
.pipe(stripCssComments({ preserve: false }))
.pipe(postcss([postcssPrefix({
prefix: '.crm-container ',
exclude: [/page-civicrm/, /crm-container/, /civicrm-menu/, /#root-menu-div/]
}), postcssDiscardDuplicates]))
.pipe(gulp.dest('css/'));
});
gulp.task('sass:sync', function(){
civicrmScssRoot.updateSync();
});
gulp.task('sass', ['sass:bootstrap', 'sass:civicrm']);
gulp.task('watch', function () {
gulp.watch(civicrmScssRoot.getWatchList(), ['sass']);
});
gulp.task('default', ['sass', 'watch']);
/**
* Apply the namespace on html and body elements
*
* @param {string} selector the current selector to be transformed
* @return string
*/
function namespaceRootElements(selector) {
var regex = /^(body|html)/;
if (regex.test(selector)) {
selector = selector.replace(regex, function (match) {
return match + bootstrapNamespace;
}) + ",\n" + selector.replace(regex, bootstrapNamespace);
}
return selector;
}