Skip to content

Commit

Permalink
Added Company Wrappers for all modules in CompanyWrapperGenerator / a…
Browse files Browse the repository at this point in the history
…dded mdoc for Version resolving in code.
  • Loading branch information
pme123 committed Dec 11, 2024
1 parent 946b54a commit 016c7ab
Show file tree
Hide file tree
Showing 29 changed files with 1,042 additions and 97 deletions.
1 change: 0 additions & 1 deletion 00-documentation/src/docs/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions 00-documentation/src/docs/helper/directory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
laika.navigationOrder = [
development.md
initCompany.md
createProject.md
projectDev.md
]
9 changes: 4 additions & 5 deletions 00-documentation/src/docs/helper/initCompany.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ So try to stick to the conventions, whenever possible.
mkdir ~/dev-myCompany
```

1. Create `helperCompany.scala` in your company directory.
1. Create `helperCompany.scala` in your company directory and open it.
```bash
cd ~/dev-myCompany
touch helperCompany.scala
open helperCompany.scala
```

1. Copy the following content to `helperCompany.scala`:
```scala
```scala mdoc
#!/usr/bin/env -S scala shebang
// DO NOT ADJUST. This file is replaced by `./helper.scala update`.

//> using toolkit 0.5.0
//> using dep io.github.pme123::camundala-helper:${project.version}
//> using dep io.github.pme123::camundala-helper:@VERSION@

import camundala.helper.dev.DevCompanyHelper

Expand All @@ -49,8 +50,6 @@ open helperCompany.scala
DevCompanyHelper.run(command, arguments*)
```

1. Replace `${project.version}` with _${project.version}_.

1. Make the file executable:
```bash
chmod +x helperCompany.scala
Expand Down
17 changes: 16 additions & 1 deletion 00-documentation/src/docs/helper/projectDev.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# Project Development
**Experimental**

TODO
The following chapters describe the tasks to support the project development.

## update
Whenever you have changes in the `company-camundala` project or in one of your dependencies,
you can update the project with the following command:

```bash
./helper.scala update
```

This will create or update your project with the latest changes.

Files that contain the `DO NOT ADJUST` comment will be replaced.
If you do adjust them, remove this comment.
You will get a warning, but the file will not be replaced.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import camundala.domain.*
import camundala.bpmn.*
import pme123.camunda.dmn.tester.shared.*

import java.io.FileNotFoundException
import java.time.LocalDateTime
import scala.language.reflectiveCalls
import scala.reflect.ClassTag
Expand All @@ -16,7 +17,11 @@ trait DmnTesterConfigCreator extends DmnConfigWriter:
// the path where the DMN Configs are
protected def dmnConfigPath: os.Path = starterConfig.dmnConfigPaths.head
// creating the Path to the DMN - by default the _dmnName_ is `decisionDmn.decisionDefinitionKey`.
protected def defaultDmnPath(dmnName: String): os.Path = dmnBasePath / s"$dmnName.dmn"
protected def defaultDmnPath(dmnName: String): os.Path =
val dmnPath = dmnBasePath / s"${dmnName.replace(s"${starterConfig.companyName}-", "")}.dmn"
if (!dmnPath.toIO.exists())
throw FileNotFoundException(s"There is no DMN in $dmnPath")
dmnPath

protected def createDmnConfigs(dmnTesterObjects: DmnTesterObject[?]*): Unit =
dmnConfigs(dmnTesterObjects)
Expand Down
5 changes: 3 additions & 2 deletions 03-dmn/src/main/scala/camundala/dmn/DmnTesterHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import os.CommandResult
import sttp.client3.*

trait DmnTesterHelpers:
protected def starterConfig: DmnTesterStarterConfig = DmnTesterStarterConfig()
protected def starterConfig: DmnTesterStarterConfig
protected def projectBasePath: os.Path = os.pwd
private lazy val exposedPort: Int = starterConfig.exposedPort
protected lazy val client: SimpleHttpClient = SimpleHttpClient()
protected lazy val apiUrl = s"http://localhost:$exposedPort/api"
protected lazy val infoUrl = s"http://localhost:$exposedPort/info"

protected case class DmnTesterStarterConfig(
companyName: String,
// the name of the container that will be started
containerName: String = "camunda-dmn-tester",
// path to where the configs should be created in
dmnConfigPaths: Seq[os.Path] = Seq(
projectBasePath / "src" / "main" / "resources" / "dmnConfigs"
projectBasePath / "03-dmn" / "src" / "main" / "resources" / "dmnConfigs"
),
// paths where the DMNs are (could be different places)
dmnPaths: Seq[os.Path] = Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import camundala.helper.dev.update.*
import camundala.helper.util.{TestType, VersionHelper}

case class CompanySbtGenerator()(using
config: DevConfig
config: DevConfig
):
lazy val sbtGenerator = SbtGenerator()
lazy val generate: Unit =
Expand All @@ -15,7 +15,7 @@ case class CompanySbtGenerator()(using
end generate

lazy val generatePluginsSbt =
createOrUpdate(config.sbtProjectDir / "plugins.sbt", pluginsSbt)
createIfNotExists(config.sbtProjectDir / "plugins.sbt", pluginsSbt)
private lazy val projectConf = config.apiProjectConf
private lazy val versionHelper = VersionHelper(projectConf)
private lazy val buildSbtDir = config.projectDir / "build.sbt"
Expand Down Expand Up @@ -56,7 +56,8 @@ case class CompanySbtGenerator()(using
| scalaVersion,
| sbtVersion,
| BuildInfoKey("camundalaV", camundalaV)
| )
| ),
| buildInfoPackage := s"$$companyName.camundala"
| )
| .settings(generalSettings())
| .settings(publicationSettings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,154 @@
package camundala.helper.dev.company

import camundala.helper.dev.update.createOrUpdate
import camundala.helper.dev.update.createIfNotExists
import camundala.helper.util.*

case class CompanyWrapperGenerator()(using config: DevConfig):

lazy val generate: Unit =
createOrUpdate(projectDevPath, helperConfig)
createIfNotExists(projectBpmnPath, bpmnWrapper)
createIfNotExists(projectApiPath, apiWrapper)
createIfNotExists(projectDmnPath, dmnWrapper)
createIfNotExists(projectSimulationPath, simulationWrapper)
createIfNotExists(projectWorkerPath, workerWrapper)
createIfNotExists(projectHelperPath, helperWrapper)

private lazy val companyName = config.companyName
private lazy val helperPath =
config.projectDir / ModuleConfig.helperModule.packagePath(config.projectPath)
private lazy val projectDevPath = helperPath / "CompanyDevHelper.scala"

private lazy val helperConfig =
objectContent("CompanyDevHelper"):
s"""
| def config(projectName: String, subProjects: Seq[String] = Seq.empty): DevConfig =
| DevConfig.defaultConfig(projectName) //TODO Implement your Config!
| .copy(subProjects = subProjects)
|""".stripMargin
end helperConfig

private def objectContent(objName: String)(body: String) =

private lazy val projectBpmnPath = ModuleConfig.bpmnModule.srcPath / "CompanyBpmnDsl.scala"
private lazy val projectApiPath = ModuleConfig.apiModule.srcPath / "CompanyApiCreator.scala"
private lazy val projectDmnPath = ModuleConfig.dmnModule.srcPath / "CompanyDmnTester.scala"
private lazy val projectSimulationPath = ModuleConfig.simulationModule.testPath / "CompanySimulation.scala"
private lazy val projectWorkerPath = ModuleConfig.workerModule.srcPath / "CompanyWorkerHandler.scala"
private lazy val projectHelperPath = ModuleConfig.helperModule.srcPath / "CompanyDevHelper.scala"

private lazy val bpmnWrapper =
s"""package $companyName.camundala.bpmn
|
|import camundala.bpmn.*
|import camundala.domain.*
|
|/**
| * Add here company specific stuff, like documentation or custom elements.
| */
|trait CompanyBpmnDsl
|
|trait CompanyBpmnProcessDsl extends BpmnProcessDsl, CompanyBpmnDsl
|trait CompanyBpmnServiceTaskDsl extends BpmnServiceTaskDsl, CompanyBpmnDsl
|trait CompanyBpmnCustomTaskDsl extends BpmnCustomTaskDsl, CompanyBpmnDsl
|trait CompanyBpmnDecisionDsl extends BpmnDecisionDsl, CompanyBpmnDsl
|trait CompanyBpmnUserTaskDsl extends BpmnUserTaskDsl, CompanyBpmnDsl
|trait CompanyBpmnMessageEventDsl extends BpmnMessageEventDsl, CompanyBpmnDsl
|trait CompanyBpmnSignalEventDsl extends BpmnSignalEventDsl, CompanyBpmnDsl
|trait CompanyBpmnTimerEventDsl extends BpmnTimerEventDsl, CompanyBpmnDsl
|""".stripMargin

private lazy val apiWrapper =
s"""package $companyName.camundala.api
|
|import camundala.api.*
|
|/**
| * Add here company specific stuff, to create the Api documentation and the Postman collection.
| */
|trait CompanyApiCreator extends ApiCreator, ApiDsl, CamundaPostmanApiCreator:
|
| // override the config if needed
| //override protected def apiConfig: ApiConfig = ???
|
| lazy val companyDescr = ??? //TODO Add your Company Description!
|""".stripMargin

private lazy val dmnWrapper =
s"""package $companyName.camundala.dmn
|
|import camundala.dmn.*
|
|/**
| * Add here company specific stuff, to run the DMN Tester.
| */
|trait CompanyDmnTester extends DmnTesterConfigCreator, DmnTesterStarter:
|
| def starterConfig: DmnTesterStarterConfig =
| DmnTesterStarterConfig( // adjust paths if needed
| companyName = "$companyName",
| )
|""".stripMargin

private lazy val simulationWrapper =
s"""package $companyName.camundala.simulation
|
|import camundala.simulation.custom.*
|
|/**
| * Add here company specific stuff, to run the Simulations.
| */
|trait CompanySimulation extends BasicSimulationDsl:
|
| override implicit def config =
| super.config //TODO Adjust config if needed
|""".stripMargin

private lazy val workerWrapper =
s"""package $companyName.camundala.worker
|
|import camundala.camunda7.worker.C7WorkerHandler
|import camundala.worker.*
|
|import scala.reflect.ClassTag
|
|/**
| * Add here company specific stuff, to run the Workers.
| * You also define the implementation of the WorkerHandler here.
| */
|trait CompanyWorkerHandler extends C7WorkerHandler
|
|trait CompanyInitWorkerDsl[
| In <: Product: InOutCodec,
| Out <: Product: InOutCodec,
| InitIn <: Product: InOutCodec,
| InConfig <: Product: InOutCodec
|] extends CompanyWorkerHandler, InitWorkerDsl[In, Out, InitIn, InConfig]
|
|trait CompanyValidationWorkerDsl[
| In <: Product: InOutCodec
|] extends CompanyWorkerHandler, ValidationWorkerDsl[In]
|
|trait CompanyCustomWorkerDsl[
| In <: Product: InOutCodec,
| Out <: Product: InOutCodec
|] extends CompanyWorkerHandler, CustomWorkerDsl[In, Out]
|
|trait CompanyServiceWorkerDsl[
| In <: Product: InOutCodec,
| Out <: Product: InOutCodec,
| ServiceIn: InOutEncoder,
| ServiceOut: InOutDecoder: ClassTag
|] extends CompanyWorkerHandler, ServiceWorkerDsl[In, Out, ServiceIn, ServiceOut]
|""".stripMargin

private lazy val helperWrapper =
s"""package $companyName.camundala.helper
|
|import camundala.helper.dev.*
|import camundala.helper.util.*
|
|object $objName:
|object CompanyDevHelper:
|
|$body
|end $objName""".stripMargin
| def config(projectName: String, subProjects: Seq[String] = Seq.empty): DevConfig =
| DevConfig.defaultConfig(projectName) //TODO Implement your Config!
| .copy(subProjects = subProjects)
|""".stripMargin
end helperWrapper

extension (module: ModuleConfig)
def srcPath: os.Path =
config.projectDir / module.packagePath(
config.projectPath
)
def testPath: os.Path =
config.projectDir / module.packagePath(
config.projectPath,
mainOrTest = "test"
)
end CompanyWrapperGenerator
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ case class SbtSettingsGenerator()(using config: DevConfig):
}""".stripMargin

private lazy val sbtDocker =
s"""
| lazy val dockerSettings = ${config.sbtDockerSettings}
|""".stripMargin
s" lazy val dockerSettings = " +
config.sbtDockerSettings
.getOrElse("Seq()")

private lazy val testSettings =
s""" lazy val testSettings = Seq(
| libraryDependencies += mUnit,
Expand Down
11 changes: 9 additions & 2 deletions 04-helper/src/main/scala/camundala/helper/util/DevConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case class DevConfig(
reposConfig: ReposConfig = ReposConfig.dummyRepos,
// path where the BPMNs are - must be relative to the project path
bpmnPath: os.RelPath = os.rel / "src" / "main" / "resources",
sbtDockerSettings: String = ""
sbtDockerSettings: Option[String] = None
):
lazy val companyName: String = apiProjectConf.org
lazy val companyClassName: String = companyName.head.toUpper + companyName.tail
Expand Down Expand Up @@ -59,7 +59,7 @@ object DevConfig:
ApiProjectConf.init(projectName, projectDir(projectName, os.pwd) / packageConfRelPath),
versionConfig = versionConfig,
reposConfig = reposConfig,
sbtDockerSettings = sbtDockerSettings,
sbtDockerSettings = Some(sbtDockerSettings),
bpmnPath = bpmnPath
)

Expand Down Expand Up @@ -116,6 +116,13 @@ case class ModuleConfig(
os.rel / nameWithLevel /
subModule / "src" / mainOrTest / sourceOrResource
end packagePath

def emptyExportsFile(projPackage: String): String =
s"""package $projPackage.$name
|
|// put here your exports - dummy file if you don't have any classes
|""".stripMargin

end ModuleConfig

object ModuleConfig:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ Just run `amm ./publish-release.sc VERSION`.

`sbt publishLocal`

## Documentation
We use [mdoc](https://scalameta.org/mdoc/) to verify the documentation
and [laika](https://typelevel.org/Laika/) to generate the htmls.

Run mdoc: `sbt "documentation/mdoc --watch"`
And laika: `sbt documentation/laikaPreview`
Check the result in http://localhost:4242
Loading

0 comments on commit 016c7ab

Please sign in to comment.