diff --git a/main.go b/main.go index 0c71910..050e6b8 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( "path/filepath" "strings" - "github.com/extism/go-sdk" + extism "github.com/extism/go-sdk" ) // TODO this is wonk @@ -47,12 +47,14 @@ func CopyFile(src, dst string) error { func main() { schemaCtx := ` { - "project": {"name": "hello", "description": "a new plugin that does something"}, + "project": {"name": "hello", "description": "a new plugin that does something", "appId": "app_1234", "extensionPointId": "ext_1234" }, "schema": { "exports": [ { "name": "voidFunc", - "description": "This demonstrates how you can create an export with\nno inputs or outputs.\n" + "description": "This demonstrates how you can create an export with\nno inputs or outputs.\n", + "input": { "name": "" }, + "output": { "name": "" } }, { "name": "primitiveTypeFunc", diff --git a/output/src/index.d.ts b/output/src/index.d.ts index 409e128..7479887 100755 --- a/output/src/index.d.ts +++ b/output/src/index.d.ts @@ -1,4 +1,4 @@ -declare module "main" { +declare module 'main' { export function voidFunc(): I32; export function primitiveTypeFunc(): I32; export function referenceTypeFunc(): I32; diff --git a/output/src/index.ts b/output/src/index.ts index 468cdb5..3a0c3b7 100755 --- a/output/src/index.ts +++ b/output/src/index.ts @@ -1,29 +1,38 @@ -import * as main from "./main"; +import * as main from "./main" -import { Fruit, GhostGang, ComplexObject } from "./pdk"; +import { + Fruit, + GhostGang, + ComplexObject, + } from './pdk' -export function voidFunc(): number { - main.voidFuncImpl(); - return 0; +export function voidFunc(): number { + main.voidFuncImpl() + + + return 0 } export function primitiveTypeFunc(): number { - const input = Host.inputString(); - - const output = main.primitiveTypeFuncImpl(input); - - Host.outputString(JSON.stringify(output)); - - return 0; + const input = Host.inputString() + + const output = main.primitiveTypeFuncImpl(input) + + Host.outputString(JSON.stringify(output)) + + return 0 } export function referenceTypeFunc(): number { - const input = Host.inputString() as Fruit; + const input = Host.inputString() as Fruit + + const output = main.referenceTypeFuncImpl(input) + + Host.outputString(JSON.stringify(output)) + + return 0 +} - const output = main.referenceTypeFuncImpl(input); - Host.outputString(JSON.stringify(output)); - return 0; -} diff --git a/output/src/main.ts b/output/src/main.ts index ffc32cd..47638a3 100755 --- a/output/src/main.ts +++ b/output/src/main.ts @@ -1,6 +1,17 @@ -import { Fruit, GhostGang, ComplexObject } from "./pdk"; -import { eatAFruit } from "./pdk"; +import { + Fruit, + GhostGang, + ComplexObject, + } from './pdk' + + +import { + eatAFruit, + } from './pdk' + + + /** * This demonstrates how you can create an export with @@ -19,7 +30,7 @@ export function voidFuncImpl() { * @param input {string} A string passed into plugin input * @returns {boolean} A boolean encoded as json */ -export function primitiveTypeFuncImpl(input: string): boolean { +export function primitiveTypeFuncImpl(input: string):boolean { // TODO: fill out your implementation here throw new Error("Function not implemented."); } @@ -31,7 +42,10 @@ export function primitiveTypeFuncImpl(input: string): boolean { * @param input {Fruit} A set of available fruits you can consume * @returns {ComplexObject} A complex json object */ -export function referenceTypeFuncImpl(input: Fruit): ComplexObject { +export function referenceTypeFuncImpl(input: Fruit):ComplexObject { // TODO: fill out your implementation here throw new Error("Function not implemented."); } + + + diff --git a/output/src/pdk.ts b/output/src/pdk.ts index 4fdb518..5d29a91 100755 --- a/output/src/pdk.ts +++ b/output/src/pdk.ts @@ -1,59 +1,91 @@ -const hostFunctions = Host.getFunctions(); + +const hostFunctions = Host.getFunctions() + + + + /** * A set of available fruits you can consume */ export enum Fruit { - apple = "apple", - orange = "orange", - banana = "banana", - strawberry = "strawberry", -} + apple = "apple", + orange = "orange", + banana = "banana", + strawberry = "strawberry", + } + + + + + /** * A set of all the enemies of pac-man */ export enum GhostGang { - blinky = "blinky", - pinky = "pinky", - inky = "inky", - clyde = "clyde", -} + blinky = "blinky", + pinky = "pinky", + inky = "inky", + clyde = "clyde", + } + + + + + /** * A complex json object */ export class ComplexObject { + + + /** * I can override the description for the property here */ - // @ts-expect-error TS2564 + // @ts-expect-error TS2564 ghost: GhostGang; + + /** * A boolean prop */ - // @ts-expect-error TS2564 + // @ts-expect-error TS2564 aBoolean: boolean; + + /** * An int prop */ - // @ts-expect-error TS2564 + // @ts-expect-error TS2564 aString: number; + + /** * An int prop */ - // @ts-expect-error TS2564 + // @ts-expect-error TS2564 anInt: number; + + /** * A datetime object, we will automatically serialize and deserialize - * this for you. + * this for you. */ - anOptionalDate?: string; + anOptionalDate?: string; + } + + + + + /** * This is a host function. Right now host functions can only be the type (i64) -> i64. @@ -62,7 +94,7 @@ export class ComplexObject { * @param input {Fruit} A set of available fruits you can consume * @returns {boolean} boolean encoded as json */ -export function eatAFruit(input: Fruit): boolean { +export function eatAFruit(input:Fruit) :boolean { const json = JSON.stringify(input); const mem = Memory.fromString(json); @@ -72,3 +104,4 @@ export function eatAFruit(input: Fruit): boolean { return JSON.parse(Memory.find(ptr).readString()); } + diff --git a/output/xtp.toml b/output/xtp.toml new file mode 100644 index 0000000..3f67714 --- /dev/null +++ b/output/xtp.toml @@ -0,0 +1,14 @@ +app_id = "app_1234" + +# This is where 'xtp plugin push' expects to find the wasm file after the build script has run. +bin = "dist/plugin.wasm" +extension_point_id = "ext_1234" +name = "hello" + +[scripts] + + # xtp plugin build runs this script to generate the wasm file + build = "npm run build" + + # xtp plugin init runs this script to format the code + format = "npm run format" diff --git a/template/xtp.toml.ejs b/template/xtp.toml.ejs new file mode 100644 index 0000000..a20de31 --- /dev/null +++ b/template/xtp.toml.ejs @@ -0,0 +1,14 @@ +app_id = "<%= project.appId %>" + +# This is where 'xtp plugin push' expects to find the wasm file after the build script has run. +bin = "dist/plugin.wasm" +extension_point_id = "<%= project.extensionPointId %>" +name = "<%= project.name %>" + +[scripts] + + # xtp plugin build runs this script to generate the wasm file + build = "npm run build" + + # xtp plugin init runs this script to format the code + format = "npm run format"