Skip to content

Commit

Permalink
Restructured Helper - Added DevCompanyHelper.createProject.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Dec 10, 2024
1 parent c450c28 commit 946b54a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 62 deletions.
46 changes: 45 additions & 1 deletion 00-documentation/src/docs/helper/createProject.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
# Create Project

**Experimental**

TODO
Creating a Project is done in two steps:

1. Create the project directory and the Helper Script.
2. Run the Helper Script to create the project structure.

Here we focus on the first step.

1. We can use the same `helperCompany.scala` script, we created in the [Init Company] step.
```scala
cd ~/dev-myCompany
./helperCompany.scala project myProject
```
This creates:

```bash
dev-myCompany
| projects
| | myProject
| | | helper.scala
```

1. Make `helper.scala` executable:
```bash
cd ~/projects/myProject
chmod +x helper.scala
```

1. Open the `myCompany-myProject` directory with your IDE (I use Intellij).

@:callout(info)
If you haven't released `company-camundala` yet,
you need to run it at least locally (`sbt publishLocal`)
and set the version in the `helper.scala` manually.

```scala
//> using dep myCompany::myCompany-camundala-helper:VERSION NOT FOUND
// replace with:
//> using dep myCompany::myCompany-camundala-helper:0.1.0-SNAPSHOT
```

@:@

### Next Step: [Project Development]

2 changes: 2 additions & 0 deletions 00-documentation/src/docs/helper/initCompany.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ chmod +x helperCompany.scala

1. Open the `company-camundala` directory with your IDE (I use Intellij).
1. Import the sbt project. The project should compile without errors.
1. Update `build.sbt` with your repository settings.
1. Release the `company-camundala` project to your repository.

### Next Step: [Create Project]
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@ object DevCompanyHelper:
case init, project

def initCompany: Unit =
val companyName = os.pwd.last.replace("dev-", "")
println(s"Init Company $companyName")
given config: DevConfig = InitCompanyGenerator.init(companyName) //, repoConfig)
given config: DevConfig = InitCompanyGenerator.init(companyName)
InitCompanyGenerator().generate

def createCompany(companyName: String) = //, repoConfig: RepoConfig) =
println(s"Create/Update Company: $companyName")

// given config: DevConfig = SetupCompanyGenerator.init(companyName, repoConfig)
def createProject(projectName: String): Unit =
println(s"Create Project: $projectName - Company: $companyName")
given config: DevConfig = DevConfig.defaultConfig(s"$companyName-$projectName")
InitCompanyGenerator().createProject

// SetupCompanyGenerator().generate
private lazy val companyName = os.pwd.last.replace("dev-", "")

def createProject(projectName: String): Unit =
println(s"Update Project: $projectName")
// SetupGenerator()(using config.setupConfig).generate
end DevCompanyHelper
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package camundala.helper.dev.company

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

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

Expand All @@ -16,7 +15,13 @@ case class InitCompanyGenerator()(using config: DevConfig):
CompanySbtGenerator().generate
end generate

lazy val createProject: Unit =
generateProjectDirectories
createOrUpdate(projects / projectName / "helper.scala", ScriptCreator().projectHelper)
end createProject

private lazy val companyName = config.companyName
private lazy val projectName = config.projectName

private lazy val generateDirectories: Unit =
os.makeDir.all(gitTemp)
Expand All @@ -25,6 +30,8 @@ case class InitCompanyGenerator()(using config: DevConfig):
os.makeDir.all(companyCamundala)
os.makeDir.all(projects)
end generateDirectories
private lazy val generateProjectDirectories: Unit =
os.makeDir.all(projects / projectName)

private lazy val gitTemp = os.pwd / "git-temp"
private lazy val docker = os.pwd / "docker"
Expand All @@ -36,24 +43,7 @@ end InitCompanyGenerator

