mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-19 09:26:07 -05:00
feat: auto-generate manifest
This commit is contained in:
49
bin/index.js
49
bin/index.js
@@ -6,25 +6,59 @@ import { dirname } from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { generateManifest } from './manifest.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const REPO_URL = 'https://github.com/lucas-neynar/frames-v2-quickstart.git';
|
||||
const SCRIPT_VERSION = '0.1.0';
|
||||
const SCRIPT_VERSION = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8')).version;
|
||||
|
||||
async function init() {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'projectName',
|
||||
message: 'What is the name of your project?',
|
||||
message: 'What is the name of your frame?',
|
||||
validate: (input) => {
|
||||
if (input.trim() === '') {
|
||||
return 'Project name cannot be empty';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'description',
|
||||
message: 'Give a one-line description of your frame:',
|
||||
validate: (input) => {
|
||||
if (input.trim() === '') {
|
||||
return 'Description cannot be empty';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'fid',
|
||||
message: 'Enter your Farcaster FID:',
|
||||
validate: (input) => {
|
||||
if (input.trim() === '') {
|
||||
return 'FID cannot be empty';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'password',
|
||||
name: 'seedPhrase',
|
||||
message: 'Enter your Farcaster account seed phrase:',
|
||||
validate: (input) => {
|
||||
if (input.trim() === '') {
|
||||
return 'Seed phrase cannot be empty';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -40,6 +74,14 @@ async function init() {
|
||||
console.log('\nRemoving .git directory...');
|
||||
fs.rmSync(path.join(projectPath, '.git'), { recursive: true, force: true });
|
||||
|
||||
// Generate manifest and write to public folder
|
||||
console.log('\nGenerating manifest...');
|
||||
const manifest = await generateManifest(answers.fid, answers.seedPhrase);
|
||||
fs.writeFileSync(
|
||||
path.join(projectPath, 'public/manifest.json'),
|
||||
JSON.stringify(manifest)
|
||||
);
|
||||
|
||||
// Update package.json
|
||||
console.log('\nUpdating package.json...');
|
||||
const packageJsonPath = path.join(projectPath, 'package.json');
|
||||
@@ -68,6 +110,9 @@ async function init() {
|
||||
if (fs.existsSync(envExamplePath)) {
|
||||
fs.copyFileSync(envExamplePath, envPath);
|
||||
fs.unlinkSync(envExamplePath);
|
||||
// Append project name and description to .env
|
||||
fs.appendFileSync(envPath, `\nNEXT_PUBLIC_FRAME_NAME="${answers.projectName}"`);
|
||||
fs.appendFileSync(envPath, `\nNEXT_PUBLIC_FRAME_DESCRIPTION="${answers.description}"`);
|
||||
console.log('\nCreated .env file from .env.example');
|
||||
} else {
|
||||
console.log('\n.env.example does not exist, skipping copy and remove operations');
|
||||
|
||||
43
bin/manifest.js
Normal file
43
bin/manifest.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// utils to generate a manifest.json file for a frames v2 app
|
||||
const { mnemonicToAccount } = require('viem/accounts');
|
||||
|
||||
async function generateManifest(fid, seedPhrase) {
|
||||
if (!Number.isInteger(fid) || fid <= 0) {
|
||||
throw new Error('FID must be a positive integer');
|
||||
}
|
||||
|
||||
let account;
|
||||
try {
|
||||
account = mnemonicToAccount(seedPhrase);
|
||||
} catch (error) {
|
||||
throw new Error('Invalid seed phrase');
|
||||
}
|
||||
const custodyAddress = account.address;
|
||||
|
||||
const header = {
|
||||
fid,
|
||||
type: 'custody', // question: do we want to support type of 'app_key', which indicates the signature is from a registered App Key for the FID
|
||||
key: custodyAddress,
|
||||
};
|
||||
const encodedHeader = Buffer.from(JSON.stringify(header), 'utf-8').toString('base64');
|
||||
|
||||
const payload = {
|
||||
domain: 'warpcast.com'
|
||||
};
|
||||
const encodedPayload = Buffer.from(JSON.stringify(payload), 'utf-8').toString('base64url');
|
||||
|
||||
const signature = await account.signMessage({
|
||||
message: `${encodedHeader}.${encodedPayload}`
|
||||
});
|
||||
const encodedSignature = Buffer.from(signature, 'utf-8').toString('base64url');
|
||||
|
||||
const jsonJfs = {
|
||||
header: encodedHeader,
|
||||
payload: encodedPayload,
|
||||
signature: encodedSignature
|
||||
};
|
||||
|
||||
return jsonJfs;
|
||||
}
|
||||
|
||||
module.exports = { generateManifest };
|
||||
Reference in New Issue
Block a user