Provide a rebuild option (restart w/ re-install node modules)

This commit is contained in:
Will Chen
2025-04-21 16:46:10 -07:00
parent 09b3bf3fee
commit ee3d2e7f4e
5 changed files with 125 additions and 57 deletions

View File

@@ -378,7 +378,10 @@ export function registerAppHandlers() {
"restart-app",
async (
event: Electron.IpcMainInvokeEvent,
{ appId }: { appId: number }
{
appId,
removeNodeModules,
}: { appId: number; removeNodeModules?: boolean }
) => {
logger.log(`Restarting app ${appId}`);
return withLock(appId, async () => {
@@ -410,6 +413,24 @@ export function registerAppHandlers() {
}
const appPath = getDyadAppPath(app.path);
// Remove node_modules if requested
if (removeNodeModules) {
const nodeModulesPath = path.join(appPath, "node_modules");
logger.log(
`Removing node_modules for app ${appId} at ${nodeModulesPath}`
);
if (fs.existsSync(nodeModulesPath)) {
await fsPromises.rm(nodeModulesPath, {
recursive: true,
force: true,
});
logger.log(`Successfully removed node_modules for app ${appId}`);
} else {
logger.log(`No node_modules directory found for app ${appId}`);
}
}
logger.debug(
`Executing app ${appId} in path ${app.path} after restart request`
); // Adjusted log