Skip to content

Commit

Permalink
feat(cli): remove deno serverless & support run .ts serverless in nod…
Browse files Browse the repository at this point in the history
…ejs (#935)

# Description

1. Support users use `TypeScript` to write a llm sfn, For an example,
refer to `example/10-ai/llm-sfn-get-weather-ts`.
2. Add `yomo run app.ts` command to run the ts sfn.
3. Remove the default SFN name 'app'. If a name is not provided, the cli
will prompt the user to add it.
4. Remove deno serverless support
  • Loading branch information
woorui authored Nov 5, 2024
1 parent b790a89 commit 2221a74
Show file tree
Hide file tree
Showing 22 changed files with 1,027 additions and 478 deletions.
1 change: 1 addition & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// defaultSFNFile is the default serverless file name
const (
defaultSFNSourceFile = "app.go"
defaultSFNSourceTSFile = "app.ts"
defaultSFNTestSourceFile = "app_test.go"
defaultSFNCompliedFile = "sfn.yomo"
defaultSFNWASIFile = "sfn.wasm"
Expand Down
29 changes: 8 additions & 21 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ package cli

import (
"os"
"path/filepath"

"github.com/spf13/cobra"
"github.com/yomorun/yomo/pkg/log"

// serverless registrations
"github.com/yomorun/yomo/cli/serverless"
_ "github.com/yomorun/yomo/cli/serverless/deno"
_ "github.com/yomorun/yomo/cli/serverless/exec"
_ "github.com/yomorun/yomo/cli/serverless/golang"
_ "github.com/yomorun/yomo/cli/serverless/nodejs"
_ "github.com/yomorun/yomo/cli/serverless/wasm"
"github.com/yomorun/yomo/cli/viper"
)
Expand All @@ -37,7 +36,7 @@ var runCmd = &cobra.Command{
Short: "Run a YoMo Stream Function",
Long: "Run a YoMo Stream Function",
Run: func(cmd *cobra.Command, args []string) {
if err := parseFileArg(args, &opts, defaultSFNCompliedFile, defaultSFNWASIFile, defaultSFNSourceFile); err != nil {
if err := parseFileArg(args, &opts, defaultSFNCompliedFile, defaultSFNWASIFile, defaultSFNSourceFile, defaultSFNSourceTSFile); err != nil {
log.FailureStatusEvent(os.Stdout, err.Error())
return
}
Expand Down Expand Up @@ -68,24 +67,12 @@ var runCmd = &cobra.Command{
)
return
}
// build if it's go file
if ext := filepath.Ext(opts.Filename); ext == ".go" {
log.PendingStatusEvent(os.Stdout, "Building YoMo Stream Function instance...")
if err := s.Build(true); err != nil {
log.FailureStatusEvent(os.Stdout, err.Error())
os.Exit(127)
}
log.SuccessStatusEvent(os.Stdout, "YoMo Stream Function build successful!")
}
// run
// wasi
if ext := filepath.Ext(opts.Filename); ext == ".wasm" {
wasmRuntime := opts.Runtime
if wasmRuntime == "" {
wasmRuntime = "wazero"
}
log.InfoStatusEvent(os.Stdout, "WASM runtime: %s", wasmRuntime)

if err := s.Build(true); err != nil {
log.FailureStatusEvent(os.Stdout, err.Error())
os.Exit(127)
}

log.InfoStatusEvent(
os.Stdout,
"Starting YoMo Stream Function instance, connecting to zipper: %v",
Expand All @@ -103,7 +90,7 @@ func init() {
rootCmd.AddCommand(runCmd)

runCmd.Flags().StringVarP(&opts.ZipperAddr, "zipper", "z", "localhost:9000", "YoMo-Zipper endpoint addr")
runCmd.Flags().StringVarP(&opts.Name, "name", "n", "app", "yomo stream function name.")
runCmd.Flags().StringVarP(&opts.Name, "name", "n", "", "yomo stream function name.")
runCmd.Flags().StringVarP(&opts.ModFile, "modfile", "m", "", "custom go.mod")
runCmd.Flags().StringVarP(&opts.Credential, "credential", "d", "", "client credential payload, eg: `token:dBbBiRE7`")
runCmd.Flags().StringVarP(&opts.Runtime, "runtime", "r", "", "serverless runtime type")
Expand Down
116 changes: 0 additions & 116 deletions cli/serverless/deno/mod/mod.ts

This file was deleted.

198 changes: 0 additions & 198 deletions cli/serverless/deno/runtime.go

This file was deleted.

Loading

0 comments on commit 2221a74

Please sign in to comment.