Logo

dev-resources.site

for different kinds of informations.

Enabling Application Downloads in Local bolt.new

Published at
11/17/2024
Categories
javascript
claude
boltnew
Author
m_sea_bass
Categories
3 categories in total
javascript
open
claude
open
boltnew
open
Author
10 person written this
m_sea_bass
open
Enabling Application Downloads in Local bolt.new

In this article, I will modify bolt.new to allow applications created in the tool to be downloaded locally. This feature will facilitate internal deployment of bolt.new applications, making it particularly useful for corporate environments.

Objective

  • Add functionality to download the project files as a ZIP archive.

Steps to Implement

  1. Integrate a download button in the interface
    • Add a download button in the sidebar or toolbar.
  2. Generate a ZIP archive of the project
    • Use a library like JSZip to bundle project files into a ZIP archive.
  3. Download the ZIP archive
    • Trigger the browser's download functionality with the generated ZIP file.
  4. Test the feature
    • Ensure that the downloaded ZIP contains the expected files and directory structure.

In the next article, we will cover how to modify bolt.new to integrate with Azure OpenAI Service, streamlining the application for enterprise-level use cases. Please check it.

Adding a Download Button

To enable the feature for downloading project files as a ZIP, we modify the file bolt.new/app/components/workbench/EditorPanel.tsx. The changes are marked between // Append start and // Append end for clarity.

...  
// Append start  
import JSZip from 'jszip';  
// Append end  
...  

export const EditorPanel = memo(  
  ({  
    files,  
    unsavedFiles,  
    editorDocument,  
    selectedFile,  
    isStreaming,  
    onFileSelect,  
    onEditorChange,  
    onEditorScroll,  
    onFileSave,  
    onFileReset,  
  }: EditorPanelProps) => {  

    ...  

    // Append start  
    const handleDownloadZip = useCallback(async () => {  
      const zip = new JSZip();  
      const files = workbenchStore.files.get();  

      // Check if there are files to download  
      if (Object.keys(files).length === 0) {  
        toast.error('No files to download');  
        return;  
      }  

      try {  
        // Add files to the ZIP, maintaining relative paths from WORK_DIR  
        Object.entries(files).forEach(([path, content]) => {  
          if (content && content.content) {  
            const relativePath = path.startsWith(WORK_DIR)   
              ? path.slice(WORK_DIR.length + 1)   
              : path;  
            zip.file(relativePath, content.content);  
          }  
        });  

        const zipBlob = await zip.generateAsync({ type: 'blob' });  
        const downloadLink = document.createElement('a');  
        downloadLink.href = URL.createObjectURL(zipBlob);  

        // Use the project name from `package.json` if available  
        const projectName = files[`${WORK_DIR}/package.json`]?.content  
          ? JSON.parse(files[`${WORK_DIR}/package.json`].content).name  
          : 'project';  
        downloadLink.download = `${projectName}.zip`;  

        downloadLink.click();  
        URL.revokeObjectURL(downloadLink.href);  
        toast.success('Files downloaded successfully');  
      } catch (error) {  
        toast.error('Failed to create zip file');  
        console.error(error);  
      }  
    }, []);  
    // Append end  

    return (  
      <PanelGroup direction="vertical">  
        <Panel defaultSize={showTerminal ? DEFAULT_EDITOR_SIZE : 100} minSize={20}>  
          <PanelGroup direction="horizontal">  
            <Panel defaultSize={20} minSize={10} collapsible>  
              <div className="flex flex-col border-r border-bolt-elements-borderColor h-full">  
                <PanelHeader>  
                  <div className="i-ph:tree-structure-duotone shrink-0" />  
                  Files  
                  {/* Append start */}  
                  <div className="flex-1" />  
                  <button  
                    className="px-2 py-1 rounded-md text-bolt-elements-item-contentDefault bg-transparent enabled:hover:text-bolt-elements-item-contentActive enabled:hover:bg-bolt-elements-item-backgroundActive"  
                    onClick={handleDownloadZip}  
                    title="Download as ZIP"  
                  >  
                    <div className="i-ph:download-simple text-xl" />  
                  </button>  
                  {/* Append end */}  
                </PanelHeader>  
    ...  
Enter fullscreen mode Exit fullscreen mode

Explanation of Changes

  1. Added JSZip import:

    This library is used to generate the ZIP archive.

  2. handleDownloadZip function:

    • Retrieves files from the workbenchStore.
    • Creates a ZIP file with relative paths from WORK_DIR.
    • Automatically names the ZIP file using the project name from package.json, if available.
  3. Download button in the interface:

    • A button is added to the Files panel header to trigger the ZIP download process.
    • Styled and includes a tooltip for user clarity.

With this change, users can download the project files as a ZIP archive directly from the interface.

Updating package.json

To use the JSZip library for generating ZIP archives, add it to the dependencies in package.json.

{  
  ...  
  "dependencies": {  
    "@ai-sdk/anthropic": "^0.0.39",  
    // Append start  
    "jszip": "^3.10.1",  
    // Append end  
  },  
  ...  
}  
Enter fullscreen mode Exit fullscreen mode

Steps to Apply the Update

  1. Open the package.json file.
  2. Add "jszip": "^3.10.1" under the "dependencies" section as shown above.
  3. Run the following command to install the library:
pnpm install  
Enter fullscreen mode Exit fullscreen mode

This ensures that the required library is available in your project for the ZIP generation functionality.

Testing the Download Feature

After completing the modifications, follow these steps to verify the new functionality:

Start the Application

Run the following commands to build and start bolt.new:

pnpm run build  
pnpm run start  
Enter fullscreen mode Exit fullscreen mode
  1. Open the Application in a Browser and navigate to the "Code" tab of the application interface.

  2. Confirm that a download button is visible in the "Files" section, as shown below:

Image description

  1. Download the Project Files: Click the download button and download the ZIP file.
claude Article's
29 articles in total
Favicon
Integrating Locally running Postgres with Claude Desktop
Favicon
Write tools for LLMs with go - mcp-golang
Favicon
MCP using node on asdf
Favicon
Modify the local bolt.new interface to allow input of the API key
Favicon
Enabling Application Downloads in Local bolt.new
Favicon
Running bolt.new Locally
Favicon
In the Beginning...
Favicon
Dario Amodei: Anthropic CEO on Claude, AGI & the Future of AI & Humanity | Podcast Summary
Favicon
Certainly! Absolutely! I apologize!
Favicon
Claude prompting guide - General tips for effective prompting
Favicon
How I used ChatGPT o1 and Claude for generating a SQL RBAC report and was surprised by the results
Favicon
How to use AI for coding the right way
Favicon
Using Cursor + Claude to Make Full-Stack SaaS Apps
Favicon
Exploring Anthropic Claude: A Safe and Ethical AI Assistant
Favicon
Claude 3.5 API Introductory Tutorial
Favicon
Unlocking Rapid Data Extraction: Groq + OCR and Claude Vision
Favicon
Free AI Chat and AI Art
Favicon
Optimising Function Calling (GPT4 vs Opus vs Haiku vs Sonnet)
Favicon
DEMO - Voice to PDF - Complete PDF documents with voice commands using the Claude 3 Opus API
Favicon
Claude LLM - Pros and Cons Compared with Other LLMs
Favicon
Is Claude Self Aware
Favicon
Guide to Effective Prompt Engineering for ChatGPT and LLM Responses
Favicon
AI powered video summarizer with Amazon Bedrock and Anthropic’s Claude
Favicon
Claude 2.1 Unleashed: The AI Revolution That's Outshining GPT-4
Favicon
AWS Bedrock Claude 2.1 - Return only JSON
Favicon
Claude: 10 Minute Docs Audit
Favicon
New Discoveries in No-Code AI App Building with ChatGPT
Favicon
Meet Claude - The AI Assistant That Understands The World Like You Do
Favicon
La IA de Anthropic, Claude, Supera a ChatGPT

Featured ones: