From 55c7c4b129ca58757398d39c7b2aff3f0cbb05dc Mon Sep 17 00:00:00 2001 From: veganbeef Date: Thu, 7 Aug 2025 16:10:19 -0700 Subject: [PATCH] feat: udpate script to support --return-url flag [NEYN-6533] --- bin/index.js | 16 +++++++++++++++- bin/init.js | 36 ++++++++++++++++++++++++++++-------- package.json | 2 +- src/lib/constants.ts | 2 +- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/bin/index.js b/bin/index.js index 82f597f..4160ecf 100755 --- a/bin/index.js +++ b/bin/index.js @@ -11,6 +11,7 @@ let noWallet = false; let noTunnel = false; let sponsoredSigner = false; let seedPhrase = null; +let returnUrl = null; // Check for -y flag const yIndex = args.indexOf('-y'); @@ -74,6 +75,19 @@ if (yIndex !== -1) { console.error('Error: --seed-phrase requires a seed phrase'); process.exit(1); } + } else if (arg === '-r' || arg === '--return-url') { + if (i + 1 < args.length) { + returnUrl = args[i + 1]; + if (returnUrl.startsWith('-')) { + console.error('Error: Return URL cannot start with a dash (-)'); + process.exit(1); + } + args.splice(i, 2); // Remove both the flag and its value + i--; // Adjust index since we removed 2 elements + } else { + console.error('Error: -r/--return-url requires a return URL'); + process.exit(1); + } } } @@ -85,7 +99,7 @@ if (autoAcceptDefaults && !projectName) { process.exit(1); } -init(projectName, autoAcceptDefaults, apiKey, noWallet, noTunnel, sponsoredSigner, seedPhrase).catch((err) => { +init(projectName, autoAcceptDefaults, apiKey, noWallet, noTunnel, sponsoredSigner, seedPhrase, returnUrl).catch((err) => { console.error('Error:', err); process.exit(1); }); diff --git a/bin/init.js b/bin/init.js index c610a8b..533a928 100644 --- a/bin/init.js +++ b/bin/init.js @@ -63,7 +63,16 @@ async function queryNeynarApp(apiKey) { } // Export the main CLI function for programmatic use -export async function init(projectName = null, autoAcceptDefaults = false, apiKey = null, noWallet = false, noTunnel = false, sponsoredSigner = false, seedPhrase = null) { +export async function init( + projectName = null, + autoAcceptDefaults = false, + apiKey = null, + noWallet = false, + noTunnel = false, + sponsoredSigner = false, + seedPhrase = null, + returnUrl = null +) { printWelcomeMessage(); // Ask about Neynar usage @@ -246,6 +255,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe enableAnalytics: true, seedPhrase: seedPhraseValue, useSponsoredSigner: useSponsoredSignerValue, + returnUrl: returnUrl, }; } else { // If autoAcceptDefaults is false but we have a projectName, we still need to ask for other options @@ -610,13 +620,14 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe USE_WALLET: /^export const USE_WALLET\s*:\s*boolean\s*=\s*(true|false);$/m, ANALYTICS_ENABLED: /^export const ANALYTICS_ENABLED\s*:\s*boolean\s*=\s*(true|false);$/m, + RETURN_URL: /^export const RETURN_URL\s*:\s*string\s*\|\s*undefined\s*=\s*(undefined|['"`][^'"`]*['"`]);$/m, }; // Update APP_NAME constantsContent = safeReplace( constantsContent, patterns.APP_NAME, - `export const APP_NAME = '${escapeString(answers.projectName)}';`, + `export const APP_NAME: string = '${escapeString(answers.projectName)}';`, 'APP_NAME' ); @@ -624,7 +635,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe constantsContent = safeReplace( constantsContent, patterns.APP_DESCRIPTION, - `export const APP_DESCRIPTION = '${escapeString( + `export const APP_DESCRIPTION: string = '${escapeString( answers.description )}';`, 'APP_DESCRIPTION' @@ -634,7 +645,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe constantsContent = safeReplace( constantsContent, patterns.APP_PRIMARY_CATEGORY, - `export const APP_PRIMARY_CATEGORY = '${escapeString( + `export const APP_PRIMARY_CATEGORY: string = '${escapeString( answers.primaryCategory || '' )}';`, 'APP_PRIMARY_CATEGORY' @@ -648,7 +659,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe constantsContent = safeReplace( constantsContent, patterns.APP_TAGS, - `export const APP_TAGS = ${tagsString};`, + `export const APP_TAGS: string[] = ${tagsString};`, 'APP_TAGS' ); @@ -656,7 +667,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe constantsContent = safeReplace( constantsContent, patterns.APP_BUTTON_TEXT, - `export const APP_BUTTON_TEXT = '${escapeString( + `export const APP_BUTTON_TEXT: string = '${escapeString( answers.buttonText || '' )}';`, 'APP_BUTTON_TEXT' @@ -666,7 +677,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe constantsContent = safeReplace( constantsContent, patterns.USE_WALLET, - `export const USE_WALLET = ${answers.useWallet};`, + `export const USE_WALLET: boolean = ${answers.useWallet};`, 'USE_WALLET' ); @@ -674,10 +685,19 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe constantsContent = safeReplace( constantsContent, patterns.ANALYTICS_ENABLED, - `export const ANALYTICS_ENABLED = ${answers.enableAnalytics};`, + `export const ANALYTICS_ENABLED: boolean = ${answers.enableAnalytics};`, 'ANALYTICS_ENABLED' ); + // Update RETURN_URL + const returnUrlValue = answers.returnUrl ? `'${escapeString(answers.returnUrl)}'` : 'undefined'; + constantsContent = safeReplace( + constantsContent, + patterns.RETURN_URL, + `export const RETURN_URL: string | undefined = ${returnUrlValue};`, + 'RETURN_URL' + ); + fs.writeFileSync(constantsPath, constantsContent); } else { console.log('⚠️ constants.ts not found, skipping constants update'); diff --git a/package.json b/package.json index 6c16307..0de0202 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@neynar/create-farcaster-mini-app", - "version": "1.8.4", + "version": "1.8.5", "type": "module", "private": false, "access": "public", diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 109a3c2..696fa31 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -131,7 +131,7 @@ export const APP_REQUIRED_CHAINS: string[] = []; * If provided, the mini app will be rendered with a return URL to be rendered if the * back button is pressed from the home page. */ -export const RETURN_URL: string | null = null; +export const RETURN_URL: string | undefined = undefined; // PLEASE DO NOT UPDATE THIS export const SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN = {