mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-24 02:02:29 +03:00
Vendorize Elm.Project.encode
This commit is contained in:
parent
05d2622923
commit
47ff4a0f0f
74
src/Review/ElmProjectEncoder.elm
Normal file
74
src/Review/ElmProjectEncoder.elm
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
module Review.ElmProjectEncoder exposing (encode)
|
||||||
|
|
||||||
|
import Elm.Constraint as Constraint exposing (Constraint)
|
||||||
|
import Elm.License as License exposing (License)
|
||||||
|
import Elm.Module as Module
|
||||||
|
import Elm.Package as Package
|
||||||
|
import Elm.Project exposing (Deps, Exposed(..), Project(..))
|
||||||
|
import Elm.Version as Version exposing (Version)
|
||||||
|
import Json.Encode as E
|
||||||
|
|
||||||
|
|
||||||
|
{-| Turn a `Project` into the JSON that goes in `elm.json`
|
||||||
|
-}
|
||||||
|
encode : Project -> E.Value
|
||||||
|
encode project =
|
||||||
|
case project of
|
||||||
|
Application { elm, dirs, depsDirect, depsIndirect, testDepsDirect, testDepsIndirect } ->
|
||||||
|
E.object
|
||||||
|
[ ( "type", E.string "application" )
|
||||||
|
, ( "source-directories", E.list E.string dirs )
|
||||||
|
, ( "elm-version", Version.encode elm )
|
||||||
|
, ( "dependencies"
|
||||||
|
, E.object
|
||||||
|
[ ( "direct", encodeDeps Version.encode depsDirect )
|
||||||
|
, ( "indirect", encodeDeps Version.encode depsIndirect )
|
||||||
|
]
|
||||||
|
)
|
||||||
|
, ( "test-dependencies"
|
||||||
|
, E.object
|
||||||
|
[ ( "direct", encodeDeps Version.encode testDepsDirect )
|
||||||
|
, ( "indirect", encodeDeps Version.encode testDepsIndirect )
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
Package { name, summary, license, version, exposed, deps, testDeps, elm } ->
|
||||||
|
E.object
|
||||||
|
[ ( "type", E.string "package" )
|
||||||
|
, ( "name", Package.encode name )
|
||||||
|
, ( "summary", E.string summary )
|
||||||
|
, ( "license", License.encode license )
|
||||||
|
, ( "version", Version.encode version )
|
||||||
|
, ( "exposed-modules", encodeExposed exposed )
|
||||||
|
, ( "elm-version", Constraint.encode elm )
|
||||||
|
, ( "dependencies", encodeDeps Constraint.encode deps )
|
||||||
|
, ( "test-dependencies", encodeDeps Constraint.encode testDeps )
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
encodeExposed : Exposed -> E.Value
|
||||||
|
encodeExposed exposed =
|
||||||
|
case exposed of
|
||||||
|
ExposedList modules ->
|
||||||
|
E.list Module.encode modules
|
||||||
|
|
||||||
|
ExposedDict chunks ->
|
||||||
|
E.object (List.map encodeChunk chunks)
|
||||||
|
|
||||||
|
|
||||||
|
encodeChunk : ( String, List Module.Name ) -> ( String, E.Value )
|
||||||
|
encodeChunk ( header, list ) =
|
||||||
|
( header, E.list Module.encode list )
|
||||||
|
|
||||||
|
|
||||||
|
encodeDeps : (constraint -> E.Value) -> Deps constraint -> E.Value
|
||||||
|
encodeDeps encodeConstraint deps =
|
||||||
|
E.object <|
|
||||||
|
List.sortBy Tuple.first <|
|
||||||
|
List.map (encodeDep encodeConstraint) deps
|
||||||
|
|
||||||
|
|
||||||
|
encodeDep : (constraint -> E.Value) -> ( Package.Name, constraint ) -> ( String, E.Value )
|
||||||
|
encodeDep encodeConstraint ( name, constraint ) =
|
||||||
|
( Package.toString name, encodeConstraint constraint )
|
@ -278,6 +278,7 @@ import Elm.Syntax.Type
|
|||||||
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
|
import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation)
|
||||||
import Elm.Type
|
import Elm.Type
|
||||||
import Json.Encode as Encode
|
import Json.Encode as Encode
|
||||||
|
import Review.ElmProjectEncoder
|
||||||
import Review.Error exposing (InternalError)
|
import Review.Error exposing (InternalError)
|
||||||
import Review.Exceptions as Exceptions exposing (Exceptions)
|
import Review.Exceptions as Exceptions exposing (Exceptions)
|
||||||
import Review.Fix as Fix exposing (Fix)
|
import Review.Fix as Fix exposing (Fix)
|
||||||
@ -3115,7 +3116,7 @@ errorForElmJsonWithFix (ElmJsonKey elmJson) getErrorInfo getFix =
|
|||||||
encoded : String
|
encoded : String
|
||||||
encoded =
|
encoded =
|
||||||
updatedProject
|
updatedProject
|
||||||
|> Elm.Project.encode
|
|> Review.ElmProjectEncoder.encode
|
||||||
|> Encode.encode 4
|
|> Encode.encode 4
|
||||||
in
|
in
|
||||||
[ Fix.replaceRangeBy
|
[ Fix.replaceRangeBy
|
||||||
|
Loading…
Reference in New Issue
Block a user