Skip to content

Commit

Permalink
feat: Add frames package (poap-xyz#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin authored Mar 21, 2024
1 parent 92460eb commit 4967d45
Show file tree
Hide file tree
Showing 18 changed files with 581 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
'./packages/providers/tsconfig.json',
'./packages/utils/tsconfig.json',
'./packages/poaps/tsconfig.json',
'./packages/frames/tsconfig.json',
'./tsconfig.json',
],
},
Expand All @@ -53,4 +54,4 @@ module.exports = {
},
},
],
};
};
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ Please ensure that your code adheres to the project's code style and passes all
<br />
<a href="#" title="Code">💻</a>
</td>
<td align="center">
<a href="https://github.com/reobin">
<img src="https://avatars.githubusercontent.com/u/5920450?v=4" width="100px;" alt=""/>
<br />
<sub>
<b>Robin Gagnon</b>
</sub>
</a>
<br />
<a href="#" title="Code">💻</a>
</td>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions examples/frames/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
28 changes: 28 additions & 0 deletions examples/frames/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "backend-frames-example",
"version": "1.0.0",
"description": "Backend example for using the library",
"main": "src/index.ts",
"scripts": {
"start": "ts-node ./src/index.ts",
"build": "tsc",
"test": "echo \"No tests specified\" && exit 0"
},
"dependencies": {
"@poap-xyz/frames": "*",
"@poap-xyz/providers": "*",
"@poap-xyz/utils": "*",
"@types/node": "^18.16.0",
"axios": "^1.3.5",
"dotenv": "^16.0.3",
"stream": "^0.0.2"
},
"devDependencies": {
"@types/node-fetch": "^2.6.3",
"ts-node": "^10.4.0",
"typescript": "^4.5.5"
},
"engines": {
"node": ">=18"
}
}
8 changes: 8 additions & 0 deletions examples/frames/src/frames/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Frame, FrameAspectRatio } from '@poap-xyz/frames';

export const BASE_FRAME = new Frame({
title: 'Hello World',
image: 'https://placehold.co/600x600',
aspectRatio: FrameAspectRatio.SQUARE,
postUrl: 'https://poap.xyz',
});
21 changes: 21 additions & 0 deletions examples/frames/src/frames/buttons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Frame, FrameAspectRatio, FrameButtonAction } from '@poap-xyz/frames';

export const FRAME_WITH_BUTTONS = new Frame({
title: 'Hello World',
image: 'https://placehold.co/600x600',
aspectRatio: FrameAspectRatio.SQUARE,
postUrl: 'https://poap.xyz',
buttons: [
{ label: 'Button 1' },
{
label: 'Button 2',
action: FrameButtonAction.POST,
target: 'https://poap.xyz',
},
{
label: 'Button 3',
action: FrameButtonAction.LINK,
target: 'https://poap.xyz',
},
],
});
22 changes: 22 additions & 0 deletions examples/frames/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import dotenv from 'dotenv';
import { Frame } from '@poap-xyz/frames';
import { BASE_FRAME } from './frames/base';
import { FRAME_WITH_BUTTONS } from './frames/buttons';

dotenv.config();

function main(): void {
runFrameExample('Base frame', BASE_FRAME);
runFrameExample('Frame with buttons', FRAME_WITH_BUTTONS);
}

function runFrameExample(name: string, frame: Frame): void {
console.log(name);
console.log('meta tags:');
console.log(frame.toMetaTags());
console.log('html:');
console.log(frame.render());
console.log('---------');
}

main();
17 changes: 17 additions & 0 deletions examples/frames/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"lib": ["es6"],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"resolveJsonModule": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"sourceMap": true,
"allowSyntheticDefaultImports": true,
},
"include": ["src/**/*.ts", "src/assets/*.png"],
"exclude": ["node_modules", "**/*.spec.ts"],
}
1 change: 1 addition & 0 deletions package-order.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ DIRS=(
"packages/drops"
"packages/poaps"
"packages/moments"
"packages/frames"
)
65 changes: 65 additions & 0 deletions packages/frames/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# @poap-xyz/frames

[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

@poap-xyz/frames is a package to help with the development of Farcaster Frames.

## Features

- Generate the frame meta tags
- Generate the frame HTML markup

## Installation

### NPM

```bash
npm install @poap-xyz/frames
```

### Yarn

```bash
yarn add @poap-xyz/frames
```

## Usage

### Meta tags

```javascript
const frame = useMemo(() => new Frame({ ... });
return (
<>
<NextSeo
title="Hello World"
description="..."
openGraph={{ images: [...] }}
additionalMetaTags={frame.toMetaTags()}
/>
<div>...</div>
</>
)
```
### HTML render
```javascript
// /api/frame.ts
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const frame = new Frame({ ... });
return res.status(200).send(frame.render());
}
```
## Examples
For example scripts and usage, please check the [examples](https://github.com/poap-xyz/poap.js/tree/main/examples).
## Contributing
We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines.
## License
@poap-xyz/frames is released under the [MIT License](https://opensource.org/licenses/MIT).
34 changes: 34 additions & 0 deletions packages/frames/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@poap-xyz/frames",
"version": "1.0.0",
"description": "Frames module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"typings": "dist/cjs/index.d.ts",
"browser": "dist/umd/index.js",
"exports": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs",
"browser": "./dist/umd/index.js"
},
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/poap-xyz/poap.js.git"
},
"author": "POAP",
"license": "MIT",
"bugs": {
"url": "https://github.com/poap-xyz/poap.js/issues"
},
"homepage": "https://github.com/poap-xyz/poap.js#readme",
"scripts": {
"build": "rollup -c --bundleConfigAsCjs"
},
"engines": {
"node": ">=18"
},
"dependencies": {
"next-seo": "^6.4.0"
}
}
3 changes: 3 additions & 0 deletions packages/frames/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import configs from '../../rollup.base.config';

export default configs;
Loading

0 comments on commit 4967d45

Please sign in to comment.