Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stub with sample feature #5

Merged
merged 18 commits into from
Jul 16, 2024
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ jobs:
with:
node-version: '21'

- name: Install
run: |
npm ci

- name: Build
run: |
npm i
npm run build

- name: Run test script
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ dist
bundle.zip
bundle
tests/output
output
myplugin
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ dependencies:
- npm

available-feature-flags:
# - camelize-properties
- stub-with-code-samples
# - map-iso8601-dates
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xtp-typescript-bindgen",
"version": "0.0.7",
"description": "",
"version": "0.0.8",
"description": "XTP TypeScript bindgen plugin",
"main": "dist/index.js",
"scripts": {
"build": "tsc --noEmit && node esbuild.js && extism-js dist/index.js -i src/index.d.ts -o dist/plugin.wasm"
Expand All @@ -18,6 +18,6 @@
},
"dependencies": {
"ejs": "^3.1.10",
"@dylibso/xtp-bindgen": "^0.0.3"
"@dylibso/xtp-bindgen": "^0.0.9"
}
}
4 changes: 4 additions & 0 deletions template/src/main.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ import {
*/
<% -%>
export function <%= ex.name %>Impl(<%- ex.input ? `input: ${toTypeScriptType(ex.input)}`: null %>)<%- ex.output ? `:${toTypeScriptType(ex.output)}` : null %> {
<% if (featureFlags['stub-with-code-samples']) { -%>
<%- codeSamples(ex, 'typescript')[0].source %>
<% } else { -%>
// TODO: fill out your implementation here
throw new Error("Function not implemented.");
<% } -%>
}
<% }) %>

Expand Down
12 changes: 12 additions & 0 deletions tests/schemas/fruit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ exports:
description: |
This demonstrates how you can create an export with
no inputs or outputs.
codeSamples:
- lang: typescript
source: |
console.log('Hello World!')
- name: topLevelPrimitives
description: |
This demonstrates how you can accept or return primtive types.
This function takes a utf8 string and returns a json encoded array of booleans
codeSamples:
- lang: typescript
source: |
return [true, false]
input:
type: string
contentType: text/plain; charset=UTF-8
Expand All @@ -21,6 +29,10 @@ exports:
description: |
This demonstrates how parameters can be references.
It takes a Fruit enum and returns a ComplexObject json object
codeSamples:
- lang: typescript
source: |
return { ghost: GhostGang.inky, aBoolean: true, aString: "okay", anInt: 123 }
input:
$ref: "#/schemas/Fruit"
output:
Expand Down
2 changes: 1 addition & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cd tests
for file in ./schemas/*.yaml; do
echo "Generating and testing $file..."
rm -rf output
xtp plugin init --schema-file $file --template ../bundle --path output -y
xtp plugin init --schema-file $file --template ../bundle --path output -y --feature stub-with-code-samples
cd output
xtp plugin build
cd ..
Expand Down
Loading