object InitCompanyGenerator:
def init(companyName: String) = //, repoConfig: RepoConfig.Artifactory) =
// createOrUpdate(os.pwd / api.defaultProjectPath, defaultProjectContent(companyName))
DevConfig.defaultConfig(s"$companyName-camundala")
/* .copy(reposConfig =
ReposConfig(
repos = Seq(repoConfig),
repoSearch = repoConfig.repoSearch,
ammoniteRepos = Seq(repoConfig)
)
) */
end init

private def defaultProjectContent(companyName: String) =
s"""
|org = "$companyName"
|name = "$companyName-services"
|version = "0.1.0-SNAPSHOT"
|dependencies: {
|
|}
|""".stripMargin
end InitCompanyGenerator
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ case class CompanySbtGenerator()(using
|
|lazy val publicationSettings = Seq(
| isSnapshot := false,
| //publishTo := Some(releaseRepo), //TODO define releaseRepo
| // Enables publishing to maven repo
| credentials ++= Seq(repoCredentials),
| publishTo := Some(releaseRepo),
| resolvers ++= Seq(releaseRepo), //TODO add additional resolvers
| publishMavenStyle := true,
| packageDoc / publishArtifact := false,
| // disable using the Scala version in output paths and artifacts
Expand Down Expand Up @@ -190,6 +191,21 @@ case class CompanySbtGenerator()(using
| testFrameworks += new TestFramework("munit.Framework")
|)
|
|lazy val releaseRepoStr: String =
| s"https://bin.mycompany.com/artifactory/mycompany-maven-local" //TODO Change with yours
|lazy val releaseRepo: MavenRepository = "Artifactory Realm" at releaseRepoStr
|
|// TODO change with yours
|lazy val repoCredentials: Credentials = Credentials("Artifactory Realm", "bin.mycompany.com", "user", "pwd")
|/*(for {
| user <- sys.env.get("MVN_REPOSITORY_USERNAME")
| pwd <- sys.env.get("MVN_REPOSITORY_PASSWORD")
|} yield Credentials("Artifactory Realm", "bin.mycompany.com", user, pwd))
| .getOrElse(
| throw new IllegalArgumentException(
| "System Environment Variables MVN_REPOSITORY_USERNAME and/ or REPOSITORY_PASSWORD are not set."
| )
| )*/
|""".stripMargin
end buildSbt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ case class CompanyWrapperGenerator()(using config: DevConfig):

private lazy val helperConfig =
objectContent("CompanyDevHelper"):
"""
| def config(projectName: String): DevConfig =
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) =
s"""package $companyName.helper
s"""package $companyName.camundala.helper
|
|import camundala.helper.dev.*
|import camundala.helper.util.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,6 @@ import camundala.helper.util.CompanyVersionHelper

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

lazy val companyHelper =
s"""$helperHeader
|
|@main(doc =
| \"\"\"> Creates the directories and generic files for the company BPMN Projects
| \"\"\")
|def update(
|): Unit =
| DevHelper.updateCompany()
|
|""".stripMargin

lazy val projectCreate: String =
s"""$helperHeader
|
|@main(doc =
| \"\"\"> Creates the directories and generic files for the company BPMN Projects
| \"\"\")
|def create(
| @arg(doc = "The project name - should be generated automatically after creation.")
| projectName: String
|): Unit = {
| val config = ProjectDevHelper.config(projectName)
| DevHelper.createProject(config)
|}
|""".stripMargin

lazy val projectHelper =
val projectName = config.projectName
Expand All @@ -39,12 +13,11 @@ case class ScriptCreator()(using config: DevConfig):
|lazy val subProjects = Seq(
| ${config.subProjects.map(sp => s"\"$sp\"").mkString(", ")}
|)
|lazy val config: HelperConfig = ProjectDevHelper.config(projectName, subProjects)
|given setup.DevConfig = config.setupConfig
|given util.DevConfig = CompanyDevHelper.config(projectName, subProjects)
|
|@main
|def run(command: String, arguments: String*): Unit =
| ${config.companyClassName}DevHelper.run(command, arguments*)
| dev.DevHelper.run(command, arguments*)
|""".stripMargin
end projectHelper

Expand Down

0 comments on commit 946b54a

Please sign in to comment.