feat: udpate script to support --return-url flag [NEYN-6533]

This commit is contained in:
veganbeef 2025-08-07 16:10:19 -07:00
parent 055dc4adbd
commit 55c7c4b129
No known key found for this signature in database
4 changed files with 45 additions and 11 deletions

View File

@ -11,6 +11,7 @@ let noWallet = false;
let noTunnel = false; let noTunnel = false;
let sponsoredSigner = false; let sponsoredSigner = false;
let seedPhrase = null; let seedPhrase = null;
let returnUrl = null;
// Check for -y flag // Check for -y flag
const yIndex = args.indexOf('-y'); const yIndex = args.indexOf('-y');
@ -74,6 +75,19 @@ if (yIndex !== -1) {
console.error('Error: --seed-phrase requires a seed phrase'); console.error('Error: --seed-phrase requires a seed phrase');
process.exit(1); 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); 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); console.error('Error:', err);
process.exit(1); process.exit(1);
}); });

View File

@ -63,7 +63,16 @@ async function queryNeynarApp(apiKey) {
} }
// Export the main CLI function for programmatic use // 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(); printWelcomeMessage();
// Ask about Neynar usage // Ask about Neynar usage
@ -246,6 +255,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe
enableAnalytics: true, enableAnalytics: true,
seedPhrase: seedPhraseValue, seedPhrase: seedPhraseValue,
useSponsoredSigner: useSponsoredSignerValue, useSponsoredSigner: useSponsoredSignerValue,
returnUrl: returnUrl,
}; };
} else { } else {
// If autoAcceptDefaults is false but we have a projectName, we still need to ask for other options // 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, USE_WALLET: /^export const USE_WALLET\s*:\s*boolean\s*=\s*(true|false);$/m,
ANALYTICS_ENABLED: ANALYTICS_ENABLED:
/^export const ANALYTICS_ENABLED\s*:\s*boolean\s*=\s*(true|false);$/m, /^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 // Update APP_NAME
constantsContent = safeReplace( constantsContent = safeReplace(
constantsContent, constantsContent,
patterns.APP_NAME, patterns.APP_NAME,
`export const APP_NAME = '${escapeString(answers.projectName)}';`, `export const APP_NAME: string = '${escapeString(answers.projectName)}';`,
'APP_NAME' 'APP_NAME'
); );
@ -624,7 +635,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe
constantsContent = safeReplace( constantsContent = safeReplace(
constantsContent, constantsContent,
patterns.APP_DESCRIPTION, patterns.APP_DESCRIPTION,
`export const APP_DESCRIPTION = '${escapeString( `export const APP_DESCRIPTION: string = '${escapeString(
answers.description answers.description
)}';`, )}';`,
'APP_DESCRIPTION' 'APP_DESCRIPTION'
@ -634,7 +645,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe
constantsContent = safeReplace( constantsContent = safeReplace(
constantsContent, constantsContent,
patterns.APP_PRIMARY_CATEGORY, patterns.APP_PRIMARY_CATEGORY,
`export const APP_PRIMARY_CATEGORY = '${escapeString( `export const APP_PRIMARY_CATEGORY: string = '${escapeString(
answers.primaryCategory || '' answers.primaryCategory || ''
)}';`, )}';`,
'APP_PRIMARY_CATEGORY' 'APP_PRIMARY_CATEGORY'
@ -648,7 +659,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe
constantsContent = safeReplace( constantsContent = safeReplace(
constantsContent, constantsContent,
patterns.APP_TAGS, patterns.APP_TAGS,
`export const APP_TAGS = ${tagsString};`, `export const APP_TAGS: string[] = ${tagsString};`,
'APP_TAGS' 'APP_TAGS'
); );
@ -656,7 +667,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe
constantsContent = safeReplace( constantsContent = safeReplace(
constantsContent, constantsContent,
patterns.APP_BUTTON_TEXT, patterns.APP_BUTTON_TEXT,
`export const APP_BUTTON_TEXT = '${escapeString( `export const APP_BUTTON_TEXT: string = '${escapeString(
answers.buttonText || '' answers.buttonText || ''
)}';`, )}';`,
'APP_BUTTON_TEXT' 'APP_BUTTON_TEXT'
@ -666,7 +677,7 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe
constantsContent = safeReplace( constantsContent = safeReplace(
constantsContent, constantsContent,
patterns.USE_WALLET, patterns.USE_WALLET,
`export const USE_WALLET = ${answers.useWallet};`, `export const USE_WALLET: boolean = ${answers.useWallet};`,
'USE_WALLET' 'USE_WALLET'
); );
@ -674,10 +685,19 @@ export async function init(projectName = null, autoAcceptDefaults = false, apiKe
constantsContent = safeReplace( constantsContent = safeReplace(
constantsContent, constantsContent,
patterns.ANALYTICS_ENABLED, patterns.ANALYTICS_ENABLED,
`export const ANALYTICS_ENABLED = ${answers.enableAnalytics};`, `export const ANALYTICS_ENABLED: boolean = ${answers.enableAnalytics};`,
'ANALYTICS_ENABLED' '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); fs.writeFileSync(constantsPath, constantsContent);
} else { } else {
console.log('⚠️ constants.ts not found, skipping constants update'); console.log('⚠️ constants.ts not found, skipping constants update');

View File

@ -1,6 +1,6 @@
{ {
"name": "@neynar/create-farcaster-mini-app", "name": "@neynar/create-farcaster-mini-app",
"version": "1.8.4", "version": "1.8.5",
"type": "module", "type": "module",
"private": false, "private": false,
"access": "public", "access": "public",

View File

@ -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 * 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. * 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 // PLEASE DO NOT UPDATE THIS
export const SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN = { export const SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN = {