style: fix code formatting and remove unused imports

- Fix indentation in Preview.tsx and normalize quotes
- Remove unused import in selectStarterTemplate.ts
- Improve code readability in api.github-template.ts
This commit is contained in:
KevIsDev 2025-04-15 15:33:12 +01:00
parent 63129a93cd
commit 76ed2bef69
4 changed files with 52 additions and 46 deletions

View File

@ -773,14 +773,14 @@ export const Preview = memo(() => {
<span className="text-sm font-medium text-[#111827] dark:text-gray-300">Device Options</span> <span className="text-sm font-medium text-[#111827] dark:text-gray-300">Device Options</span>
</div> </div>
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<button <button
className={`flex w-full justify-between items-center text-start bg-transparent text-xs text-bolt-elements-textTertiary hover:text-bolt-elements-textPrimary`} className={`flex w-full justify-between items-center text-start bg-transparent text-xs text-bolt-elements-textTertiary hover:text-bolt-elements-textPrimary`}
onClick={() => { onClick={() => {
openInNewTab(); openInNewTab();
}} }}
> >
<span>Open in new tab</span> <span>Open in new tab</span>
<div className='i-ph:arrow-square-out h-5 w-4'/> <div className="i-ph:arrow-square-out h-5 w-4" />
</button> </button>
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<span className="text-xs text-bolt-elements-textTertiary">Show Device Frame</span> <span className="text-xs text-bolt-elements-textTertiary">Show Device Frame</span>

View File

@ -4,90 +4,93 @@ import JSZip from 'jszip';
export async function loader({ request }: { request: Request }) { export async function loader({ request }: { request: Request }) {
const url = new URL(request.url); const url = new URL(request.url);
const repo = url.searchParams.get('repo'); const repo = url.searchParams.get('repo');
if (!repo) { if (!repo) {
return json({ error: 'Repository name is required' }, { status: 400 }); return json({ error: 'Repository name is required' }, { status: 400 });
} }
try { try {
const baseUrl = 'https://api.github.com'; const baseUrl = 'https://api.github.com';
// Get the latest release // Get the latest release
const releaseResponse = await fetch(`${baseUrl}/repos/${repo}/releases/latest`, { const releaseResponse = await fetch(`${baseUrl}/repos/${repo}/releases/latest`, {
headers: { headers: {
'Accept': 'application/vnd.github.v3+json', Accept: 'application/vnd.github.v3+json',
// Add GitHub token if available in environment variables // Add GitHub token if available in environment variables
...(process.env.GITHUB_TOKEN ? { 'Authorization': `Bearer ${process.env.GITHUB_TOKEN}` } : {}) ...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}),
} },
}); });
if (!releaseResponse.ok) { if (!releaseResponse.ok) {
throw new Error(`GitHub API error: ${releaseResponse.status}`); throw new Error(`GitHub API error: ${releaseResponse.status}`);
} }
const releaseData = await releaseResponse.json() as any; const releaseData = (await releaseResponse.json()) as any;
const zipballUrl = releaseData.zipball_url; const zipballUrl = releaseData.zipball_url;
// Fetch the zipball // Fetch the zipball
const zipResponse = await fetch(zipballUrl, { const zipResponse = await fetch(zipballUrl, {
headers: { headers: {
...(process.env.GITHUB_TOKEN ? { 'Authorization': `Bearer ${process.env.GITHUB_TOKEN}` } : {}) ...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}),
} },
}); });
if (!zipResponse.ok) { if (!zipResponse.ok) {
throw new Error(`Failed to fetch release zipball: ${zipResponse.status}`); throw new Error(`Failed to fetch release zipball: ${zipResponse.status}`);
} }
// Get the zip content as ArrayBuffer // Get the zip content as ArrayBuffer
const zipArrayBuffer = await zipResponse.arrayBuffer(); const zipArrayBuffer = await zipResponse.arrayBuffer();
// Use JSZip to extract the contents // Use JSZip to extract the contents
const zip = await JSZip.loadAsync(zipArrayBuffer); const zip = await JSZip.loadAsync(zipArrayBuffer);
// Process the zip contents
const files: { name: string; path: string; content: string }[] = [];
// Find the root folder name // Find the root folder name
let rootFolderName = ''; let rootFolderName = '';
zip.forEach((relativePath, zipEntry) => { zip.forEach((relativePath) => {
if (!rootFolderName && relativePath.includes('/')) { if (!rootFolderName && relativePath.includes('/')) {
rootFolderName = relativePath.split('/')[0]; rootFolderName = relativePath.split('/')[0];
} }
}); });
// Extract all files // Extract all files
const promises = Object.keys(zip.files).map(async (filename) => { const promises = Object.keys(zip.files).map(async (filename) => {
const zipEntry = zip.files[filename]; const zipEntry = zip.files[filename];
// Skip directories // Skip directories
if (zipEntry.dir) return null; if (zipEntry.dir) {
return null;
}
// Skip the root folder itself // Skip the root folder itself
if (filename === rootFolderName) return null; if (filename === rootFolderName) {
return null;
}
// Remove the root folder from the path // Remove the root folder from the path
let normalizedPath = filename; let normalizedPath = filename;
if (rootFolderName && filename.startsWith(rootFolderName + '/')) { if (rootFolderName && filename.startsWith(rootFolderName + '/')) {
normalizedPath = filename.substring(rootFolderName.length + 1); normalizedPath = filename.substring(rootFolderName.length + 1);
} }
// Get the file content // Get the file content
const content = await zipEntry.async('string'); const content = await zipEntry.async('string');
return { return {
name: normalizedPath.split('/').pop() || '', name: normalizedPath.split('/').pop() || '',
path: normalizedPath, path: normalizedPath,
content, content,
}; };
}); });
const results = await Promise.all(promises); const results = await Promise.all(promises);
const fileList = results.filter(Boolean) as { name: string; path: string; content: string }[]; const fileList = results.filter(Boolean) as { name: string; path: string; content: string }[];
return json(fileList); return json(fileList);
} catch (error) { } catch (error) {
console.error('Error processing GitHub template:', error); console.error('Error processing GitHub template:', error);
return json({ error: 'Failed to fetch template files' }, { status: 500 }); return json({ error: 'Failed to fetch template files' }, { status: 500 });
} }
} }

