Merge branch 'main' into diff-view-v2
This commit is contained in:
@@ -70,6 +70,7 @@ export class ActionRunner {
|
||||
runnerId = atom<string>(`${Date.now()}`);
|
||||
actions: ActionsMap = map({});
|
||||
onAlert?: (alert: ActionAlert) => void;
|
||||
buildOutput?: { path: string; exitCode: number; output: string };
|
||||
|
||||
constructor(
|
||||
webcontainerPromise: Promise<WebContainer>,
|
||||
@@ -156,6 +157,13 @@ export class ActionRunner {
|
||||
await this.#runFileAction(action);
|
||||
break;
|
||||
}
|
||||
case 'build': {
|
||||
const buildOutput = await this.#runBuildAction(action);
|
||||
|
||||
// Store build output for deployment
|
||||
this.buildOutput = buildOutput;
|
||||
break;
|
||||
}
|
||||
case 'start': {
|
||||
// making the start app non blocking
|
||||
|
||||
@@ -299,6 +307,7 @@ export class ActionRunner {
|
||||
logger.error('Failed to write file\n\n', error);
|
||||
}
|
||||
}
|
||||
|
||||
#updateAction(id: string, newState: ActionStateUpdate) {
|
||||
const actions = this.actions.get();
|
||||
|
||||
@@ -331,4 +340,39 @@ export class ActionRunner {
|
||||
#getHistoryPath(filePath: string) {
|
||||
return nodePath.join('.history', filePath);
|
||||
}
|
||||
}
|
||||
|
||||
async #runBuildAction(action: ActionState) {
|
||||
if (action.type !== 'build') {
|
||||
unreachable('Expected build action');
|
||||
}
|
||||
|
||||
const webcontainer = await this.#webcontainer;
|
||||
|
||||
// Create a new terminal specifically for the build
|
||||
const buildProcess = await webcontainer.spawn('npm', ['run', 'build']);
|
||||
|
||||
let output = '';
|
||||
buildProcess.output.pipeTo(
|
||||
new WritableStream({
|
||||
write(data) {
|
||||
output += data;
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const exitCode = await buildProcess.exit;
|
||||
|
||||
if (exitCode !== 0) {
|
||||
throw new ActionCommandError('Build Failed', output || 'No Output Available');
|
||||
}
|
||||
|
||||
// Get the build output directory path
|
||||
const buildDir = nodePath.join(webcontainer.workdir, 'dist');
|
||||
|
||||
return {
|
||||
path: buildDir,
|
||||
exitCode,
|
||||
output,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user