feat: add one-click netlify deployment
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,12 @@ 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
|
||||
|
||||
@@ -304,4 +311,38 @@ export class ActionRunner {
|
||||
|
||||
this.actions.setKey(id, { ...actions[id], ...newState });
|
||||
}
|
||||
|
||||
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 = path.join(webcontainer.workdir, 'dist');
|
||||
|
||||
return {
|
||||
path: buildDir,
|
||||
exitCode,
|
||||
output
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user