Skip to content

Commit

Permalink
Merge pull request #37 from disneystreaming/misc-improvements
Browse files Browse the repository at this point in the history
Misc improvements
  • Loading branch information
daddykotex authored Sep 5, 2023
2 parents 837472c + cfd516e commit 8c30287
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 163 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ A simple Giter8 template to generate a http4s server that read/write json via [s

The command below will generate a project that works with the latest version of Smithy4s. If you decide to go with another version, you might need to adjust the generated project to make it work.

## sbt

`sbt new disneystreaming/smithy4s.g8`

## mill
# SBT / Mill

You will be prompted for the build tool you want to generate a build for. By default, SBT is selected. For mill, reply "no" to "sbt",
and "yes" to "mill".

`sbt new disneystreaming/smithy4s.g8 --directory mill`.

## how-to run?

Expand Down
53 changes: 0 additions & 53 deletions mill/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions mill/.scalafmt.conf

This file was deleted.

2 changes: 0 additions & 2 deletions mill/default.properties

This file was deleted.

44 changes: 0 additions & 44 deletions mill/service/src/com/example/Main.scala

This file was deleted.

8 changes: 0 additions & 8 deletions mill/smithy-build.json

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import \$ivy.`com.disneystreaming.smithy4s::smithy4s-mill-codegen-plugin::$smith
import smithy4s.codegen.mill._
import mill._, mill.scalalib._

object service extends ScalaModule with Smithy4sModule {

object service extends SbtModule with Smithy4sModule {

def millSourcePath = os.pwd
def smithy4sInputDirs = T.sources(millSourcePath / "src" / "main" / "smithy")

def scalaVersion = "2.13.9"
override def ivyDeps = Agg(
ivy"com.disneystreaming.smithy4s::smithy4s-core:\${smithy4sVersion()}",
Expand Down
49 changes: 49 additions & 0 deletions src/main/g8/$if(mill.truthy)$.$endif$/mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env sh

# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with MILL_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
DEFAULT_MILL_VERSION=0.10.5

set -e

if [ -z "\$MILL_VERSION" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="\$(head -n 1 .mill-version 2> /dev/null)"
elif [ -f "mill" ] && [ "\$0" != "mill" ] ; then
MILL_VERSION=\$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
else
MILL_VERSION=\$DEFAULT_MILL_VERSION
fi
fi

if [ "x\${XDG_CACHE_HOME}" != "x" ] ; then
MILL_DOWNLOAD_PATH="\${XDG_CACHE_HOME}/mill/download"
else
MILL_DOWNLOAD_PATH="\${HOME}/.cache/mill/download"
fi
MILL_EXEC_PATH="\${MILL_DOWNLOAD_PATH}/\${MILL_VERSION}"

version_remainder="\$MILL_VERSION"
MILL_MAJOR_VERSION="\${version_remainder%%.*}"; version_remainder="\${version_remainder#*.}"
MILL_MINOR_VERSION="\${version_remainder%%.*}"; version_remainder="\${version_remainder#*.}"

if [ ! -s "\$MILL_EXEC_PATH" ] ; then
mkdir -p "\$MILL_DOWNLOAD_PATH"
if [ "\$MILL_MAJOR_VERSION" -gt 0 ] || [ "\$MILL_MINOR_VERSION" -ge 5 ] ; then
ASSEMBLY="-assembly"
fi
DOWNLOAD_FILE=\$MILL_EXEC_PATH-tmp-download
MILL_VERSION_TAG=\$(echo \$MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/\${MILL_VERSION_TAG}/\$MILL_VERSION\${ASSEMBLY}"
curl --fail -L -o "\$DOWNLOAD_FILE" "\$MILL_DOWNLOAD_URL"
chmod +x "\$DOWNLOAD_FILE"
mv "\$DOWNLOAD_FILE" "\$MILL_EXEC_PATH"
unset DOWNLOAD_FILE
unset MILL_DOWNLOAD_URL
fi

unset MILL_DOWNLOAD_PATH
unset MILL_VERSION

exec \$MILL_EXEC_PATH "\$@"
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ lazy val root = (project in file("."))
"com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value,
"com.disneystreaming.smithy4s" %% "smithy4s-http4s-swagger" % smithy4sVersion.value,
"org.http4s" %% "http4s-ember-server" % "0.23.16"
)
),
Compile / run / fork := true,
Compile / run / connectInput := true
)
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/main/g8/default.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
name = MyApi
name = smithy4s-quickstart
sbt = yes
mill = no
smithy4s_version = maven(com.disneystreaming.smithy4s, smithy4s-core_2.13, stable)
35 changes: 22 additions & 13 deletions src/main/g8/src/main/scala/com/example/Main.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.example

import com.example.hello._
import hello._
import cats.syntax.all._
import cats.effect._
import cats.implicits._
import cats.effect.syntax.all._
import org.http4s.implicits._
import org.http4s.ember.server._
import org.http4s._
Expand All @@ -29,16 +30,24 @@ object Routes {
}

object Main extends IOApp.Simple {
val run = Routes.all.flatMap { routes =>
val thePort = port"9000"
val theHost = host"localhost"
EmberServerBuilder
.default[IO]
.withPort(thePort)
.withHost(theHost)
.withHttpApp(routes.orNotFound)
.build <*
Resource.eval(IO.println(s"Server started on: \$theHost:\$thePort"))
}.useForever
val run = Routes.all
.flatMap { routes =>
val thePort = port"9000"
val theHost = host"localhost"
val message =
s"Server started on: \$theHost:\$thePort, press enter to stop"

EmberServerBuilder
.default[IO]
.withPort(thePort)
.withHost(theHost)
.withHttpApp(routes.orNotFound)
.build
.productL(IO.println(message).toResource)
}
.useForever
.race(IO.readLine)
.void
.guarantee(IO.println("Goodbye!"))

}
31 changes: 0 additions & 31 deletions src/main/g8/src/main/smithy/MyApi.smithy

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\$version: "2"

namespace com.example.hello
namespace hello

use alloy#simpleRestJson

Expand All @@ -10,7 +10,7 @@ service HelloWorldService {
operations: [Hello]
}

@http(method: "POST", uri: "/{name}", code: 200)
@http(method: "GET", uri: "/hello/{name}", code: 200)
operation Hello {
input: Person,
output: Greeting
Expand Down

0 comments on commit 8c30287

Please sign in to comment.