1 | var pogo = require('pogo');
|
2 | var fs = require('fs');
|
3 | var through = require('through');
|
4 | var convert = require('convert-source-map');
|
5 |
|
6 | function 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 |
|
17 | function isPogo (file) {
|
18 | return /\.pogo$/.test(file);
|
19 | }
|
20 |
|
21 | module.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 | };
|