Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jxxcarlson/elm-review-codeinstaller…
Browse files Browse the repository at this point in the history
… after fixing merge conflicts
  • Loading branch information
jxxcarlson committed Jun 22, 2024
2 parents 8e1aa3e + fc62a8b commit 6ff4313
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 212 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ update msg model =
- **Install.FieldInTypeAlias**: Add a field to a specified type alias in a specified module. For more details, see the [docs](https://package.elm-lang.org/packages/jxxcarlson/elm-review-codeinstaller/latest/Install-FieldInTypeAlias).
- **Install.Initializer**: Add a field to the body of an initializer function where the return value is of the form `( Model, Cmd msg )`. For more details, see the [docs](https://package.elm-lang.org/packages/jxxcarlson/elm-review-codeinstaller/latest/Install-Initializer).
- **Install.TypeVariant**: Add a variant to a specified type in a specified module. For more details, see the [docs](https://package.elm-lang.org/packages/jxxcarlson/elm-review-codeinstaller/latest/Install-TypeVariant).
- **Install.Function**: Replace a function in a given module with a new implementation or add that function definition if it is not present in the module. For more details, see the [docs](https://package.elm-lang.org/packages/jxxcarlson/elm-review-codeinstaller/latest/Install-Function).
- **Install.Function.ReplaceFunction**: Replace a function in a given module with a new implementation. For more details, see the [docs](https://package.elm-lang.org/packages/jxxcarlson/elm-review-codeinstaller/latest/Install-Function-ReplaceFunction).
- **Install.Function.InsertFunction**: Add a function in a given module if it is not present. For more details, see the [docs](https://package.elm-lang.org/packages/jxxcarlson/elm-review-codeinstaller/latest/Install-Function-InsertFunction).
- **Install.Import**: Add import statements to a given module. For more details, see the [docs](https://package.elm-lang.org/packages/jxxcarlson/elm-review-codeinstaller/latest/Install-Import).

## Try it out
Expand Down
3 changes: 2 additions & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"Install.FieldInTypeAlias",
"Install.Initializer",
"Install.TypeVariant",
"Install.Function",
"Install.Function.InsertFunction",
"Install.Function.ReplaceFunction",
"Install.Import",
"Install.Type"
],
Expand Down
218 changes: 133 additions & 85 deletions preview/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,36 @@ when inside the directory containing this file.
-}

import Install.Import
import Install.TypeVariant
import Install.ClauseInCase
import Install.FieldInTypeAlias
import Install.Type
import Install.Function.InsertFunction
import Install.Function.ReplaceFunction
import Install.Import
import Install.Initializer
import Install.ClauseInCase
import Install.Function
import Install.Type
import Install.TypeVariant
import Review.Rule exposing (Rule)

config = config1

config =
config1


config1 : List Rule
config1 =
[
Install.TypeVariant.makeRule "Types" "ToBackend" "CounterReset"
, Install.TypeVariant.makeRule "Types" "FrontendMsg" "Reset"
, Install.ClauseInCase.init "Frontend" "updateLoaded" "Reset" "( { model | counter = 0 }, sendToBackend CounterReset )"
[ Install.TypeVariant.makeRule "Types" "ToBackend" "CounterReset"
, Install.TypeVariant.makeRule "Types" "FrontendMsg" "Reset"
, Install.ClauseInCase.init "Frontend" "update" "Reset" "( { model | counter = 0 }, sendToBackend CounterReset )"
|> Install.ClauseInCase.withInsertAfter "Increment"
|> Install.ClauseInCase.makeRule
, Install.ClauseInCase.init "Backend" "updateFromFrontend" "CounterReset" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )"
|> Install.ClauseInCase.makeRule
, Install.Function.init "Pages.Counter" "view" viewFunction |>Install.Function.makeRule

, Install.Function.ReplaceFunction.init "Frontend" "view" viewFunction |> Install.Function.ReplaceFunction.makeRule
]

viewFunction = """view model =

viewFunction =
"""view model =
Html.div [ style "padding" "50px" ]
[ Html.button [ onClick Increment ] [ text "+" ]
, Html.div [ style "padding" "10px" ] [ Html.text (String.fromInt model.counter) ]
Expand All @@ -47,80 +50,125 @@ viewFunction = """view model =
]"""


viewFunction2 =
"""view model =
Html.div [ style "padding" "50px" ]
[ Html.button [ onClick Increment ] [ text "+" ]
, Html.div [ style "padding" "10px" ] [ Html.text (String.fromInt model.counter) ]
, Html.button [ onClick Decrement ] [ text "-" ]
, Html.div [ style "padding-top" "15px", style "padding-bottom" "15px" ] [ Html.text "Click me then refresh me!" ]
, Html.button [ onClick Reset ] [ text "Reset" ]
]"""


viewFunction3 =
"""view model =
Html.div [ style "padding" "50px" ]
[ Html.button [ onClick Increment ] [ text "+" ]
, Html.div [ style "padding" "10px" ] [ Html.text (String.fromInt model.counter) ]
, Html.button [ onClick Decrement ] [ text "-" ]
, Html.div [ style "padding-top" "15px", style "padding-bottom" "15px" ] [ Html.text "Click me then refresh me!" ]
, Html.button [ onClick Reset ] [ text "Reset" ]
]"""


config2 : List Rule
config2 =
[
-- TYPES
Install.Type.makeRule "Types" "SignInState" [ "SignedOut", "SignUp", "SignedIn" ]
, Install.Type.makeRule "Types" "BackendDataStatus" [ "Sunny", "LoadedBackendData" ]
-- TYPES IMPORTS
, Install.Import.initSimple "Types" ["Auth.Common", "Url", "MagicLink.Types", "User"
, "Session", "Dict", "AssocList"] |>Install.Import.makeRule
-- Type Frontend, MagicLink
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "authFlow : Auth.Common.Flow"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "authRedirectBaseUrl : Url"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "signinForm : MagicLink.Types.SigninForm"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "loginErrorMessage : Maybe String"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "signInStatus : MagicLink.Types.SignInStatus"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "currentUserData : Maybe User.LoginData"
-- Type Frontend, User
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "currentUser : Maybe User.User"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "signInState : SignInState"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "realname : String"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "username : String"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "email : String"
-- Type BackendModel
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "pendingAuths : Dict Lamdera.SessionId Auth.Common.PendingAuth"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "pendingEmailAuths : Dict Lamdera.SessionId Auth.Common.PendingEmailAuth"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "sessions : Dict SessionId Auth.Common.UserInfo"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "secretCounter : Int"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "sessionDict : AssocList.Dict SessionId String"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "pendingLogins: MagicLink.Types.PendingLogins"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "log : MagicLink.Types.Log"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "users: Dict.Dict User.EmailString User.User"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "userNameToEmailString : Dict.Dict User.Username User.EmailString"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "sessionInfo : Session.SessionInfo"
-- Type ToBackend
, Install.TypeVariant.makeRule "Types" "ToBackend" "AuthToBackend Auth.Common.ToBackend"
, Install.TypeVariant.makeRule "Types" "ToBackend" "AddUser String String String"
, Install.TypeVariant.makeRule "Types" "ToBackend" "RequestSignup String String String"
-- Type BackendMsg
, Install.TypeVariant.makeRule "Types" "BackendMsg" "AuthBackendMsg Auth.Common.BackendMsg"
, Install.TypeVariant.makeRule "Types" "BackendMsg" "AutoLogin SessionId User.LoginData"
-- Type ToFrontend
, Install.TypeVariant.makeRule "Types" "ToFrontend" "AuthToFrontend Auth.Common.ToFrontend"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "AuthSuccess Auth.Common.UserInfo"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "UserInfoMsg (Maybe Auth.Common.UserInfo)"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "CheckSignInResponse (Result BackendDataStatus User.LoginData)"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "GetLoginTokenRateLimited"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "RegistrationError String"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "SignInError String"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "UserSignedIn (Maybe User.User)"
-- Initialize BackendModel
, Install.Initializer.makeRule "Backend" "init" "users" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "sessions" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "time" "Time.millisToPosix 0"
, Install.Initializer.makeRule "Backend" "init" "time" "Time.millisToPosix 0"
, Install.Initializer.makeRule "Backend" "init" "randomAtmosphericNumbers" "Nothing"
, Install.Initializer.makeRule "Backend" "init" "localUuidData" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "pendingAuths" "Nothing"
, Install.Initializer.makeRule "Backend" "init" "localUuidData" "Nothing"
, Install.Initializer.makeRule "Backend" "init" "secretCounter" "0"
, Install.Initializer.makeRule "Backend" "init" "pendingAuths" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "pendingEmailAuths" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "sessionDict" "AssocList.empty"
, Install.Initializer.makeRule "Backend" "init" "sessionDict" "AssocList.empty"
, Install.Initializer.makeRule "Backend" "init" "log" "[]"
-- Backend import
, Install.Import.initSimple "Backend" ["Auth.Common","AssocList","Auth.Flow","Dict"
, "Helper", "Lamdera","LocalUUID", "MagicLink.Auth" , "Process"
, "Task", "Time", "User" ] |>Install.Import.makeRule
---
, Install.ClauseInCase.init
"Frontend" "updateFromBacked"
"AuthToFrontend authToFrontendMsg"
"MagicLink.Auth.updateFromBackend authToFrontendMsg model"
|> Install.ClauseInCase.makeRule
[ -- TYPES
Install.Type.makeRule "Types" "SignInState" [ "SignedOut", "SignUp", "SignedIn" ]
, Install.Type.makeRule "Types" "BackendDataStatus" [ "Sunny", "LoadedBackendData" ]

-- TYPES IMPORTS
, Install.Import.initSimple "Types" [ "Auth.Common", "MagicLink.Types", "User", "Session", "Dict", "AssocList" ] |> Install.Import.makeRule
, Install.Import.init "Types" [ { moduleToImport = "Url", alias_ = Nothing, exposedValues = Just [ "Url" ] } ] |> Install.Import.makeRule

-- Type Frontend, MagicLink
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "authFlow : Auth.Common.Flow"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "authRedirectBaseUrl : Url"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "signinForm : MagicLink.Types.SigninForm"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "loginErrorMessage : Maybe String"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "signInStatus : MagicLink.Types.SignInStatus"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "currentUserData : Maybe User.LoginData"

-- Type Frontend, User
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "currentUser : Maybe User.User"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "signInState : SignInState"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "realname : String"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "username : String"
, Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" "email : String"

-- Type BackendModel
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "pendingAuths : Dict Lamdera.SessionId Auth.Common.PendingAuth"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "pendingEmailAuths : Dict Lamdera.SessionId Auth.Common.PendingEmailAuth"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "sessions : Dict SessionId Auth.Common.UserInfo"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "secretCounter : Int"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "sessionDict : AssocList.Dict SessionId String"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "pendingLogins: MagicLink.Types.PendingLogins"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "log : MagicLink.Types.Log"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "users: Dict.Dict User.EmailString User.User"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "userNameToEmailString : Dict.Dict User.Username User.EmailString"
, Install.FieldInTypeAlias.makeRule "Types" "BackendModel" "sessionInfo : Session.SessionInfo"

-- Type ToBackend
, Install.TypeVariant.makeRule "Types" "ToBackend" "AuthToBackend Auth.Common.ToBackend"
, Install.TypeVariant.makeRule "Types" "ToBackend" "AddUser String String String"
, Install.TypeVariant.makeRule "Types" "ToBackend" "RequestSignup String String String"

-- Type BackendMsg
, Install.TypeVariant.makeRule "Types" "BackendMsg" "AuthBackendMsg Auth.Common.BackendMsg"
, Install.TypeVariant.makeRule "Types" "BackendMsg" "AutoLogin SessionId User.LoginData"

-- Type ToFrontend
, Install.TypeVariant.makeRule "Types" "ToFrontend" "AuthToFrontend Auth.Common.ToFrontend"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "AuthSuccess Auth.Common.UserInfo"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "UserInfoMsg (Maybe Auth.Common.UserInfo)"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "CheckSignInResponse (Result BackendDataStatus User.LoginData)"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "GetLoginTokenRateLimited"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "RegistrationError String"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "SignInError String"
, Install.TypeVariant.makeRule "Types" "ToFrontend" "UserSignedIn (Maybe User.User)"

-- Initialize BackendModel
, Install.Initializer.makeRule "Backend" "init" "users" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "sessions" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "time" "Time.millisToPosix 0"
, Install.Initializer.makeRule "Backend" "init" "time" "Time.millisToPosix 0"
, Install.Initializer.makeRule "Backend" "init" "randomAtmosphericNumbers" "Nothing"
, Install.Initializer.makeRule "Backend" "init" "localUuidData" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "pendingAuths" "Nothing"
, Install.Initializer.makeRule "Backend" "init" "localUuidData" "Nothing"
, Install.Initializer.makeRule "Backend" "init" "secretCounter" "0"
, Install.Initializer.makeRule "Backend" "init" "pendingAuths" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "pendingEmailAuths" "Dict.empty"
, Install.Initializer.makeRule "Backend" "init" "sessionDict" "AssocList.empty"
, Install.Initializer.makeRule "Backend" "init" "sessionDict" "AssocList.empty"
, Install.Initializer.makeRule "Backend" "init" "log" "[]"

-- Backend import
, Install.Import.initSimple "Backend"
[ "Auth.Common"
, "AssocList"
, "Auth.Flow"
, "Dict"
, "Helper"
, "LocalUUID"
, "MagicLink.Auth"
, "Process"
, "Task"
, "Time"
, "User"
]
|> Install.Import.makeRule
, Install.Import.init "Backend" [ { moduleToImport = "Lamdera", alias_ = Nothing, exposedValues = Just [ "ClientId", "SessionId" ] } ] |> Install.Import.makeRule

---
, Install.ClauseInCase.init
"Frontend"
"updateFromBacked"
"AuthToFrontend authToFrontendMsg"
"MagicLink.Auth.updateFromBackend authToFrontendMsg model"
|> Install.ClauseInCase.makeRule
]

]

Expand Down
9 changes: 3 additions & 6 deletions review/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"elm/core": "1.0.5",
"elm/json": "1.1.3",
"elm/project-metadata-utils": "1.0.2",
"jfmengels/elm-review": "2.13.2",
"jfmengels/elm-review": "2.14.0",
"jfmengels/elm-review-debug": "1.0.8",
"jfmengels/elm-review-unused": "1.2.3",
"jxxcarlson/elm-review-codeinstaller": "1.0.0",
Expand All @@ -20,11 +20,11 @@
"elm/html": "1.0.0",
"elm/parser": "1.1.0",
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/virtual-dom": "1.0.3",
"elm-explorations/test": "2.2.0",
"miniBill/elm-unicode": "1.1.1",
"pzp1997/assoc-list": "1.0.0",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/structured-writer": "1.0.3"
}
Expand All @@ -33,9 +33,6 @@
"direct": {
"elm-explorations/test": "2.2.0"
},
"indirect": {
"elm/regex": "1.0.0",
"pzp1997/assoc-list": "1.0.0"
}
"indirect": {}
}
}
Loading

0 comments on commit 6ff4313

Please sign in to comment.