Skip to content

Commit

Permalink
Merge pull request #463 from innFactory/feat/v5
Browse files Browse the repository at this point in the history
Feat/v5
  • Loading branch information
MoeQuadrat authored Oct 4, 2023
2 parents 2e42753 + f1319ef commit b36d457
Show file tree
Hide file tree
Showing 183 changed files with 5,038 additions and 2,658 deletions.
13 changes: 2 additions & 11 deletions .bin/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ version: '3.1'
services:
db:
container_name: bootstrapPlay2PG
image: postgis/postgis:12-master
image: postgres:13
environment:
POSTGRES_PASSWORD: test
POSTGRES_DB: test
POSTGRES_USER: test
ports:
- 5432:5432
volumes:
- ./postgis-volume/data:/var/lib/postgresql/data
mkdocs:
container_name: bootstrapPlay2MkDocs
image: squidfunk/mkdocs-material
volumes:
- ../doc:/docs/docs/doc
- ./mkdocs.yml:/docs/mkdocs.yml
- ../README.md:/docs/docs/README.md
ports:
- 8000:8000
- ./postgis-volume/data:/var/lib/postgresql/data
17 changes: 0 additions & 17 deletions .bin/mkdocs.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .bin/mock/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.1'

services:
mock:
container_name: mock-server
image: stoplight/prism:4.10.3
command: >
mock -p 4010 --host 0.0.0.0 -m false /root/apis/openapi.yaml
ports:
- 9003:4010
volumes:
- ./yaml/openapi:/root/apis
4 changes: 4 additions & 0 deletions .bin/mock/mock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.bin/swagger/merge.sh && docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
-i /local/output.swagger.json \
-g openapi-yaml \
-o /local/.bin/mock/yaml && cd .bin/mock && docker-compose up
4 changes: 2 additions & 2 deletions .bin/runFor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ printf ".\n"
DOCKER_CONNECT=0

docker-compose up -d
printf "\n ${BLUE}"Wating for Database for ${NAME} "${NC}"
printf "\n ${BLUE}"Waiting for Database for ${NAME} "${NC}"

(
for i in `seq 1 20`;
Expand Down Expand Up @@ -118,4 +118,4 @@ printf "\n ${BLUE}Generating Code for ${NAME} ${NC} \n"
sbt slickGen
clear
printf "\n ${BLUE}Starting Service for ${NAME} ${NC} \n"
sbt run
sbt "run -Dconfig.resource=dev-application.conf -Dlogger.resource=logback-local.xml"
9 changes: 9 additions & 0 deletions .bin/schemaspy/schemaspy.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
schemaspy.t=pgsql
schemaspy.host=localhost
schemaspy.port=5432
schemaspy.db=test
schemaspy.u=test
schemaspy.p=test
schemaspy.schemas=postgis
schemaspy.o=./output
schemaspy.dp=./
12 changes: 12 additions & 0 deletions .bin/setup/.scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version=3.5.9
runner.dialect=scala213
maxColumn = 120
docstrings.style = Asterisk
lineEndings = preserve
includeCurlyBraceInSelectChains = false
newlines.alwaysBeforeMultilineDef = false
newlines.penalizeSingleSelectMultiArgList = false
align.openParenCallSite = false
rewrite.rules = [SortImports, RedundantBraces, RedundantParens, PreferCurlyFors]
rewrite.redundantBraces.generalExpressions = false
optIn.annotationNewlines = true
22 changes: 22 additions & 0 deletions .bin/setup/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sbtassembly.MergeStrategy

resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"

lazy val root = (project in file("."))
.settings(
name := "Setup",
version := "0.0.1",
scalaVersion := "2.13.8",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.8.0",
"com.typesafe.play" %% "play-json" % "2.9.2",
"org.rogach" %% "scallop" % "4.1.0"
),
assembly / assemblyMergeStrategy := {
case "module-info.class" => MergeStrategy.discard
case x =>
// For all the other files, use the default sbt-assembly merge strategy
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
}
)
1 change: 1 addition & 0 deletions .bin/setup/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.2
1 change: 1 addition & 0 deletions .bin/setup/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.0.0-RC1")
12 changes: 12 additions & 0 deletions .bin/setup/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

