aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js62
1 files changed, 0 insertions, 62 deletions
diff --git a/index.js b/index.js
deleted file mode 100644
index 4a74d15..0000000
--- a/index.js
+++ /dev/null
@@ -1,62 +0,0 @@
1var cp = require('child_process')
2 , path = require('path')
3 , fs = require('fs')
4 , glob = require('glob')
5 , lodash = require('lodash')
6 , chalk = require('chalk')
7 , lu = require('loader-utils')
8 , cwd = process.cwd()
9 , MODULE_RE = /^module\s+([\w\.]+)\s+/i
10 , BOWER_PATTERN = path.join('bower_components', 'purescript-*', 'src')
11 , PSC_MAKE = 'psc-make'
12 , OUTPUT = 'output'
13 , OPTIONS = {
14 'no-prelude': '--no-prelude',
15 'no-opts': '--no-opts',
16 'no-magic-do': '--no-magic-do',
17 'no-tco': '--no-tco',
18 'verbose-errors': '--verbose-errors',
19 'output': '--output'
20 }
21;
22
23function pattern(root) {
24 var as = [ BOWER_PATTERN, root ];
25 return path.join('{' + as.join(',') + '}', '**', '*.purs');
26}
27
28module.exports = function(source){
29 var callback = this.async()
30 , request = lu.getRemainingRequest(this)
31 , root = path.dirname(path.relative(cwd, request))
32 , query = lu.parseQuery(this.query)
33 , opts = lodash.foldl(lodash.keys(query), function(acc, k){
34 var h = function(v){return acc.concat(query[k] && OPTIONS[k] ? [v] : []);}
35 if (k === OUTPUT) return h(OPTIONS[k] + '=' + query[k]);
36 else return h(OPTIONS[k]);
37 }, [])
38 ;
39 glob(pattern(root), function(e, files){
40 if (e !== null) callback(e);
41 else {
42 var cmd = cp.spawn(PSC_MAKE, opts.concat(files));
43 cmd.on('close', function(e){
44 if (e) callback(e);
45 else {
46 var result = MODULE_RE.exec(source);
47 var module = result.length > 1 ? result[1] : '';
48 fs.readFile(path.join(query[OUTPUT] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){
49 if (e) callback(e);
50 else callback(e, output);
51 });
52 }
53 });
54 cmd.stdout.on('data', function(stdout){
55 console.log('Stdout from \'' + chalk.cyan(PSC_MAKE) + '\'\n' + chalk.magenta(stdout));
56 });
57 cmd.stderr.on('data', function(stderr){
58 console.log('Stderr from \'' + chalk.cyan(PSC_MAKE) + '\'\n' + chalk.magenta(stderr));
59 });
60 }
61 });
62};