]> git.immae.eu Git - github/fretlink/purs-loader.git/commitdiff
Merge pull request #6 from ethul/topic/bower-components
authoreric <thul.eric@gmail.com>
Sat, 17 Jan 2015 21:31:01 +0000 (16:31 -0500)
committereric <thul.eric@gmail.com>
Sat, 17 Jan 2015 21:31:01 +0000 (16:31 -0500)
Topic/bower components

12 files changed:
.gitignore
README.md
example/README.md
example/bower.json [new file with mode: 0644]
example/index.html [deleted file]
example/package.json
example/src/Foo.purs [new file with mode: 0644]
example/src/Foo/Bar.purs [new file with mode: 0644]
example/src/Foo/Baz.purs [new file with mode: 0644]
example/src/Test.purs
example/src/entry.js
index.js

index 63d8f4cedda4b3e593d05727b3493ea00a91b072..8cde68436c403ff7b4250b4be5b7f04bd488628d 100644 (file)
@@ -1,4 +1,6 @@
+npm-debug.log
 node_modules/
 example/node_modules/
+example/bower_components/
 example/dist/
 example/output/
index 630f82edc4b41b5f6b437848c372367d5dd8fa44..dcbedf285102349f9d2a002448af136529f1625d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -27,27 +27,4 @@ npm install purs-loader --save-dev
 
 ## Example
 
-```js
-var path = require('path');
-
-module.exports = {
-  entry: './src/test',
-  output: {
-    path: path.join(__dirname, 'dist'),
-    filename: 'app.js'
-  },
-  module: {
-    loaders: [{
-      test: /\.purs$/,
-      loader: 'purs-loader?no-prelude&output=output'
-    }]
-  },
-  resolve: {
-    modulesDirectories: [
-      'node_modules',
-      'web_modules',
-      'output'
-    ]
-  }
-};
-```
+See the [example](https://github.com/ethul/purs-loader/tree/topic/bower-components/example) directory for a complete example.
index ae798e7ca4187139606cd515323704774788f3d9..87b9bc7c84c9b0c0429a50bd9e0062317e1608ea 100644 (file)
@@ -1,4 +1,5 @@
 ```bash
+bower install
 npm install
 npm run-script webpack
 npm run-script run
diff --git a/example/bower.json b/example/bower.json
new file mode 100644 (file)
index 0000000..8d71688
--- /dev/null
@@ -0,0 +1,15 @@
+{
+  "name": "example",
+  "license": "MIT",
+  "private": true,
+  "ignore": [
+    "**/.*",
+    "node_modules",
+    "bower_components",
+    "test",
+    "tests"
+  ],
+  "devDependencies": {
+    "purescript-maybe": "~0.2.1"
+  }
+}
diff --git a/example/index.html b/example/index.html
deleted file mode 100644 (file)
index 8db646e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<!doctype html>
-<html class="no-js" lang="">
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <title></title>
-    <meta name="description" content="">
-    <meta name="viewport" content="width=device-width, initial-scale=1">
-  </head>
-  <body>
-    <!--[if lt IE 8]>
-        <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
-    <![endif]-->
-    <!-- Add your site or application content here -->
-    <p>Hello world! This is HTML5 Boilerplate.</p>
-    <script src="dist/app.js"></script>
-  </body>
-</html>
index b2d0d86efee4a5dd47bbed511a82d1934ece487c..6b0c04ce1f2d1c2a7b00b263999d775f7b7d1895 100644 (file)
@@ -4,11 +4,12 @@
   "private": true,
   "scripts": {
     "webpack": "./node_modules/.bin/webpack",
-    "run": "node dist/app.js"
+    "run": "node dist/app.js",
+    "clean": "rm -rf bower_components && rm -rf dist && rm -rf node_modules && rm -rf output"
   },
   "license": "MIT",
   "devDependencies": {
-    "purs-loader": "0.0.2",
+    "purs-loader": "file:../",
     "webpack": "^1.4.15"
   }
 }
diff --git a/example/src/Foo.purs b/example/src/Foo.purs
new file mode 100644 (file)
index 0000000..3e3a04c
--- /dev/null
@@ -0,0 +1,6 @@
+module Foo (foo) where
+
+import Data.Maybe
+import qualified Foo.Bar as B
+
+foo = "b"
diff --git a/example/src/Foo/Bar.purs b/example/src/Foo/Bar.purs
new file mode 100644 (file)
index 0000000..4ae100d
--- /dev/null
@@ -0,0 +1,3 @@
+module Foo.Bar (bar) where
+
+bar = "c"
diff --git a/example/src/Foo/Baz.purs b/example/src/Foo/Baz.purs
new file mode 100644 (file)
index 0000000..7b0451e
--- /dev/null
@@ -0,0 +1,3 @@
+module Foo.Baz (baz) where
+
+baz = "d"
index 7409c6e3a962dcc9bc7a1ba9277e1a651c57eeff..8a5cb888d986343e19bd86c71b8404a1049a6e9e 100644 (file)
@@ -1,3 +1,5 @@
 module Test (test) where
 
+import Data.Maybe
+
 test = "a"
index 65119f6b4ce7937386fec89401c2e31ddf5d8866..160bee48b47067d9d31e8b0364eeb305d4c043ae 100644 (file)
@@ -1,3 +1,7 @@
-var test = require('purs?no-prelude&output=output!./Test.purs');
+var test = require('purs?output=output!./Test.purs');
 
-console.log(test);
+var foo = require('purs?output=output!./Foo.purs');
+
+var baz = require('purs?output=output!./Foo/Baz.purs');
+
+console.log(test, foo, baz);
index 07988a233c0109935d026a7398ca3b3dea05ecfe..4a74d154ad45a16ac73237279bb06284d3f8817c 100644 (file)
--- a/index.js
+++ b/index.js
@@ -6,6 +6,8 @@ var cp = require('child_process')
   , chalk = require('chalk')
   , lu = require('loader-utils')
   , cwd = process.cwd()
+  , MODULE_RE = /^module\s+([\w\.]+)\s+/i
+  , BOWER_PATTERN = path.join('bower_components', 'purescript-*', 'src')
   , PSC_MAKE = 'psc-make'
   , OUTPUT = 'output'
   , OPTIONS = {
@@ -18,6 +20,11 @@ var cp = require('child_process')
     }
 ;
 
+function pattern(root) {
+  var as = [ BOWER_PATTERN, root ];
+  return path.join('{' + as.join(',') + '}', '**', '*.purs');
+}
+
 module.exports = function(source){
   var callback = this.async()
     , request = lu.getRemainingRequest(this)
@@ -29,14 +36,15 @@ module.exports = function(source){
         else return h(OPTIONS[k]);
       }, [])
   ;
-  glob(path.join(root, '**', '*.purs'), function(e, files){
+  glob(pattern(root), function(e, files){
     if (e !== null) callback(e);
     else {
       var cmd = cp.spawn(PSC_MAKE, opts.concat(files));
       cmd.on('close', function(e){
         if (e) callback(e);
         else {
-          var module = path.basename(request, '.purs');
+          var result = MODULE_RE.exec(source);
+          var module = result.length > 1 ? result[1] : '';
           fs.readFile(path.join(query[OUTPUT] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){
             if (e) callback(e);
             else callback(e, output);