Skip to content

Commit

Permalink
Changed configuration for Project to PROJECT.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Jan 4, 2025
1 parent ae70c4a commit ea26b5c
Show file tree
Hide file tree
Showing 28 changed files with 537 additions and 361 deletions.
11 changes: 5 additions & 6 deletions 03-api/src/main/scala/camundala/api/ApiCreator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package camundala.api
import camundala.BuildInfo
import camundala.bpmn.InputParams
import camundala.domain.*
import com.typesafe.config.ConfigFactory
import io.circe.Encoder
import sttp.apispec.openapi.*
import sttp.apispec.openapi.circe.yaml.*
Expand Down Expand Up @@ -281,7 +280,7 @@ trait ApiCreator extends PostmanApiCreator, TapirApiCreator, App:

protected def dependencies: String =

def docPortal(projectName: String) = s"${apiConfig.docBaseUrl}/$projectName/OpenApi.html"
def docPortal(projectName: String) = s"${apiConfig.docBaseUrl.getOrElse("NOT_SET")}/$projectName/OpenApi.html"

val projects = apiConfig.projectsConfig.perGitRepoConfigs.flatMap(_.projects)
println(s"Projects: $projects")
Expand All @@ -292,7 +291,7 @@ trait ApiCreator extends PostmanApiCreator, TapirApiCreator, App:
|
|${
apiProjectConf.dependencies
.map(dep => s"- _**[${dep.name}](${documentations.getOrElse(dep.name, "NOT FOUND")})**_")
.map(dep => s"- _**[${dep.projectName}](${documentations.getOrElse(dep.projectName, "NOT FOUND")})**_")
.mkString("\n")
}
|""".stripMargin
Expand Down Expand Up @@ -325,8 +324,8 @@ trait ApiCreator extends PostmanApiCreator, TapirApiCreator, App:
|
|> Created with:
|> - [camundala-api v${BuildInfo.version}](https://github.com/pme123/camundala)
|> - ${apiProjectConf.org}-camundala-api $companyProjectVersion
|> - ${apiProjectConf.org}-camundala-helper
|> - ${apiProjectConf.companyName}-camundala-api $companyProjectVersion
|> - ${apiProjectConf.companyName}-camundala-helper
|
|""".stripMargin

Expand Down Expand Up @@ -399,6 +398,6 @@ trait ApiCreator extends PostmanApiCreator, TapirApiCreator, App:
|like `"$example"`""".stripMargin

private lazy val packageConfPath = apiConfig.basePath / apiConfig.projectsConfig.projectConfPath
private lazy val apiProjectConf = ApiProjectConf(packageConfPath)
private lazy val apiProjectConf = DocProjectConfig(packageConfPath)

end ApiCreator
139 changes: 0 additions & 139 deletions 03-api/src/main/scala/camundala/api/ApiProjectConf.scala

This file was deleted.

118 changes: 118 additions & 0 deletions 03-api/src/main/scala/camundala/api/ApiProjectConfig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package camundala.api

import com.typesafe.config.ConfigFactory
import scala.jdk.CollectionConverters.*

final case class ApiProjectConfig(
projectName: String,
projectVersion: VersionConfig,
subProjects: Seq[String],
dependencies: Seq[DependencyConfig]
):
lazy val companyName: String = projectName.split("-").head
end ApiProjectConfig

object ApiProjectConfig:

def init(projectName: String, newPackageFile: os.Path = os.pwd / defaultProjectConfigPath) =
if !os.exists(newPackageFile)
then
println(s"Created initial $newPackageFile")
os.makeDir.all(newPackageFile / os.up)
os.write(
newPackageFile,
s"""
|org = "${projectName.split("-").head}"
|name = "$projectName"
|version = "${DocProjectConfig.defaultVersion}"
|dependencies: {
|
|}
|""".stripMargin
)
end if
apply(newPackageFile)
end init

def apply(projectConfigPath: os.Path = os.pwd / defaultProjectConfigPath): ApiProjectConfig =
val projectConfig = ConfigFactory.parseFile(projectConfigPath.toIO)
val projectName = projectConfig.getString("projectName")
val projectVersion = projectConfig.getString("projectVersion")
val subProjects = projectConfig.getStringList("subProjects").asScala.toSeq
val dependencies = projectConfig
.getObject("dependencies")
.unwrapped()
.asScala
.map:
case k -> v =>
DependencyConfig.apply(k, v.toString)
.toSeq

ApiProjectConfig(
projectName,
VersionConfig(projectVersion),
subProjects,
dependencies
)
end apply

def apply(projectName: String, projectVersion: String): ApiProjectConfig =
ApiProjectConfig(
projectName = projectName,
projectVersion = VersionConfig(projectVersion),
subProjects = Seq.empty,
dependencies = Seq.empty
)
end ApiProjectConfig

case class VersionConfig(major: Int, minor: Int, patch: Int, isSnapshot: Boolean = false):
def isMajor(version: VersionConfig): Boolean =
major != version.major

def isMinor(version: VersionConfig): Boolean =
major == version.major && minor != version.minor

def isPatch(version: VersionConfig): Boolean =
major == version.major && minor == version.minor && patch != version.patch

lazy val minorVersion: String = s"$major.$minor"
lazy val versionAsInt: Int =
major * 100000 + minor * 1000 + patch

override def toString: String = s"$minorVersion.$patch${if isSnapshot then "-SNAPSHOT" else ""}"
end VersionConfig

object VersionConfig:
def apply(version: String): VersionConfig =
version.split("\\.") match
case Array(major, minor, patch) =>
if patch.endsWith("-SNAPSHOT") then
VersionConfig(major.toInt, minor.toInt, patch.dropRight(9).toInt, isSnapshot = true)
else
VersionConfig(major.toInt, minor.toInt, patch.toInt)
end VersionConfig

final case class DependencyConfig(
projectName: String,
projectVersion: VersionConfig
):
lazy val minorVersion: String = projectVersion.minorVersion
lazy val companyName: String = projectName.split("-").head
lazy val fullName = s"$companyName:$projectName:$projectVersion"
lazy val projectPackage = s"${projectName.split("-").mkString(".")}"

def equalTo(packageConf: DocProjectConfig): Boolean =
packageConf.companyName == companyName && packageConf.projectName == projectName && packageConf.minorVersion == projectVersion.minorVersion
end DependencyConfig

object DependencyConfig:
def apply(projectName: String, version: String): DependencyConfig =
DependencyConfig(projectName, VersionConfig(version))
// "org:name:version" => DependencyConfig - only works for the company-project
def apply(dependency: String): DependencyConfig =
val dArray = dependency.replace("\"", "").split(":")
// DependencyConfig(dArray(0), dArray(1), dArray(2))
val lastVersion = VersionHelper.repoSearch(dArray(1), dArray(0))
DependencyConfig(dArray(1), VersionConfig(lastVersion))

end DependencyConfig
79 changes: 79 additions & 0 deletions 03-api/src/main/scala/camundala/api/DocProjectConfig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package camundala.api

import com.typesafe.config.ConfigFactory

import scala.jdk.CollectionConverters.CollectionHasAsScala
import scala.util.Try

case class DocProjectConfig(
apiProjectConfig: ApiProjectConfig,
versionPrevious: String,
changelog: Seq[String] = Seq.empty,
isWorker: Boolean = false
):
lazy val companyName: String = apiProjectConfig.companyName
lazy val projectName: String = apiProjectConfig.projectName
lazy val projectVersion: VersionConfig = apiProjectConfig.projectVersion
lazy val versionPreviousConf: VersionConfig = versionFor(versionPrevious)
lazy val version: String = projectVersion.toString
lazy val versionAsInt: Int = projectVersion.versionAsInt

lazy val dependencies: Seq[DependencyConfig] = apiProjectConfig.dependencies

lazy val isNew =
projectVersion.isMajor(versionPreviousConf) || projectVersion.isMinor(versionPreviousConf)
lazy val isPatched = !isNew && projectVersion.isPatch(versionPreviousConf)
lazy val minorVersion: String = projectVersion.minorVersion
lazy val fullName = s"$companyName:$projectName:$projectVersion"

private def versionFor(version: String) =
Try(VersionConfig(version))
.getOrElse:
println(s"Version $version is not valid. for $companyName:$projectName")
VersionConfig(DocProjectConfig.defaultVersion)

end DocProjectConfig

object DocProjectConfig:
lazy val defaultVersion = "0.1.0"

def apply(
packageFile: os.Path
): DocProjectConfig =
apply(packageFile, Seq.empty, DocProjectConfig.defaultVersion, false)
def apply(
packageFile: os.Path,
changelog: Seq[String],
versionPrevious: String,
isWorker: Boolean
): DocProjectConfig =
val apiProjectConfig = ApiProjectConfig(packageFile)
DocProjectConfig(
apiProjectConfig,
versionPrevious,
changelog,
isWorker
)
end apply

def init(projectName: String, newPackageFile: os.Path) =
if !os.exists(newPackageFile)
then
println(s"Created initial $newPackageFile")
os.makeDir.all(newPackageFile / os.up)
os.write(
newPackageFile,
s"""
|org = "${projectName.split("-").head}"
|name = "$projectName"
|version = "${DocProjectConfig.defaultVersion}"
|dependencies: {
|
|}
|""".stripMargin
)
end if
apply(newPackageFile)
end init

end DocProjectConfig
Loading

0 comments on commit ea26b5c

Please sign in to comment.