Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 938b3c4

Browse files
committed
Updates to the psci task
Renaming the task to `psci` and writing the result of the command to the `.psci` file. Note that previous commits resolved #40
1 parent c76e143 commit 938b3c4

File tree

8 files changed

+183
-89
lines changed

8 files changed

+183
-89
lines changed

MODULE.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,47 @@ multipipe2 :: forall a b c. Stream a b -> Stream b c -> Stream a c
140140

141141

142142

143+
## Module GulpPurescript.OS
144+
145+
#### `OS`
146+
147+
``` purescript
148+
data OS :: !
149+
```
150+
151+
152+
#### `Platform`
153+
154+
``` purescript
155+
data Platform
156+
= Darwin
157+
| Linux
158+
| Win32
159+
```
160+
161+
162+
#### `showPlatform`
163+
164+
``` purescript
165+
instance showPlatform :: Show Platform
166+
```
167+
168+
169+
#### `isForeignPlatform`
170+
171+
``` purescript
172+
instance isForeignPlatform :: IsForeign Platform
173+
```
174+
175+
176+
#### `platform`
177+
178+
``` purescript
179+
platform :: forall eff. Eff (os :: OS | eff) (Maybe Platform)
180+
```
181+
182+
183+
143184
## Module GulpPurescript.Options
144185

145186
#### `isForeignEither`
@@ -269,47 +310,6 @@ pscDocsOptions :: Foreign -> Either ForeignError [String]
269310

270311

271312

272-
## Module GulpPurescript.OS
273-
274-
#### `OS`
275-
276-
``` purescript
277-
data OS :: !
278-
```
279-
280-
281-
#### `Platform`
282-
283-
``` purescript
284-
data Platform
285-
= Darwin
286-
| Linux
287-
| Win32
288-
```
289-
290-
291-
#### `showPlatform`
292-
293-
``` purescript
294-
instance showPlatform :: Show Platform
295-
```
296-
297-
298-
#### `isForeignPlatform`
299-
300-
``` purescript
301-
instance isForeignPlatform :: IsForeign Platform
302-
```
303-
304-
305-
#### `platform`
306-
307-
``` purescript
308-
platform :: forall eff. Eff (os :: OS | eff) (Maybe Platform)
309-
```
310-
311-
312-
313313
## Module GulpPurescript.Package
314314

