From: eric thul Date: Wed, 12 Aug 2015 00:57:07 +0000 (-0400) Subject: PureScript 0.7 updates and migration to pulp X-Git-Tag: 0.3.3~2^2~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=03b840cb5fb8ff5217fefc9e1240a3131db309fc;p=github%2Ffretlink%2Fpurs-loader.git PureScript 0.7 updates and migration to pulp --- diff --git a/MODULE.md b/MODULE.md deleted file mode 100644 index 45f6cca..0000000 --- a/MODULE.md +++ /dev/null @@ -1,178 +0,0 @@ -# Module Documentation - -## Module PursLoader.ChildProcess - -#### `ChildProcess` - -``` purescript -data ChildProcess :: ! -``` - - -#### `spawn` - -``` purescript -spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String -``` - - - -## Module PursLoader.FS - -#### `FS` - -``` purescript -data FS :: ! -``` - - -#### `writeFileUtf8` - -``` purescript -writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit -``` - - - -## Module PursLoader.Glob - -#### `Glob` - -``` purescript -data Glob :: ! -``` - - -#### `globAll` - -``` purescript -globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]] -``` - - - -## Module PursLoader.Loader - -#### `Effects` - -``` purescript -type Effects eff = (loader :: Loader, glob :: Glob, fs :: FS, cp :: ChildProcess | eff) -``` - - -#### `loader` - -``` purescript -loader :: forall eff. LoaderRef -> String -> Eff (Effects eff) Unit -``` - - -#### `loaderFn` - -``` purescript -loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects eff) Unit) -``` - - - -## Module PursLoader.LoaderRef - -#### `LoaderRef` - -``` purescript -data LoaderRef -``` - - -#### `Loader` - -``` purescript -data Loader :: ! -``` - - -#### `async` - -``` purescript -async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) -``` - - -#### `cacheable` - -``` purescript -cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit -``` - - -#### `query` - -``` purescript -query :: LoaderRef -> String -``` - - - -## Module PursLoader.LoaderUtil - -#### `parseQuery` - -``` purescript -parseQuery :: String -> Foreign -``` - - - -## Module PursLoader.Options - -#### `isForeignOptions` - -``` purescript -instance isForeignOptions :: IsForeign Options -``` - - -#### `booleanLoaderOption` - -``` purescript -instance booleanLoaderOption :: LoaderOption Boolean -``` - - -#### `stringLoaderOption` - -``` purescript -instance stringLoaderOption :: LoaderOption String -``` - - -#### `arrayLoaderOption` - -``` purescript -instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] -``` - - -#### `pscOptions` - -``` purescript -pscOptions :: Foreign -> [String] -``` - - -#### `loaderSrcOption` - -``` purescript -loaderSrcOption :: Foreign -> Maybe [String] -``` - - -#### `loaderFFIOption` - -``` purescript -loaderFFIOption :: Foreign -> Maybe [String] -``` - - - - diff --git a/bower.json b/bower.json index 2ee2486..0e676f4 100644 --- a/bower.json +++ b/bower.json @@ -2,16 +2,8 @@ "name": "purs-loader", "private": true, "devDependencies": { - "purescript-aff": "~0.9.1", - "purescript-exceptions": "~0.2.3", - "purescript-strings": "~0.4.5", - "purescript-maybe": "~0.2.2", - "purescript-foreign": "~0.4.2", - "purescript-foldable-traversable": "~0.3.1", - "purescript-tuples": "~0.3.4", - "purescript-maps": "~0.3.3", - "purescript-arrays": "~0.3.7", - "purescript-monad-eff": "~0.1.0", - "purescript-sets": "0.3.2" + "purescript-aff": "~0.11.3", + "purescript-strings": "~0.6.0", + "purescript-foreign": "~0.6.0" } } diff --git a/docs/PursLoader/ChildProcess.md b/docs/PursLoader/ChildProcess.md new file mode 100644 index 0000000..7c2e414 --- /dev/null +++ b/docs/PursLoader/ChildProcess.md @@ -0,0 +1,15 @@ +## Module PursLoader.ChildProcess + +#### `ChildProcess` + +``` purescript +data ChildProcess :: ! +``` + +#### `spawn` + +``` purescript +spawn :: forall eff. String -> Array String -> Aff (cp :: ChildProcess | eff) String +``` + + diff --git a/docs/PursLoader/FS.md b/docs/PursLoader/FS.md new file mode 100644 index 0000000..811fcbd --- /dev/null +++ b/docs/PursLoader/FS.md @@ -0,0 +1,21 @@ +## Module PursLoader.FS + +#### `FS` + +``` purescript +data FS :: ! +``` + +#### `writeFileUtf8` + +``` purescript +writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit +``` + +#### `findFileUtf8` + +``` purescript +findFileUtf8 :: forall eff. Regex -> Array String -> Aff (fs :: FS | eff) (Maybe String) +``` + + diff --git a/docs/PursLoader/Glob.md b/docs/PursLoader/Glob.md new file mode 100644 index 0000000..f7abe78 --- /dev/null +++ b/docs/PursLoader/Glob.md @@ -0,0 +1,15 @@ +## Module PursLoader.Glob + +#### `Glob` + +``` purescript +data Glob :: ! +``` + +#### `globAll` + +``` purescript +globAll :: forall eff. Array String -> Aff (glob :: Glob | eff) (Array (Array String)) +``` + + diff --git a/docs/PursLoader/Loader.md b/docs/PursLoader/Loader.md new file mode 100644 index 0000000..8e91c4a --- /dev/null +++ b/docs/PursLoader/Loader.md @@ -0,0 +1,21 @@ +## Module PursLoader.Loader + +#### `Effects` + +``` purescript +type Effects eff = (cp :: ChildProcess, fs :: FS, glob :: Glob, loader :: Loader | eff) +``` + +#### `loader` + +``` purescript +loader :: forall eff. LoaderRef -> String -> Eff (Effects eff) Unit +``` + +#### `loaderFn` + +``` purescript +loaderFn :: forall eff. Fn2 LoaderRef String (Eff (Effects eff) Unit) +``` + + diff --git a/docs/PursLoader/LoaderRef.md b/docs/PursLoader/LoaderRef.md new file mode 100644 index 0000000..36c1550 --- /dev/null +++ b/docs/PursLoader/LoaderRef.md @@ -0,0 +1,51 @@ +## Module PursLoader.LoaderRef + +#### `LoaderRef` + +``` purescript +data LoaderRef +``` + +#### `Loader` + +``` purescript +data Loader :: ! +``` + +#### `async` + +``` purescript +async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) +``` + +#### `cacheable` + +``` purescript +cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit +``` + +#### `query` + +``` purescript +query :: LoaderRef -> String +``` + +#### `clearDependencies` + +``` purescript +clearDependencies :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit +``` + +#### `resourcePath` + +``` purescript +resourcePath :: LoaderRef -> String +``` + +#### `addDependency` + +``` purescript +addDependency :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit +``` + + diff --git a/docs/PursLoader/LoaderUtil.md b/docs/PursLoader/LoaderUtil.md new file mode 100644 index 0000000..36d6879 --- /dev/null +++ b/docs/PursLoader/LoaderUtil.md @@ -0,0 +1,9 @@ +## Module PursLoader.LoaderUtil + +#### `parseQuery` + +``` purescript +parseQuery :: String -> Foreign +``` + + diff --git a/docs/PursLoader/Options.md b/docs/PursLoader/Options.md new file mode 100644 index 0000000..d04b721 --- /dev/null +++ b/docs/PursLoader/Options.md @@ -0,0 +1,21 @@ +## Module PursLoader.Options + +#### `pscOptions` + +``` purescript +pscOptions :: Foreign -> Array String +``` + +#### `loaderSrcOption` + +``` purescript +loaderSrcOption :: Foreign -> Maybe (Array String) +``` + +#### `loaderFFIOption` + +``` purescript +loaderFFIOption :: Foreign -> Maybe (Array String) +``` + + diff --git a/package.json b/package.json index 0775c1b..7871a67 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,11 @@ "email": "thul.eric@gmail.com" }, "scripts": { - "build": "npm run-script build:compile && npm run-script build:package", + "build": "npm run-script build:compile && npm run-script build:docs && npm run-script build:package", "build:compile": "./node_modules/.bin/pulp build -o build", - "build:watch": "./node_modules/.bin/pulp -w build -o build", + "build:docs": "./node_modules/.bin/pulp docs", "build:package": "./node_modules/.bin/webpack --progress --colors --profile --bail", + "build:watch": "./node_modules/.bin/pulp -w build -o build", "build:json": "./node_modules/.bin/webpack --progress --colors --profile --bail --json > index.json", "prepublish": "npm run-script build" }, diff --git a/src/PursLoader/ChildProcess.js b/src/PursLoader/ChildProcess.js new file mode 100644 index 0000000..d62aef6 --- /dev/null +++ b/src/PursLoader/ChildProcess.js @@ -0,0 +1,40 @@ +'use strict'; + +// module PursLoader.ChildProcess + +var child_process = require('child_process'); + +var chalk = require('chalk'); + +function spawnFn(command, args, errback, callback) { + return function(){ + var process = child_process.spawn(command, args); + + var stdout = new Buffer(0); + + var stderr = new Buffer(0); + + process.stdout.on('data', function(data){ + stdout = Buffer.concat([stdout, new Buffer(data)]); + }); + + process.stderr.on('data', function(data){ + stderr = Buffer.concat([stderr, new Buffer(data)]); + }); + + process.on('close', function(code){ + var output = stdout.toString('utf-8'); + + var error = stderr.toString('utf-8'); + + if (error.length > 0) { + console.error('\n' + chalk.red('*') + ' ' + error); + } + + if (code !== 0) errback(new Error('Process terminated with code ' + code))(); + else callback(output)(); + }); + }; +} + +exports.spawnFn = spawnFn; diff --git a/src/PursLoader/ChildProcess.purs b/src/PursLoader/ChildProcess.purs index 34558fa..3bd960b 100644 --- a/src/PursLoader/ChildProcess.purs +++ b/src/PursLoader/ChildProcess.purs @@ -3,6 +3,8 @@ module PursLoader.ChildProcess , spawn ) where +import Prelude (Unit(), ($)) + import Control.Monad.Aff (Aff(), makeAff) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Exception (Error()) @@ -11,46 +13,11 @@ import Data.Function foreign import data ChildProcess :: ! -spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String +spawn :: forall eff. String -> Array String -> Aff (cp :: ChildProcess | eff) String spawn command args = makeAff $ runFn4 spawnFn command args -foreign import spawnFn """ -function spawnFn(command, args, errback, callback) { - return function(){ - var child_process = require('child_process'); - - var process = child_process.spawn(command, args); - - var stdout = new Buffer(0); - - var stderr = new Buffer(0); - - process.stdout.on('data', function(data){ - stdout = Buffer.concat([stdout, new Buffer(data)]); - }); - - process.stderr.on('data', function(data){ - stderr = Buffer.concat([stderr, new Buffer(data)]); - }); - - process.on('close', function(code){ - var chalk = require('chalk'); - - var output = stdout.toString('utf-8'); - - var error = stderr.toString('utf-8'); - - if (error.length > 0) { - console.error('\n' + chalk.red('*') + ' ' + error); - } - - if (code !== 0) errback(new Error('Process terminated with code ' + code))(); - else callback(output)(); - }); - }; -} -""" :: forall eff. Fn4 String - [String] - (Error -> Eff (cp :: ChildProcess | eff) Unit) - (String -> Eff (cp :: ChildProcess | eff) Unit) - (Eff (cp :: ChildProcess | eff) Unit) +foreign import spawnFn :: forall eff. Fn4 String + (Array String) + (Error -> Eff (cp :: ChildProcess | eff) Unit) + (String -> Eff (cp :: ChildProcess | eff) Unit) + (Eff (cp :: ChildProcess | eff) Unit) diff --git a/src/PursLoader/FS.js b/src/PursLoader/FS.js new file mode 100644 index 0000000..1a7f5b0 --- /dev/null +++ b/src/PursLoader/FS.js @@ -0,0 +1,36 @@ +'use strict'; + +// module PursLoader.FS + +var fs = require('fs'); + +var async = require('async'); + +function writeFileUtf8Fn(filepath, contents, errback, callback) { + return function(){ + fs.writeFile(filepath, contents, function(error){ + if (error) errback(error)(); + else callback()(); + }); + }; +} + +function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) { + return function(){ + function findFile(filepath, callback) { + fs.readFile(filepath, {encoding: 'utf-8'}, function(error, result){ + if (error) callback(false); + else callback(regex.test(result)); + }); + } + + async.detect(filepaths, findFile, function(result){ + if (!result) callback(nothing)(); + else callback(just(result))(); + }); + }; +} + +exports.writeFileUtf8Fn = writeFileUtf8Fn; + +exports.findFileUtf8Fn = findFileUtf8Fn; diff --git a/src/PursLoader/FS.purs b/src/PursLoader/FS.purs index 6955a63..969e3d0 100644 --- a/src/PursLoader/FS.purs +++ b/src/PursLoader/FS.purs @@ -4,6 +4,8 @@ module PursLoader.FS , findFileUtf8 ) where +import Prelude (Unit(), ($)) + import Control.Monad.Aff (Aff(), makeAff) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Exception (Error()) @@ -18,50 +20,19 @@ foreign import data FS :: ! writeFileUtf8 :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit writeFileUtf8 filepath contents = makeAff $ runFn4 writeFileUtf8Fn filepath contents -foreign import writeFileUtf8Fn """ -function writeFileUtf8Fn(filepath, contents, errback, callback) { - return function(){ - var fs = require('fs'); - - fs.writeFile(filepath, contents, function(error){ - if (error) errback(error)(); - else callback()(); - }); - }; -} -""" :: forall eff. Fn4 String - String - (Error -> Eff (fs :: FS | eff) Unit) - (Unit -> Eff (fs :: FS | eff) Unit) - (Eff (fs :: FS | eff) Unit) +foreign import writeFileUtf8Fn :: forall eff. Fn4 String + String + (Error -> Eff (fs :: FS | eff) Unit) + (Unit -> Eff (fs :: FS | eff) Unit) + (Eff (fs :: FS | eff) Unit) -findFileUtf8 :: forall eff. Regex -> [String] -> Aff (fs :: FS | eff) (Maybe String) +findFileUtf8 :: forall eff. Regex -> Array String -> Aff (fs :: FS | eff) (Maybe String) findFileUtf8 regexp filepaths = makeAff $ runFn6 findFileUtf8Fn Nothing Just regexp filepaths -foreign import findFileUtf8Fn """ -function findFileUtf8Fn(nothing, just, regex, filepaths, errback, callback) { - return function(){ - var fs = require('fs'); - - var async = require('async'); - - function findFile(filepath, callback) { - fs.readFile(filepath, {encoding: 'utf-8'}, function(error, result){ - if (error) callback(false); - else callback(regex.test(result)); - }); - } - - async.detect(filepaths, findFile, function(result){ - if (!result) callback(nothing)(); - else callback(just(result))(); - }); - }; -} -""" :: forall eff. Fn6 (Maybe String) - (String -> Maybe String) - Regex - [String] - (Error -> Eff (fs :: FS | eff) Unit) - (Maybe String -> Eff (fs :: FS | eff) Unit) - (Eff (fs :: FS | eff) Unit) +foreign import findFileUtf8Fn :: forall eff. Fn6 (Maybe String) + (String -> Maybe String) + Regex + (Array String) + (Error -> Eff (fs :: FS | eff) Unit) + (Maybe String -> Eff (fs :: FS | eff) Unit) + (Eff (fs :: FS | eff) Unit) diff --git a/src/PursLoader/Glob.js b/src/PursLoader/Glob.js new file mode 100644 index 0000000..960ae9a --- /dev/null +++ b/src/PursLoader/Glob.js @@ -0,0 +1,18 @@ +'use strict'; + +// module PursLoader.Glob + +var glob = require('glob'); + +var async = require('async'); + +function globAllFn(patterns, errback, callback) { + return function(){ + async.map(patterns, glob, function(error, result){ + if (error) errback(new Error(error))(); + else callback(result)(); + }); + }; +} + +exports.globAllFn = globAllFn; diff --git a/src/PursLoader/Glob.purs b/src/PursLoader/Glob.purs index 392d9e4..45eeb56 100644 --- a/src/PursLoader/Glob.purs +++ b/src/PursLoader/Glob.purs @@ -3,6 +3,8 @@ module PursLoader.Glob , globAll ) where +import Prelude (Unit(), ($)) + import Control.Monad.Aff (Aff(), makeAff) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Exception (Error()) @@ -11,23 +13,10 @@ import Data.Function foreign import data Glob :: ! -globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]] +globAll :: forall eff. Array String -> Aff (glob :: Glob | eff) (Array (Array String)) globAll patterns = makeAff $ runFn3 globAllFn patterns -foreign import globAllFn """ -function globAllFn(patterns, errback, callback) { - return function(){ - var glob = require('glob'); - - var async = require('async'); - - async.map(patterns, glob, function(error, result){ - if (error) errback(new Error(error))(); - else callback(result)(); - }); - }; -} -""" :: forall eff. Fn3 [String] - (Error -> Eff (glob :: Glob | eff) Unit) - ([[String]] -> Eff (glob :: Glob | eff) Unit) - (Eff (glob :: Glob | eff) Unit) +foreign import globAllFn :: forall eff. Fn3 (Array String) + (Error -> Eff (glob :: Glob | eff) Unit) + ((Array (Array String)) -> Eff (glob :: Glob | eff) Unit) + (Eff (glob :: Glob | eff) Unit) diff --git a/src/PursLoader/Loader.js b/src/PursLoader/Loader.js new file mode 100644 index 0000000..d7b5578 --- /dev/null +++ b/src/PursLoader/Loader.js @@ -0,0 +1,17 @@ +'use strict' + +// module PursLoader.Loader + +var path = require('path'); + +var cwd = process.cwd(); + +function relative(from) { + return function(to){ + return path.relative(from, to); + }; +} + +exports.cwd = cwd; + +exports.relative = relative; diff --git a/src/PursLoader/Loader.purs b/src/PursLoader/Loader.purs index e9e03c4..5373d2f 100644 --- a/src/PursLoader/Loader.purs +++ b/src/PursLoader/Loader.purs @@ -4,6 +4,8 @@ module PursLoader.Loader , loaderFn ) where +import Prelude (Unit(), ($), (<>), (>>=), (<$>), (++), bind, flip, id, pure, return, unit) + import Control.Monad.Aff (Aff(), runAff) import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Class (liftEff) @@ -36,18 +38,11 @@ psciFilename = ".psci" (!!!) = flip (!!) -foreign import cwd "var cwd = process.cwd();" :: String +foreign import cwd :: String -foreign import relative """ -function relative(from) { - return function(to){ - var path = require('path'); - return path.relative(from, to); - }; -} -""" :: String -> String -> String +foreign import relative :: String -> String -> String -mkPsci :: [[String]] -> [[String]] -> String +mkPsci :: Array (Array String) -> Array (Array String) -> String mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign <$> concat ffis)) where loadModule :: String -> String @@ -56,7 +51,7 @@ mkPsci srcs ffis = joinWith "\n" ((loadModule <$> concat srcs) <> (loadForeign < loadForeign :: String -> String loadForeign a = ":f " ++ relative cwd a -findFFI :: forall eff. [[String]] -> String -> Aff (fs :: FS | eff) (Maybe String) +findFFI :: forall eff. Array (Array String) -> String -> Aff (fs :: FS | eff) (Maybe String) findFFI ffiss name = findFileUtf8 re (concat ffiss) where re = regex ("(?:^|\\n)//\\s*module\\s*" ++ name ++ "\\s*\\n") noFlags @@ -79,7 +74,7 @@ loader' ref source = do writeFileUtf8 psciFilename psciFile - let moduleName = match moduleRegex source >>= (!!!) 1 + let moduleName = match moduleRegex source >>= (!!!) 1 >>= id hasForeign = test foreignRegex source result = (\a -> "module.exports = require('" ++ a ++ "');") <$> moduleName diff --git a/src/PursLoader/LoaderRef.js b/src/PursLoader/LoaderRef.js new file mode 100644 index 0000000..3ce0970 --- /dev/null +++ b/src/PursLoader/LoaderRef.js @@ -0,0 +1,56 @@ +'use strict'; + +// module PursLoader.LoaderRef + +function asyncFn(isJust, fromMaybe, ref){ + return function(){ + var callback = ref.async(); + return function(error){ + return function(value){ + return function(){ + return isJust(error) ? callback(fromMaybe(new Error())(error)) + : callback(null, value); + }; + }; + }; + }; +} +function cacheable(ref){ + return function(){ + return ref.cacheable && ref.cacheable(); + }; +} + +function query(ref){ + return ref.query; +} + +function clearDependencies(ref){ + return function(){ + return ref.clearDependencies(); + }; +} + +function resourcePath(ref){ + return ref.resourcePath; +} + +function addDependency(ref){ + return function(dep){ + return function(){ + return ref.addDependency(dep); + }; + }; +} + +exports.asyncFn = asyncFn; + +exports.cacheable = cacheable; + +exports.query = query; + +exports.clearDependencies = clearDependencies; + +exports.resourcePath = resourcePath; + +exports.addDependency = addDependency; diff --git a/src/PursLoader/LoaderRef.purs b/src/PursLoader/LoaderRef.purs index f1efa04..33c4f7e 100644 --- a/src/PursLoader/LoaderRef.purs +++ b/src/PursLoader/LoaderRef.purs @@ -9,6 +9,8 @@ module PursLoader.LoaderRef , resourcePath ) where +import Prelude (Unit()) + import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Exception (Error()) @@ -19,56 +21,20 @@ data LoaderRef foreign import data Loader :: ! -foreign import asyncFn """ -function asyncFn(isJust, fromMaybe, ref){ - return function(){ - var callback = ref.async(); - return function(error){ - return function(value){ - return function(){ - return isJust(error) ? callback(fromMaybe(new Error())(error)) - : callback(null, value); - }; - }; - }; - }; -}""" :: forall eff a. Fn3 (Maybe Error -> Boolean) - (Error -> Maybe Error -> Error) - LoaderRef - (Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit)) +foreign import asyncFn :: forall eff a. Fn3 (Maybe Error -> Boolean) + (Error -> Maybe Error -> Error) + LoaderRef + (Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit)) async :: forall eff a. LoaderRef -> Eff (loader :: Loader | eff) (Maybe Error -> a -> Eff (loader :: Loader | eff) Unit) async ref = runFn3 asyncFn isJust fromMaybe ref -foreign import cacheable """ -function cacheable(ref){ - return function(){ - return ref.cacheable && ref.cacheable(); - }; -}""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit +foreign import cacheable :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit -foreign import query """ -function query(ref){ - return ref.query; -}""" :: LoaderRef -> String +foreign import query :: LoaderRef -> String -foreign import clearDependencies """ -function clearDependencies(ref){ - return function(){ - return ref.clearDependencies(); - }; -}""" :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit +foreign import clearDependencies :: forall eff. LoaderRef -> Eff (loader :: Loader | eff) Unit -foreign import resourcePath """ -function resourcePath(ref){ - return ref.resourcePath; -}""" :: LoaderRef -> String +foreign import resourcePath :: LoaderRef -> String -foreign import addDependency """ -function addDependency(ref){ - return function(dep){ - return function(){ - return ref.addDependency(dep); - }; - }; -}""" :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit +foreign import addDependency :: forall eff. LoaderRef -> String -> Eff (loader :: Loader | eff) Unit diff --git a/src/PursLoader/LoaderUtil.js b/src/PursLoader/LoaderUtil.js new file mode 100644 index 0000000..45f2703 --- /dev/null +++ b/src/PursLoader/LoaderUtil.js @@ -0,0 +1,7 @@ +'use strict'; + +// module PursLoader.LoaderUtil + +var loaderUtils = require('loader-utils'); + +exports.parseQuery = loaderUtils.parseQuery; diff --git a/src/PursLoader/LoaderUtil.purs b/src/PursLoader/LoaderUtil.purs index 86be124..3e5a7bc 100644 --- a/src/PursLoader/LoaderUtil.purs +++ b/src/PursLoader/LoaderUtil.purs @@ -6,8 +6,4 @@ import Data.Foreign (Foreign()) import PursLoader.LoaderRef (LoaderRef()) -foreign import parseQuery """ -function parseQuery(query){ - var loaderUtils = require('loader-utils'); - return loaderUtils.parseQuery(query); -}""" :: String -> Foreign +foreign import parseQuery :: String -> Foreign diff --git a/src/PursLoader/Options.purs b/src/PursLoader/Options.purs index 51e9be5..e3957eb 100644 --- a/src/PursLoader/Options.purs +++ b/src/PursLoader/Options.purs @@ -4,6 +4,8 @@ module PursLoader.Options , loaderFFIOption ) where +import Prelude (Unit(), (<>), (<$>), (<<<), (++), (<*>), const) + import Data.Array (concat) import Data.Either (either) @@ -45,8 +47,8 @@ newtype Options , output :: NullOrUndefined String , noPrefix :: NullOrUndefined Boolean , requirePath :: NullOrUndefined String - , src :: NullOrUndefined [String] - , ffi :: NullOrUndefined [String] + , src :: NullOrUndefined (Array String) + , ffi :: NullOrUndefined (Array String) } instance isForeignOptions :: IsForeign Options where @@ -74,7 +76,7 @@ instance isForeignOptions :: IsForeign Options where <*> readProp ffiOpt obj) class LoaderOption a where - opt :: String -> NullOrUndefined a -> [String] + opt :: String -> NullOrUndefined a -> Array String instance booleanLoaderOption :: LoaderOption Boolean where opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val) @@ -82,11 +84,11 @@ instance booleanLoaderOption :: LoaderOption Boolean where instance stringLoaderOption :: LoaderOption String where opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val) -instance arrayLoaderOption :: (LoaderOption a) => LoaderOption [a] where +instance arrayLoaderOption :: (LoaderOption a) => LoaderOption (Array a) where opt key val = concat (opt key <$> (NullOrUndefined <<< Just) <$> (fromMaybe [] (runNullOrUndefined val))) -pscOptions :: Foreign -> [String] +pscOptions :: Foreign -> Array String pscOptions query = either (const []) fold parsed where parsed = read query :: F Options fold (Options a) = opt noPreludeOpt a.noPrelude <> @@ -100,8 +102,8 @@ pscOptions query = either (const []) fold parsed opt requirePathOpt a.requirePath <> opt ffiOpt a.ffi -loaderSrcOption :: Foreign -> Maybe [String] +loaderSrcOption :: Foreign -> Maybe (Array String) loaderSrcOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.src) (read query) -loaderFFIOption :: Foreign -> Maybe [String] +loaderFFIOption :: Foreign -> Maybe (Array String) loaderFFIOption query = either (const Nothing) (\(Options a) -> runNullOrUndefined a.ffi) (read query)