PATH_TO_SETUP_JAR=$(dirname "$0")"/target/scala-2.13/Setup-assembly-0.0.1.jar"

if [ ! -f "$PATH_TO_SETUP_JAR" ]; then
echo "$PATH_TO_SETUP_JAR does not exist."
echo "Creating..."
(cd $(dirname "$0"); sbt assembly)
:

fi
exec scala "$PATH_TO_SETUP_JAR" "$@"
9 changes: 9 additions & 0 deletions .bin/setup/src/main/resources/bootstrap-conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"project": {
"name": "bootstrap-play2",
"domain": "de.innfactory.bootstrapplay2"
},
"bootstrap": {
"paths": ["conf", "test", ".github"]
}
}
55 changes: 55 additions & 0 deletions .bin/setup/src/main/scala/Setup.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import packagedomain.PackageDomain
import arguments.Args
import bootstrap.Bootstrap
import cats.data.Validated
import config.SetupConfig
import config.SetupConfig.{BootstrapConfig, ProjectConfig, SmithyConfig}

import java.nio.file.{Files, Paths}

object Setup extends App {

implicit val config: SetupConfig = SetupConfig.get()
val arguments = new Args(args)

workingDirectoryIsProjectRoot() match {
case Left(_) =>
println(
s"Execute this script from your project root! Your project root must contain the directories ${config.project.sourcesRoot} and ${config.smithy.sourcesRoot}"
)
case Right(_) =>
if (args.isEmpty) {
arguments.printHelp()
}
if (args.contains(Args.packageDomainKey)) {
PackageDomain.create(
arguments.packageDomain.packageName.toOption,
arguments.packageDomain.domain.toOption,
arguments.packageDomain.withCrud.toOption
)
}
if (args.contains(Args.bootstrapKey)) {
Bootstrap.init(
SetupConfig(
project = ProjectConfig(
domain = arguments.bootstrap.projectDomain.toOption.getOrElse(""),
name = arguments.bootstrap.projectName.toOption.getOrElse("")
),
bootstrap = BootstrapConfig(
paths = arguments.bootstrap.bootstrapPaths.toOption.getOrElse(Seq.empty)
)
)
)
}
}

def workingDirectoryIsProjectRoot()(implicit config: SetupConfig) =
Validated
.cond(
Files.exists(Paths.get(System.getProperty("user.dir") + "/" + config.project.sourcesRoot.replace('.', '/'))) &&
Files.exists(Paths.get(System.getProperty("user.dir") + "/" + config.smithy.sourcesRoot.replace('.', '/'))),
(),
()
)
.toEither
}
52 changes: 52 additions & 0 deletions .bin/setup/src/main/scala/arguments/Args.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package arguments

import arguments.booleanarg.BooleanArgValidations
import arguments.stringarg.StringArgValidations
import org.rogach.scallop.{ScallopConf, ScallopOption, Subcommand}

class Args(arguments: Seq[String]) extends ScallopConf(arguments) {
object packageDomain extends Subcommand(Args.packageDomainKey) {
val packageName: ScallopOption[String] = opt[String](
descr = "Name of the package e.g. companies",
validate = (input: String) => StringArgValidations.onlyLetters(input).isRight
)
val domain: ScallopOption[String] = opt[String](
descr = "Name of the domain e.g. company",
validate = (input: String) => StringArgValidations.onlyLettersDot(input).isRight
)
val withCrud: ScallopOption[String] =
opt[String](
name = "crud",
short = 'c',
descr = "(y/n) generates code for crud operations",
validate = (booleanString: String) => BooleanArgValidations.isBooleanString(booleanString).isRight
)
}

object bootstrap extends Subcommand(Args.bootstrapKey) {
val projectName: ScallopOption[String] =
opt[String](
descr = "Name of the project e.g. bootstrap-play2",
validate = (input: String) => StringArgValidations.onlyLettersNumbersHyphen(input).isRight
)
val projectDomain: ScallopOption[String] =
opt[String](
descr = "Folder name of the projects packages, e.g. de.innfactory.bootstrapplay2",
validate = (input: String) => StringArgValidations.onlyLettersDot(input).isRight
)
val bootstrapPaths: ScallopOption[List[String]] = opt[List[String]](
descr =
"Paths of files and directories which shall be included during the bootstrap process, sources roots and build.sbt are always included",
validate =
(inputs: List[String]) => inputs.forall(input => StringArgValidations.onlyLettersDotSlash(input).isRight)
)
}
addSubcommand(packageDomain)
addSubcommand(bootstrap)
verify()
}

object Args {
val packageDomainKey = "package"
val bootstrapKey = "bootstrap"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package arguments.booleanarg

import scala.annotation.tailrec
import scala.io.StdIn.readLine

object BooleanArgRetriever {
@tailrec
def askFor(message: String): Boolean = {
println(s"$message (y/n)")
val is = readLine().toLowerCase()
BooleanArgValidations.isBooleanString(is) match {
case Left(error) =>
println(error)
askFor(message)
case Right(boolean) => boolean
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package arguments.booleanarg

object BooleanArgValidations {
def isBooleanString(booleanString: String): Either[String, Boolean] = booleanString.toLowerCase match {
case "y" | "yes" => Right(true)
case "n" | "no" => Right(false)
case _ => Left("Invalid! Valid: y | yes | n | no")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package arguments.stringarg

import scala.annotation.tailrec
import scala.io.StdIn.readLine

object StringArgRetriever {
@tailrec
def askFor(
message: String,
validations: Seq[String => Either[String, Unit]] =
Seq(StringArgValidations.cantBeEmpty, StringArgValidations.onlyLetters)
): String = {
println(message)
val arg = readLine().toLowerCase()
validateInput(validations.map(validate => validate(arg))) match {
case Left(validationErrors) =>
println(validationErrors)
askFor(message, validations)
case Right(_) => arg
}
}

private def validateInput(validations: Seq[Either[String, Unit]]) =
validations.fold(Right(())) { (result, validation) =>
validation match {
case Left(validationError) =>
result match {
case Left(resultError) => Left(s"$resultError\n$validationError")
case Right(_) => Left(validationError)
}
case Right(_) => result
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package arguments.stringarg

import cats.data.Validated

object StringArgValidations {
val cantBeEmpty: String => Either[String, Unit] = (toValidate: String) =>
Validated.cond(toValidate.nonEmpty, (), "Can't be empty!").toEither
val onlyLetters: String => Either[String, Unit] = (toValidate: String) =>
Validated.cond(toValidate.matches("^[a-zA-Z]*?$"), (), "Can only consist out of letters!").toEither
val onlyLettersNumbersHyphen: String => Either[String, Unit] = (toValidate: String) =>
Validated
.cond(
toValidate.matches("^([a-zA-Z0-9]+(?:\\-?[a-zA-Z0-9]+))*?$"),
(),
"Can only consist out of letters and numbers separated by a single hyphen!"
)
.toEither
val onlyLettersDot: String => Either[String, Unit] = (toValidate: String) =>
Validated
.cond(
toValidate.matches("^([a-zA-Z]+(?:\\.[a-zA-Z]+))*?$"),
(),
"Can only consist out of letters separated by a single dot!"
)
.toEither
val onlyLettersDotHyphen: String => Either[String, Unit] = (toValidate: String) =>
Validated
.cond(
toValidate.matches("^([a-zA-Z]+(?:[\\.\\-]?[a-zA-Z]+))*?$"),
(),
"Can only consist out of letters separated by a single dot or hyphen!"
)
.toEither
val onlyLettersDotSlash: String => Either[String, Unit] = (toValidate: String) =>
Validated
.cond(
toValidate.matches("^([a-zA-Z]+(?:[\\.\\/]?[a-zA-Z]+))*?$"),
(),
"Can only consist out of letters separated by a single dot or slash!"
)
.toEither
}
Loading

0 comments on commit b36d457

Please sign in to comment.