Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 45b6f51

Browse files
committed
Initial commit
0 parents  commit 45b6f51

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.sw[mnopqrstuv]
2+
*.un~
3+
.psci
4+
node_modules
5+
bower_components
6+
output

bower.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "purescript-node-fs-aff",
3+
"version": "0.0.1",
4+
"authors": [
5+
"Felix Schlitter <[email protected]>"
6+
],
7+
"description": "Aff wrappers for purescript-node-fs",
8+
"keywords": [
9+
"purescript",
10+
"node"
11+
],
12+
"license": "MIT",
13+
"homepage": "https://github.com/felixSchl/purescript-node-fs-aff",
14+
"ignore": [
15+
"**/.*",
16+
"node_modules",
17+
"bower_components",
18+
"test",
19+
"tests"
20+
],
21+
"dependencies": {
22+
"purescript-aff": "~0.10.1",
23+
"purescript-node-fs": "~0.6.0",
24+
"purescript-either": "~0.1.8"
25+
}
26+
}

gulpfile.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
var gulp = require('gulp')
4+
, purs = require('gulp-purescript')
5+
, Promise = require('bluebird')
6+
, del = Promise.promisifyAll(require('del'))
7+
, _ = require('lodash')
8+
;
9+
10+
var src = [ 'src/**/*.purs' ]
11+
, deps = [ 'bower_components/purescript-*/src/**/*.purs' ]
12+
, output = [ 'output' ]
13+
;
14+
15+
gulp.task('psci', function() {
16+
return gulp
17+
.src(_.flatten([ src, deps ], false))
18+
.pipe(purs.dotPsci())
19+
;
20+
});
21+
22+
gulp.task('make', [ 'psci' ], function() {
23+
return gulp
24+
.src(_.flatten([ src, deps ], false))
25+
.pipe(purs.pscMake({}))
26+
;
27+
});

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"private": true,
3+
"devDependencies": {
4+
"bluebird": "^2.9.27",
5+
"del": "^1.2.0",
6+
"gulp": "^3.9.0",
7+
"gulp-purescript": "^0.5.0-rc.1",
8+
"lodash": "^3.9.3"
9+
}
10+
}

src/Node/FS/Aff.purs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module Node.FS.Aff
2+
( rename
3+
, truncate
4+
, chown
5+
, chmod
6+
, stat
7+
, link
8+
, symlink
9+
, readlink
10+
, realpath
11+
, realpath'
12+
, unlink
13+
, rmdir
14+
, mkdir
15+
, mkdir'
16+
, readdir
17+
, utimes
18+
, readFile
19+
, readTextFile
20+
, writeFile
21+
, writeTextFile
22+
, appendFile
23+
, appendTextFile
24+
, exists
25+
) where
26+
27+
import Control.Monad.Eff (Eff(..))
28+
import Data.Either (either)
29+
import Control.Monad.Aff (Aff(..), makeAff)
30+
import qualified Node.FS as F
31+
import qualified Node.FS.Async as A
32+
33+
toAff :: forall eff a.
34+
(A.Callback eff a -> Eff (fs :: F.FS | eff) Unit) ->
35+
Aff (fs :: F.FS | eff) a
36+
toAff p = makeAff (\e a -> p $ either e a)
37+
38+
toAff1 f a = toAff (f a)
39+
toAff2 f a b = toAff (f a b)
40+
toAff3 f a b c = toAff (f a b c)
41+
42+
rename = toAff2 A.rename
43+
truncate = toAff2 A.truncate
44+
chown = toAff3 A.chown
45+
chmod = toAff2 A.chmod
46+
stat = toAff1 A.stat
47+
link = toAff2 A.link
48+
symlink = toAff3 A.symlink
49+
readlink = toAff1 A.readlink
50+
realpath = toAff1 A.realpath
51+
realpath' = toAff2 A.realpath'
52+
unlink = toAff1 A.unlink
53+
rmdir = toAff1 A.rmdir
54+
mkdir = toAff1 A.mkdir
55+
mkdir' = toAff2 A.mkdir'
56+
readdir = toAff1 A.readdir
57+
utimes = toAff3 A.utimes
58+
readFile = toAff1 A.readFile
59+
readTextFile = toAff2 A.readTextFile
60+
writeFile = toAff2 A.writeFile
61+
writeTextFile = toAff3 A.writeTextFile
62+
appendFile = toAff2 A.appendFile
63+
appendTextFile = toAff3 A.appendTextFile
64+
65+
-- |
66+
-- Patch `Node.FS.Async.exists`
67+
--
68+
import Data.Function
69+
foreign import fs "var fs = require('fs');" ::
70+
{ exists :: forall a. Fn2 String (Boolean -> a) Unit }
71+
72+
exists :: forall e. String -> Aff (fs :: F.FS | e) Boolean
73+
exists file = makeAff \_ a -> pure $ runFn2 fs.exists file a

0 commit comments

Comments
 (0)