diff --git a/plugins/jk-plugin-echo/main.go b/plugins/jk-plugin-echo/main.go new file mode 100644 index 00000000..a3ced92c --- /dev/null +++ b/plugins/jk-plugin-echo/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "os" + + "github.com/hashicorp/go-hclog" + "github.com/hashicorp/go-plugin" + + "github.com/jkcfg/jk/pkg/plugin/renderer" +) + +// Echo outputs its input. +type Echo struct { + log hclog.Logger +} + +// Render implements renderer.Renderer. +func (h *Echo) Render(input []byte) ([]byte, error) { + h.log.Debug("debug message from echo plugin") + return input, nil +} + +func main() { + logger := hclog.New(&hclog.LoggerOptions{ + Level: hclog.Info, + Output: os.Stderr, + }) + + r := &Echo{ + log: logger, + } + // pluginMap is the map of plugins we can dispense. + var pluginMap = map[string]plugin.Plugin{ + "renderer": &renderer.Plugin{Impl: r}, + } + + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: renderer.RendererV1, + Plugins: pluginMap, + }) +} diff --git a/tests/echo.json b/tests/echo.json new file mode 100644 index 00000000..bcea0422 --- /dev/null +++ b/tests/echo.json @@ -0,0 +1,8 @@ +{ + "name": "echo", + "version": "0.1.0", + "binaries": { + "linux-amd64": "jk-plugin-echo", + "darwin-amd64": "jk-plugin-echo" + } +} diff --git a/tests/test-plugin-echo.js b/tests/test-plugin-echo.js new file mode 100644 index 00000000..914e4ff7 --- /dev/null +++ b/tests/test-plugin-echo.js @@ -0,0 +1,4 @@ +import * as std from '@jkcfg/std'; +import { render } from '@jkcfg/std/render'; + +render('echo.json', { message: 'success' }).then(r => std.log(r.message)); diff --git a/tests/test-plugin-echo.js.expected b/tests/test-plugin-echo.js.expected new file mode 100644 index 00000000..2e9ba477 --- /dev/null +++ b/tests/test-plugin-echo.js.expected @@ -0,0 +1 @@ +success