@@ -9,6 +9,7 @@ module Compiler.Backend exposing
9
9
, DocsFlags
10
10
, DocsOutput(..)
11
11
, DiffArgs(..)
12
+ , encodeCommand
12
13
, run
13
14
--
14
15
, UnsupportedPlatform(..)
@@ -25,7 +26,7 @@ module Compiler.Backend exposing
25
26
26
27
@docs UnsupportedPlatform, downloadUrl, download, cachePath, isCached
27
28
28
- @docs Command, InitFlags, ReplFlags, MakeFlags, MakeOutput, DocsFlags, DocsOutput, DiffArgs, Platform, run
29
+ @docs Command, InitFlags, ReplFlags, MakeFlags, MakeOutput, DocsFlags, DocsOutput, DiffArgs, Platform, encodeCommand, run
29
30
30
31
-}
31
32
@@ -257,9 +258,7 @@ type DiffArgs
257
258
258
259
{-|-}
259
260
type alias RunOptions msg =
260
- { command : Command
261
- , interactiveSession : Bool
262
- , useColor : Bool
261
+ { useColor : Bool
263
262
, compilerPath : Path
264
263
, pathToString : (Path -> String)
265
264
, onInit : { processId : Process.Id, streams : Maybe ChildProcess.StreamIO } -> msg
@@ -269,35 +268,36 @@ type alias RunOptions msg =
269
268
270
269
{-| Execute the compiler backend. The backend will write to stdout and stderr. There's currently no way
271
270
to redirect what is written to these streams.
272
-
273
- The `encodedCommand` should be fed to the backend's stdin stream on initialization.
274
271
-}
275
- run : ChildProcess.Permission -> RunOptions msg -> { encodedCommand : String, command : Cmd msg }
272
+ run : ChildProcess.Permission -> RunOptions msg -> Cmd msg
276
273
run permission options =
277
274
let
278
- commandAsJson =
279
- options.command
280
- |> commandEncoder options.interactiveSession options.pathToString
281
- |> Json.encode 0
282
-
283
275
colorEnvVar =
284
276
if options.useColor then
285
277
Dict.singleton "FORCE_COLOR" "1"
286
278
else
287
279
Dict.singleton "NO_COLOR" "1"
288
280
in
289
- { encodedCommand = commandAsJson
290
- , command =
291
- ChildProcess.spawn
292
- permission
293
- (options.pathToString options.compilerPath)
294
- []
295
- { ( ChildProcess.defaultSpawnOptions options.onInit options.onComplete )
296
- | shell = NoShell
297
- , environmentVariables =
298
- ChildProcess.MergeWithEnvironmentVariables colorEnvVar
299
- }
300
- }
281
+ ChildProcess.spawn
282
+ permission
283
+ (options.pathToString options.compilerPath)
284
+ []
285
+ { ( ChildProcess.defaultSpawnOptions options.onInit options.onComplete )
286
+ | shell = NoShell
287
+ , environmentVariables =
288
+ ChildProcess.MergeWithEnvironmentVariables colorEnvVar
289
+ }
290
+
291
+
292
+ {-| Encode a backend command to JSON. This should be fed to the compiler backend upon
293
+ initialization.
294
+ -}
295
+ encodeCommand : { interactiveSession : Bool, pathToString : Path -> String } -> Command -> Bytes
296
+ encodeCommand options command =
297
+ command
298
+ |> commandEncoder options.interactiveSession options.pathToString
299
+ |> Json.encode 0
300
+ |> Bytes.fromString
301
301
302
302
303
303
commandEncoder : Bool -> (Path -> String) -> Command -> Json.Value
0 commit comments