mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-12-05 08:52:31 -05:00
Revert "Merge pull request #15 from neynarxyz/shreyas-formatting"
This reverts commitb1fdfc19a9, reversing changes made tob9e2087bd8.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import localtunnel from 'localtunnel';
|
||||
import { spawn } from 'child_process';
|
||||
import { createServer } from 'net';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import dotenv from 'dotenv';
|
||||
import localtunnel from 'localtunnel';
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config({ path: '.env.local' });
|
||||
@@ -33,18 +33,18 @@ args.forEach((arg, index) => {
|
||||
});
|
||||
|
||||
async function checkPort(port) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
const server = createServer();
|
||||
|
||||
|
||||
server.once('error', () => {
|
||||
resolve(true); // Port is in use
|
||||
});
|
||||
|
||||
|
||||
server.once('listening', () => {
|
||||
server.close();
|
||||
resolve(false); // Port is free
|
||||
});
|
||||
|
||||
|
||||
server.listen(port);
|
||||
});
|
||||
}
|
||||
@@ -54,32 +54,29 @@ async function killProcessOnPort(port) {
|
||||
if (process.platform === 'win32') {
|
||||
// Windows: Use netstat to find the process
|
||||
const netstat = spawn('netstat', ['-ano', '|', 'findstr', `:${port}`]);
|
||||
netstat.stdout.on('data', data => {
|
||||
netstat.stdout.on('data', (data) => {
|
||||
const match = data.toString().match(/\s+(\d+)$/);
|
||||
if (match) {
|
||||
const pid = match[1];
|
||||
spawn('taskkill', ['/F', '/PID', pid]);
|
||||
}
|
||||
});
|
||||
await new Promise(resolve => netstat.on('close', resolve));
|
||||
await new Promise((resolve) => netstat.on('close', resolve));
|
||||
} else {
|
||||
// Unix-like systems: Use lsof
|
||||
const lsof = spawn('lsof', ['-ti', `:${port}`]);
|
||||
lsof.stdout.on('data', data => {
|
||||
data
|
||||
.toString()
|
||||
.split('\n')
|
||||
.forEach(pid => {
|
||||
if (pid) {
|
||||
try {
|
||||
process.kill(parseInt(pid), 'SIGKILL');
|
||||
} catch (e) {
|
||||
if (e.code !== 'ESRCH') throw e;
|
||||
}
|
||||
lsof.stdout.on('data', (data) => {
|
||||
data.toString().split('\n').forEach(pid => {
|
||||
if (pid) {
|
||||
try {
|
||||
process.kill(parseInt(pid), 'SIGKILL');
|
||||
} catch (e) {
|
||||
if (e.code !== 'ESRCH') throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
await new Promise(resolve => lsof.on('close', resolve));
|
||||
await new Promise((resolve) => lsof.on('close', resolve));
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore errors if no process found
|
||||
@@ -90,15 +87,13 @@ async function startDev() {
|
||||
// Check if the specified port is already in use
|
||||
const isPortInUse = await checkPort(port);
|
||||
if (isPortInUse) {
|
||||
console.error(
|
||||
`Port ${port} is already in use. To find and kill the process using this port:\n\n` +
|
||||
(process.platform === 'win32'
|
||||
? `1. Run: netstat -ano | findstr :${port}\n` +
|
||||
'2. Note the PID (Process ID) from the output\n' +
|
||||
'3. Run: taskkill /PID <PID> /F\n'
|
||||
: 'On macOS/Linux, run:\nnpm run cleanup\n') +
|
||||
'\nThen try running this command again.',
|
||||
);
|
||||
console.error(`Port ${port} is already in use. To find and kill the process using this port:\n\n` +
|
||||
(process.platform === 'win32'
|
||||
? `1. Run: netstat -ano | findstr :${port}\n` +
|
||||
'2. Note the PID (Process ID) from the output\n' +
|
||||
'3. Run: taskkill /PID <PID> /F\n'
|
||||
: `On macOS/Linux, run:\nnpm run cleanup\n`) +
|
||||
'\nThen try running this command again.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -110,9 +105,7 @@ async function startDev() {
|
||||
tunnel = await localtunnel({ port: port });
|
||||
let ip;
|
||||
try {
|
||||
ip = await fetch('https://ipv4.icanhazip.com')
|
||||
.then(res => res.text())
|
||||
.then(ip => ip.trim());
|
||||
ip = await fetch('https://ipv4.icanhazip.com').then(res => res.text()).then(ip => ip.trim());
|
||||
} catch (error) {
|
||||
console.error('Error getting IP address:', error);
|
||||
}
|
||||
@@ -150,17 +143,15 @@ async function startDev() {
|
||||
4. Click "Preview" to test your mini app (note that it may take ~5 seconds to load the first time)
|
||||
`);
|
||||
}
|
||||
|
||||
|
||||
// Start next dev with appropriate configuration
|
||||
const nextBin = path.normalize(
|
||||
path.join(projectRoot, 'node_modules', '.bin', 'next'),
|
||||
);
|
||||
const nextBin = path.normalize(path.join(projectRoot, 'node_modules', '.bin', 'next'));
|
||||
|
||||
nextDev = spawn(nextBin, ['dev', '-p', port.toString()], {
|
||||
stdio: 'inherit',
|
||||
env: { ...process.env, NEXT_PUBLIC_URL: miniAppUrl },
|
||||
cwd: projectRoot,
|
||||
shell: process.platform === 'win32', // Add shell option for Windows
|
||||
shell: process.platform === 'win32' // Add shell option for Windows
|
||||
});
|
||||
|
||||
// Handle cleanup
|
||||
@@ -190,7 +181,7 @@ async function startDev() {
|
||||
console.log('Note: Next.js process already terminated');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (tunnel) {
|
||||
try {
|
||||
await tunnel.close();
|
||||
@@ -218,4 +209,4 @@ async function startDev() {
|
||||
}
|
||||
}
|
||||
|
||||
startDev().catch(console.error);
|
||||
startDev().catch(console.error);
|
||||
Reference in New Issue
Block a user