aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.js
diff options
context:
space:
mode:
authoreric <thul.eric@gmail.com>2015-01-17 16:31:01 -0500
committereric <thul.eric@gmail.com>2015-01-17 16:31:01 -0500
commit84bdfea8eab66d3f797d1616db0e4fd63138fb6f (patch)
tree254850b971c699f0547b70b3c5e5137c29555e9f /index.js
parentebf06d39692b92058df757b2ec0009f0935d4563 (diff)
parent9f398b64af9025e146362a6cf7a2817255700337 (diff)
downloadpurs-loader-84bdfea8eab66d3f797d1616db0e4fd63138fb6f.tar.gz
purs-loader-84bdfea8eab66d3f797d1616db0e4fd63138fb6f.tar.zst
purs-loader-84bdfea8eab66d3f797d1616db0e4fd63138fb6f.zip
Merge pull request #6 from ethul/topic/bower-components
Topic/bower components
Diffstat (limited to 'index.js')
-rw-r--r--index.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/index.js b/index.js
index 07988a2..4a74d15 100644
--- a/index.js
+++ b/index.js
@@ -6,6 +6,8 @@ var cp = require('child_process')
6 , chalk = require('chalk') 6 , chalk = require('chalk')
7 , lu = require('loader-utils') 7 , lu = require('loader-utils')
8 , cwd = process.cwd() 8 , cwd = process.cwd()
9 , MODULE_RE = /^module\s+([\w\.]+)\s+/i
10 , BOWER_PATTERN = path.join('bower_components', 'purescript-*', 'src')
9 , PSC_MAKE = 'psc-make' 11 , PSC_MAKE = 'psc-make'
10 , OUTPUT = 'output' 12 , OUTPUT = 'output'
11 , OPTIONS = { 13 , OPTIONS = {
@@ -18,6 +20,11 @@ var cp = require('child_process')
18 } 20 }
19; 21;
20 22
23function pattern(root) {
24 var as = [ BOWER_PATTERN, root ];
25 return path.join('{' + as.join(',') + '}', '**', '*.purs');
26}
27
21module.exports = function(source){ 28module.exports = function(source){
22 var callback = this.async() 29 var callback = this.async()
23 , request = lu.getRemainingRequest(this) 30 , request = lu.getRemainingRequest(this)
@@ -29,14 +36,15 @@ module.exports = function(source){
29 else return h(OPTIONS[k]); 36 else return h(OPTIONS[k]);
30 }, []) 37 }, [])
31 ; 38 ;
32 glob(path.join(root, '**', '*.purs'), function(e, files){ 39 glob(pattern(root), function(e, files){
33 if (e !== null) callback(e); 40 if (e !== null) callback(e);
34 else { 41 else {
35 var cmd = cp.spawn(PSC_MAKE, opts.concat(files)); 42 var cmd = cp.spawn(PSC_MAKE, opts.concat(files));
36 cmd.on('close', function(e){ 43 cmd.on('close', function(e){
37 if (e) callback(e); 44 if (e) callback(e);
38 else { 45 else {
39 var module = path.basename(request, '.purs'); 46 var result = MODULE_RE.exec(source);
47 var module = result.length > 1 ? result[1] : '';
40 fs.readFile(path.join(query[OUTPUT] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){ 48 fs.readFile(path.join(query[OUTPUT] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){
41 if (e) callback(e); 49 if (e) callback(e);
42 else callback(e, output); 50 else callback(e, output);