feat: update deploy parsing

This commit is contained in:
lucas-neynar 2025-03-21 14:08:06 -07:00
parent 01231de8f4
commit 28cafb2808
No known key found for this signature in database
3 changed files with 112 additions and 69 deletions

View File

@ -17,6 +17,12 @@ cd <PROJECT_NAME>
npm run dev npm run dev
``` ```
## Deploy to Vercel
For projects that have made minimal changes to the quickstart template, deploy to vercel by running:
```{bash}
npm run deploy:vercel
```
## Building for Production ## Building for Production
To create a production build, run: To create a production build, run:

View File

@ -1,6 +1,6 @@
{ {
"name": "create-neynar-farcaster-frame", "name": "create-neynar-farcaster-frame",
"version": "1.1.6", "version": "1.1.7",
"type": "module", "type": "module",
"files": [ "files": [
"bin/index.js" "bin/index.js"

View File

@ -373,13 +373,7 @@ async function deployToVercel(useGitHub = false) {
...(process.env.NEYNAR_API_KEY && { NEYNAR_API_KEY: process.env.NEYNAR_API_KEY }), ...(process.env.NEYNAR_API_KEY && { NEYNAR_API_KEY: process.env.NEYNAR_API_KEY }),
...(process.env.NEYNAR_CLIENT_ID && { NEYNAR_CLIENT_ID: process.env.NEYNAR_CLIENT_ID }), ...(process.env.NEYNAR_CLIENT_ID && { NEYNAR_CLIENT_ID: process.env.NEYNAR_CLIENT_ID }),
// Frame metadata and images // Frame metadata
...(process.env.NEXT_PUBLIC_FRAME_SPLASH_IMAGE_URL && {
NEXT_PUBLIC_FRAME_SPLASH_IMAGE_URL: process.env.NEXT_PUBLIC_FRAME_SPLASH_IMAGE_URL
}),
...(process.env.NEXT_PUBLIC_FRAME_ICON_IMAGE_URL && {
NEXT_PUBLIC_FRAME_ICON_IMAGE_URL: process.env.NEXT_PUBLIC_FRAME_ICON_IMAGE_URL
}),
...(frameMetadata && { FRAME_METADATA: frameMetadata }), ...(frameMetadata && { FRAME_METADATA: frameMetadata }),
// Public vars // Public vars
@ -388,8 +382,6 @@ async function deployToVercel(useGitHub = false) {
.filter(([key]) => key.startsWith('NEXT_PUBLIC_')) .filter(([key]) => key.startsWith('NEXT_PUBLIC_'))
) )
}; };
console.log('vercelEnv');
console.log(vercelEnv);
// Add or update env vars in Vercel project // Add or update env vars in Vercel project
console.log('\n📝 Setting up environment variables...'); console.log('\n📝 Setting up environment variables...');
@ -439,88 +431,133 @@ async function deployToVercel(useGitHub = false) {
// Verify the actual domain after deployment // Verify the actual domain after deployment
console.log('\n🔍 Verifying deployment domain...'); console.log('\n🔍 Verifying deployment domain...');
const projectOutput = execSync('vercel project ls', {
cwd: projectRoot,
encoding: 'utf8',
stdio: ['inherit', 'pipe', 'inherit'] // Capture stdout but show stderr
});
const projectLines = projectOutput.split('\n'); // Create a temporary file path
console.log('Project lines:', projectLines); const tempOutputFile = path.join(projectRoot, 'vercel_output.txt');
// Find the line containing our project name try {
const currentProject = projectLines.find(line => // Redirect output to a file
line.includes(projectName) && line.includes('https://') execSync(`vercel project ls > "${tempOutputFile}" 2>&1`, {
); cwd: projectRoot,
shell: true
});
console.log('Current project line:', currentProject); // Read the output file
const projectOutput = fs.readFileSync(tempOutputFile, 'utf8');
console.log('Raw project output:', projectOutput);
if (currentProject) { // Process the output
// Extract the domain from the line const projectLines = projectOutput
const domainMatch = currentProject.match(/https:\/\/([^\s]+)/); .split('\n')
if (domainMatch) { .filter(line => line.includes('https://'));
const actualDomain = domainMatch[1];
if (actualDomain !== domain) {
console.log(`⚠️ Actual domain (${actualDomain}) differs from assumed domain (${domain})`);
console.log('🔄 Updating environment variables with correct domain...');
// Update domain-dependent environment variables console.log('Project lines:', projectLines);
const webhookUrl = process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID
? `https://api.neynar.com/f/app/${process.env.NEYNAR_CLIENT_ID}/event`
: `https://${actualDomain}/api/webhook`;
if (frameMetadata) { // Find the line containing our project name
frameMetadata = await generateFarcasterMetadata(actualDomain, await validateSeedPhrase(process.env.SEED_PHRASE), process.env.SEED_PHRASE, webhookUrl); const currentProject = projectLines.find(line =>
// Update FRAME_METADATA env var line.includes(projectName)
);
console.log('Current project line:', currentProject);
if (currentProject) {
// Extract the domain from the line
const domainMatch = currentProject.match(/https:\/\/([^\s]+)/);
if (domainMatch) {
const actualDomain = domainMatch[1];
if (actualDomain !== domain) {
console.log(`⚠️ Actual domain (${actualDomain}) differs from assumed domain (${domain})`);
console.log('🔄 Updating environment variables with correct domain...');
// Update domain-dependent environment variables
const webhookUrl = process.env.NEYNAR_API_KEY && process.env.NEYNAR_CLIENT_ID
? `https://api.neynar.com/f/app/${process.env.NEYNAR_CLIENT_ID}/event`
: `https://${actualDomain}/api/webhook`;
if (frameMetadata) {
frameMetadata = await generateFarcasterMetadata(actualDomain, await validateSeedPhrase(process.env.SEED_PHRASE), process.env.SEED_PHRASE, webhookUrl);
// Update FRAME_METADATA env var
try {
execSync(`vercel env rm FRAME_METADATA production -y`, {
cwd: projectRoot,
stdio: 'ignore',
env: process.env
});
execSync(`printf "%s" "${frameMetadata}" | vercel env add FRAME_METADATA production`, {
cwd: projectRoot,
stdio: 'inherit',
env: process.env
});
} catch (error) {
console.warn('⚠️ Warning: Failed to update FRAME_METADATA with correct domain');
}
}
// Update NEXTAUTH_URL
try { try {
execSync(`vercel env rm FRAME_METADATA production -y`, { execSync(`vercel env rm NEXTAUTH_URL production -y`, {
cwd: projectRoot, cwd: projectRoot,
stdio: 'ignore', stdio: 'ignore',
env: process.env env: process.env
}); });
execSync(`printf "%s" "${frameMetadata}" | vercel env add FRAME_METADATA production`, { execSync(`printf "%s" "https://${actualDomain}" | vercel env add NEXTAUTH_URL production`, {
cwd: projectRoot, cwd: projectRoot,
stdio: 'inherit', stdio: 'inherit',
env: process.env env: process.env
}); });
} catch (error) { } catch (error) {
console.warn('⚠️ Warning: Failed to update FRAME_METADATA with correct domain'); console.warn('⚠️ Warning: Failed to update NEXTAUTH_URL with correct domain');
} }
}
// Update NEXTAUTH_URL // Update NEXT_PUBLIC_URL
try { try {
execSync(`vercel env rm NEXTAUTH_URL production -y`, { execSync(`vercel env rm NEXT_PUBLIC_URL production -y`, {
cwd: projectRoot, cwd: projectRoot,
stdio: 'ignore', stdio: 'ignore',
env: process.env env: process.env
}); });
execSync(`printf "%s" "https://${actualDomain}" | vercel env add NEXTAUTH_URL production`, { execSync(`printf "%s" "https://${actualDomain}" | vercel env add NEXT_PUBLIC_URL production`, {
cwd: projectRoot,
stdio: 'inherit',
env: process.env
});
} catch (error) {
console.warn('⚠️ Warning: Failed to update NEXT_PUBLIC_URL with correct domain');
}
// Redeploy with updated environment variables
console.log('\n📦 Redeploying with correct domain...');
execSync('vercel deploy --prod', {
cwd: projectRoot, cwd: projectRoot,
stdio: 'inherit', stdio: 'inherit',
env: process.env env: process.env
}); });
} catch (error) {
console.warn('⚠️ Warning: Failed to update NEXTAUTH_URL with correct domain'); domain = actualDomain;
} }
} else {
// Redeploy with updated environment variables console.warn('⚠️ Could not extract domain from project line');
console.log('\n📦 Redeploying with correct domain...');
execSync('vercel deploy --prod', {
cwd: projectRoot,
stdio: 'inherit',
env: process.env
});
domain = actualDomain;
} }
} else { } else {
console.warn('⚠️ Could not extract domain from project line'); console.warn('⚠️ Could not find project in Vercel project list');
} }
} else {
console.warn('⚠️ Could not find project in Vercel project list');
}
// Clean up the temporary file
fs.unlinkSync(tempOutputFile);
} catch (error) {
console.error('Error:', error);
// Try to read the output file even if there was an error
try {
if (fs.existsSync(tempOutputFile)) {
const errorOutput = fs.readFileSync(tempOutputFile, 'utf8');
console.log('Error output file contents:', errorOutput);
fs.unlinkSync(tempOutputFile);
}
} catch (readError) {
console.error('Error reading output file:', readError);
}
}
console.log('\n✨ Deployment complete! Your frame is now live at:'); console.log('\n✨ Deployment complete! Your frame is now live at:');
console.log(`🌐 https://${domain}`); console.log(`🌐 https://${domain}`);