UNPKG

863 BJavaScriptView Raw
1var pogo = require('pogo');
2var fs = require('fs');
3var through = require('through');
4var convert = require('convert-source-map');
5
6function compile(file, data) {
7 var compiled = '';
8 try {
9 compiled = pogo.compile(fs.readFileSync(file, 'utf8'));
10 }
11 catch (e) {
12 throw new Error("PogoScript compilation failed for '" + file + "'\n" + e.toString())
13 }
14 return compiled;
15}
16
17function isPogo (file) {
18 return /\.pogo$/.test(file);
19}
20
21module.exports = function (file) {
22 if (!isPogo(file)) return through();
23
24 var data = '';
25 return through(write, end);
26
27 function write (buf) { data += buf }
28 function end () {
29 var src;
30 try {
31 src = compile(file, data);
32 } catch (error) {
33 this.emit('error', error);
34 }
35 this.queue(src);
36 this.queue(null);
37 }
38};