Created
August 16, 2024 15:27
-
-
Save peterbe/d969d97b51bee4868c22a39dd12c4b51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require("child_process"); | |
function vite() { | |
const child = spawn("npm", ["run", "dev"], { | |
cwd: "my-vite-react-ts-app", | |
}); | |
// console.log(`Spawned process PID: ${child.pid}`); | |
console.time("Getting 200 OK"); | |
setInterval(() => { | |
fetch("http://localhost:5173") | |
.then((r) => { | |
if (r.ok) { | |
console.timeEnd("Getting 200 OK"); | |
child.kill(); | |
process.exit(0); | |
} else { | |
console.log("NOT OK!", r); | |
} | |
}) | |
.catch((err) => { | |
if (err instanceof Error && err.cause.code === "ECONNREFUSED") { | |
// Try again later" | |
} else { | |
throw err; | |
} | |
}); | |
}, 10); | |
setTimeout(() => { | |
console.warn("Circuit break"); | |
child.kill(); | |
console.log(`Killed process PID: ${child.pid}`); | |
process.exit(1); | |
}, 10000); | |
} | |
function nextjs() { | |
const child = spawn("npm", ["run", "dev"], { | |
cwd: "my-nextjs-ts-app", | |
}); | |
// console.log(`Spawned process PID: ${child.pid}`); | |
console.time("Getting 200 OK"); | |
setInterval(() => { | |
fetch("http://localhost:3000") | |
.then((r) => { | |
if (r.ok) { | |
console.timeEnd("Getting 200 OK"); | |
child.kill(); | |
process.exit(0); | |
} else { | |
console.log("NOT OK!", r); | |
} | |
}) | |
.catch((err) => { | |
if (err instanceof Error && err.cause.code === "ECONNREFUSED") { | |
// Try again later; | |
} else { | |
throw err; | |
} | |
}); | |
}, 10); | |
setTimeout(() => { | |
console.warn("Circuit break"); | |
child.kill(); | |
console.log(`Killed process PID: ${child.pid}`); | |
process.exit(1); | |
}, 10000); | |
} | |
vite(); | |
// nextjs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment