Skip to content

Commit 4967d45

Browse files
authored
feat: Add frames package (poap-xyz#96)
1 parent 92460eb commit 4967d45

18 files changed

+581
-5
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = {
4141
'./packages/providers/tsconfig.json',
4242
'./packages/utils/tsconfig.json',
4343
'./packages/poaps/tsconfig.json',
44+
'./packages/frames/tsconfig.json',
4445
'./tsconfig.json',
4546
],
4647
},
@@ -53,4 +54,4 @@ module.exports = {
5354
},
5455
},
5556
],
56-
};
57+
};

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ Please ensure that your code adheres to the project's code style and passes all
157157
<br />
158158
<a href="#" title="Code">💻</a>
159159
</td>
160+
<td align="center">
161+
<a href="https://github.com/reobin">
162+
<img src="https://avatars.githubusercontent.com/u/5920450?v=4" width="100px;" alt=""/>
163+
<br />
164+
<sub>
165+
<b>Robin Gagnon</b>
166+
</sub>
167+
</a>
168+
<br />
169+
<a href="#" title="Code">💻</a>
170+
</td>
160171
</tr>
161172
</table>
162173

examples/frames/.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18

examples/frames/package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "backend-frames-example",
3+
"version": "1.0.0",
4+
"description": "Backend example for using the library",
5+
"main": "src/index.ts",
6+
"scripts": {
7+
"start": "ts-node ./src/index.ts",
8+
"build": "tsc",
9+
"test": "echo \"No tests specified\" && exit 0"
10+
},
11+
"dependencies": {
12+
"@poap-xyz/frames": "*",
13+
"@poap-xyz/providers": "*",
14+
"@poap-xyz/utils": "*",
15+
"@types/node": "^18.16.0",
16+
"axios": "^1.3.5",
17+
"dotenv": "^16.0.3",
18+
"stream": "^0.0.2"
19+
},
20+
"devDependencies": {
21+
"@types/node-fetch": "^2.6.3",
22+
"ts-node": "^10.4.0",
23+
"typescript": "^4.5.5"
24+
},
25+
"engines": {
26+
"node": ">=18"
27+
}
28+
}

examples/frames/src/frames/base.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Frame, FrameAspectRatio } from '@poap-xyz/frames';
2+
3+
export const BASE_FRAME = new Frame({
4+
title: 'Hello World',
5+
image: 'https://placehold.co/600x600',
6+
aspectRatio: FrameAspectRatio.SQUARE,
7+
postUrl: 'https://poap.xyz',
8+
});

examples/frames/src/frames/buttons.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Frame, FrameAspectRatio, FrameButtonAction } from '@poap-xyz/frames';
2+
3+
export const FRAME_WITH_BUTTONS = new Frame({
4+
title: 'Hello World',
5+
image: 'https://placehold.co/600x600',
6+
aspectRatio: FrameAspectRatio.SQUARE,
7+
postUrl: 'https://poap.xyz',
8+
buttons: [
9+
{ label: 'Button 1' },
10+
{
11+
label: 'Button 2',
12+
action: FrameButtonAction.POST,
13+
target: 'https://poap.xyz',
14+
},
15+
{
16+
label: 'Button 3',
17+
action: FrameButtonAction.LINK,
18+
target: 'https://poap.xyz',
19+
},
20+
],
21+
});

examples/frames/src/index.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import dotenv from 'dotenv';
2+
import { Frame } from '@poap-xyz/frames';
3+
import { BASE_FRAME } from './frames/base';
4+
import { FRAME_WITH_BUTTONS } from './frames/buttons';
5+
6+
dotenv.config();
7+
8+
function main(): void {
9+
runFrameExample('Base frame', BASE_FRAME);
10+
runFrameExample('Frame with buttons', FRAME_WITH_BUTTONS);
11+
}
12+
13+
function runFrameExample(name: string, frame: Frame): void {
14+
console.log(name);
15+
console.log('meta tags:');
16+
console.log(frame.toMetaTags());
17+
console.log('html:');
18+
console.log(frame.render());
19+
console.log('---------');
20+
}
21+
22+
main();

examples/frames/tsconfig.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es6"],
4+
"target": "es6",
5+
"module": "commonjs",
6+
"moduleResolution": "node",
7+
"outDir": "dist",
8+
"resolveJsonModule": true,
9+
"emitDecoratorMetadata": true,
10+
"esModuleInterop": true,
11+
"experimentalDecorators": true,
12+
"sourceMap": true,
13+
"allowSyntheticDefaultImports": true,
14+
},
15+
"include": ["src/**/*.ts", "src/assets/*.png"],
16+
"exclude": ["node_modules", "**/*.spec.ts"],
17+
}

package-order.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ DIRS=(
77
"packages/drops"
88
"packages/poaps"
99
"packages/moments"
10+
"packages/frames"
1011
)

packages/frames/README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# @poap-xyz/frames
2+
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
4+
5+
@poap-xyz/frames is a package to help with the development of Farcaster Frames.
6+
7+
## Features
8+
9+
- Generate the frame meta tags
10+
- Generate the frame HTML markup
11+
12+
## Installation
13+
14+
### NPM
15+
16+
```bash
17+
npm install @poap-xyz/frames
18+
```
19+
20+
### Yarn
21+
22+
```bash
23+
yarn add @poap-xyz/frames
24+
```
25+
26+
## Usage
27+
28+
### Meta tags
29+
30+
```javascript
31+
const frame = useMemo(() => new Frame({ ... });
32+
return (
33+
<>
34+
<NextSeo
35+
title="Hello World"
36+
description="..."
37+
openGraph={{ images: [...] }}
38+
additionalMetaTags={frame.toMetaTags()}
39+
/>
40+
<div>...</div>
41+
</>
42+
)
43+
```
44+
45+
### HTML render
46+
47+
```javascript
48+
// /api/frame.ts
49+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
50+
const frame = new Frame({ ... });
51+
return res.status(200).send(frame.render());
52+
}
53+
```
54+
55+
## Examples
56+
57+
For example scripts and usage, please check the [examples](https://github.com/poap-xyz/poap.js/tree/main/examples).
58+
59+
## Contributing
60+
61+
We welcome contributions! Please see the `CONTRIBUTING.md` file for guidelines.
62+
63+
## License
64+
65+
@poap-xyz/frames is released under the [MIT License](https://opensource.org/licenses/MIT).

packages/frames/package.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@poap-xyz/frames",
3+
"version": "1.0.0",
4+
"description": "Frames module for the poap.js library",
5+
"main": "dist/cjs/index.cjs",
6+
"module": "dist/esm/index.mjs",
7+
"typings": "dist/cjs/index.d.ts",
8+
"browser": "dist/umd/index.js",
9+
"exports": {
10+
"require": "./dist/cjs/index.cjs",
11+
"import": "./dist/esm/index.mjs",
12+
"browser": "./dist/umd/index.js"
13+
},
14+
"type": "module",
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/poap-xyz/poap.js.git"
18+
},
19+
"author": "POAP",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/poap-xyz/poap.js/issues"
23+
},
24+
"homepage": "https://github.com/poap-xyz/poap.js#readme",
25+
"scripts": {
26+
"build": "rollup -c --bundleConfigAsCjs"
27+
},
28+
"engines": {
29+
"node": ">=18"
30+
},
31+
"dependencies": {
32+
"next-seo": "^6.4.0"
33+
}
34+
}

packages/frames/rollup.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import configs from '../../rollup.base.config';
2+
3+
export default configs;

0 commit comments

Comments
 (0)