Skip to content

Commit

Permalink
Watch smithy4s and add mprocs configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Nov 15, 2024
1 parent 2738aef commit 23c6ee1
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 5 deletions.
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,69 @@ run-backend:

run-frontend:
cd frontend && npm install && npm run dev

export WATCHER_SCRIPT
watch-smithy4s:
cd shared && \
echo "$$WATCHER_SCRIPT" | scala-cli run _.sc -- watch



define WATCHER_SCRIPT

//> using scala 3.5.2
//> using dep "com.disneystreaming.smithy4s:smithy4s-codegen-cli_2.13:0.18.25"
//> using dep com.lihaoyi::os-lib::0.11.3
//> using dep com.lihaoyi::os-lib-watch::0.11.3

import scala.util.*
import util.chaining.*

import smithy4s.codegen.cli.CodegenCommand

var cache = Map.empty[os.Path, os.StatInfo]

def collect(paths: Seq[os.Path]): Map[os.Path, os.StatInfo] =
paths.map(path => path -> os.stat(path)).toMap


def regenerate(paths: Set[os.Path]) =
if paths.exists(_.ext == "smithy") then
val files =
os.walk(os.pwd).filter(_.ext == "smithy")

val args =
files.map(_.toString) ++
List("--skip", "resource", "--skip", "openapi") ++
List("--output", (os.pwd / "generated").toString)

val incoming = collect(files)
if incoming != cache then
val codegenArgs = CodegenCommand.command.parse(args).right.get.args

try
os.remove.all(os.pwd / "generated")
smithy4s.codegen.Codegen.generateToDisk(codegenArgs)
cache = incoming
println("OK")
catch case exc =>
println("Failed to generate spec")
println(exc.getMessage())
else
println("Skipping generation")

val files =
os.walk(os.pwd).filter(_.ext == "smithy")

args.headOption match
case Some("watch") =>
regenerate(files.toSet)
os.watch.watch(Seq(os.pwd), regenerate)
while(true) do Thread.sleep(1000)
case Some("generate") =>
regenerate(files.toSet)
case _ =>
println("pass either watch or generate")
sys.exit(1)

endef
1 change: 0 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions mprocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
procs:
backend:
shell: "make run-backend"
frontend:
shell: "make run-frontend"
smithy4s: "make watch-smithy4s"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait TestServiceGen[F[_, _, _, _, _]] {
def listTests(): F[Unit, Nothing, ListTestsOutput, Nothing, Nothing]
def createTest(attributes: TestAttributes): F[CreateTestInput, Nothing, CreateTestOutput, Nothing, Nothing]

def transform: Transformation.PartiallyApplied[TestServiceGen[F]] = Transformation.of[TestServiceGen[F]](this)
final def transform: Transformation.PartiallyApplied[TestServiceGen[F]] = Transformation.of[TestServiceGen[F]](this)
}

object TestServiceGen extends Service.Mixin[TestServiceGen, TestServiceOperation] {
Expand All @@ -36,7 +36,7 @@ object TestServiceGen extends Service.Mixin[TestServiceGen, TestServiceOperation
type Default[F[+_, +_]] = Constant[smithy4s.kinds.stubs.Kind2[F]#toKind5]
}

val endpoints: Vector[smithy4s.Endpoint[TestServiceOperation, ?, ?, ?, ?, ?]] = Vector(
val endpoints: Vector[smithy4s.Endpoint[TestServiceOperation, _, _, _, _, _]] = Vector(
TestServiceOperation.ListTests,
TestServiceOperation.CreateTest,
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package object protocol {
type TestService[F[_]] = smithy4s.kinds.FunctorAlgebra[TestServiceGen, F]
val TestService = TestServiceGen

type TestTitle = fullstack_scala.protocol.TestTitle.Type
type TestDescription = fullstack_scala.protocol.TestDescription.Type
type TestId = fullstack_scala.protocol.TestId.Type
type TestTitle = fullstack_scala.protocol.TestTitle.Type
type Tests = fullstack_scala.protocol.Tests.Type

}
2 changes: 1 addition & 1 deletion shared/protocol.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloy#uuidFormat

@simpleRestJson
service TestService {

version: "1.0.0",
operations: [ListTests, CreateTest]
}
Expand All @@ -23,7 +24,6 @@ operation ListTests {
@idempotent
@http(method: "PUT", uri: "/api/test", code: 200)
operation CreateTest {

input := {
@required
attributes: TestAttributes
Expand Down

0 comments on commit 23c6ee1

Please sign in to comment.