-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (72 loc) · 2.09 KB
/
index.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
/*!
* customize-engine-less <https://github.com/nknapp/customize-engine-less>
*
* Copyright (c) 2015 Nils Knappmeier.
* Released under the MIT license.
*/
'use strict'
var less = require('less')
var path = require('path')
/**
* @typedef {object} CustomizeLessConfig
* Configuration for the customize less-engine
* @property {string|string[]} main absolute path to a lesscss-file or a list of absolute paths to less files
* @property {string|string[]} paths absolute path (or a list of those) to paths to use as import path
* @api public
*/
module.exports = {
schema: require('./schema.js'),
defaultConfig: {
main: [],
paths: []
},
preprocessConfig: function (config) {
return {
main: coerceToArray(config.main),
paths: coerceToArray(config.paths)
}
},
watched: function (config) {
return coerceToArray(config.main).concat(coerceToArray(config.paths))
},
/**
* Compute the raw CSS from the input files and store them as "main.css" and the source-map
* as "main.css.map"
* @param config
*/
run: function (config) {
var lessSource = config.main.map(function (file) {
if (path.extname(file) === '.css') {
return '@import (inline) "' + file + '";'
} else {
return '@import "' + file + '";'
}
}).join('\n')
return less.render(lessSource, {
paths: config.paths,
sourceMap: {
sourceMapURL: 'main.css.map',
outputSourceFiles: true
},
filename: 'customize-bundle.less',
compress: true
}).then(function (lessResult) {
return {
'main.css': lessResult.css,
'main.css.map': lessResult.map
}
})
}
}
/**
* If `objOrArray` exists and is a non-array, it is replaced by
* an array with the property as single object.
* @param {object|object[]} objOrArray the object or an array
* @return {object[]} objOrArray, if it is an array or an array containing `objOrArray` (if it is no array)
*/
function coerceToArray (objOrArray) {
if (objOrArray !== undefined && !Array.isArray(objOrArray)) {
return [ objOrArray ]
}
return objOrArray
}