Skip to content

Commit

Permalink
Add elm test support and docs on insiders builds (#398)
Browse files Browse the repository at this point in the history
* Provide insiders channel

* Changes

* Add morphir elm test command

* Update docs about insiders builds
  • Loading branch information
DamianReeves authored Sep 8, 2023
1 parent e2b45f0 commit 996ace1
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 21 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ You can install the `morphir-cli` in the following ways:
cs install --channel https://raw.githubusercontent.com/finos/morphir-scala/main/coursier-channel.json morphir-cli
```

Then run the CLI:

```
morphir-cli setup
```

We also offer an insiders channel that grants access to snapshot releases of the CLI.

```
cs install --channel https://raw.githubusercontent.com/finos/morphir-scala/main/coursier-channel.json morphir-insiders-cli
```

Then run the CLI:

```
morphir-cli setup
```

NOTE: The main channel above (non-insiders), also offers insiders builds under the name `morphir-insiders-cli`:

```
cs install --channel https://raw.githubusercontent.com/finos/morphir-scala/main/coursier-channel.json morphir-insiders-cli
```

Then run the CLI:

```
morphir-insiders-cli setup
```

---
## Development

Expand Down
12 changes: 12 additions & 0 deletions coursier-channel.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,17 @@
"org.finos.morphir:morphir-main_3:latest.release"
],
"mainClass": "org.finos.morphir.cli.MorphirCliMain"
},
"morphir-insiders-cli": {
"repositories": [
"central",
"sonatype:releases",
"sonatype:snapshots",
"typesafe:ivy-releases"
],
"dependencies": [
"org.finos.morphir:morphir-main_3:latest.release"
],
"maincClass": "org.finos.morphir.cli.MorphirCliMain"
}
}
File renamed without changes.
7 changes: 5 additions & 2 deletions examples/morphir-elm-projects/finance/morphir.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "Morphir.Examples",
"sourceDirectory": "src/elm",
"exposedModules": ["Accounting.Book"]
}
"exposedModules": [
"Accounting.TAccount",
"Accounting.Journal"
]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Morphir.Examples.Accounting.Journal exposing (..)
import Morphir.SDK.LocalDate exposing (LocalDate)

type alias Journal =
{ entries : List Entry
, nextId : Int
}

type alias Entry =
{ id : Int
, date: LocalDate
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Morphir.Examples.Accounting.TAccount exposing (..)

type alias Amount = Int
type alias AccountName = String

type alias TAccount =
{ name: AccountName
, balance: Amount
, debits: List Amount
, credits: List Amount
}

make: AccountName -> Amount -> TAccount
make name balance =
{ name = name
, balance = balance
, debits = []
, credits = []
}

entry: TAccount -> TAccount -> Amount -> ( TAccount, TAccount )
entry debitAccount creditAccount amount =
( { debitAccount | debits = amount :: debitAccount.debits }
, { creditAccount | credits = amount :: creditAccount.credits }
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,12 @@ trait MorphirElmDriverPlatformSpecific {
_ <- Console.printLine(s"\tprojectDir: $projectDir")
_ <- Console.printLine("Elm restore command executed")
} yield ()

def test(projectDir: VFilePath): Task[Unit] =
for {
_ <- Console.printLine("Elm test command executed")
_ <- Console.printLine(s"\tprojectDir: $projectDir")
_ <- Console.printLine("Elm test command executed")
} yield ()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ trait MorphirElmDriverPlatformSpecific {
_ <- Console.printLine("Elm restore command executed")
} yield ()

def test(projectDir: VFilePath): Task[Unit] =
for {
_ <- ZIO.logDebug(s"Executing tests...")
_ <- ZIO.logDebug(s"\tprojectDir: $projectDir")
_ <- processIO.exec(
"morphir-elm",
"test",
"--project-dir",
projectDir.toString
)
} yield ()

private def launchInBrowser(url: String): ZIO[Any, Throwable, Unit] = {
val notify = Console.printLine(s"Attempting to open $url in browser")
for {
Expand Down
40 changes: 38 additions & 2 deletions morphir/main/src/org/finos/morphir/cli/MorphirCliMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,38 @@ object MorphirCliMain extends ZIOCliDefault {
MorphirElmDriver.develop(port, host, VFilePath.fromJava(projectDir), openInBrowser)
case MorphirCommand.Setup(morphirHomeDir) => MorphirSetup.setup(morphirHomeDir)
case MorphirCommand.Test(irFiles) => MorphirRuntimeDriver.test()
case MorphirCommand.ElmDevelop(port, host, projectDir, openInBrowser) =>
MorphirElmDriver.develop(port, host, VFilePath.fromJava(projectDir), openInBrowser)
case MorphirCommand.ElmInit(morphirHomeDir, projectDir) =>
MorphirElmDriver.init(VFilePath.fromJava(morphirHomeDir), VFilePath.fromJava(projectDir))
case MorphirCommand.ElmMake(projectDir, output, typesOnly, fallbackCli, indentJson) =>
MorphirElmDriver.make(VFilePath.fromJava(projectDir), VFilePath.fromJava(output), fallbackCli)
case MorphirCommand.ElmRestore(elmHome, projectDir) =>
MorphirElmDriver.restore(VFilePath.fromJava(elmHome), VFilePath.fromJava(projectDir))
case MorphirCommand.ElmTest(projectDir) => MorphirElmDriver.test(VFilePath.fromJava(projectDir))
}

object commands {

object Elm {

val develop = {
val port = Options.integer("port").alias("p").withDefault(BigInt(3000)).map(
_.intValue
) ?? "Port to bind the web server to."
val host = Options.text("host").alias("h").withDefault("localhost") ?? "Host to bind the web server to."
val projectDir = Options.directory("project-dir").alias("i").withDefault(
Paths.get(".")
) ?? "Root directory of the project where morphir.json is located."
val openInBrowser = Options.boolean("open-in-browser").alias("o") ?? "Open in browser."

Command("develop", port ++ host ++ projectDir ++ openInBrowser).withHelp(
"Start up a web server and expose developer tools through a web UI."
).map { case (port, host, projectDir, openInBrowser) =>
MorphirCommand.ElmDevelop(port, host, projectDir, openInBrowser)
}
}

val init = {
val projectDir = Options.directory("project-dir").alias("p").withDefault(Paths.get("."))

Expand Down Expand Up @@ -74,9 +95,24 @@ object MorphirCliMain extends ZIOCliDefault {
}
}

val root =
Command("elm").withHelp("Elm specific commands for morphir-cli.").subcommands(init, make, restore)
lazy val root =
Command("elm").withHelp("Elm specific commands for morphir-cli.").subcommands(
develop,
init,
make,
restore,
test
)

val test = {
val projectDir = Options.directory("project-dir").alias("p").withDefault(
Paths.get(".")
) ?? "Root directory of the project where morphir.json is located."

Command("test", projectDir).withHelp("Test Morphir models using morphir-elm.").map { projectDir =>
MorphirCommand.ElmTest(projectDir)
}
}
}

object Morphir {
Expand Down
2 changes: 2 additions & 0 deletions morphir/main/src/org/finos/morphir/cli/MorphirCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum MorphirCommand {
case Develop(port: Int, host: String, projectDir: Path, openInBrowser: Boolean)
case Setup(morphirHomeDir: Path)
case Test(irFiles: List[Path])
case ElmDevelop(port: Int, host: String, projectDir: Path, openInBrowser: Boolean)
case ElmInit(morphirHomeDir: Path, projectDir: Path)
case ElmMake(
projectDir: Path,
Expand All @@ -15,4 +16,5 @@ enum MorphirCommand {
indentJson: Boolean = false
)
case ElmRestore(elmHome: Path, projectDir: Path)
case ElmTest(projectDir: Path)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,12 @@ trait MorphirElmDriverPlatformSpecific {
_ <- Console.printLine(s"\tprojectDir: $projectDir")
_ <- Console.printLine("Elm restore command executed")
} yield ()

def test(projectDir: VFilePath): Task[Unit] =
for {
_ <- Console.printLine("Elm test command executed")
_ <- Console.printLine(s"\tprojectDir: $projectDir")
_ <- Console.printLine("Elm test command executed")
} yield ()
}
}
8 changes: 8 additions & 0 deletions morphir/src/org/finos/morphir/service/MorphirElmDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ trait MorphirElmDriver {

/// Restore the Elm dependencies for the current project/workspace.
def restore(elmHome: VFilePath, projectDir: VFilePath): Task[Unit]

/// Start testing the models.
def test(projectDir: VFilePath): Task[Unit]

}

/// Provides constructors and accessors for a MorphirElmDriver.
Expand Down Expand Up @@ -61,4 +65,8 @@ object MorphirElmDriver extends MorphirElmDriverPlatformSpecific {
/// Restore the Elm dependencies for the current project/workspace.
def restore(elmHome: VFilePath, projectDir: VFilePath): ZIO[MorphirElmDriver, Throwable, Unit] =
ZIO.serviceWithZIO[MorphirElmDriver](_.restore(elmHome, projectDir))

/// Start testing the models.
def test(projectDir: VFilePath): ZIO[MorphirElmDriver, Throwable, Unit] =
ZIO.serviceWithZIO[MorphirElmDriver](_.test(projectDir))
}

0 comments on commit 996ace1

Please sign in to comment.