diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | README.md | 25 | ||||
-rw-r--r-- | example/README.md | 1 | ||||
-rw-r--r-- | example/bower.json | 15 | ||||
-rw-r--r-- | example/index.html | 18 | ||||
-rw-r--r-- | example/package.json | 5 | ||||
-rw-r--r-- | example/src/Foo.purs | 6 | ||||
-rw-r--r-- | example/src/Foo/Bar.purs | 3 | ||||
-rw-r--r-- | example/src/Foo/Baz.purs | 3 | ||||
-rw-r--r-- | example/src/Test.purs | 2 | ||||
-rw-r--r-- | example/src/entry.js | 8 | ||||
-rw-r--r-- | index.js | 12 |
12 files changed, 52 insertions, 48 deletions
@@ -1,4 +1,6 @@ | |||
1 | npm-debug.log | ||
1 | node_modules/ | 2 | node_modules/ |
2 | example/node_modules/ | 3 | example/node_modules/ |
4 | example/bower_components/ | ||
3 | example/dist/ | 5 | example/dist/ |
4 | example/output/ | 6 | example/output/ |
@@ -27,27 +27,4 @@ npm install purs-loader --save-dev | |||
27 | 27 | ||
28 | ## Example | 28 | ## Example |
29 | 29 | ||
30 | ```js | 30 | See the [example](https://github.com/ethul/purs-loader/tree/topic/bower-components/example) directory for a complete example. |
31 | var path = require('path'); | ||
32 | |||
33 | module.exports = { | ||
34 | entry: './src/test', | ||
35 | output: { | ||
36 | path: path.join(__dirname, 'dist'), | ||
37 | filename: 'app.js' | ||
38 | }, | ||
39 | module: { | ||
40 | loaders: [{ | ||
41 | test: /\.purs$/, | ||
42 | loader: 'purs-loader?no-prelude&output=output' | ||
43 | }] | ||
44 | }, | ||
45 | resolve: { | ||
46 | modulesDirectories: [ | ||
47 | 'node_modules', | ||
48 | 'web_modules', | ||
49 | 'output' | ||
50 | ] | ||
51 | } | ||
52 | }; | ||
53 | ``` | ||
diff --git a/example/README.md b/example/README.md index ae798e7..87b9bc7 100644 --- a/example/README.md +++ b/example/README.md | |||
@@ -1,4 +1,5 @@ | |||
1 | ```bash | 1 | ```bash |
2 | bower install | ||
2 | npm install | 3 | npm install |
3 | npm run-script webpack | 4 | npm run-script webpack |
4 | npm run-script run | 5 | npm run-script run |
diff --git a/example/bower.json b/example/bower.json new file mode 100644 index 0000000..8d71688 --- /dev/null +++ b/example/bower.json | |||
@@ -0,0 +1,15 @@ | |||
1 | { | ||
2 | "name": "example", | ||
3 | "license": "MIT", | ||
4 | "private": true, | ||
5 | "ignore": [ | ||
6 | "**/.*", | ||
7 | "node_modules", | ||
8 | "bower_components", | ||
9 | "test", | ||
10 | "tests" | ||
11 | ], | ||
12 | "devDependencies": { | ||
13 | "purescript-maybe": "~0.2.1" | ||
14 | } | ||
15 | } | ||
diff --git a/example/index.html b/example/index.html deleted file mode 100644 index 8db646e..0000000 --- a/example/index.html +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | <!doctype html> | ||
2 | <html class="no-js" lang=""> | ||
3 | <head> | ||
4 | <meta charset="utf-8"> | ||
5 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
6 | <title></title> | ||
7 | <meta name="description" content=""> | ||
8 | <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
9 | </head> | ||
10 | <body> | ||
11 | <!--[if lt IE 8]> | ||
12 | <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> | ||
13 | <![endif]--> | ||
14 | <!-- Add your site or application content here --> | ||
15 | <p>Hello world! This is HTML5 Boilerplate.</p> | ||
16 | <script src="dist/app.js"></script> | ||
17 | </body> | ||
18 | </html> | ||
diff --git a/example/package.json b/example/package.json index b2d0d86..6b0c04c 100644 --- a/example/package.json +++ b/example/package.json | |||
@@ -4,11 +4,12 @@ | |||
4 | "private": true, | 4 | "private": true, |
5 | "scripts": { | 5 | "scripts": { |
6 | "webpack": "./node_modules/.bin/webpack", | 6 | "webpack": "./node_modules/.bin/webpack", |
7 | "run": "node dist/app.js" | 7 | "run": "node dist/app.js", |
8 | "clean": "rm -rf bower_components && rm -rf dist && rm -rf node_modules && rm -rf output" | ||
8 | }, | 9 | }, |
9 | "license": "MIT", | 10 | "license": "MIT", |
10 | "devDependencies": { | 11 | "devDependencies": { |
11 | "purs-loader": "0.0.2", | 12 | "purs-loader": "file:../", |
12 | "webpack": "^1.4.15" | 13 | "webpack": "^1.4.15" |
13 | } | 14 | } |
14 | } | 15 | } |
diff --git a/example/src/Foo.purs b/example/src/Foo.purs new file mode 100644 index 0000000..3e3a04c --- /dev/null +++ b/example/src/Foo.purs | |||
@@ -0,0 +1,6 @@ | |||
1 | module Foo (foo) where | ||
2 | |||
3 | import Data.Maybe | ||
4 | import qualified Foo.Bar as B | ||
5 | |||
6 | foo = "b" | ||
diff --git a/example/src/Foo/Bar.purs b/example/src/Foo/Bar.purs new file mode 100644 index 0000000..4ae100d --- /dev/null +++ b/example/src/Foo/Bar.purs | |||
@@ -0,0 +1,3 @@ | |||
1 | module Foo.Bar (bar) where | ||
2 | |||
3 | bar = "c" | ||
diff --git a/example/src/Foo/Baz.purs b/example/src/Foo/Baz.purs new file mode 100644 index 0000000..7b0451e --- /dev/null +++ b/example/src/Foo/Baz.purs | |||
@@ -0,0 +1,3 @@ | |||
1 | module Foo.Baz (baz) where | ||
2 | |||
3 | baz = "d" | ||
diff --git a/example/src/Test.purs b/example/src/Test.purs index 7409c6e..8a5cb88 100644 --- a/example/src/Test.purs +++ b/example/src/Test.purs | |||
@@ -1,3 +1,5 @@ | |||
1 | module Test (test) where | 1 | module Test (test) where |
2 | 2 | ||
3 | import Data.Maybe | ||
4 | |||
3 | test = "a" | 5 | test = "a" |
diff --git a/example/src/entry.js b/example/src/entry.js index 65119f6..160bee4 100644 --- a/example/src/entry.js +++ b/example/src/entry.js | |||
@@ -1,3 +1,7 @@ | |||
1 | var test = require('purs?no-prelude&output=output!./Test.purs'); | 1 | var test = require('purs?output=output!./Test.purs'); |
2 | 2 | ||
3 | console.log(test); | 3 | var foo = require('purs?output=output!./Foo.purs'); |
4 | |||
5 | var baz = require('purs?output=output!./Foo/Baz.purs'); | ||
6 | |||
7 | console.log(test, foo, baz); | ||
@@ -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 | ||
23 | function pattern(root) { | ||
24 | var as = [ BOWER_PATTERN, root ]; | ||
25 | return path.join('{' + as.join(',') + '}', '**', '*.purs'); | ||
26 | } | ||
27 | |||
21 | module.exports = function(source){ | 28 | module.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); |