forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
172 lines (161 loc) · 4.88 KB
/
Gruntfile.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
module.exports = function(grunt) {
require('jit-grunt')(grunt); // Just in time library loading
var fs = require('fs');
function getLoadPaths(file) {
var config;
var parts = file.split('/');
parts.pop(); // eliminate filename
// initialize search path with directory containing LESS file
var retVal = [];
retVal.push(parts.join('/'));
// Iterate through theme.config.php files collecting parent themes in search path:
while (config = fs.readFileSync("themes/" + parts[1] + "/theme.config.php", "UTF-8")) {
var matches = config.match(/["']extends["']\s*=>\s*['"](\w+)['"]/);
// "extends" set to "false" or missing entirely? We've hit the end of the line:
if (matches === null || matches[1] === 'false') {
break;
}
parts[1] = matches[1];
retVal.push(parts.join('/') + '/');
}
return retVal;
}
var fontAwesomePath = '"../../bootstrap3/css/fonts"';
grunt.initConfig({
// LESS compilation
less: {
compile: {
options: {
paths: getLoadPaths,
compress: true,
modifyVars: {
'fa-font-path': fontAwesomePath
}
},
files: [{
expand: true,
src: "themes/*/less/compiled.less",
rename: function (dest, src) {
return src.replace('/less/', '/css/').replace('.less', '.css');
}
}]
}
},
// SASS compilation
scss: {
sass: {
options: {
style: 'compress'
}
}
},
// Convert LESS to SASS, mostly for development team use
lessToSass: {
convert: {
files: [
{
expand: true,
cwd: 'themes/bootstrap3/less',
src: ['*.less', 'components/*.less'],
ext: '.scss',
dest: 'themes/bootstrap3/scss'
},
{
expand: true,
cwd: 'themes/bootprint3/less',
src: ['*.less'],
ext: '.scss',
dest: 'themes/bootprint3/scss'
}
],
options: {
replacements: [
{ // Replace ; in include with ,
pattern: /(\s+)@include ([^\(]+)\(([^\)]+)\);/gi,
replacement: function mixinCommas(match, space, $1, $2) {
return space + '@include ' + $1 + '(' + $2.replace(/;/g, ',') + ');';
},
order: 3
},
{ // Inline &:extends converted
pattern: /&:extend\(([^\)]+)\)/gi,
replacement: '@extend $1',
order: 3
},
{ // Inline variables not default
pattern: / !default; }/gi,
replacement: '; }',
order: 3
},
{ // VuFind: Correct paths
pattern: 'vendor/bootstrap/bootstrap',
replacement: 'vendor/bootstrap',
order: 4
},
{
pattern: '$fa-font-path: "../../../fonts" !default;\n',
replacement: '',
order: 4
},
{
pattern: '@import "vendor/font-awesome/font-awesome";',
replacement: '$fa-font-path: ' + fontAwesomePath + ';\n@import "vendor/font-awesome/font-awesome";',
order: 4
},
{ // VuFind: Bootprint fixes
pattern: '@import "bootstrap";\n@import "variables";',
replacement: '@import "variables", "bootstrap";',
order: 4
},
{
pattern: '$brand-primary: #619144 !default;',
replacement: '$brand-primary: #619144;',
order: 4
}
]
}
}
},
watch: {
options: {
atBegin: true
},
less: {
files: 'themes/*/less/**/*.less',
tasks: ['less']
},
scss: {
files: 'themes/*/scss/**/*.scss',
tasks: ['scss']
}
}
});
grunt.registerMultiTask('scss', function sassScan() {
var sassConfig = {},
path = require('path'),
themeList = fs.readdirSync(path.resolve('themes')).filter(function (theme) {
return fs.existsSync(path.resolve('themes/' + theme + '/scss/compiled.scss'));
});
for (var i in themeList) {
var config = {
options: {
outputStyle: 'compressed'
},
files: [{
expand: true,
cwd: path.join('themes', themeList[i], 'scss'),
src: ['compiled.scss'],
dest: path.join('themes', themeList[i], 'css'),
ext: '.css'
}]
};
for (var key in this.data.options) {
config.options[key] = this.data.options[key] + '';
}
config.options.includePaths = getLoadPaths('themes/' + themeList[i] + '/scss/compiled.scss');
sassConfig[themeList[i]] = config;
}
grunt.config.set('sass', sassConfig);
grunt.task.run('sass');
});
};