Skip to content

Commit

Permalink
fix: run npm install if cli start fails (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala authored Jan 29, 2025
1 parent 3e9ffb8 commit 05de943
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions packages/main/src/modules/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import log from 'electron-log/main';
import type { DeployOptions } from '/shared/types/ipc';
import { run, type Child } from './bin';
import { getAvailablePort } from './port';
import { getProjectId } from './analytics';
import { install } from './npm';

async function getEnv(path: string) {
const projectId = await getProjectId(path);
Expand All @@ -21,17 +23,28 @@ export async function init(path: string, repo?: string) {
}

export let previewServer: Child | null = null;
export async function start(path: string) {
export async function start(path: string, retry = true) {
if (previewServer) {
await previewServer.kill();
}
previewServer = run('@dcl/sdk-commands', 'sdk-commands', {
args: ['start', '--explorer-alpha', '--hub'],
cwd: path,
workspace: path,
env: await getEnv(path),
});
await previewServer.waitFor(/decentraland:\/\//i);
try {
previewServer = run('@dcl/sdk-commands', 'sdk-commands', {
args: ['start', '--explorer-alpha', '--hub'],
cwd: path,
workspace: path,
env: await getEnv(path),
});

await previewServer.waitFor(/decentraland:\/\//i);
} catch (error) {
if (retry) {
log.info('[CLI] Something went wrong trying to start preview:', (error as Error).message);
await install(path);
await start(path, false);
} else {
throw error;
}
}
}

export let deployServer: Child | null = null;
Expand Down

0 comments on commit 05de943

Please sign in to comment.