Skip to content

Commit 3c561a9

Browse files
FEAT: DVR-292 | Prompts to create new example apps (#2615)
Co-authored-by: Craig M. <[email protected]>
1 parent 457a073 commit 3c561a9

File tree

26 files changed

+4267
-3398
lines changed

26 files changed

+4267
-3398
lines changed

examples/README.md

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121
- [Contribution guidelines](#contribution-guidelines)
2222
- [Adding examples](#adding-examples)
2323
- [End to end testing](#end-to-end-testing)
24+
- [Generating examples apps using Cursor](#generating-example-apps-using-cursor)
2425
- [Using code examples in the docs site](#using-code-examples-in-the-docs-site)
25-
- [Generating Tutorials and Metadata](#generating-tutorials-and-metadata)
26+
- [Generating Tutorials and Metadata with cursor](#generating-tutorials-and-metadata-with-cursor)
2627

2728
<hr />
2829

2930
# Introduction
3031

3132
The example apps in this examples directory are compiled and tested as part of our CI CD pipeline. The goal of this is to ensure the examples found here are always able to run against the latest version of the Immutable Typescript SDK.
3233

33-
Selected portions of code from these example apps are then displayed as code snippets in our docs site, which means our code snippets in the docs are inherently always accurate as well. How to include the code from here in the docs site is explained below.
34+
Selected portions of code from these example apps are then displayed as code snippets in our docs site, which means our code snippets in the docs are inherently always accurate as well. How to include the code from here in the docs site is explained below.
3435

3536
These example apps can also be used directly as a reference and run locally to test and develop with.
3637

@@ -325,6 +326,95 @@ Run your tests
325326
```bash
326327
pnpm test
327328
```
329+
330+
# Generating example apps using cursor
331+
332+
1) Open the product folder under /examples/{product}
333+
334+
2) Under the {product} directory, open the prompt-part2.txt file.
335+
336+
3) Copy all of the content in the prompt-part2.txt file.
337+
338+
4) Paste it on to Cursor. Make sure that you're using Agent mode and the model to be used is Claude 3.7 (Thinking)
339+
340+
5) After pasting the prompt, in the chat window you can type:
341+
app name: <app name(if exists)>
342+
feature name: <name of the feature>
343+
and cursor will generate the feature page in the given app.
344+
345+
6) To update an existing feature, the prompt will identify if the given <feature name> exists in the <app name> directory. If it does, it will check if
346+
the <feature name> has the manually-edited field value as true in the feature.json file.
347+
348+
7) If the flag above exists, it will ask for a confirmation, otherwise, it will use best practices to update the existing feature page.
349+
350+
8) Once the feature page is completed, under the same directory as prompt-part2.txt, open prompt-part3.txt and copy all of its contents.
351+
352+
9) Paste it on to a new Cursor window and in the chat window you can type:
353+
354+
feature name: <name of the feature>
355+
356+
Here, cursor will check and fix pages with styling issues to ensure that it looks consistent with other example apps.
357+
358+
10) Once the styling changes have been made, under the same directory as prompt-part2.txt, open prompt-part4.txt and copy all of its contents.
359+
360+
11) Paste it on to a new Cursor window and in the chat window you can type:
361+
app name: <app name(if exists)>
362+
feature name: <name of the feature>
363+
364+
12) Cursor will then run tests and build until everything passes and renders properly.
365+
366+
13) When the prompt is done running, make sure to double check if the tests are comprehensive enough and also check if the feature page was built properly using best practices.
367+
368+
14) Run `pnpm dev` and check every page's styling. If something looks off, you can manually fix it.
369+
370+
## If an App Doesn't Exist Yet
371+
372+
You must create the app first by going to the prompt-part1.txt file and paste it on to Cursor's chat window and use Agent Mode + Claude 3.7 Sonnet Thinking.
373+
374+
In the chat window, type in:
375+
feature name: <name>
376+
377+
Then Cursor will build out the example app's setup, etc.
378+
IF Cursor doesn't run build at the end, manually type on the chat window 'run build'.
379+
380+
IMPORTANT: For any prompts, if cursor is not done with its operations but it has reached 25 tool calls, you will need to manually type "continue" on the chat window for cursor to continue building.
381+
382+
## Understanding the Prompt Files
383+
384+
The example generation process uses three different prompt files, each with a specific purpose:
385+
386+
### prompt-part1.txt
387+
- **Purpose**: Creates the initial app structure and boilerplate
388+
- **When to use**: Only when you need to create a completely new example app
389+
- **What it does**: Sets up the project structure, configuration files, basic components, and placeholder pages
390+
- **Output**: A functioning but minimal app with no implemented features
391+
392+
### prompt-part2.txt
393+
- **Purpose**: Implements or updates a specific feature within an existing app
394+
- **When to use**: After creating an app with prompt-part1.txt, or when adding/updating features
395+
- **What it does**: Creates or modifies the feature implementation with proper error handling, UI states, and best practices
396+
- **Output**: A fully implemented feature page within the app structure
397+
398+
### prompt-part3.txt
399+
- **Purpose**: Apply styling changes to the given example app if possible to ensure styling consistency with other example apps
400+
- **When to use**: After running prompt-part2.txt to implement a feature
401+
- **What it does**: Modifies the example app's UI/UX to ensure that the app looks consistent with other example apps
402+
- **Output**: A fully implemented feature page within the app structure with consistent UI/UX looks.
403+
404+
### prompt-part4.txt
405+
- **Purpose**: Tests, validates, and fixes issues in the implementation
406+
- **When to use**: After running prompt-part2.txt to implement a feature
407+
- **What it does**: Runs tests, checks coverage, builds the app, and fixes any detected issues
408+
- **Output**: A tested, validated feature ready for use
409+
410+
**Typical Workflow:**
411+
1. Use prompt-part1.txt to create a new app (only once per app)
412+
1. Use prompt-part2.txt to implement each feature in the app
413+
1. Use prompt-part3.txt to fix the app's UI/UX styling and make it look consistent to other example apps.
414+
1. Use prompt-part4.txt after each feature implementation to test and validate
415+
1. Once you've generated the example app or feature, you should manually review the implementation and the UI. It's likely you will need to make some manual adjustments to get the app to function and look like our other example apps because the cursor can not reliably get it 100% correct.
416+
1. Once you're happy with your example app or feature, you need to [re-run the tutorial generation prompt](#generating-tutorials-and-metadata-with-cursor) for your example app before creating your PR so the new example app or feature is piped into the docs site with it's corresponding tutorial.
417+
328418
# Using code examples in the docs site
329419

330420
Creating and using code snippets is relatively straight forward. You can pull in a whole file or by adding some comments you can pull in just a particular few lines of a file as necessary.
@@ -369,7 +459,6 @@ It's very simple to use the code snippet in the docs site, you just add a code b
369459
````md
370460
```tsx reference=examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx#get-wallet-allow-list title="Get the wallet allow list"
371461
```
372-
```
373462
````
374463
Or if you want to display the whole file just don't include a `#` label at the end of the file reference e.g.
375464

@@ -416,7 +505,7 @@ Once your `docs` PR is merged, Netlify should automatically build and deploy the
416505

417506
If this happens you will need to log into the Netlify site, check the error and retry the build. Usually this will fix the deployment issue, otherwise follow up on the error message shown by Netlify.
418507

419-
# Generating Tutorials and Metadata
508+
# Generating tutorials and metadata with cursor
420509

421510
Whenever you add a new example app, or update an existing example app, you can use the prompts in the `prompt.txt` files in each `examples/product` folder to generate the tutorials and metadata for the example apps using Cursor AI.
422511

examples/checkout/prompt-part1.txt

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
## Immutable Checkout SDK Example App Generator - Part 1: Create the App
2+
3+
Make sure to always write tests first. You must do Test Driven Development.
4+
# Overview
5+
This prompt helps you create a new React example app that demonstrates the {feature name} feature of the Immutable Checkout SDK. The output will be a fully functional, self-contained example with proper documentation and adherence to best practices.
6+
7+
# App Information
8+
- Feature name: {feature name}
9+
- Framework: nextjs
10+
11+
## UI Best Practices
12+
- Always ensure that you ONLY use available Biom3 Components without assuming they exist. (Text and Spinner DOES NOT exist in the Biom3 UI Library)
13+
- Use standard HTML elements (h1, h2, h3, p) for text content.
14+
- Use Biom3 Button and other UI components as documented
15+
- Show clear loading/error states
16+
- Keep UI simple and focused on demonstrating the {feature name}
17+
18+
## Critical Error Prevention
19+
- Always check if objects exist before accessing their properties or methods
20+
- Use optional chaining when accessing potentially undefined properties: obj?.prop?.method?.()
21+
- Wrap all {feature name} setup and teardown in try/catch blocks
22+
- Test component mounting/unmounting thoroughly to catch cleanup issues
23+
24+
## ALWAYS READ THIS BEFORE YOU DO ANYTHING
25+
- DO NOT call methods that don't exist on the SDK instances
26+
- DO NOT try to import types that aren't explicitly exported
27+
- DO NOT forget to clean up {feature name} setup and teardown
28+
- DO NOT use custom components or providers unless necessary
29+
- DO NOT modify dependency versions in package.json
30+
- DO NOT use inconsistent import methods (mixing default and named imports)
31+
- DO NOT forget to include 'use client' directive in client components
32+
- DO NOT assume any property or method exists without checking first
33+
- DO NOT MAKE ANY TUTORIAL/METADATA FILE FOR THE {feature name} EXAMPLE APP
34+
- NEVER ADD `"ignoreDuringBuilds": true` TO .eslintrc.json
35+
- ALways do lint checks and never turn it off when building.
36+
- NEVER FORGET TO RUN BUILD ONCE YOU'RE DONE WITH EVERYTHING ELSE. THIS IS VERY VERY VERY IMPORTANT TO ENSURE THAT EVERYTHING WORKS.
37+
38+
39+
# Step 1: Core Setup
40+
Create a new example app named {feature name}-with-nextjs in /examples/checkout/ with this structure:
41+
42+
```
43+
/examples/checkout/{feature name}-with-nextjs/
44+
├── src/app/
45+
│ ├── page.tsx # Main landing page with feature links
46+
│ ├── {feature name}/page.tsx # Primary feature implementation
47+
│ ├── redirect/page.tsx # Auth redirect handler
48+
│ ├── logout/page.tsx # Logout functionality
49+
│ ├── utils/ # Shared utilities
50+
│ │ ├── setupDefault.ts # SDK initialization
51+
│ │ └── wrapper.tsx # App context wrapper
52+
│ ├── layout.tsx # App layout with wrapper
53+
│ └── globals.css # Basic styles
54+
├── tests # Test directory
55+
│ └── base.spec.ts # E2E Test file
56+
├── README.md # Documentation
57+
├── package.json # Dependencies
58+
├── next.config.mjs # Next.js config
59+
├── tsconfig.json # TypeScript config
60+
├── .env.example # Environment variables
61+
├── .gitignore # Git ignore file
62+
├── playwright.config.ts # Playwright configuration
63+
|── eslintrc.json # ESLint configuration
64+
|── babel.config.jest.js # Babel config for tests
65+
└── features.json # JSON file showcasing the feature present in the {feature name} app
66+
```
67+
Copy these essential files from an existing example (e.g., login-with-nextjs):
68+
- package.json (update the name to "{feature name}-with-nextjs", but keep ALL dependency versions the same)
69+
- next.config.mjs
70+
- tsconfig.json
71+
- .env.example
72+
- .gitignore
73+
- src/app/utils/setupDefault.ts
74+
- src/app/utils/wrapper.tsx
75+
- src/app/layout.tsx (modify to use AppWrapper)
76+
- src/app/globals.css
77+
- playwright.config.ts
78+
- .eslintrc.json
79+
80+
IMPORTANT: Ensure that you've gone through the Checkout SDK Documentation and have a very deep understanding of the SDK before you start.
81+
IMPORTANT: We have an internal UI Library called Biom3. Make sure that you thoroughly understand all of the components. DON'T ASSUME that a component exists. ALWAYS DOUBLE CHECK BEFORE YOU IMPORT OR USE ANYTHING
82+
IF THE COMPONENT THAT YOU WANT DOESN'T EXIST IN BIOM3, ALWAYS USE NORMAL CSS/HTML AND NEVER ASSUME. (https://github.com/immutable/biom3 | https://immutable.atlassian.net/wiki/spaces/DS/pages/2335965298/BIOME+Docs)
83+
84+
# Step 2: Features.json creation (IMPORTANT: This must be done before you make components, etc. Without this file, you're not allowed to make components/pages.)
85+
Take a look at another example apps' (such as login-with-nextjs) features.json file and understand the structure.
86+
Once that's done, create the features.json file in the {feature name} example app root directory
87+
Make sure that IF {feature name} is to showcase login functionality, set silent-login/silent-logout to false. Otherwise, set it to true.
88+
The feature name in the features.json file will always be {feature name}
89+
The manually-edited field will always be false if you're the one who's generating the feature.
90+
Set the order field to be {total number of apps under product (e.g. Checkout, checkout, etc)} + 1
91+
92+
# Step 3: Testing Files
93+
COPY OVER THE RELEVANT E2E TEST FILES (INCLUDING SETUP, ETC) FROM OTHER EXAMPLE APPS SUCH AS LOGIN-WITH-NEXTJS
94+
95+
- Add the following dependencies to package.json:
96+
- @playwright/test
97+
98+
- Test all pages renders perfectly
99+
- Test {feature name} functionality thoroughly with all possible scenarios. (If it's Checkout specific, this is not required)
100+
- Test all {feature name} handling and cleanup
101+
- Explicitly validate that components render without errors
102+
- Use act() for all asynchronous operations
103+
104+
# Step 4: Component Implementation
105+
106+
## Critical Import/Export Requirements
107+
For ALL component files:
108+
- ALWAYS use default exports for page components (export default function ComponentName)
109+
- ALWAYS import React explicitly if using JSX fragments (<>...</>): import React from 'react'
110+
- Verify all imports are correctly spelled and point to existing files
111+
- When importing from libraries, verify the component exists in that library
112+
- For Next.js client components, always include 'use client' at the top of the file
113+
114+
IMPORTANT: MAKE SURE THAT THE Checkout SDK IS INITIALIZED CORRECTLY IN THE SETUPDEFAULT.TS FILE. REFER TO OTHER EXAMPLE APPS LIKE LOGIN-WITH-NEXTJS FOR THE CORRECT SETUP.
115+
IMPORTANT: DON'T IMPLEMENT THE {feature name} AT ALL. JUST SETUP THE PROJECT STRUCTURE AND DOCUMENTATION.
116+
117+
## Main Landing Page (src/app/page.tsx)
118+
Create a simple landing page with:
119+
- Brief description of the Checkout {feature name} features
120+
- Link to the {feature name} implementation page
121+
- Clear, concise UI using standard HTML (h1, h2, p) and Biom3 Button components
122+
123+
## Redirect and Logout Pages
124+
Create minimal, functional redirect and logout pages:
125+
- Ensure the redirect page properly handles the authentication callback
126+
- Implement robust error handling for failed auth callbacks
127+
- For the logout page, implement proper token cleanup
128+
- VERIFY that all components used in these pages are properly imported
129+
130+
## Feature Implementation (src/app/{feature name}/page.tsx)
131+
- THIS PAGE SHOULD JUST BE A PLACEHOLDER FOR NOW. IT SHOULD NOT IMPLEMENT ANY FUNCTIONALITY.
132+
133+
## setupDefault modification (If Applicable)
134+
- Go to the features.json file and check for the silent logout field.
135+
- If {feature name} has the silent logout field as true, ensure that the 'logoutMode' field in the setupDefault file is set to 'silent'
136+
137+
## Silent Login mode (If Applicable)
138+
- Go to the features.json file and check for the silent login field.
139+
- If {feature name} has the silent login field as true, go through all of the pages in the app and change all login modes to silent login.
140+
141+
# Step 5: Documentation
142+
IMPORTANT: Ensure that the command for installation, etc uses pnpm not npm.
143+
Create a comprehensive README.md including:
144+
- {feature name} feature description and purpose
145+
- Setup instructions including environment variables
146+
- Usage instructions with code examples for all {feature name} types
147+
- Common issues and troubleshooting
148+
- References to official documentation
149+
- {feature name} cleanup best practices
150+
151+
# Step 6: Implementation Guidelines
152+
IMPORTANT: MAKE SURE THAT THE Checkout SDK IS INITIALIZED CORRECTLY IN THE SETUPDEFAULT.TS FILE. REFER TO OTHER EXAMPLE APPS LIKE LOGIN-WITH-NEXTJS FOR THE CORRECT SETUP.
153+
## SDK Usage Best Practices
154+
- Use only documented public SDK methods
155+
- If using internal properties, document with comments and type assertions
156+
- Always implement proper cleanup in useEffect hooks
157+
- Use local type definitions instead of importing non-exported types
158+
- Add robust error handling for all {feature name} and operations
159+
- Add TypeScript type guards for any SDK properties that might be undefined
160+
161+
# Step 7: Final Checks
162+
- Ensure that the app can build.
163+
- Ensure that all of the components, etc are used appropriately.
164+
- run `pnpm build` and ensure that the setup is perfect.
165+
- Ensure that there's no problem in all files. Make sure that when using a component, you use the available properties and values.
166+
- Features.json exists and everything make sense
167+
- Always check for the login/logout mode if they are consistent with the features.json file.
168+
169+
## UI Best Practices
170+
- Always ensure that you ONLY use available Biom3 Components without assuming they exist. (Text and Spinner DOES NOT exist in the Biom3 UI Library)
171+
- Use standard HTML elements (h1, h2, h3, p) for text content.
172+
- Use Biom3 Button and other UI components as documented
173+
- Show clear loading/error states
174+
- Keep UI simple and focused on demonstrating the {feature name}
175+
176+
## Critical Error Prevention
177+
- Always check if objects exist before accessing their properties or methods
178+
- Use optional chaining when accessing potentially undefined properties: obj?.prop?.method?.()
179+
- Wrap all {feature name} setup and teardown in try/catch blocks
180+
- Test component mounting/unmounting thoroughly to catch cleanup issues
181+
182+
## ALWAYS READ THIS BEFORE YOU DO ANYTHING
183+
- DO NOT call methods that don't exist on the SDK instances
184+
- DO NOT try to import types that aren't explicitly exported
185+
- DO NOT forget to clean up {feature name} setup and teardown
186+
- DO NOT use custom components or providers unless necessary
187+
- DO NOT modify dependency versions in package.json
188+
- DO NOT use inconsistent import methods (mixing default and named imports)
189+
- DO NOT forget to include 'use client' directive in client components
190+
- DO NOT assume any property or method exists without checking first
191+
- DO NOT MAKE ANY TUTORIAL/METADATA FILE FOR THE {feature name} EXAMPLE APP
192+
- NEVER ADD `"ignoreDuringBuilds": true` TO .eslintrc.json
193+
- ALways do lint checks and never turn it off when building.

0 commit comments

Comments
 (0)