Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start of work supporting workspace in CLI tooling #17

Merged
merged 5 commits into from
May 5, 2020
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
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
with:
java-version: 1.8

- name: Write

- name: Cache SBT ivy cache
uses: actions/cache@v1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ mill.iml
bsp.log
contrib/bsp/test/
lowered.hnir
models/order-taking/elm.json
models/shared-domain/elm-stuff/
models/shared-domain/elm.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "morphir/bindings/elm/morphir-elm"]
path = morphir/toolbox/modules/morphir-elm
url = https://github.com/Morgan-Stanley/morphir-elm.git
16 changes: 15 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
version = "2.4.1"
version = "2.4.2"
maxColumn = 120
align = most
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses = true
spaces {
inImportCurlyBraces = true
}
optIn.annotationNewlines = true

rewrite.rules = [SortImports, RedundantBraces]
105 changes: 77 additions & 28 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,42 @@ lazy val root = project
)
)
.aggregate(
morphirCoreJS,
morphirCoreJVM,
morphirSdkCoreJS,
morphirSdkCoreJVM
morphirSdkCoreJVM,
//morphirSdkJsonJS,
//morphirSdkJsonJVM,
// morphirIRCoreJS,
// morphirIRCoreJVM,
// morphirCliJS,
// morphirCliJVM
morphirToolboxJS,
morphirToolboxJVM,
morphirCliJVM
)

lazy val morphirCore = crossProject(JSPlatform, JVMPlatform)
.in(file("morphir/core"))
.settings(stdSettings("morphir-core"))
.settings(crossProjectSettings)
.settings(buildInfoSettings("morphir.core"))
.settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))

lazy val morphirCoreJS = morphirCore.js
.settings(testJsSettings)

lazy val morphirCoreJVM = morphirCore.jvm
.settings(dottySettings)

lazy val morphirSdkCore = crossProject(JSPlatform, JVMPlatform)
.in(file("morphir/sdk/core"))
.dependsOn(morphirCore)
.settings(stdSettings("morphir-sdk-core"))
.settings(crossProjectSettings)
.settings(buildInfoSettings("morphir.sdk.core"))
.settings(
libraryDependencies ++= Seq(
"dev.zio" %%% "zio" % Versions.zio,
//"io.estatico" %%% "newtype" % "0.4.3",
"dev.zio" %%% "zio-test" % Versions.zio % "test",
"dev.zio" %%% "zio" % Versions.zio,
"dev.zio" %%% "zio-test" % Versions.zio % "test",
"dev.zio" %%% "zio-test-sbt" % Versions.zio % "test"
)
)
Expand Down Expand Up @@ -106,7 +122,7 @@ lazy val morphirSdkCoreJVM = morphirSdkCore.jvm
//lazy val morphirIRCore = crossProject(JSPlatform, JVMPlatform)
// .in(file("morphir/ir/core"))
// .dependsOn(morphirSdkCore)
// .settings(stdSettings("morphirIRCore"))
// .settings(stdSettings("morphir-ir-core"))
// .settings(crossProjectSettings)
// .settings(buildInfoSettings("morphir.ir.core"))
// .settings(
Expand All @@ -121,31 +137,64 @@ lazy val morphirSdkCoreJVM = morphirSdkCore.jvm
// .settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))
//
//lazy val morphirIRCoreJS = morphirIRCore.js
// .settings(testJsSettings)
//
//lazy val morphirIRCoreJVM = morphirIRCore.jvm
// .settings(dottySettings)
// .settings(zioNioSettings("1.0.0-RC6"))
//
//lazy val morphirCli = crossProject(JSPlatform, JVMPlatform)
// .in(file("morphir/cli"))
// .dependsOn(morphirIRCore, morphirSdkCore)
// .settings(stdSettings("morphirCli"))
// .settings(crossProjectSettings)
// .settings(buildInfoSettings("morphir.cli"))
// .settings(
// libraryDependencies ++= Seq(
// "dev.zio" %% "zio" % Versions.zio,
// "dev.zio" %% "zio-test" % Versions.zio % "test",
// "dev.zio" %% "zio-test-sbt" % Versions.zio % "test"
// )
// )
// .settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))
//
//lazy val morphirCliJS = morphirCli.js
// .settings(scalaJSUseMainModuleInitializer := true)
//
//lazy val morphirCliJVM = morphirCli.jvm
// .settings(dottySettings)

lazy val morphirToolbox = crossProject(JSPlatform, JVMPlatform)
.in(file("morphir/toolbox"))
.dependsOn(morphirCore)
.settings(stdSettings("morphir-toolbox", Some(Seq(ScalaVersions.Scala212, ScalaVersions.Scala213))))
.settings(crossProjectSettings)
.settings(buildInfoSettings("org.morphir.toolbox"))
.settings(
libraryDependencies ++= Seq(
"dev.zio" %%% "zio-streams" % Versions.zio,
"io.circe" %%% "circe-generic" % Versions.circe,
"io.circe" %%% "circe-parser" % Versions.circe,
"dev.zio" %%% "zio-test" % Versions.zio % "test",
"dev.zio" %%% "zio-test-sbt" % Versions.zio % "test",
"com.lihaoyi" %%% "pprint" % "0.5.9",
"com.lihaoyi" %%% "fansi" % "0.2.9",
"tech.sparse" %%% "toml-scala" % "0.2.2"
)
)
.settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))

lazy val morphirToolboxJS = morphirToolbox.js
.settings(testJsSettings)
.settings(zioNioSettings("1.0.0-RC6"))
.settings(scalaJSModuleKind := ModuleKind.CommonJSModule)

lazy val morphirToolboxJVM = morphirToolbox.jvm
.settings(zioNioSettings("1.0.0-RC6"))
.settings(
libraryDependencies ++= Seq(
"io.github.soc" % "directories" % "11"
)
)

lazy val morphirCli = crossProject(JVMPlatform)
.in(file("morphir/cli"))
.dependsOn(morphirToolbox)
.settings(stdSettings("morphir-cli", Some(Seq(ScalaVersions.Scala213, ScalaVersions.Scala212))))
.settings(crossProjectSettings)
.settings(buildInfoSettings("org.morphir.cli"))
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % Versions.zio,
"dev.zio" %% "zio-test" % Versions.zio % "test",
"dev.zio" %% "zio-test-sbt" % Versions.zio % "test",
"dev.zio" %% "zio-logging" % "0.2.8",
"com.monovore" %% "decline-effect" % "1.2.0",
"com.lihaoyi" %% "pprint" % "0.5.9"
)
)
.settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))

lazy val morphirCliJVM = morphirCli.jvm

lazy val docs = project
.in(file("morphir-jvm-docs"))
Expand Down
10 changes: 10 additions & 0 deletions examples/workspaces/multi-project-workspace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Created by .ignore support plugin (hsz.mobi)
### Elm template
# elm-package generated files
elm-stuff
# elm-repl generated files
repl-temp-*

### Morphir
# Morphir output
.morphir
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module OrderInput exposing (..)


type alias UnvalidatedOrder =
{ orderId : String }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "application",
"source-directories": [
"src/elm"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/regex": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module GlobalCo.Comms.CustomerEmail exposing (CustomerEmail(..), VerifiedEmailAddress)

import EmailAddress exposing (EmailAddress)


type VerifiedEmailAddress
= VerifiedEmailAddress String


type CustomerEmail
= Unverified EmailAddress
| Verified VerifiedEmailAddress
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module EmailAddress exposing (..)


type EmailAddress
= EmailAddress String


create : String -> Result String EmailAddress
create text =
let
len =
String.length text

endIdx =
len - 1
in
if String.isEmpty text then
"An email address cannot be empty" |> Result.Err

else
case String.indices "@" text of
[] ->
"Invalid email address" |> Result.Err

idx :: [] ->
if idx < endIdx then
EmailAddress text |> Result.Ok

else
"Invalid email address" |> Result.Err
5 changes: 5 additions & 0 deletions examples/workspaces/multi-project-workspace/morphir.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[projects.globalco-shared]
projectDir = "models/shared-domain"

[projects.globalco-order-taking]
projectDir = "models/order-taking"
57 changes: 57 additions & 0 deletions morphir/cli/shared/src/main/scala/org/morphir/cli/Cli.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.morphir.cli

import java.nio.file.Path

import com.monovore.decline._
import org.morphir.toolbox.cli.CliCommand
import org.morphir.toolbox.cli.commands.{ BuildCommand, WorkspaceInfoCommand }
import zio.{ IO, ZIO }

object Cli {

def parse(args: Seq[String]): IO[Help, CliCommand] =
ZIO.fromEither(Cli.rootCommand.parse(args))

lazy val rootCommand: Command[CliCommand] = Command("morphir", "Morphir CLI")(
buildCommand orElse projectCommand orElse workspaceCommand
)

lazy val buildCommand: Opts[BuildCommand] = Opts
.subcommand("build", help = "Build the workspace")(
workspaceOpt.orNone
)
.map(BuildCommand)

lazy val projectCommand: Opts[CliCommand.ProjectList] = Opts.subcommand("project", help = "Work with projects")(
Opts
.subcommand(name = "list", help = "List projects in the workspace")(
workspaceOpt.orNone
)
.map(CliCommand.ProjectList)
)

lazy val workspaceCommand: Opts[CliCommand] =
Opts.subcommand("workspace", help = "Work wth workspaces") {
val initCmd = Opts
.subcommand("init", help = "Initialize a workspace")(
workspaceOpt.orNone
)
.map(CliCommand.WorkspaceInit)

val infoCmd = Opts
.subcommand("info", help = "Get information about a workspace")(
workspaceOpt.orNone
)
.map(WorkspaceInfoCommand)

infoCmd orElse initCmd
}

private lazy val workspaceOpt = Opts.option[Path](
"workspace",
short = "w",
metavar = "workspace-path",
help = "The path to the workspace folder or manifest file."
)

}
17 changes: 17 additions & 0 deletions morphir/cli/shared/src/main/scala/org/morphir/cli/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.morphir.cli

import org.morphir.toolbox.workspace.WorkspaceModule
import zio._

object Main extends App {

override def run(args: List[String]): ZIO[zio.ZEnv, Nothing, Int] =
(for {
cmd <- ZIO.fromEither(Cli.rootCommand.parse(args))
exitCode <- cmd.execute
ec = exitCode.code
} yield ec)
.provideSomeLayer[zio.ZEnv](WorkspaceModule.live)
.catchAll(help => ZIO.effectTotal(System.err.println(help)) *> ZIO.succeed(1))

}
Loading