315315
#### `Pkg`
@@ -389,10 +389,10 @@ pscDocs :: forall eff. Foreign -> (Error -> Eff (Effects eff) Unit) -> (File ->
389389
```
390390

391391

392-
#### `dotPsci`
392+
#### `psci`
393393

394394
``` purescript
395-
dotPsci :: forall eff. Eff (Effects eff) (Stream File Unit)
395+
psci :: forall eff. Eff (Effects eff) (Stream File Unit)
396396
```
397397

398398

entry.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
'use strict';
22

33
var gulpPurescript = require('GulpPurescript.Plugin');
4+
45
var Promise = require('promise');
56

67
function promisify(aff) {
7-
return new Promise(function (resolve, reject) {
8-
var errback = function (err) {
9-
return function () {
10-
reject(err);
8+
return new Promise(function(resolve, reject){
9+
var errback = function(error){
10+
return function(){
11+
reject(error);
1112
};
1213
};
13-
var callback = function (x) {
14-
return function () {
15-
resolve(x);
14+
var callback = function(result){
15+
return function(){
16+
resolve(result);
1617
};
1718
};
1819
aff(errback)(callback)();
@@ -31,9 +32,8 @@ function pscDocs(options) {
3132
return promisify(gulpPurescript.pscDocs(options));
3233
}
3334

34-
function dotPsci() {
35-
var result = gulpPurescript.dotPsci();
36-
return result;
35+
function psci(options) {
36+
return promisify(gulpPurescript.psci(options));
3737
}
3838

3939
module.exports.psc = psc;
@@ -42,4 +42,4 @@ module.exports.pscBundle = pscBundle;
4242

4343
module.exports.pscDocs = pscDocs;
4444

45-
module.exports.dotPsci = dotPsci;
45+
module.exports.psci = psci;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"purescript"
3030
],
3131
"dependencies": {
32+
"async": "^1.3.0",
3233
"cross-spawn": "^0.4.0",
3334
"glob": "^5.0.5",
3435
"gulp-util": "^3.0.4",

src/FS.purs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
module GulpPurescript.FS
22
( FS()
33
, Stream()
4-
, createWriteStream
4+
, writeFile
55
) where
66

7+
import Control.Monad.Aff (Aff(), makeAff)
78
import Control.Monad.Eff (Eff())
9+
import Control.Monad.Eff.Exception (Error())
10+
11+
import Data.Function
812

913
foreign import data FS :: !
1014

1115
data Stream i o
1216

13-
foreign import createWriteStream """
14-
function createWriteStream(path) {
17+
writeFile :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit
18+
writeFile filename contents = makeAff $ runFn4 writeFileFn filename contents
19+
20+
foreign import writeFileFn """
21+
function writeFileFn(filename, contents, errback, callback) {
1522
return function(){
1623
var fs = require('fs');
17-
return fs.createWriteStream(path);
24+
fs.writeFile(filename, contents, function(error){
25+
if (error) errback(new Error(error))();
26+
else callback()();
27+
});
1828
};
1929
}
20-
""" :: forall eff. String -> Eff (fs :: FS | eff) (Stream String Unit)
30+
""" :: forall eff. Fn4 String
31+
String
32+
(Error -> Eff (fs :: FS | eff) Unit)
33+
(Unit -> Eff (fs :: FS | eff) Unit)
34+
(Eff (fs :: FS | eff) Unit)

src/Glob.purs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module GulpPurescript.Glob
2+
( Glob()
3+
, glob
4+
, globAll
5+
) where
6+
7+
import Control.Monad.Aff (Aff(), makeAff)
8+
import Control.Monad.Eff (Eff())
9+
import Control.Monad.Eff.Exception (Error())
10+
11+
import Data.Function
12+
13+
foreign import data Glob :: !
14+
15+
glob :: forall eff. String -> Aff (glob :: Glob | eff) [String]
16+
glob pattern = makeAff $ runFn3 globFn pattern
17+
18+
foreign import globFn """
19+
function globFn(pattern, errback, callback) {
20+
return function(){
21+
var glob = require('glob');
22+
23+
glob(pattern, function(error, result){
24+
if (error) errback(new Error(error))();
25+
else callback(result)();
26+
});
27+
};
28+
}
29+
""" :: forall eff. Fn3 String
30+
(Error -> Eff (glob :: Glob | eff) Unit)
31+
([String] -> Eff (glob :: Glob | eff) Unit)
32+
(Eff (glob :: Glob | eff) Unit)
33+
34+
globAll :: forall eff. [String] -> Aff (glob :: Glob | eff) [[String]]
35+
globAll patterns = makeAff $ runFn3 globAllFn patterns
36+
37+
foreign import globAllFn """
38+
function globAllFn(patterns, errback, callback) {
39+
return function(){
40+
var glob = require('glob');
41+
42+
var async = require('async');
43+
44+
async.map(patterns, glob, function(error, result){
45+
if (error) errback(new Error(error))();
46+
else callback(result)();
47+
});
48+
};
49+
}
50+
""" :: forall eff. Fn3 [String]
51+
(Error -> Eff (glob :: Glob | eff) Unit)
52+
([[String]] -> Eff (glob :: Glob | eff) Unit)
53+
(Eff (glob :: Glob | eff) Unit)

src/Options.purs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module GulpPurescript.Options
2-
( pscOptions
2+
( Psci(..)
3+
, pscOptions
34
, pscBundleOptions
45
, pscDocsOptions
56
) where
@@ -99,10 +100,10 @@ newtype PscDocs
99100
, docgen :: NullOrUndefined Docgen
100101
}
101102

102-
newtype DotPsci
103-
= DotPsci { src :: Either String PathArray
104-
, ffi :: NullOrUndefined (Either String PathArray)
105-
}
103+
newtype Psci
104+
= Psci { src :: Either String [String]
105+
, ffi :: NullOrUndefined (Either String [String])
106+
}
106107

107108
newtype Docgen = Docgen Foreign
108109

@@ -157,12 +158,12 @@ instance isForeignPscDocs :: IsForeign PscDocs where
157158
<*> readProp formatKey obj
158159
<*> readProp docgenOpt obj)
159160

160-
instance isForeignDotPsci :: IsForeign DotPsci where
161+
instance isForeignPsci :: IsForeign Psci where
161162
read obj =
162-
DotPsci <$> ({ src: _
163-
, ffi: _
164-
} <$> readProp srcKey obj
165-
<*> readProp ffiKey obj)
163+
Psci <$> ({ src: _
164+
, ffi: _
165+
} <$> readProp srcKey obj
166+
<*> readProp ffiKey obj)
166167

167168
instance isForeignPathArray :: IsForeign PathArray where
168169
read val = PathArray <$> read val

0 commit comments

Comments
 (0)