View File

@ -29,4 +29,4 @@ export const loader: LoaderFunction = async ({ request }) => {
return new Response(htmlContent, { return new Response(htmlContent, {
headers: { 'Content-Type': 'text/html' }, headers: { 'Content-Type': 'text/html' },
}); });
}; };

View File

@ -2,7 +2,6 @@ import ignore from 'ignore';
import type { ProviderInfo } from '~/types/model'; import type { ProviderInfo } from '~/types/model';
import type { Template } from '~/types/template'; import type { Template } from '~/types/template';
import { STARTER_TEMPLATES } from './constants'; import { STARTER_TEMPLATES } from './constants';
import Cookies from 'js-cookie';
const starterTemplateSelectionPrompt = (templates: Template[]) => ` const starterTemplateSelectionPrompt = (templates: Template[]) => `
You are an experienced developer who helps people choose the best starter template for their projects. You are an experienced developer who helps people choose the best starter template for their projects.
@ -111,20 +110,18 @@ export const selectStarterTemplate = async (options: { message: string; model: s
} }
}; };
const getGitHubRepoContent = async ( const getGitHubRepoContent = async (repoName: string): Promise<{ name: string; path: string; content: string }[]> => {
repoName: string,
path: string = '',
): Promise<{ name: string; path: string; content: string }[]> => {
try { try {
// Instead of directly fetching from GitHub, use our own API endpoint as a proxy // Instead of directly fetching from GitHub, use our own API endpoint as a proxy
const response = await fetch(`/api/github-template?repo=${encodeURIComponent(repoName)}`); const response = await fetch(`/api/github-template?repo=${encodeURIComponent(repoName)}`);
if (!response.ok) { if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`); throw new Error(`HTTP error! status: ${response.status}`);
} }
// Our API will return the files in the format we need // Our API will return the files in the format we need
const files = await response.json() as any; const files = (await response.json()) as any;
return files; return files;
} catch (error) { } catch (error) {
console.error('Error fetching release contents:', error); console.error('Error fetching release contents:', error);
@ -150,10 +147,16 @@ export async function getTemplates(templateName: string, title?: string) {
*/ */
filteredFiles = filteredFiles.filter((x) => x.path.startsWith('.git') == false); filteredFiles = filteredFiles.filter((x) => x.path.startsWith('.git') == false);
// exclude lock files /*
// WE NOW INCLUDE LOCK FILES FOR IMPROVED INSTALL TIMES * exclude lock files
{/*const comminLockFiles = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml']; * WE NOW INCLUDE LOCK FILES FOR IMPROVED INSTALL TIMES
filteredFiles = filteredFiles.filter((x) => comminLockFiles.includes(x.name) == false);*/} */
{
/*
*const comminLockFiles = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml'];
*filteredFiles = filteredFiles.filter((x) => comminLockFiles.includes(x.name) == false);
*/
}
// exclude .bolt // exclude .bolt
filteredFiles = filteredFiles.filter((x) => x.path.startsWith('.bolt') == false); filteredFiles = filteredFiles.filter((x) => x.path.startsWith('.bolt') == false);