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

Commit d5a0ab6

Browse files
committed
Converting the pscBundle task to a stream
Note that this is part of the updates for PureScript 0.7, which along with previous commits resolves #38
1 parent 938b3c4 commit d5a0ab6

File tree

9 files changed

+84
-243
lines changed

9 files changed

+84
-243
lines changed

foreign.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
function test(){
2+
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
"gulp-util": "^3.0.4",
3636
"logalot": "^2.1.0",
3737
"minimist": "^1.1.1",
38-
"multipipe": "^0.1.2",
3938
"promise": "^7.0.3",
4039
"resolve-bin": "^0.3.0",
41-
"through2": "^0.6.3",
4240
"which": "^1.0.9"
4341
},
4442
"devDependencies": {
@@ -50,6 +48,7 @@
5048
"run-sequence": "^1.0.2",
5149
"tap-spec": "^2.2.2",
5250
"tape": "^3.5.0",
51+
"through2": "^0.6.3",
5352
"webpack": "^1.8.9"
5453
}
5554
}

src/FS.purs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module GulpPurescript.FS
22
( FS()
3-
, Stream()
43
, writeFile
54
) where
65

@@ -12,8 +11,6 @@ import Data.Function
1211

1312
foreign import data FS :: !
1413

15-
data Stream i o
16-
1714
writeFile :: forall eff. String -> String -> Aff (fs :: FS | eff) Unit
1815
writeFile filename contents = makeAff $ runFn4 writeFileFn filename contents
1916

src/GulpUtil.purs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ module GulpPurescript.GulpUtil
22
( File()
33
, mkPluginError
44
, mkFile
5-
, filePath
6-
, fileIsNull
7-
, fileIsStream
85
) where
96

107
import Control.Monad.Eff.Exception (Error())
@@ -34,21 +31,3 @@ function mkFileFn(path, contents) {
3431
return new gutil.File({path: path, contents: contents});
3532
}
3633
""" :: Fn2 String Buffer File
37-
38-
foreign import filePath """
39-
function filePath(file) {
40-
return file.path;
41-
}
42-
""" :: File -> String
43-
44-
foreign import fileIsNull"""
45-
function fileIsNull(file) {
46-
return file.isNull();
47-
}
48-
""" :: File -> Boolean
49-
50-
foreign import fileIsStream """
51-
function fileIsStream(file) {
52-
return file.isStream();
53-
}
54-
""" :: File -> Boolean

src/Multipipe.purs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Plugin.purs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ import GulpPurescript.Buffer (Buffer(), mkBufferFromString)
2828
import GulpPurescript.ChildProcess (ChildProcess(), spawn)
2929
import GulpPurescript.FS (FS(), writeFile)
3030
import GulpPurescript.Glob (Glob(), globAll)
31-
import GulpPurescript.GulpUtil (File(), fileIsNull, fileIsStream, filePath, mkFile, mkPluginError)
31+
import GulpPurescript.GulpUtil (File(), mkFile, mkPluginError)
3232
import GulpPurescript.Logalot (Logalot(), info)
3333
import GulpPurescript.Minimist (minimist)
34-
import GulpPurescript.Multipipe (multipipe2)
3534
import GulpPurescript.OS (OS(), Platform(Win32), platform)
3635
import GulpPurescript.Options (Psci(..), pscOptions, pscBundleOptions, pscDocsOptions)
3736
import GulpPurescript.Package (Pkg(), Package(..), package)
3837
import GulpPurescript.Path (relative)
3938
import GulpPurescript.ResolveBin (ResolveBin(), resolveBin)
40-
import GulpPurescript.Through2 (Through2(), objStream, accStream)
39+
import GulpPurescript.Stream (Stream(), ReadableStream(), mkReadableStreamFromBuffer)
4140
import GulpPurescript.Which (Which(), which)
4241

4342
newtype Argv = Argv { verbose :: Boolean }
@@ -53,7 +52,7 @@ type Effects eff =
5352
, os :: OS
5453
, package :: Pkg
5554
, resolveBin :: ResolveBin
56-
, through2 :: Through2
55+
, stream :: Stream
5756
, which :: Which
5857
| eff
5958
)
@@ -120,24 +119,23 @@ psc opts eb cb = runAff eb cb $ do
120119
then liftEff $ info $ pscCommand ++ "\n" ++ output
121120
else pure unit
122121

123-
pscBundle :: forall eff. Foreign -> Errorback eff -> Callback eff Unit -> Eff (Effects eff) Unit
124-
pscBundle opts eb cb = runAff eb cb $ do
125-
output <- either (throwPluginError <<< show)
126-
(execute pscBundleCommand)
127-
(pscBundleOptions opts)
128-
if isVerbose
129-
then liftEff $ info $ pscCommand ++ "\n" ++ output
130-
else pure unit
122+
pscBundle :: forall eff. Foreign -> Errorback eff -> Callback eff (ReadableStream Buffer) -> Eff (Effects eff) Unit
123+
pscBundle opts eb cb = runAff eb cb (either (throwPluginError <<< show) run (pscBundleOptions opts))
124+
where
125+
run :: [String] -> Aff (Effects eff) (ReadableStream Buffer)
126+
run args = do
127+
bundle <- execute pscBundleCommand args
128+
liftEff (mkReadableStreamFromBuffer (mkBufferFromString bundle))
131129

132130
pscDocs :: forall eff. Foreign -> Errorback eff -> Callback eff File -> Eff (Effects eff) Unit
133-
pscDocs opts eb cb = runAff eb cb $ do
134-
case pscDocsOptions opts of
135-
Left e -> throwPluginError (show e)
136-
Right a -> mkFile "." <$> mkBufferFromString
137-
<$> execute pscDocsCommand a
131+
pscDocs opts eb cb = runAff eb cb (either (throwPluginError <<< show) run (pscDocsOptions opts))
132+
where
133+
run :: [String] -> Aff (Effects eff) File
134+
run args = mkFile "." <$> mkBufferFromString
135+
<$> execute pscDocsCommand args
138136

139137
psci :: forall eff. Foreign -> Errorback eff -> Callback eff Unit -> Eff (Effects eff) Unit
140-
psci opts eb cb = runAff eb cb (either (\e -> throwPluginError (show e)) write (read opts))
138+
psci opts eb cb = runAff eb cb (either (throwPluginError <<< show) write (read opts))
141139
where
142140
write :: Psci -> Aff (Effects eff) Unit
143141
write (Psci a) = do

src/Stream.purs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module GulpPurescript.Stream
2+
( Stream()
3+
, ReadableStream()
4+
, mkReadableStreamFromBuffer
5+
) where
6+
7+
import Control.Monad.Eff (Eff())
8+
9+
import GulpPurescript.Buffer (Buffer())
10+
11+
foreign import data Stream :: !
12+
13+
data ReadableStream o
14+
15+
foreign import mkReadableStreamFromBuffer """
16+
function mkReadableStreamFromBuffer(buffer) {
17+
return function(){
18+
var Readable = require('stream').Readable;
19+
20+
var stream = Readable();
21+
22+
stream._read = function(){
23+
stream.push(buffer);
24+
return stream.push(null);
25+
};
26+
27+
return stream;
28+
};
29+
}
30+
""" :: forall eff. Buffer -> Eff (stream :: Stream | eff) (ReadableStream Buffer)

src/Through2.purs

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)