feat: make cli scripts more beginner friendly

This commit is contained in:
lucas-neynar 2025-04-04 18:42:54 -07:00
parent fb67300f55
commit df9769a270
No known key found for this signature in database
3 changed files with 18 additions and 21 deletions

View File

@ -193,7 +193,7 @@ export async function init() {
{ {
type: 'input', type: 'input',
name: 'projectName', name: 'projectName',
message: '⚠️ Note: choosing a longer, more unique project name will help avoid conflicts with other existing domains\nWhat is the name of your frame?', message: 'What is the name of your frame?',
default: defaultFrameName, default: defaultFrameName,
validate: (input) => { validate: (input) => {
if (input.trim() === '') { if (input.trim() === '') {
@ -206,7 +206,7 @@ export async function init() {
type: 'input', type: 'input',
name: 'description', name: 'description',
message: 'Give a one-line description of your frame (optional):', message: 'Give a one-line description of your frame (optional):',
default: 'A Farcaster mini-app created with @neynar/create-farcaster-mini-app' default: 'A Farcaster mini-app created with Neynar'
}, },
{ {
type: 'input', type: 'input',
@ -227,17 +227,9 @@ export async function init() {
{ {
type: 'confirm', type: 'confirm',
name: 'useTunnel', name: 'useTunnel',
message: 'Would you like to use a tunnel for development?\n\n' + message: 'Would you like to test on mobile, or through a desktop browser?\n' +
'Using a tunnel:\n' + 'Mobile testing requires setting up a tunnel to serve your app from localhost to the broader internet.\n' +
'- No sudo privileges required\n' + 'Configure mobile testing?',
'- Works with all Warpcast Frame Developer Tools\n' +
'- Possible to test on mobile devices\n\n' +
'Using localhost:\n' +
'- Requires sudo privileges to enable HTTPS\n' +
'- Only works with the "Preview Frame" Warpcast tool\n' +
'- Cannot test frame embeds or mobile devices\n\n' +
'Note: You can always switch between localhost and tunnel by editing the USE_TUNNEL environment variable in .env.local\n\n' +
'Use tunnel?',
default: false default: false
} }
]); ]);

View File

@ -7,6 +7,11 @@ import inquirer from 'inquirer';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import crypto from 'crypto'; import crypto from 'crypto';
// ANSI color codes
const yellow = '\x1b[33m';
const italic = '\x1b[3m';
const reset = '\x1b[0m';
// Load environment variables in specific order // Load environment variables in specific order
// First load .env for main config // First load .env for main config
dotenv.config({ path: '.env' }); dotenv.config({ path: '.env' });
@ -45,7 +50,7 @@ async function loadEnvLocal() {
{ {
type: 'confirm', type: 'confirm',
name: 'loadLocal', name: 'loadLocal',
message: 'Found .env.local - would you like to load its values? (except for SEED_PHRASE, values will be written to .env)', message: 'Found .env.local, likely created by the install script - would you like to load its values?',
default: false default: false
} }
]); ]);
@ -286,14 +291,16 @@ async function main() {
} }
} }
// Get seed phrase from user if not already in .env.local // Get seed phrase from user
let seedPhrase = process.env.SEED_PHRASE; let seedPhrase = process.env.SEED_PHRASE;
if (!seedPhrase) { if (!seedPhrase) {
const { seedPhrase: inputSeedPhrase } = await inquirer.prompt([ const { seedPhrase: inputSeedPhrase } = await inquirer.prompt([
{ {
type: 'password', type: 'password',
name: 'seedPhrase', name: 'seedPhrase',
message: 'Enter your seed phrase (this will only be used to sign the frame manifest):', message: 'Your farcaster custody account seed phrase is required to create a signature proving this app was created by you.\n' +
`⚠️ ${yellow}${italic}seed phrase is only used to sign the frame manifest, then discarded${reset} ⚠️\n` +
'Seed phrase:',
validate: async (input) => { validate: async (input) => {
try { try {
await validateSeedPhrase(input); await validateSeedPhrase(input);

View File

@ -119,15 +119,13 @@ async function startDev() {
5. Click "Preview" (note that it may take ~10 seconds to load) 5. Click "Preview" (note that it may take ~10 seconds to load)
`); `);
} else { } else {
frameUrl = 'https://localhost:3000'; frameUrl = 'http://localhost:3000';
console.log(` console.log(`
💻 To test your frame: 💻 To test your frame:
1. Open the Warpcast Frame Developer Tools: https://warpcast.com/~/developers/frames 1. Open the Warpcast Frame Developer Tools: https://warpcast.com/~/developers/frames
2. Scroll down to the "Preview Frame" tool 2. Scroll down to the "Preview Frame" tool
3. Enter this URL: ${frameUrl} 3. Enter this URL: ${frameUrl}
4. Click "Preview" to test your frame 4. Click "Preview" to test your frame (note that it may take ~5 seconds to load the first time)
Note: You may need to accept the self-signed certificate in your browser when first visiting ${frameUrl}
`); `);
} }
@ -136,7 +134,7 @@ Note: You may need to accept the self-signed certificate in your browser when fi
? path.join(projectRoot, 'node_modules', '.bin', 'next.cmd') ? path.join(projectRoot, 'node_modules', '.bin', 'next.cmd')
: path.join(projectRoot, 'node_modules', '.bin', 'next'); : path.join(projectRoot, 'node_modules', '.bin', 'next');
nextDev = spawn(nextBin, ['dev', ...(useTunnel ? [] : ['--experimental-https'])], { nextDev = spawn(nextBin, ['dev'], {
stdio: 'inherit', stdio: 'inherit',
env: { ...process.env, NEXT_PUBLIC_URL: frameUrl, NEXTAUTH_URL: frameUrl }, env: { ...process.env, NEXT_PUBLIC_URL: frameUrl, NEXTAUTH_URL: frameUrl },
cwd: projectRoot cwd: projectRoot