forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathGruntfile.local.js
92 lines (80 loc) · 2.97 KB
/
Gruntfile.local.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
module.exports = function(grunt) {
const fs = require("fs");
const os = require("node:os");
const style = grunt.option('style') ?? 'expanded';
grunt.registerTask("finna:scss", function finnaScssFunc() {
const config = getFinnaSassConfig({
outputStyle: style,
quietDeps: true
}, false);
grunt.config.set('dart-sass', config);
grunt.task.run('dart-sass');
});
grunt.registerTask('finna:check:scss', function sassCheck() {
const config = getFinnaSassConfig({
quietDeps: true
}, true);
grunt.config.set('dart-sass', config);
grunt.task.run('dart-sass');
});
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")) {
// First identify mixins:
var mixinMatches = config.match(/["']mixins["']\s*=>\s*\[([^\]]+)\]/);
if (mixinMatches !== null) {
var mixinParts = mixinMatches[1].split(',');
for (var i = 0; i < mixinParts.length; i++) {
parts[1] = mixinParts[i].trim().replace(/['"]/g, '');
retVal.push(parts.join('/') + '/');
}
}
// Now move up to parent theme:
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;
}
function getFinnaSassConfig(additionalOptions, checkOnly) {
var sassConfig = {},
path = require('path'),
themeList = fs.readdirSync(path.resolve('themes')).filter(function (theme) {
return fs.existsSync(path.resolve('themes/' + theme + '/scss/finna.scss'));
});
for (var i in themeList) {
if (Object.prototype.hasOwnProperty.call(themeList, i)) {
var config = {
options: {},
files: [{
expand: true,
cwd: path.join('themes', themeList[i], 'scss'),
src: ['finna.scss'],
dest: path.join(checkOnly ? os.tmpdir() : 'themes', themeList[i], 'css'),
ext: '.css'
}]
};
for (var key in additionalOptions) {
if (Object.prototype.hasOwnProperty.call(additionalOptions, key)) {
config.options[key] = additionalOptions[key];
}
}
config.options.includePaths = getLoadPaths('themes/' + themeList[i] + '/scss/finna.scss');
config.options.includePaths.push('vendor/');
config.options.includePaths.push(path.resolve('themes/bootstrap3/scss/vendor'));
sassConfig[themeList[i]] = config;
}
}
return sassConfig;
}
};