feat: auto-register template creator as referrer via echo.json#739
Open
pannous wants to merge 2 commits intoMerit-Systems:masterfrom
Open
feat: auto-register template creator as referrer via echo.json#739pannous wants to merge 2 commits intoMerit-Systems:masterfrom
pannous wants to merge 2 commits intoMerit-Systems:masterfrom
Conversation
When scaffolding from an external GitHub template that contains an echo.json with a referralCode, echo-start now automatically registers the template creator as the referrer for the new app via the template-referral API. The echo.json file is cleaned up after registration to keep the scaffolded project tidy. Closes Merit-Systems#612
Contributor
|
@pannous is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
Pull request overview
Adds support for “template referrals” so that when users scaffold from an external GitHub template, echo-start can read an echo.json referral code and register the template creator as the referrer for the newly created app.
Changes:
- Extend
echo-startto detectecho.jsonin external templates and call a template-referral API, then clean up the file. - Update Prisma schema to persist a template-referrer referral code relationship on
EchoAppand add the reverse relation onReferralCode. - Document how template creators can embed referral codes in
echo.json.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| packages/sdk/echo-start/src/index.ts | Reads echo.json, calls POST /api/v1/apps/template-referral, and removes echo.json after scaffolding. |
| packages/app/control/prisma/schema.prisma | Adds templateReferrerCodeId / templateReferrerCode to EchoApp and reverse relation on ReferralCode. |
| packages/app/control/docs/money/referrals.mdx | Documents template referral setup and behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+187
to
+193
| 5. The `echo.json` file is removed from the scaffolded project automatically | ||
|
|
||
| ### Important Notes | ||
|
|
||
| - Template referrals are separate from user-to-user referrals | ||
| - Only the first referral code registered per app is kept | ||
| - The referral code must be valid and not expired |
packages/sdk/echo-start/src/index.ts
Outdated
| const configPath = path.join(projectPath, 'echo.json'); | ||
| if (!existsSync(configPath)) return null; | ||
| try { | ||
| return JSON.parse(readFileSync(configPath, 'utf-8')); |
Comment on lines
+459
to
+476
| // Register template referral for external templates | ||
| if (isExternal) { | ||
| const echoConfig = readEchoTemplateConfig(absoluteProjectPath); | ||
| if (echoConfig?.referralCode) { | ||
| const registered = await registerTemplateReferral( | ||
| appId!, | ||
| echoConfig.referralCode | ||
| ); | ||
| if (registered) { | ||
| log.message('Template creator registered as referrer'); | ||
| } | ||
| // Remove echo.json from the scaffolded project — it's only for referral tracking | ||
| const echoConfigPath = path.join(absoluteProjectPath, 'echo.json'); | ||
| if (existsSync(echoConfigPath)) { | ||
| unlinkSync(echoConfigPath); | ||
| } | ||
| } | ||
| } |
| // Remove echo.json from the scaffolded project — it's only for referral tracking | ||
| const echoConfigPath = path.join(absoluteProjectPath, 'echo.json'); | ||
| if (existsSync(echoConfigPath)) { | ||
| unlinkSync(echoConfigPath); |
Comment on lines
+208
to
+214
| const response = await fetch( | ||
| `${ECHO_CONTROL_URL}/api/v1/apps/template-referral`, | ||
| { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ echoAppId: appId, referralCode }), | ||
| } |
Comment on lines
+109
to
+110
| templateReferrerCodeId String? @db.Uuid // Referral code of the external template creator | ||
| templateReferrerCode ReferralCode? @relation("TemplateReferrer", fields: [templateReferrerCodeId], references: [id]) |
- Validate parsed JSON shape and referralCode type in readEchoTemplateConfig - Always remove echo.json for external templates regardless of parse outcome - Wrap unlinkSync in try/catch to avoid aborting scaffolding on cleanup failure - Add missing API route for /api/v1/apps/template-referral - Add Prisma migration for templateReferrerCodeId column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #612
When a user scaffolds an app from an external GitHub template via
echo-start, the CLI now automatically registers the template creator as the referrer for the new app — if the template contains anecho.jsonwith areferralCode.Changes
packages/sdk/echo-start/src/index.ts— AddedreadEchoTemplateConfig()andregisterTemplateReferral()functions. After cloning an external template, ifecho.jsoncontains areferralCode, the CLI callsPOST /api/v1/apps/template-referralto register the referral, then removesecho.jsonfrom the scaffolded project.packages/app/control/prisma/schema.prisma— AddedtemplateReferrerCodeIdandtemplateReferrerCodefields to theEchoAppmodel, plus atemplateReferredAppsreverse relation onReferralCode.packages/app/control/docs/money/referrals.mdx— Added documentation section explaining how template creators can embed referral codes.How it works
echo.jsonwith{ "referralCode": "THEIR_CODE" }to their template reponpx echo-start -t https://github.com/creator/templateecho-startclones the template, detectsecho.json, calls the template-referral APIecho.jsonis cleaned up from the scaffolded projectThe existing
POST /api/v1/apps/template-referralendpoint handles the backend logic.Test plan
echo-startcorrectly readsecho.jsonfrom a cloned external templateappIdandreferralCodeecho.jsonis removed after referral registrationecho.jsonis missing or malformed