feat: add one-click netlify deployment

This commit is contained in:
KevIsDev
2025-02-24 17:24:00 +00:00
parent bffb8a2a90
commit 2a8472ed17
9 changed files with 1343 additions and 346 deletions

View File

@@ -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
};
}
}

27
app/lib/stores/netlify.ts Normal file
View File

@@ -0,0 +1,27 @@
import { atom } from 'nanostores';
import type { NetlifyConnection } from '~/types/netlify';
// Initialize with stored connection or defaults
const storedConnection = typeof window !== 'undefined' ? localStorage.getItem('netlify_connection') : null;
const initialConnection: NetlifyConnection = storedConnection
? JSON.parse(storedConnection)
: {
user: null,
token: '',
stats: undefined,
};
export const netlifyConnection = atom<NetlifyConnection>(initialConnection);
export const isConnecting = atom<boolean>(false);
export const isFetchingStats = atom<boolean>(false);
export const updateNetlifyConnection = (updates: Partial<NetlifyConnection>) => {
const currentState = netlifyConnection.get();
const newState = { ...currentState, ...updates };
netlifyConnection.set(newState);
// Persist to localStorage
if (typeof window !== 'undefined') {
localStorage.setItem('netlify_connection', JSON.stringify(newState));
}
};