diff --git a/.github/scripts/plugin-manifest.sh b/.github/scripts/plugin-manifest.sh new file mode 100755 index 0000000..e0b48fa --- /dev/null +++ b/.github/scripts/plugin-manifest.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +export CLI_VERSION=$GITHUB_REF_NAME +export MACOS_AMD64_SHA256=$(sha256sum "_output/hasura-ndc-go-darwin-amd64" | awk '{ print $1 }') +export MACOS_ARM64_SHA256=$(sha256sum "_output/hasura-ndc-go-darwin-arm64" | awk '{ print $1 }') +export LINUX_AMD64_SHA256=$(sha256sum "_output/hasura-ndc-go-linux-amd64" | awk '{ print $1 }') +export LINUX_ARM64_SHA256=$(sha256sum "_output/hasura-ndc-go-linux-arm64" | awk '{ print $1 }') +export WINDOWS_AMD64_SHA256=$(sha256sum "_output/hasura-ndc-go-windows-amd64.exe" | awk '{ print $1 }') + +envsubst < .github/scripts/plugin-manifest.yaml > release/manifest.yaml \ No newline at end of file diff --git a/.github/scripts/plugin-manifest.yaml b/.github/scripts/plugin-manifest.yaml new file mode 100644 index 0000000..e51316b --- /dev/null +++ b/.github/scripts/plugin-manifest.yaml @@ -0,0 +1,41 @@ +name: ndc-go +version: "${CLI_VERSION}" +shortDescription: "CLI plugin for Hasura ndc-go" +homepage: https://github.com/hasura/ndc-sdk-go +hidden: true +platforms: + - selector: darwin-arm64 + uri: "https://github.com/hasura/ndc-sdk-go/releases/download/${CLI_VERSION}/hasura-ndc-go-darwin-arm64" + sha256: "${MACOS_ARM64_SHA256}" + bin: "hasura-ndc-go" + files: + - from: "./hasura-ndc-go-darwin-arm64" + to: "hasura-ndc-go" + - selector: linux-arm64 + uri: "https://github.com/hasura/ndc-sdk-go/releases/download/${CLI_VERSION}/hasura-ndc-go-linux-arm64" + sha256: "${LINUX_ARM64_SHA256}" + bin: "hasura-ndc-go" + files: + - from: "./hasura-ndc-go-linux-arm64" + to: "hasura-ndc-go" + - selector: darwin-amd64 + uri: "https://github.com/hasura/ndc-sdk-go/releases/download/${CLI_VERSION}/hasura-ndc-go-darwin-amd64" + sha256: "${MACOS_AMD64_SHA256}" + bin: "hasura-ndc-go" + files: + - from: "./hasura-ndc-go-darwin-amd64" + to: "hasura-ndc-go" + - selector: windows-amd64 + uri: "https://github.com/hasura/ndc-sdk-go/releases/download/${CLI_VERSION}/hasura-ndc-go-windows-amd64.exe" + sha256: "${WINDOWS_AMD64_SHA256}" + bin: "hasura-ndc-go.exe" + files: + - from: "./hasura-ndc-go-windows-amd64.exe" + to: "hasura-ndc-go.exe" + - selector: linux-amd64 + uri: "https://github.com/hasura/ndc-sdk-go/releases/download/${CLI_VERSION}/hasura-ndc-go-linux-amd64" + sha256: "${LINUX_AMD64_SHA256}" + bin: "hasura-ndc-go" + files: + - from: "./hasura-ndc-go-linux-amd64" + to: "hasura-ndc-go" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0c11a07..6e8149b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,8 +22,14 @@ jobs: run: | VERSION="$GITHUB_REF_NAME" make ci-build-codegen mkdir release + .github/scripts/plugin-manifest.sh mv _output/* release + - uses: actions/upload-artifact@v4 + with: + path: release/manifest.yaml + if-no-files-found: error + - uses: actions/upload-artifact@v4 with: path: release/hasura-ndc-go-* diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3d49ede..3d4286e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -49,7 +49,7 @@ jobs: run: | make build-codegen pushd example/codegen - ../../_output/hasura-ndc-go generate + ../../_output/hasura-ndc-go update go test -v -race -timeout 3m ./... popd - name: Run ndc-test diff --git a/cmd/hasura-ndc-go/README.md b/cmd/hasura-ndc-go/README.md index fb40c7f..2bc6a33 100644 --- a/cmd/hasura-ndc-go/README.md +++ b/cmd/hasura-ndc-go/README.md @@ -33,7 +33,7 @@ Commands: hasura-ndc-go new -n example -m github.com/foo/example - generate + update Generate schema and implementation for the connector from functions. test snapshots @@ -44,9 +44,9 @@ Commands: The `new` command generates a boilerplate project for connector development from [template](templates/new) with the following folder structure: -- `functions`: the folder contains query and mutation functions. The `generate` command will parse `.go` files in this folder. +- `functions`: the folder contains query and mutation functions. The `update` command will parse `.go` files in this folder. - `types`: the folder contains reusable types such as `RawConfiguration`, `Configuration` and `State`. -- `connector.go`: parts of Connector methods, except `GetSchema`, `Query` and `Mutation` methods that will be generated by the `generate` command. +- `connector.go`: parts of Connector methods, except `GetSchema`, `Query` and `Mutation` methods that will be generated by the `update` command. - `main.go`: the main function that runs the connector CLI. - `go.mod`: the module file with required dependencies. - `README.md`: the index README file. @@ -60,13 +60,13 @@ hasura-ndc-go new -n example -m github.com/foo/example -o . ### Generate queries and mutations -The `generate` command parses code in the `functions` folder, finds functions and types that are allowed to be exposed and generates the following files: +The `update` command parses code in the `functions` folder, finds functions and types that are allowed to be exposed and generates the following files: - `schema.generated.json`: the generated connector schema in JSON format. - `connector.generated.go`: implement `GetSchema`, `Query` and `Mutation` methods with exposed functions. ```bash -hasura-ndc-go generate +hasura-ndc-go update ``` ## How it works diff --git a/cmd/hasura-ndc-go/connector.go b/cmd/hasura-ndc-go/connector.go index a0efa25..cdd41cb 100644 --- a/cmd/hasura-ndc-go/connector.go +++ b/cmd/hasura-ndc-go/connector.go @@ -75,7 +75,7 @@ func NewConnectorGenerator(basePath string, connectorDir string, moduleName stri } } -func parseAndGenerateConnector(args *GenerateArguments, moduleName string) error { +func parseAndGenerateConnector(args *UpdateArguments, moduleName string) error { if cli.Generate.Trace != "" { w, err := os.Create(cli.Generate.Trace) if err != nil { diff --git a/cmd/hasura-ndc-go/connector_test.go b/cmd/hasura-ndc-go/connector_test.go index a258a5c..40cb656 100644 --- a/cmd/hasura-ndc-go/connector_test.go +++ b/cmd/hasura-ndc-go/connector_test.go @@ -92,7 +92,7 @@ func TestConnectorGeneration(t *testing.T) { srcDir := path.Join(tc.BasePath, "source") assert.NoError(t, os.Chdir(srcDir)) - err = parseAndGenerateConnector(&GenerateArguments{ + err = parseAndGenerateConnector(&UpdateArguments{ ConnectorDir: tc.ConnectorDir, PackageTypes: tc.PackageTypes, Directories: tc.Directories, diff --git a/cmd/hasura-ndc-go/main.go b/cmd/hasura-ndc-go/main.go index 050cf2b..a47cefc 100644 --- a/cmd/hasura-ndc-go/main.go +++ b/cmd/hasura-ndc-go/main.go @@ -12,8 +12,9 @@ import ( "github.com/rs/zerolog/log" ) -type GenerateArguments struct { - Path string `help:"The path of the root directory where the go.mod file is present" short:"p" default:"."` +// UpdateArguments represent input arguments of the `update` command +type UpdateArguments struct { + Path string `help:"The path of the root directory where the go.mod file is present" short:"p" env:"HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" default:"."` ConnectorDir string `help:"The directory where the connector.go file is placed" default:"."` PackageTypes string `help:"The name of types package where the State struct is in"` Directories []string `help:"Folders contain NDC operation functions" short:"d"` @@ -28,9 +29,10 @@ type NewArguments struct { } var cli struct { - LogLevel string `help:"Log level." enum:"debug,info,warn,error" default:"info"` - New NewArguments `cmd:"" help:"Initialize an NDC connector boilerplate. For example:\n hasura-ndc-go new -n example -m github.com/foo/example"` - Generate GenerateArguments `cmd:"" help:"Generate schema and implementation for the connector from functions."` + LogLevel string `help:"Log level." enum:"debug,info,warn,error" env:"HASURA_PLUGIN_LOG_LEVEL" default:"info"` + New NewArguments `cmd:"" help:"Initialize an NDC connector boilerplate. For example:\n hasura-ndc-go new -n example -m github.com/foo/example"` + Update UpdateArguments `cmd:"" help:"Generate schema and implementation for the connector from functions."` + Generate UpdateArguments `cmd:"" help:"(deprecated) The alias of the 'update' command."` Test struct { Snapshots command.GenTestSnapshotArguments `cmd:"" help:"Generate test snapshots."` } `cmd:"" help:"Test helpers."` @@ -61,30 +63,10 @@ func main() { } log.Info().Str("exec_time", time.Since(start).Round(time.Second).String()). Msg("generated successfully") + case "update": + execUpdate(&cli.Update, start) case "generate": - log.Info(). - Str("path", cli.Generate.Path). - Str("connector_dir", cli.Generate.ConnectorDir). - Str("package_types", cli.Generate.PackageTypes). - Msg("generating connector schema...") - - moduleName, err := getModuleName(cli.Generate.Path) - if err != nil { - log.Fatal().Err(err).Msg("failed to get module name. The base path must contain a go.mod file") - } - - if err := os.Chdir(cli.Generate.Path); err != nil { - log.Fatal().Err(err).Msg("") - } - - if err = parseAndGenerateConnector(&cli.Generate, moduleName); err != nil { - log.Fatal().Err(err).Msg("failed to generate connector schema") - } - if err := execGoFormat("."); err != nil { - log.Fatal().Err(err).Msg("failed to format code") - } - log.Info().Str("exec_time", time.Since(start).Round(time.Millisecond).String()). - Msg("generated successfully") + execUpdate(&cli.Generate, start) case "test snapshots": log.Info(). Str("endpoint", cli.Test.Snapshots.Endpoint). @@ -102,6 +84,32 @@ func main() { } } +func execUpdate(args *UpdateArguments, start time.Time) { + log.Info(). + Str("path", args.Path). + Str("connector_dir", args.ConnectorDir). + Str("package_types", args.PackageTypes). + Msg("generating connector schema...") + + moduleName, err := getModuleName(args.Path) + if err != nil { + log.Fatal().Err(err).Msg("failed to get module name. The base path must contain a go.mod file") + } + + if err := os.Chdir(args.Path); err != nil { + log.Fatal().Err(err).Msg("") + } + + if err = parseAndGenerateConnector(args, moduleName); err != nil { + log.Fatal().Err(err).Msg("failed to generate connector schema") + } + if err := execGoFormat("."); err != nil { + log.Fatal().Err(err).Msg("failed to format code") + } + log.Info().Str("exec_time", time.Since(start).Round(time.Millisecond).String()). + Msg("generated successfully") +} + func setupGlobalLogger(level string) { logLevel, err := zerolog.ParseLevel(level) if err != nil { diff --git a/cmd/hasura-ndc-go/schema.go b/cmd/hasura-ndc-go/schema.go index c35f464..7bfddf4 100644 --- a/cmd/hasura-ndc-go/schema.go +++ b/cmd/hasura-ndc-go/schema.go @@ -356,7 +356,7 @@ func (sp SchemaParser) FindPackageByPath(input string) *packages.Package { return nil } -func parseRawConnectorSchemaFromGoCode(ctx context.Context, moduleName string, filePath string, args *GenerateArguments) (*RawConnectorSchema, error) { +func parseRawConnectorSchemaFromGoCode(ctx context.Context, moduleName string, filePath string, args *UpdateArguments) (*RawConnectorSchema, error) { rawSchema := NewRawConnectorSchema() pkgTypes, err := evalPackageTypesLocation(args.PackageTypes, moduleName, filePath, args.ConnectorDir) diff --git a/cmd/hasura-ndc-go/template.go b/cmd/hasura-ndc-go/template.go index 788e4b4..e57ec4f 100644 --- a/cmd/hasura-ndc-go/template.go +++ b/cmd/hasura-ndc-go/template.go @@ -64,7 +64,7 @@ func generateNewProject(args *NewArguments, silent bool) error { } log.Info().Msg("generating connector functions...") - if err := parseAndGenerateConnector(&GenerateArguments{ + if err := parseAndGenerateConnector(&UpdateArguments{ Path: ".", Directories: []string{"functions", "types"}, }, args.Module); err != nil { diff --git a/cmd/hasura-ndc-go/templates/new/.air.toml.tmpl b/cmd/hasura-ndc-go/templates/new/.air.toml.tmpl deleted file mode 100644 index 8516c21..0000000 --- a/cmd/hasura-ndc-go/templates/new/.air.toml.tmpl +++ /dev/null @@ -1,63 +0,0 @@ -# Config file for [Air](https://github.com/cosmtrek/air) in TOML format - -# Working directory -# . or absolute path, please note that the directories following must be under root. -root = "." -tmp_dir = "tmp" - -[build] -# Just plain old shell command. You could use `make` as well. -cmd = "hasura-ndc-go generate && go build -o ./tmp/main ." -# Binary file yields from `cmd`. -# bin = "tmp/main" -# Customize binary, can setup environment variables when run your app. -full_bin = "./tmp/main serve" -# Watch these filename extensions. -include_ext = ["go", "tpl", "tmpl"] -# Ignore these filename extensions or directories. -exclude_dir = ["assets", "tmp", "vendor"] -# Watch these directories if you specified. -include_dir = [] -# Watch these files. -include_file = [] -# Exclude files. -exclude_file = [] -# Exclude specific regular expressions. -exclude_regex = ["generated\\.go", "_test\\.go"] -# Exclude unchanged files. -exclude_unchanged = true -# Follow symlink for directories -follow_symlink = true -# This log file places in your tmp_dir. -log = "air.log" -# It's not necessary to trigger build each time file changes if it's too frequent. -delay = 0 # ms -# Stop running old binary when build errors occur. -stop_on_error = true -# Send Interrupt signal before killing process (windows does not support this feature) -send_interrupt = false -# Delay after sending Interrupt signal -kill_delay = 500 # ms -# Rerun binary or not -rerun = false -# Delay after each executions -rerun_delay = 500 -# Add additional arguments when running binary (bin/full_bin). Will run './tmp/main hello world'. -# args_bin = ["hello", "world"] - -[log] -# Show log time -time = false -# Only show main log (silences watcher, build, runner) -main_only = false - -[color] -# Customize each part's color. If no color found, use the raw app log. -main = "magenta" -watcher = "cyan" -build = "yellow" -runner = "green" - -[misc] -# Delete tmp directory on exit -clean_on_exit = true \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/.air.windows.toml.tmpl b/cmd/hasura-ndc-go/templates/new/.air.windows.toml.tmpl deleted file mode 100644 index 519d7b1..0000000 --- a/cmd/hasura-ndc-go/templates/new/.air.windows.toml.tmpl +++ /dev/null @@ -1,63 +0,0 @@ -# Config file for [Air](https://github.com/cosmtrek/air) in TOML format - -# Working directory -# . or absolute path, please note that the directories following must be under root. -root = "." -tmp_dir = "tmp" - -[build] -# Just plain old shell command. You could use `make` as well. -cmd = "hasura-ndc-go generate && go build -o ./tmp/main.exe ." -# Binary file yields from `cmd`. -bin = "./tmp/main.exe" -# Customize binary, can setup environment variables when run your app. -full_bin = "./tmp/main.exe serve" -# Watch these filename extensions. -include_ext = ["go", "tpl", "tmpl"] -# Ignore these filename extensions or directories. -exclude_dir = ["assets", "tmp", "vendor"] -# Watch these directories if you specified. -include_dir = [] -# Watch these files. -include_file = [] -# Exclude files. -exclude_file = [] -# Exclude specific regular expressions. -exclude_regex = ["generated\\.go", "_test\\.go"] -# Exclude unchanged files. -exclude_unchanged = true -# Follow symlink for directories -follow_symlink = true -# This log file places in your tmp_dir. -log = "air.log" -# It's not necessary to trigger build each time file changes if it's too frequent. -delay = 0 # ms -# Stop running old binary when build errors occur. -stop_on_error = true -# Send Interrupt signal before killing process (windows does not support this feature) -send_interrupt = false -# Delay after sending Interrupt signal -kill_delay = 500 # ms -# Rerun binary or not -rerun = false -# Delay after each executions -rerun_delay = 500 -# Add additional arguments when running binary (bin/full_bin). Will run './tmp/main hello world'. -# args_bin = ["hello", "world"] - -[log] -# Show log time -time = false -# Only show main log (silences watcher, build, runner) -main_only = false - -[color] -# Customize each part's color. If no color found, use the raw app log. -main = "magenta" -watcher = "cyan" -build = "yellow" -runner = "green" - -[misc] -# Delete tmp directory on exit -clean_on_exit = true diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/connector-metadata.yaml.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/connector-metadata.yaml.tmpl index 60cb1eb..9e7dbfc 100644 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/connector-metadata.yaml.tmpl +++ b/cmd/hasura-ndc-go/templates/new/.hasura-connector/connector-metadata.yaml.tmpl @@ -2,19 +2,10 @@ packagingDefinition: type: ManagedDockerBuild supportedEnvironmentVariables: [] commands: - commands: - start: - type: ShellScript - bash: ./start.sh - powershell: ./start.ps1 - update: - type: ShellScript - bash: ./update.sh - powershell: ./update.ps1 - watch: - type: ShellScript - bash: ./watch.sh - powershell: ./watch.ps1 + update: hasura-ndc-go update +cliPlugin: + name: ndc-go + version: {{.Version}} dockerComposeWatch: # Rebuild the container if root files or dependencies are changed - path: go.mod diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/requirements.ps1.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/requirements.ps1.tmpl deleted file mode 100644 index 5591cc3..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/requirements.ps1.tmpl +++ /dev/null @@ -1,17 +0,0 @@ -$ErrorActionPreference = "Stop" - -if (-not (Get-Command "go" -ErrorAction SilentlyContinue)) { - Write-Host "go could not be found. Please install Go v1.19+." - exit 1 -} - -if (-not (Get-Command "hasura-ndc-go" -ErrorAction SilentlyContinue)) { - Invoke-Expression "go install github.com/hasura/ndc-sdk-go/cmd/hasura-ndc-go@v0" - if (-not (Get-Command "hasura-ndc-go" -ErrorAction SilentlyContinue)) { - $env:PATH = "$($env:PATH);$($env:GOPATH)bin;$($env:USERPROFILE)bin" - if (-not (Get-Command "hasura-ndc-go" -ErrorAction SilentlyContinue)) { - Write-Host "Please configure GOPATH environment variables. See https://go.dev/wiki/SettingGOPATH#windows." - exit 1 - } - } -} diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/requirements.sh.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/requirements.sh.tmpl deleted file mode 100644 index 138437a..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/requirements.sh.tmpl +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -if ! command -v go &>/dev/null; then - echo "go could not be found on the PATH. Please install Go v1.19 or above" - exit 1 -fi - -export GOBIN="$(go env GOPATH)/bin" -export PATH=$PATH:$GOBIN - -if ! command -v hasura-ndc-go &>/dev/null; then - go install github.com/hasura/ndc-sdk-go/cmd/hasura-ndc-go@v0 -fi \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/start.ps1.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/start.ps1.tmpl deleted file mode 100644 index c49f995..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/start.ps1.tmpl +++ /dev/null @@ -1,21 +0,0 @@ -$ErrorActionPreference = "Stop" - -& ./requirements.ps1 - -if (-not (Get-Command "hasura-ndc-go" -ErrorAction SilentlyContinue)) { - $env:PATH = "$($env:PATH);$($env:GOPATH)bin;$($env:USERPROFILE)bin" -} - -Push-Location $env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH - -try { - $GenerateExpr = "hasura-ndc-go generate" - $StartExpr = "go run . serve" - Invoke-Expression $GenerateExpr - Invoke-Expression $StartExpr - if ($LASTEXITCODE -ne 0) { - exit 1 - } -} finally { - Pop-Location -} \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/start.sh.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/start.sh.tmpl deleted file mode 100644 index 8cc6b00..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/start.sh.tmpl +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -. ./requirements.sh - -cd $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH -hasura-ndc-go generate -go run . serve \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/update.ps1.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/update.ps1.tmpl deleted file mode 100644 index 2c59399..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/update.ps1.tmpl +++ /dev/null @@ -1,19 +0,0 @@ -$ErrorActionPreference = "Stop" - -& ./requirements.ps1 - -if (-not (Get-Command "hasura-ndc-go" -ErrorAction SilentlyContinue)) { - $env:PATH = "$($env:PATH);$($env:GOPATH)bin;$($env:USERPROFILE)bin" -} - -Push-Location $env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH - -try { - $GenerateExpr = "hasura-ndc-go generate" - Invoke-Expression $GenerateExpr - if ($LASTEXITCODE -ne 0) { - exit 1 - } -} finally { - Pop-Location -} \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/update.sh.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/update.sh.tmpl deleted file mode 100644 index df04426..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/update.sh.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -. ./requirements.sh - -cd $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH -hasura-ndc-go generate \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/watch.ps1.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/watch.ps1.tmpl deleted file mode 100644 index 5b71e82..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/watch.ps1.tmpl +++ /dev/null @@ -1,22 +0,0 @@ -$ErrorActionPreference = "Stop" - -& ./requirements.ps1 -if (-not (Get-Command "hasura-ndc-go" -ErrorAction SilentlyContinue)) { - $env:PATH = "$($env:PATH);$($env:GOPATH)bin;$($env:USERPROFILE)bin" -} - -if (-not (Get-Command "air" -ErrorAction SilentlyContinue)) { - Invoke-Expression "go install github.com/cosmtrek/air@v1.41.0" -} - -Push-Location $env:HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH - -try { - $WatchExpr = "air -c .air.windows.toml" - Invoke-Expression $WatchExpr - if ($LASTEXITCODE -ne 0) { - exit 1 - } -} finally { - Pop-Location -} \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/watch.sh.tmpl b/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/watch.sh.tmpl deleted file mode 100644 index 65356e6..0000000 --- a/cmd/hasura-ndc-go/templates/new/.hasura-connector/scripts/watch.sh.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -eu -o pipefail - -. ./requirements.sh - -if ! command -v air &>/dev/null; then - go install github.com/cosmtrek/air@v1.41.0 -fi - -cd $HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH -air -c .air.toml \ No newline at end of file diff --git a/cmd/hasura-ndc-go/templates/new/Makefile.tmpl b/cmd/hasura-ndc-go/templates/new/Makefile.tmpl index 5b5a82c..675f92e 100644 --- a/cmd/hasura-ndc-go/templates/new/Makefile.tmpl +++ b/cmd/hasura-ndc-go/templates/new/Makefile.tmpl @@ -1,20 +1,4 @@ .DEFAULT_GOAL := help -ROOT = $(shell pwd) - -.PHONY: start -start: ## Start the server with go run - cd .hasura-connector/scripts && \ - HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH=$(ROOT) $(SHELL) ./start.sh - -.PHONY: update -update: ## Update schema and code generation - cd .hasura-connector/scripts && \ - HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH=$(ROOT) $(SHELL) ./update.sh - -.PHONY: watch -watch: ## Watch code changes and live reload - cd .hasura-connector/scripts && \ - HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH=$(ROOT) $(SHELL) ./watch.sh .PHONY: format format: ## Format go files diff --git a/cmd/hasura-ndc-go/templates/new/README.md.tmpl b/cmd/hasura-ndc-go/templates/new/README.md.tmpl index 4f279a6..c676ec2 100644 --- a/cmd/hasura-ndc-go/templates/new/README.md.tmpl +++ b/cmd/hasura-ndc-go/templates/new/README.md.tmpl @@ -2,58 +2,35 @@ ## Get started -### DDN CLI +Start the connector server at http://localhost:8080 -The boilerplate follows [Native Connector Packaging](https://github.com/hasura/ndc-hub/blob/main/rfcs/0004-native-packaging.md) with convenience shell scripts at [the connector definition folder](.hasura-connector/scripts). DDN CLI can automatically invoke those scripts when developing with DDN projects. +```go +go run . serve +``` -### Convenience scripts (Linux & MacOS) +## Development -You can run the convenience script with `make`. Those commands reuse native scripts at [the connector definition folder](.hasura-connector/scripts). +### DDN CLI -```sh -Usage: - start Start the server with go run - update Update schema and code generation - watch Watch code changes and live reload -``` +The boilerplate follows [Native Connector Packaging](https://github.com/hasura/ndc-hub/blob/main/rfcs/0004-native-packaging.md) with convenience shell scripts at [the connector definition folder](.hasura-connector/scripts). +DDN CLI can automatically invoke those scripts when developing with DDN projects. + +### Manual -### Manual installation +#### Installation Install following tools for development: - [hasura-ndc-go](https://github.com/hasura/ndc-sdk-go/tree/main/cmd/hasura-ndc-go) -- [air](https://github.com/cosmtrek/air) (optional, install if you want live reload) ```sh go install github.com/hasura/ndc-sdk-go/cmd/hasura-ndc-go@latest -# downgrade lower version if you don't use the latest Go -go install github.com/cosmtrek/air@latest ``` -#### Live reload - -**Linux & MacOS** - -```sh -air -c air -c .air.toml -``` - -**Windows** - -```sh -air -c air -c .air.windows.toml -``` - -#### Manual +#### Code generation Whenever modifying NDC types and functions in the `functions` folder, you need to generate NDC schema and codes. ```sh -hasura-ndc-go generate -``` - -Start the connector server at http://localhost:8080 - -```go -go run . serve -``` +hasura-ndc-go update +``` \ No newline at end of file