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

Add example plugin in Typescript #71

Merged
merged 7 commits into from
Jun 25, 2024
Merged

Add example plugin in Typescript #71

merged 7 commits into from
Jun 25, 2024

Conversation

heeckhau
Copy link
Member

No description provided.

@heeckhau heeckhau marked this pull request as ready for review June 24, 2024 09:31
export function config() {
Host.outputString(
JSON.stringify({
title: 'Twitter Profile',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we move this config to config.json at top level, would we be able to import the json here?

*/
async function generateBase64Icon() {
const iconPath = path.join(__dirname, 'icon.png');
const outputPath = path.join(__dirname, 'src', 'iconBase64.ts');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move icon.png to assets/icon.png and src/iconBase64.ts to dist/assets/icon.ts? No need to append Base64 at the end. we can just keep filename the same.

await generateBase64Icon();

try {
await esbuild.build({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should use something like webpack since it's much more widely use. there are already webpack plugins for turning assets into base64 and importing json files as modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is based on the Extism template. I used what was there

* This uses the `redirect` host function (see index.d.ts)
*/
function gotoTwitter() {
const { redirect } = Host.getFunctions() as any;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to import types for Host, or create a type declaration file ourselves?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not immediately find an easy solution. I'd hoped you knew 😄

@0xtsukino 0xtsukino merged commit 1c29fee into main Jun 25, 2024
2 checks passed
@heeckhau heeckhau deleted the typescript_plugin branch June 25, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants