Skip to content

Commit

Permalink
xtp.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Jul 4, 2024
1 parent 82061a5 commit 7e9221a
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 43 deletions.
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"

"github.com/extism/go-sdk"
extism "github.com/extism/go-sdk"
)

// TODO this is wonk
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion output/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "main" {
declare module 'main' {
export function voidFunc(): I32;
export function primitiveTypeFunc(): I32;
export function referenceTypeFunc(): I32;
Expand Down
43 changes: 26 additions & 17 deletions output/src/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 18 additions & 4 deletions output/src/main.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.");
}
Expand All @@ -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.");
}



69 changes: 51 additions & 18 deletions output/src/pdk.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Expand All @@ -72,3 +104,4 @@ export function eatAFruit(input: Fruit): boolean {

return JSON.parse(Memory.find(ptr).readString());
}

14 changes: 14 additions & 0 deletions output/xtp.toml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions template/xtp.toml.ejs
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 7e9221a

Please sign in to comment.