-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.iced
39 lines (32 loc) · 1.06 KB
/
plugin.iced
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
fs = require 'fs'
path = require 'path'
less = require 'less'
regex = ///
@import\s+ # @import followed by one or more whitespace chars
['"] # single or double quote
([^'"]+) # capture chars except single or double quote
///gi
exports.findImports = findImports = (imports, file, callback) ->
await fs.readFile file, 'utf8', defer err, contents
return callback err if err
newImports = []
while match = regex.exec contents
item = match[1]
item += '.less' if path.extname(item) is ''
item = path.resolve path.dirname(file), item
unless item in imports
newImports.push item
imports.push item
for item in newImports
await findImports imports, item, defer err
return callback err if err
callback()
exports.compile = (file, flags, callback) ->
await fs.readFile file, 'utf8', defer err, contents
return callback err if err
await less.render contents,
filename: file
paths: [ path.dirname(file) ]
, defer err, output
return callback err if err
callback null, output.css