-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (33 loc) · 874 Bytes
/
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
var through = require('through2')
var parseLispyscript = require('lispyscript').parseWithSourceMap
var convert = require('convert-source-map')
function isLispyscript(file) {
return /\.ls$/.test(file)
}
module.exports = function(file, opts) {
if (isLispyscript(file)) {
var data = ''
var stream = through(function write(chunk, enc, cb) {
data += chunk
cb()
}, function end(cb) {
try {
var output = parseLispyscript(data, file)
} catch (e) {
console.error(e.message)
cb(e)
return
}
var sourceNodeGenerator = output.map
sourceNodeGenerator.setSourceContent(file, data)
var map = convert.fromJSON(sourceNodeGenerator.toString())
map.setProperty('sources', [file])
map.setProperty('file', file)
this.push(output.code + '\n' + map.toComment() + '\n')
cb()
})
return stream
} else {
return through()
}
}