mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-16 08:08:56 -05:00
feat: add script inputs
This commit is contained in:
parent
9f5d80fddd
commit
2b85800ba7
25
bin/index.js
25
bin/index.js
@ -2,7 +2,30 @@
|
|||||||
|
|
||||||
import { init } from './init.js';
|
import { init } from './init.js';
|
||||||
|
|
||||||
init().catch((err) => {
|
// Parse command line arguments
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
let projectName = null;
|
||||||
|
let autoAcceptDefaults = false;
|
||||||
|
|
||||||
|
// Check for -y flag
|
||||||
|
const yIndex = args.indexOf('-y');
|
||||||
|
if (yIndex !== -1) {
|
||||||
|
autoAcceptDefaults = true;
|
||||||
|
args.splice(yIndex, 1); // Remove -y from args
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's a remaining argument, it's the project name
|
||||||
|
if (args.length > 0) {
|
||||||
|
projectName = args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If -y is used without project name, we still need to ask for project name
|
||||||
|
if (autoAcceptDefaults && !projectName) {
|
||||||
|
// We'll handle this case in the init function by asking only for project name
|
||||||
|
autoAcceptDefaults = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
init(projectName, autoAcceptDefaults).catch((err) => {
|
||||||
console.error('Error:', err);
|
console.error('Error:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
69
bin/init.js
69
bin/init.js
@ -61,7 +61,7 @@ async function queryNeynarApp(apiKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Export the main CLI function for programmatic use
|
// Export the main CLI function for programmatic use
|
||||||
export async function init() {
|
export async function init(projectName = null, autoAcceptDefaults = false) {
|
||||||
printWelcomeMessage();
|
printWelcomeMessage();
|
||||||
|
|
||||||
// Ask about Neynar usage
|
// Ask about Neynar usage
|
||||||
@ -72,7 +72,11 @@ export async function init() {
|
|||||||
let neynarAppLogoUrl = null;
|
let neynarAppLogoUrl = null;
|
||||||
|
|
||||||
while (useNeynar) {
|
while (useNeynar) {
|
||||||
const neynarAnswers = await inquirer.prompt([
|
let neynarAnswers;
|
||||||
|
if (autoAcceptDefaults) {
|
||||||
|
neynarAnswers = { useNeynar: true };
|
||||||
|
} else {
|
||||||
|
neynarAnswers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'useNeynar',
|
name: 'useNeynar',
|
||||||
@ -87,6 +91,7 @@ export async function init() {
|
|||||||
default: true
|
default: true
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (!neynarAnswers.useNeynar) {
|
if (!neynarAnswers.useNeynar) {
|
||||||
useNeynar = false;
|
useNeynar = false;
|
||||||
@ -94,7 +99,12 @@ export async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('\n🪐 Find your Neynar API key at: https://dev.neynar.com/app\n');
|
console.log('\n🪐 Find your Neynar API key at: https://dev.neynar.com/app\n');
|
||||||
const neynarKeyAnswer = await inquirer.prompt([
|
|
||||||
|
let neynarKeyAnswer;
|
||||||
|
if (autoAcceptDefaults) {
|
||||||
|
neynarKeyAnswer = { neynarApiKey: null };
|
||||||
|
} else {
|
||||||
|
neynarKeyAnswer = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'password',
|
type: 'password',
|
||||||
name: 'neynarApiKey',
|
name: 'neynarApiKey',
|
||||||
@ -102,11 +112,16 @@ export async function init() {
|
|||||||
default: null
|
default: null
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (neynarKeyAnswer.neynarApiKey) {
|
if (neynarKeyAnswer.neynarApiKey) {
|
||||||
neynarApiKey = neynarKeyAnswer.neynarApiKey;
|
neynarApiKey = neynarKeyAnswer.neynarApiKey;
|
||||||
} else {
|
} else {
|
||||||
const useDemoKey = await inquirer.prompt([
|
let useDemoKey;
|
||||||
|
if (autoAcceptDefaults) {
|
||||||
|
useDemoKey = { useDemo: true };
|
||||||
|
} else {
|
||||||
|
useDemoKey = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'useDemo',
|
name: 'useDemo',
|
||||||
@ -114,6 +129,7 @@ export async function init() {
|
|||||||
default: true
|
default: true
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (useDemoKey.useDemo) {
|
if (useDemoKey.useDemo) {
|
||||||
console.warn('\n⚠️ Note: the demo key is for development purposes only and is aggressively rate limited.');
|
console.warn('\n⚠️ Note: the demo key is for development purposes only and is aggressively rate limited.');
|
||||||
@ -124,6 +140,10 @@ export async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!neynarApiKey) {
|
if (!neynarApiKey) {
|
||||||
|
if (autoAcceptDefaults) {
|
||||||
|
useNeynar = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
console.log('\n⚠️ No valid API key provided. Would you like to try again?');
|
console.log('\n⚠️ No valid API key provided. Would you like to try again?');
|
||||||
const { retry } = await inquirer.prompt([
|
const { retry } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
@ -148,6 +168,10 @@ export async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!neynarClientId) {
|
if (!neynarClientId) {
|
||||||
|
if (autoAcceptDefaults) {
|
||||||
|
useNeynar = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
const { retry } = await inquirer.prompt([
|
const { retry } = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
@ -169,19 +193,36 @@ export async function init() {
|
|||||||
|
|
||||||
const defaultMiniAppName = (neynarAppName && !neynarAppName.toLowerCase().includes('demo')) ? neynarAppName : undefined;
|
const defaultMiniAppName = (neynarAppName && !neynarAppName.toLowerCase().includes('demo')) ? neynarAppName : undefined;
|
||||||
|
|
||||||
const answers = await inquirer.prompt([
|
let answers;
|
||||||
|
if (autoAcceptDefaults) {
|
||||||
|
answers = {
|
||||||
|
projectName: projectName || defaultMiniAppName || 'my-farcaster-mini-app',
|
||||||
|
description: 'A Farcaster mini app created with Neynar',
|
||||||
|
primaryCategory: null,
|
||||||
|
tags: [],
|
||||||
|
buttonText: 'Launch Mini App',
|
||||||
|
useWallet: true,
|
||||||
|
useTunnel: true,
|
||||||
|
enableAnalytics: true
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// If autoAcceptDefaults is false but we have a projectName, we still need to ask for other options
|
||||||
|
const projectNamePrompt = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'projectName',
|
name: 'projectName',
|
||||||
message: 'What is the name of your mini app?',
|
message: 'What is the name of your mini app?',
|
||||||
default: defaultMiniAppName,
|
default: projectName || defaultMiniAppName,
|
||||||
validate: (input) => {
|
validate: (input) => {
|
||||||
if (input.trim() === '') {
|
if (input.trim() === '') {
|
||||||
return 'Project name cannot be empty';
|
return 'Project name cannot be empty';
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
answers = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'description',
|
name: 'description',
|
||||||
@ -240,6 +281,9 @@ export async function init() {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Merge project name from the first prompt
|
||||||
|
answers.projectName = projectNamePrompt.projectName;
|
||||||
|
|
||||||
// Ask about wallet and transaction tooling
|
// Ask about wallet and transaction tooling
|
||||||
const walletAnswer = await inquirer.prompt([
|
const walletAnswer = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
@ -281,9 +325,10 @@ export async function init() {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
answers.enableAnalytics = analyticsAnswer.enableAnalytics;
|
answers.enableAnalytics = analyticsAnswer.enableAnalytics;
|
||||||
|
}
|
||||||
|
|
||||||
const projectName = answers.projectName;
|
const finalProjectName = answers.projectName;
|
||||||
const projectDirName = projectName.replace(/\s+/g, '-').toLowerCase();
|
const projectDirName = finalProjectName.replace(/\s+/g, '-').toLowerCase();
|
||||||
const projectPath = path.join(process.cwd(), projectDirName);
|
const projectPath = path.join(process.cwd(), projectDirName);
|
||||||
|
|
||||||
console.log(`\nCreating a new mini app in ${projectPath}`);
|
console.log(`\nCreating a new mini app in ${projectPath}`);
|
||||||
@ -328,7 +373,7 @@ export async function init() {
|
|||||||
const packageJsonPath = path.join(projectPath, 'package.json');
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
||||||
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
|
|
||||||
packageJson.name = projectName;
|
packageJson.name = finalProjectName;
|
||||||
packageJson.version = '0.1.0';
|
packageJson.version = '0.1.0';
|
||||||
delete packageJson.author;
|
delete packageJson.author;
|
||||||
delete packageJson.keywords;
|
delete packageJson.keywords;
|
||||||
@ -464,7 +509,7 @@ export async function init() {
|
|||||||
execSync('git commit -m "initial commit from @neynar/create-farcaster-mini-app"', { cwd: projectPath });
|
execSync('git commit -m "initial commit from @neynar/create-farcaster-mini-app"', { cwd: projectPath });
|
||||||
|
|
||||||
// Calculate border length based on message length
|
// Calculate border length based on message length
|
||||||
const message = `✨🪐 Successfully created mini app ${projectName} with git and dependencies installed! 🪐✨`;
|
const message = `✨🪐 Successfully created mini app ${finalProjectName} with git and dependencies installed! 🪐✨`;
|
||||||
const borderLength = message.length;
|
const borderLength = message.length;
|
||||||
const borderStars = '✨'.repeat((borderLength / 2) + 1);
|
const borderStars = '✨'.repeat((borderLength / 2) + 1);
|
||||||
|
|
||||||
@ -472,6 +517,6 @@ export async function init() {
|
|||||||
console.log(`${message}`);
|
console.log(`${message}`);
|
||||||
console.log(`${borderStars}`);
|
console.log(`${borderStars}`);
|
||||||
console.log('\nTo run the app:');
|
console.log('\nTo run the app:');
|
||||||
console.log(` cd ${projectName}`);
|
console.log(` cd ${finalProjectName}`);
|
||||||
console.log(' npm run dev\n');
|
console.log(' npm run dev\n');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@neynar/create-farcaster-mini-app",
|
"name": "@neynar/create-farcaster-mini-app",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": false,
|
"private": false,
|
||||||
"access": "public",
|
"access": "public",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user