mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-18 17:09:47 -05:00
Format after fixing conflicts
This commit is contained in:
178
scripts/build.js
178
scripts/build.js
@@ -1,36 +1,37 @@
|
||||
import { execSync } from "child_process";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import inquirer from "inquirer";
|
||||
import dotenv from "dotenv";
|
||||
import crypto from "crypto";
|
||||
import { execSync } from 'child_process';
|
||||
import crypto from 'crypto';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import dotenv from 'dotenv';
|
||||
import inquirer from 'inquirer';
|
||||
|
||||
// Load environment variables in specific order
|
||||
// First load .env for main config
|
||||
dotenv.config({ path: ".env" });
|
||||
dotenv.config({ path: '.env' });
|
||||
|
||||
async function loadEnvLocal() {
|
||||
try {
|
||||
if (fs.existsSync(".env.local")) {
|
||||
if (fs.existsSync('.env.local')) {
|
||||
const { loadLocal } = await inquirer.prompt([
|
||||
{
|
||||
type: "confirm",
|
||||
name: "loadLocal",
|
||||
type: 'confirm',
|
||||
name: 'loadLocal',
|
||||
message:
|
||||
"Found .env.local, likely created by the install script - would you like to load its values?",
|
||||
'Found .env.local, likely created by the install script - would you like to load its values?',
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
|
||||
const localEnv = dotenv.parse(fs.readFileSync('.env.local'));
|
||||
|
||||
if (loadLocal) {
|
||||
console.log("Loading values from .env.local...");
|
||||
const localEnv = dotenv.parse(fs.readFileSync(".env.local"));
|
||||
console.log('Loading values from .env.local...');
|
||||
|
||||
// Copy all values to .env
|
||||
const envContent = fs.existsSync(".env")
|
||||
? fs.readFileSync(".env", "utf8") + "\n"
|
||||
: "";
|
||||
const envContent = fs.existsSync('.env')
|
||||
? fs.readFileSync('.env', 'utf8') + '\n'
|
||||
: '';
|
||||
let newEnvContent = envContent;
|
||||
|
||||
for (const [key, value] of Object.entries(localEnv)) {
|
||||
@@ -43,8 +44,8 @@ async function loadEnvLocal() {
|
||||
}
|
||||
|
||||
// Write updated content to .env
|
||||
fs.writeFileSync(".env", newEnvContent);
|
||||
console.log("✅ Values from .env.local have been written to .env");
|
||||
fs.writeFileSync('.env', newEnvContent);
|
||||
console.log('✅ Values from .env.local have been written to .env');
|
||||
}
|
||||
if (localEnv.SPONSOR_SIGNER) {
|
||||
process.env.SPONSOR_SIGNER = localEnv.SPONSOR_SIGNER;
|
||||
@@ -52,26 +53,26 @@ async function loadEnvLocal() {
|
||||
}
|
||||
} catch (error) {
|
||||
// Error reading .env.local, which is fine
|
||||
console.log("Note: No .env.local file found");
|
||||
console.log('Note: No .env.local file found');
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make sure rebuilding is supported
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const projectRoot = path.join(__dirname, "..");
|
||||
const projectRoot = path.join(__dirname, '..');
|
||||
|
||||
async function validateDomain(domain) {
|
||||
// Remove http:// or https:// if present
|
||||
const cleanDomain = domain.replace(/^https?:\/\//, "");
|
||||
const cleanDomain = domain.replace(/^https?:\/\//, '');
|
||||
|
||||
// Basic domain validation
|
||||
if (
|
||||
!cleanDomain.match(
|
||||
/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/
|
||||
/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/,
|
||||
)
|
||||
) {
|
||||
throw new Error("Invalid domain format");
|
||||
throw new Error('Invalid domain format');
|
||||
}
|
||||
|
||||
return cleanDomain;
|
||||
@@ -83,39 +84,39 @@ async function queryNeynarApp(apiKey) {
|
||||
}
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.neynar.com/portal/app_by_api_key`,
|
||||
'https://api.neynar.com/portal/app_by_api_key',
|
||||
{
|
||||
headers: {
|
||||
"x-api-key": apiKey,
|
||||
'x-api-key': apiKey,
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error querying Neynar app data:", error);
|
||||
console.error('Error querying Neynar app data:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function generateFarcasterMetadata(domain, webhookUrl) {
|
||||
const tags = process.env.NEXT_PUBLIC_MINI_APP_TAGS?.split(",");
|
||||
const tags = process.env.NEXT_PUBLIC_MINI_APP_TAGS?.split(',');
|
||||
|
||||
return {
|
||||
accountAssociation: {
|
||||
header: "",
|
||||
payload: "",
|
||||
signature: "",
|
||||
header: '',
|
||||
payload: '',
|
||||
signature: '',
|
||||
},
|
||||
frame: {
|
||||
version: "1",
|
||||
version: '1',
|
||||
name: process.env.NEXT_PUBLIC_MINI_APP_NAME,
|
||||
iconUrl: `https://${domain}/icon.png`,
|
||||
homeUrl: `https://${domain}`,
|
||||
imageUrl: `https://${domain}/api/opengraph-image`,
|
||||
buttonTitle: process.env.NEXT_PUBLIC_MINI_APP_BUTTON_TEXT,
|
||||
splashImageUrl: `https://${domain}/splash.png`,
|
||||
splashBackgroundColor: "#f7f7f7",
|
||||
splashBackgroundColor: '#f7f7f7',
|
||||
webhookUrl,
|
||||
description: process.env.NEXT_PUBLIC_MINI_APP_DESCRIPTION,
|
||||
primaryCategory: process.env.NEXT_PUBLIC_MINI_APP_PRIMARY_CATEGORY,
|
||||
@@ -126,8 +127,8 @@ async function generateFarcasterMetadata(domain, webhookUrl) {
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.log("\n📝 Checking environment variables...");
|
||||
console.log("Loading values from .env...");
|
||||
console.log('\n📝 Checking environment variables...');
|
||||
console.log('Loading values from .env...');
|
||||
|
||||
// Load .env.local if user wants to
|
||||
await loadEnvLocal();
|
||||
@@ -135,11 +136,11 @@ async function main() {
|
||||
// Get domain from user
|
||||
const { domain } = await inquirer.prompt([
|
||||
{
|
||||
type: "input",
|
||||
name: "domain",
|
||||
type: 'input',
|
||||
name: 'domain',
|
||||
message:
|
||||
"Enter the domain where your mini app will be deployed (e.g., example.com):",
|
||||
validate: async (input) => {
|
||||
'Enter the domain where your mini app will be deployed (e.g., example.com):',
|
||||
validate: async input => {
|
||||
try {
|
||||
await validateDomain(input);
|
||||
return true;
|
||||
@@ -153,13 +154,13 @@ async function main() {
|
||||
// Get frame name from user
|
||||
const { frameName } = await inquirer.prompt([
|
||||
{
|
||||
type: "input",
|
||||
name: "frameName",
|
||||
message: "Enter the name for your mini app (e.g., My Cool Mini App):",
|
||||
type: 'input',
|
||||
name: 'frameName',
|
||||
message: 'Enter the name for your mini app (e.g., My Cool Mini App):',
|
||||
default: process.env.NEXT_PUBLIC_MINI_APP_NAME,
|
||||
validate: (input) => {
|
||||
if (input.trim() === "") {
|
||||
return "Mini app name cannot be empty";
|
||||
validate: input => {
|
||||
if (input.trim() === '') {
|
||||
return 'Mini app name cannot be empty';
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@@ -169,14 +170,14 @@ async function main() {
|
||||
// Get button text from user
|
||||
const { buttonText } = await inquirer.prompt([
|
||||
{
|
||||
type: "input",
|
||||
name: "buttonText",
|
||||
message: "Enter the text for your mini app button:",
|
||||
type: 'input',
|
||||
name: 'buttonText',
|
||||
message: 'Enter the text for your mini app button:',
|
||||
default:
|
||||
process.env.NEXT_PUBLIC_MINI_APP_BUTTON_TEXT || "Launch Mini App",
|
||||
validate: (input) => {
|
||||
if (input.trim() === "") {
|
||||
return "Button text cannot be empty";
|
||||
process.env.NEXT_PUBLIC_MINI_APP_BUTTON_TEXT || 'Launch Mini App',
|
||||
validate: input => {
|
||||
if (input.trim() === '') {
|
||||
return 'Button text cannot be empty';
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@@ -192,16 +193,16 @@ async function main() {
|
||||
if (!neynarApiKey) {
|
||||
const { neynarApiKey: inputNeynarApiKey } = await inquirer.prompt([
|
||||
{
|
||||
type: "password",
|
||||
name: "neynarApiKey",
|
||||
type: 'password',
|
||||
name: 'neynarApiKey',
|
||||
message:
|
||||
"Enter your Neynar API key (optional - leave blank to skip):",
|
||||
'Enter your Neynar API key (optional - leave blank to skip):',
|
||||
default: null,
|
||||
},
|
||||
]);
|
||||
neynarApiKey = inputNeynarApiKey;
|
||||
} else {
|
||||
console.log("Using existing Neynar API key from .env");
|
||||
console.log('Using existing Neynar API key from .env');
|
||||
}
|
||||
|
||||
if (!neynarApiKey) {
|
||||
@@ -214,7 +215,7 @@ async function main() {
|
||||
const appInfo = await queryNeynarApp(neynarApiKey);
|
||||
if (appInfo) {
|
||||
neynarClientId = appInfo.app_uuid;
|
||||
console.log("✅ Fetched Neynar app client ID");
|
||||
console.log('✅ Fetched Neynar app client ID');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -226,13 +227,13 @@ async function main() {
|
||||
|
||||
// If we get here, the API key was invalid
|
||||
console.log(
|
||||
"\n⚠️ Could not find Neynar app information. The API key may be incorrect."
|
||||
'\n⚠️ Could not find Neynar app information. The API key may be incorrect.',
|
||||
);
|
||||
const { retry } = await inquirer.prompt([
|
||||
{
|
||||
type: "confirm",
|
||||
name: "retry",
|
||||
message: "Would you like to try a different API key?",
|
||||
type: 'confirm',
|
||||
name: 'retry',
|
||||
message: 'Would you like to try a different API key?',
|
||||
default: true,
|
||||
},
|
||||
]);
|
||||
@@ -248,7 +249,7 @@ async function main() {
|
||||
}
|
||||
|
||||
// Generate manifest
|
||||
console.log("\n🔨 Generating mini app manifest...");
|
||||
console.log('\n🔨 Generating mini app manifest...');
|
||||
|
||||
// Determine webhook URL based on environment variables
|
||||
const webhookUrl =
|
||||
@@ -257,13 +258,13 @@ async function main() {
|
||||
: `https://${domain}/api/webhook`;
|
||||
|
||||
const metadata = await generateFarcasterMetadata(domain, webhookUrl);
|
||||
console.log("\n✅ Mini app manifest generated");
|
||||
console.log('\n✅ Mini app manifest generated');
|
||||
|
||||
// Read existing .env file or create new one
|
||||
const envPath = path.join(projectRoot, ".env");
|
||||
const envPath = path.join(projectRoot, '.env');
|
||||
let envContent = fs.existsSync(envPath)
|
||||
? fs.readFileSync(envPath, "utf8")
|
||||
: "";
|
||||
? fs.readFileSync(envPath, 'utf8')
|
||||
: '';
|
||||
|
||||
// Add or update environment variables
|
||||
const newEnvVars = [
|
||||
@@ -273,19 +274,19 @@ async function main() {
|
||||
// Mini app metadata
|
||||
`NEXT_PUBLIC_MINI_APP_NAME="${frameName}"`,
|
||||
`NEXT_PUBLIC_MINI_APP_DESCRIPTION="${
|
||||
process.env.NEXT_PUBLIC_MINI_APP_DESCRIPTION || ""
|
||||
process.env.NEXT_PUBLIC_MINI_APP_DESCRIPTION || ''
|
||||
}"`,
|
||||
`NEXT_PUBLIC_MINI_APP_PRIMARY_CATEGORY="${
|
||||
process.env.NEXT_PUBLIC_MINI_APP_PRIMARY_CATEGORY || ""
|
||||
process.env.NEXT_PUBLIC_MINI_APP_PRIMARY_CATEGORY || ''
|
||||
}"`,
|
||||
`NEXT_PUBLIC_MINI_APP_TAGS="${
|
||||
process.env.NEXT_PUBLIC_MINI_APP_TAGS || ""
|
||||
process.env.NEXT_PUBLIC_MINI_APP_TAGS || ''
|
||||
}"`,
|
||||
`NEXT_PUBLIC_MINI_APP_BUTTON_TEXT="${buttonText}"`,
|
||||
|
||||
// Analytics
|
||||
`NEXT_PUBLIC_ANALYTICS_ENABLED="${
|
||||
process.env.NEXT_PUBLIC_ANALYTICS_ENABLED || "false"
|
||||
process.env.NEXT_PUBLIC_ANALYTICS_ENABLED || 'false'
|
||||
}"`,
|
||||
|
||||
// Neynar configuration (if it exists in current env)
|
||||
@@ -293,18 +294,19 @@ async function main() {
|
||||
? [`NEYNAR_API_KEY="${process.env.NEYNAR_API_KEY}"`]
|
||||
: []),
|
||||
...(neynarClientId ? [`NEYNAR_CLIENT_ID="${neynarClientId}"`] : []),
|
||||
...(process.env.SPONSOR_SIGNER ?
|
||||
[`SPONSOR_SIGNER="${process.env.SPONSOR_SIGNER}"`] : []),
|
||||
...(process.env.SPONSOR_SIGNER
|
||||
? [`SPONSOR_SIGNER="${process.env.SPONSOR_SIGNER}"`]
|
||||
: []),
|
||||
|
||||
// FID (if it exists in current env)
|
||||
...(process.env.FID ? [`FID="${process.env.FID}"`] : []),
|
||||
`NEXT_PUBLIC_USE_WALLET="${
|
||||
process.env.NEXT_PUBLIC_USE_WALLET || "false"
|
||||
process.env.NEXT_PUBLIC_USE_WALLET || 'false'
|
||||
}"`,
|
||||
|
||||
// NextAuth configuration
|
||||
`NEXTAUTH_SECRET="${
|
||||
process.env.NEXTAUTH_SECRET || crypto.randomBytes(32).toString("hex")
|
||||
process.env.NEXTAUTH_SECRET || crypto.randomBytes(32).toString('hex')
|
||||
}"`,
|
||||
`NEXTAUTH_URL="https://${domain}"`,
|
||||
|
||||
@@ -313,14 +315,14 @@ async function main() {
|
||||
];
|
||||
|
||||
// Filter out empty values and join with newlines
|
||||
const validEnvVars = newEnvVars.filter((line) => {
|
||||
const [, value] = line.split("=");
|
||||
const validEnvVars = newEnvVars.filter(line => {
|
||||
const [, value] = line.split('=');
|
||||
return value && value !== '""';
|
||||
});
|
||||
|
||||
// Update or append each environment variable
|
||||
validEnvVars.forEach((varLine) => {
|
||||
const [key] = varLine.split("=");
|
||||
validEnvVars.forEach(varLine => {
|
||||
const [key] = varLine.split('=');
|
||||
if (envContent.includes(`${key}=`)) {
|
||||
envContent = envContent.replace(new RegExp(`${key}=.*`), varLine);
|
||||
} else {
|
||||
@@ -331,29 +333,29 @@ async function main() {
|
||||
// Write updated .env file
|
||||
fs.writeFileSync(envPath, envContent);
|
||||
|
||||
console.log("\n✅ Environment variables updated");
|
||||
console.log('\n✅ Environment variables updated');
|
||||
|
||||
// Run next build
|
||||
console.log("\nBuilding Next.js application...");
|
||||
console.log('\nBuilding Next.js application...');
|
||||
const nextBin = path.normalize(
|
||||
path.join(projectRoot, "node_modules", ".bin", "next")
|
||||
path.join(projectRoot, 'node_modules', '.bin', 'next'),
|
||||
);
|
||||
execSync(`"${nextBin}" build`, {
|
||||
cwd: projectRoot,
|
||||
stdio: "inherit",
|
||||
shell: process.platform === "win32",
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32',
|
||||
});
|
||||
|
||||
console.log(
|
||||
"\n✨ Build complete! Your mini app is ready for deployment. 🪐"
|
||||
'\n✨ Build complete! Your mini app is ready for deployment. 🪐',
|
||||
);
|
||||
console.log(
|
||||
"📝 Make sure to configure the environment variables from .env in your hosting provider"
|
||||
'📝 Make sure to configure the environment variables from .env in your hosting provider',
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("\n❌ Error:", error.message);
|
||||
console.error('\n❌ Error:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { execSync, spawn } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import { fileURLToPath } from 'url';
|
||||
import inquirer from 'inquirer';
|
||||
import dotenv from 'dotenv';
|
||||
import crypto from 'crypto';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { Vercel } from '@vercel/sdk';
|
||||
import dotenv from 'dotenv';
|
||||
import inquirer from 'inquirer';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const projectRoot = path.join(__dirname, '..');
|
||||
@@ -99,20 +99,19 @@ async function checkRequiredEnvVars() {
|
||||
name: 'NEXT_PUBLIC_MINI_APP_NAME',
|
||||
message: 'Enter the name for your frame (e.g., My Cool Mini App):',
|
||||
default: process.env.NEXT_PUBLIC_MINI_APP_NAME,
|
||||
validate: (input) =>
|
||||
input.trim() !== '' || 'Mini app name cannot be empty',
|
||||
validate: input => input.trim() !== '' || 'Mini app name cannot be empty',
|
||||
},
|
||||
{
|
||||
name: 'NEXT_PUBLIC_MINI_APP_BUTTON_TEXT',
|
||||
message: 'Enter the text for your frame button:',
|
||||
default:
|
||||
process.env.NEXT_PUBLIC_MINI_APP_BUTTON_TEXT ?? 'Launch Mini App',
|
||||
validate: (input) => input.trim() !== '' || 'Button text cannot be empty',
|
||||
validate: input => input.trim() !== '' || 'Button text cannot be empty',
|
||||
},
|
||||
];
|
||||
|
||||
const missingVars = requiredVars.filter(
|
||||
(varConfig) => !process.env[varConfig.name]
|
||||
varConfig => !process.env[varConfig.name],
|
||||
);
|
||||
|
||||
if (missingVars.length > 0) {
|
||||
@@ -138,7 +137,7 @@ async function checkRequiredEnvVars() {
|
||||
const newLine = envContent ? '\n' : '';
|
||||
fs.appendFileSync(
|
||||
'.env',
|
||||
`${newLine}${varConfig.name}="${value.trim()}"`
|
||||
`${newLine}${varConfig.name}="${value.trim()}"`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -161,7 +160,7 @@ async function checkRequiredEnvVars() {
|
||||
if (storeSeedPhrase) {
|
||||
fs.appendFileSync(
|
||||
'.env.local',
|
||||
`\nSPONSOR_SIGNER="${sponsorSigner}"`
|
||||
`\nSPONSOR_SIGNER="${sponsorSigner}"`,
|
||||
);
|
||||
console.log('✅ Sponsor signer preference stored in .env.local');
|
||||
}
|
||||
@@ -244,7 +243,7 @@ async function getVercelToken() {
|
||||
return null; // We'll fall back to CLI operations
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'Not logged in to Vercel CLI. Please run this script again to login.'
|
||||
'Not logged in to Vercel CLI. Please run this script again to login.',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -260,7 +259,7 @@ async function loginToVercel() {
|
||||
console.log('3. Complete the Vercel account setup in your browser');
|
||||
console.log('4. Return here once your Vercel account is created\n');
|
||||
console.log(
|
||||
'\nNote: you may need to cancel this script with ctrl+c and run it again if creating a new vercel account'
|
||||
'\nNote: you may need to cancel this script with ctrl+c and run it again if creating a new vercel account',
|
||||
);
|
||||
|
||||
const child = spawn('vercel', ['login'], {
|
||||
@@ -268,14 +267,14 @@ async function loginToVercel() {
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
child.on('close', (code) => {
|
||||
child.on('close', code => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
console.log('\n📱 Waiting for login to complete...');
|
||||
console.log(
|
||||
"If you're creating a new account, please complete the Vercel account setup in your browser first."
|
||||
"If you're creating a new account, please complete the Vercel account setup in your browser first.",
|
||||
);
|
||||
|
||||
for (let i = 0; i < 150; i++) {
|
||||
@@ -287,7 +286,7 @@ async function loginToVercel() {
|
||||
if (error.message.includes('Account not found')) {
|
||||
console.log('ℹ️ Waiting for Vercel account setup to complete...');
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +312,7 @@ async function setVercelEnvVarSDK(vercelClient, projectId, key, value) {
|
||||
});
|
||||
|
||||
const existingVar = existingVars.envs?.find(
|
||||
(env) => env.key === key && env.target?.includes('production')
|
||||
env => env.key === key && env.target?.includes('production'),
|
||||
);
|
||||
|
||||
if (existingVar) {
|
||||
@@ -345,7 +344,7 @@ async function setVercelEnvVarSDK(vercelClient, projectId, key, value) {
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`⚠️ Warning: Failed to set environment variable ${key}:`,
|
||||
error.message
|
||||
error.message,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@@ -400,7 +399,7 @@ async function setVercelEnvVarCLI(key, value, projectRoot) {
|
||||
}
|
||||
console.warn(
|
||||
`⚠️ Warning: Failed to set environment variable ${key}:`,
|
||||
error.message
|
||||
error.message,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@@ -410,7 +409,7 @@ async function setEnvironmentVariables(
|
||||
vercelClient,
|
||||
projectId,
|
||||
envVars,
|
||||
projectRoot
|
||||
projectRoot,
|
||||
) {
|
||||
console.log('\n📝 Setting up environment variables...');
|
||||
|
||||
@@ -435,12 +434,12 @@ async function setEnvironmentVariables(
|
||||
}
|
||||
|
||||
// Report results
|
||||
const failed = results.filter((r) => !r.success);
|
||||
const failed = results.filter(r => !r.success);
|
||||
if (failed.length > 0) {
|
||||
console.warn(`\n⚠️ Failed to set ${failed.length} environment variables:`);
|
||||
failed.forEach((r) => console.warn(` - ${r.key}`));
|
||||
failed.forEach(r => console.warn(` - ${r.key}`));
|
||||
console.warn(
|
||||
'\nYou may need to set these manually in the Vercel dashboard.'
|
||||
'\nYou may need to set these manually in the Vercel dashboard.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -450,7 +449,7 @@ async function setEnvironmentVariables(
|
||||
async function waitForDeployment(
|
||||
vercelClient,
|
||||
projectId,
|
||||
maxWaitTime = 300000
|
||||
maxWaitTime = 300000,
|
||||
) {
|
||||
// 5 minutes
|
||||
console.log('\n⏳ Waiting for deployment to complete...');
|
||||
@@ -477,14 +476,14 @@ async function waitForDeployment(
|
||||
}
|
||||
|
||||
// Still building, wait and check again
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait 5 seconds
|
||||
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5 seconds
|
||||
} else {
|
||||
console.log('⏳ No deployment found yet, waiting...');
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('⚠️ Could not check deployment status:', error.message);
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,18 +506,18 @@ async function deployToVercel(useGitHub = false) {
|
||||
framework: 'nextjs',
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Set up Vercel project
|
||||
console.log('\n📦 Setting up Vercel project...');
|
||||
console.log(
|
||||
'An initial deployment is required to get an assigned domain that can be used in the mini app manifest\n'
|
||||
'An initial deployment is required to get an assigned domain that can be used in the mini app manifest\n',
|
||||
);
|
||||
console.log(
|
||||
'\n⚠️ Note: choosing a longer, more unique project name will help avoid conflicts with other existing domains\n'
|
||||
'\n⚠️ Note: choosing a longer, more unique project name will help avoid conflicts with other existing domains\n',
|
||||
);
|
||||
|
||||
// Use spawn instead of execSync for better error handling
|
||||
@@ -530,7 +529,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
vercelSetup.on('close', (code) => {
|
||||
vercelSetup.on('close', code => {
|
||||
if (code === 0 || code === null) {
|
||||
console.log('✅ Vercel project setup completed');
|
||||
resolve();
|
||||
@@ -540,25 +539,25 @@ async function deployToVercel(useGitHub = false) {
|
||||
}
|
||||
});
|
||||
|
||||
vercelSetup.on('error', (error) => {
|
||||
vercelSetup.on('error', error => {
|
||||
console.log('⚠️ Vercel setup command completed (this is normal)');
|
||||
resolve(); // Don't reject, as this is often expected
|
||||
});
|
||||
});
|
||||
|
||||
// Wait a moment for project files to be written
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
// Load project info
|
||||
let projectId;
|
||||
try {
|
||||
const projectJson = JSON.parse(
|
||||
fs.readFileSync('.vercel/project.json', 'utf8')
|
||||
fs.readFileSync('.vercel/project.json', 'utf8'),
|
||||
);
|
||||
projectId = projectJson.projectId;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
'Failed to load project info. Please ensure the Vercel project was created successfully.'
|
||||
'Failed to load project info. Please ensure the Vercel project was created successfully.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -574,7 +573,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'⚠️ Could not initialize Vercel SDK, falling back to CLI operations'
|
||||
'⚠️ Could not initialize Vercel SDK, falling back to CLI operations',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -593,7 +592,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
console.log('🌐 Using project name for domain:', domain);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'⚠️ Could not get project details via SDK, using CLI fallback'
|
||||
'⚠️ Could not get project details via SDK, using CLI fallback',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -606,7 +605,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
{
|
||||
cwd: projectRoot,
|
||||
encoding: 'utf8',
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const nameMatch = inspectOutput.match(/Name\s+([^\n]+)/);
|
||||
@@ -622,7 +621,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
console.log('🌐 Using project name for domain:', domain);
|
||||
} else {
|
||||
console.warn(
|
||||
'⚠️ Could not determine project name from inspection, using fallback'
|
||||
'⚠️ Could not determine project name from inspection, using fallback',
|
||||
);
|
||||
// Use a fallback domain based on project ID
|
||||
domain = `project-${projectId.slice(-8)}.vercel.app`;
|
||||
@@ -670,8 +669,8 @@ async function deployToVercel(useGitHub = false) {
|
||||
|
||||
...Object.fromEntries(
|
||||
Object.entries(process.env).filter(([key]) =>
|
||||
key.startsWith('NEXT_PUBLIC_')
|
||||
)
|
||||
key.startsWith('NEXT_PUBLIC_'),
|
||||
),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -680,7 +679,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
vercelClient,
|
||||
projectId,
|
||||
vercelEnv,
|
||||
projectRoot
|
||||
projectRoot,
|
||||
);
|
||||
|
||||
// Deploy the project
|
||||
@@ -704,7 +703,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
vercelDeploy.on('close', (code) => {
|
||||
vercelDeploy.on('close', code => {
|
||||
if (code === 0) {
|
||||
console.log('✅ Vercel deployment command completed');
|
||||
resolve();
|
||||
@@ -714,7 +713,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
}
|
||||
});
|
||||
|
||||
vercelDeploy.on('error', (error) => {
|
||||
vercelDeploy.on('error', error => {
|
||||
console.error('❌ Vercel deployment error:', error.message);
|
||||
reject(error);
|
||||
});
|
||||
@@ -728,7 +727,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'⚠️ Could not verify deployment completion:',
|
||||
error.message
|
||||
error.message,
|
||||
);
|
||||
console.log('ℹ️ Proceeding with domain verification...');
|
||||
}
|
||||
@@ -744,7 +743,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
console.log('🌐 Verified actual domain:', actualDomain);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'⚠️ Could not verify domain via SDK, using assumed domain'
|
||||
'⚠️ Could not verify domain via SDK, using assumed domain',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -769,7 +768,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
fid,
|
||||
await validateSeedPhrase(process.env.SEED_PHRASE),
|
||||
process.env.SEED_PHRASE,
|
||||
webhookUrl
|
||||
webhookUrl,
|
||||
);
|
||||
updatedEnv.MINI_APP_METADATA = updatedMetadata;
|
||||
}
|
||||
@@ -778,7 +777,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
vercelClient,
|
||||
projectId,
|
||||
updatedEnv,
|
||||
projectRoot
|
||||
projectRoot,
|
||||
);
|
||||
|
||||
console.log('\n📦 Redeploying with correct domain...');
|
||||
@@ -789,7 +788,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
vercelRedeploy.on('close', (code) => {
|
||||
vercelRedeploy.on('close', code => {
|
||||
if (code === 0) {
|
||||
console.log('✅ Redeployment completed');
|
||||
resolve();
|
||||
@@ -799,7 +798,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
}
|
||||
});
|
||||
|
||||
vercelRedeploy.on('error', (error) => {
|
||||
vercelRedeploy.on('error', error => {
|
||||
console.error('❌ Redeployment error:', error.message);
|
||||
reject(error);
|
||||
});
|
||||
@@ -811,7 +810,7 @@ async function deployToVercel(useGitHub = false) {
|
||||
console.log('\n✨ Deployment complete! Your mini app is now live at:');
|
||||
console.log(`🌐 https://${domain}`);
|
||||
console.log(
|
||||
'\n📝 You can manage your project at https://vercel.com/dashboard'
|
||||
'\n📝 You can manage your project at https://vercel.com/dashboard',
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('\n❌ Deployment failed:', error.message);
|
||||
@@ -823,7 +822,7 @@ async function main() {
|
||||
try {
|
||||
console.log('🚀 Vercel Mini App Deployment (SDK Edition)');
|
||||
console.log(
|
||||
'This script will deploy your mini app to Vercel using the Vercel SDK.'
|
||||
'This script will deploy your mini app to Vercel using the Vercel SDK.',
|
||||
);
|
||||
console.log('\nThe script will:');
|
||||
console.log('1. Check for required environment variables');
|
||||
@@ -902,4 +901,4 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user