aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2014-09-21 12:50:12 -0400
committereric thul <thul.eric@gmail.com>2014-09-22 23:43:29 -0400
commita42f24b85a304e128c45003b806cc5c4d551b3af (patch)
treedcd945d01681a2f934f257ca0ba7088ce28f12e4
parent542ab6f00d143b58345672918f831e14f40f8c25 (diff)
downloadpurs-loader-a42f24b85a304e128c45003b806cc5c4d551b3af.tar.gz
purs-loader-a42f24b85a304e128c45003b806cc5c4d551b3af.tar.zst
purs-loader-a42f24b85a304e128c45003b806cc5c4d551b3af.zip
Implementation of the loader
-rw-r--r--.gitignore1
-rw-r--r--LICENSE20
-rw-r--r--README.md57
-rw-r--r--index.js55
-rw-r--r--package.json14
5 files changed, 143 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
node_modules/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..aaed7de
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
1Copyright (c) 2014 Eric Thul
2
3Permission is hereby granted, free of charge, to any person obtaining a
4copy of this software and associated documentation files (the
5"Software"), in the Software without restriction, including without
6limitation the rights to use, copy, modify, merge, publish, distribute,
7sublicense, and/or sell copies of the Software, and to permit persons to
8whom the Software is furnished to do so, subject to the following
9conditions:
10
11The above copyright notice and this permission notice shall be included
12in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..17fe735
--- /dev/null
+++ b/README.md
@@ -0,0 +1,57 @@
1# purs-loader
2
3> [PureScript](http://www.purescript.org) loader for [webpack](https://github.com/webpack/webpack)
4
5## Install
6
7Install with [npm](https://npmjs.org/package/purs-loader)
8
9```
10npm install purs-loader --save-dev
11```
12
13## Options
14
15#### options
16
17 - **no-prelude**: Boolean value that toggles `--no-prelude`
18 - Do not include the Prelude in the generated Javascript.
19 - **no-opts**: Boolean value that toggles `--no-opts`
20 - Disable all optimizations.
21 - **no-magic-do**: Boolean value that toggles `--no-magic-do`
22 - Turn off optimizations which inline calls to >>= for the Eff monad.
23 - **no-tco**: Boolean value that toggles `--no-tco`
24 - Turn off tail-call elimination.
25 - **runtime-type-checks**: Boolean value that toggles `--runtime-type-checks`
26 - Generate simple runtime type checks for function arguments with simple types.
27 - **verbose-errors**: Boolean value that toggles `--verbose-errors`
28 - Generate verbose error messages.
29 - **output**: String value that sets `--output=<string>`
30 - Write the generated Javascript to the specified file.
31
32## Example
33
34```js
35var path = require('path');
36
37module.exports = {
38 entry: './src/test',
39 output: {
40 path: path.join(__dirname, 'dist'),
41 filename: 'app.js'
42 },
43 module: {
44 loaders: [{
45 test: /\.purs$/,
46 loader: 'purs-loader?no-prelude&output=output'
47 }]
48 },
49 resolve: {
50 modulesDirectories: [
51 'node_modules',
52 'web_modules',
53 'output'
54 ]
55 }
56};
57```
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..a7665f3
--- /dev/null
+++ b/index.js
@@ -0,0 +1,55 @@
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 , PSC_MAKE = 'psc-make'
10 , OUTPUT = 'output'
11 , OPTIONS = {
12 'no-prelude': '--no-prelude',
13 'no-opts': '--no-opts',
14 'no-magic-do': '--no-magic-do',
15 'no-tco': '--no-tco',
16 'runtime-type-checks': '--runtime-type-checks',
17 'verbose-errors': '--verbose-errors',
18 'output': '--output'
19 }
20;
21
22module.exports = function(source){
23 var callback = this.async()
24 , request = lu.getRemainingRequest(this)
25 , root = path.dirname(path.relative(cwd, request))
26 , query = lu.parseQuery(this.query)
27 , opts = lodash.foldl(lodash.keys(query), function(acc, k){
28 var h = function(v){return acc.concat(query[k] && OPTIONS[k] ? [v] : []);}
29 if (k === OUTPUT) return h(OPTIONS[k] + '=' + query[k]);
30 else return h(OPTIONS[k]);
31 }, [])
32 ;
33 glob(path.join(root, '**', '*.purs'), function(e, files){
34 if (e !== null) callback(e);
35 else {
36 var cmd = cp.spawn(PSC_MAKE, opts.concat(files));
37 cmd.on('close', function(e){
38 if (e) callback(e);
39 else {
40 var module = path.basename(request, '.purs');
41 fs.readFile(path.join(opts[OPTIONS[OUTPUT]] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){
42 if (e) callback(e);
43 else callback(e, output);
44 });
45 }
46 });
47 cmd.stdout.on('data', function(stdout){
48 console.log('Stdout from \'' + chalk.cyan(PSC_MAKE) + '\'\n' + chalk.magenta(stdout));
49 });
50 cmd.stderr.on('data', function(stderr){
51 console.log('Stderr from \'' + chalk.cyan(PSC_MAKE) + '\'\n' + chalk.magenta(stderr));
52 });
53 }
54 });
55};
diff --git a/package.json b/package.json
index 9a19a8b..eed4fd4 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
1{ 1{
2 "name": "purescript-loader", 2 "name": "purs-loader",
3 "version": "0.0.0", 3 "version": "0.0.0",
4 "description": "PureScript loader for webpack", 4 "description": "PureScript loader for webpack",
5 "main": "index.js", 5 "main": "index.js",
@@ -8,12 +8,18 @@
8 }, 8 },
9 "repository": { 9 "repository": {
10 "type": "git", 10 "type": "git",
11 "url": "git@github.com:ethul/purescript-loader.git" 11 "url": "git@github.com:ethul/purs-loader.git"
12 }, 12 },
13 "author": "Eric Thul", 13 "author": "Eric Thul",
14 "license": "MIT", 14 "license": "MIT",
15 "bugs": { 15 "bugs": {
16 "url": "https://github.com/ethul/purescript-loader/issues" 16 "url": "https://github.com/ethul/purs-loader/issues"
17 }, 17 },
18 "homepage": "https://github.com/ethul/purescript-loader" 18 "homepage": "https://github.com/ethul/purs-loader",
19 "dependencies": {
20 "chalk": "^0.5.1",
21 "glob": "4.0.6",
22 "loader-utils": "^0.2.3",
23 "lodash": "^2.4.1"
24 }
19} 25}