Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ module.exports = {
package: !!options.package
});
},
make: async (config, path, options) => {
make: async (config, path, options = {}) => {
return await runGuida(config, {
command: "make",
path,
Expand Down
16 changes: 14 additions & 2 deletions src/API/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,20 @@ app =
|> Task.bind
(\result ->
case result of
Ok output ->
exitWithResponse (Encode.object [ ( "output", Encode.string output ) ])
Ok ( output, warnings ) ->
let
warningsJson : Encode.Value
warningsJson =
E.encodeUgly (E.list Error.warningReportToJson warnings)
|> Decode.decodeString Decode.value
|> Result.withDefault Encode.null
in
exitWithResponse
(Encode.object
[ ( "output", Encode.string output )
, ( "warnings", warningsJson )
]
)

Err error ->
exitWithResponse (Encode.object [ ( "error", Encode.string (E.encodeUgly (Exit.toJson (Exit.makeToReport error))) ) ])
Expand Down
53 changes: 43 additions & 10 deletions src/API/Make.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import Builder.Stuff as Stuff
import Compiler.AST.Optimized as Opt
import Compiler.Data.NonEmptyList as NE
import Compiler.Generate.Html as Html
import Compiler.Generate.Target exposing (Target)
import Compiler.Guida.ModuleName as ModuleName
import Compiler.Reporting.Render.Code as Code
import Compiler.Reporting.Render.Type.Localizer as L
import Compiler.Reporting.Report as Report
import Compiler.Reporting.Warning as W
import Maybe.Extra as Maybe
import Task exposing (Task)
import Terminal.Terminal.Internal exposing (Parser(..))
Expand Down Expand Up @@ -52,7 +57,7 @@ type ReportType
-- RUN


run : String -> Flags -> Task Never (Result Exit.Make String)
run : String -> Flags -> Task Never (Result Exit.Make ( String, List Report.WarningModuleReport ))
run path flags =
Stuff.findRoot
|> Task.bind
Expand All @@ -66,7 +71,7 @@ run path flags =
)


runHelp : Stuff.Root -> String -> Flags -> Task Never (Result Exit.Make String)
runHelp : Stuff.Root -> String -> Flags -> Task Never (Result Exit.Make ( String, List Report.WarningModuleReport ))
runHelp root path (Flags debug optimize withSourceMaps) =
BW.withScope
(\scope ->
Expand All @@ -83,17 +88,32 @@ runHelp root path (Flags debug optimize withSourceMaps) =
Task.eio Exit.MakeBadDetails (Details.load style scope root)
|> Task.bind
(\details ->
buildPaths style root details (NE.Nonempty path [])
buildPaths style root details False False (NE.Nonempty path [])
|> Task.bind
(\artifacts ->
(\((Build.Artifacts warnings _ _ _ _) as artifacts) ->
case getMains artifacts of
[] ->
-- Task.pure ()
crash "No main!"

[ name ] ->
toBuilder withSourceMaps Html.leadingLines root details desiredMode artifacts
|> Task.bind (Task.pure << Html.sandwich (Stuff.rootToTarget root) name)
let
target : Target
target =
Stuff.rootToTarget root

buildOutput : Task Exit.Make String
buildOutput =
toBuilder withSourceMaps Html.leadingLines root details desiredMode artifacts
|> Task.fmap (Html.sandwich target name)

buildWarnings : Task Exit.Make (List Report.WarningModuleReport)
buildWarnings =
warnings
|> Utils.listTraverse (warningToReport target)
|> Task.mapError never
in
Task.map2 Tuple.pair buildOutput buildWarnings

_ ->
crash "TODO"
Expand Down Expand Up @@ -128,18 +148,31 @@ getMode debug optimize =
-- BUILD PROJECTS


buildPaths : Reporting.Style -> Stuff.Root -> Details.Details -> NE.Nonempty FilePath -> Task Exit.Make Build.Artifacts
buildPaths style root details paths =
buildPaths : Reporting.Style -> Stuff.Root -> Details.Details -> Bool -> Bool -> NE.Nonempty FilePath -> Task Exit.Make Build.Artifacts
buildPaths style root details suppressWarnings denyWarnings paths =
Task.eio Exit.MakeCannotBuild <|
Build.fromPaths style root details paths
Build.fromPaths style root details suppressWarnings denyWarnings paths



-- EXTRACT WARNINGS


warningToReport : Target -> W.Module -> Task Never Report.WarningModuleReport
warningToReport target { absolutePath, name, source, warnings } =
Task.pure
{ path = absolutePath
, name = name
, warnings = List.map (W.toReport target L.empty (Code.toSource source)) warnings
}



-- GET MAINS


getMains : Build.Artifacts -> List ModuleName.Raw
getMains (Build.Artifacts _ _ roots modules) =
getMains (Build.Artifacts _ _ _ roots modules) =
List.filterMap (getMain modules) (NE.toList roots)


Expand Down
Loading
Loading