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>
</div>
<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`}
onClick={() => {
openInNewTab();
}}
>
<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>
<div className="flex items-center justify-between">
<span className="text-xs text-bolt-elements-textTertiary">Show Device Frame</span>

View File

@ -15,24 +15,25 @@ export async function loader({ request }: { request: Request }) {
// Get the latest release
const releaseResponse = await fetch(`${baseUrl}/repos/${repo}/releases/latest`, {
headers: {
'Accept': 'application/vnd.github.v3+json',
Accept: 'application/vnd.github.v3+json',
// 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) {
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;
// Fetch the zipball
const zipResponse = await fetch(zipballUrl, {
headers: {
...(process.env.GITHUB_TOKEN ? { 'Authorization': `Bearer ${process.env.GITHUB_TOKEN}` } : {})
}
...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}),
},
});
if (!zipResponse.ok) {
@ -45,12 +46,9 @@ export async function loader({ request }: { request: Request }) {
// Use JSZip to extract the contents
const zip = await JSZip.loadAsync(zipArrayBuffer);
// Process the zip contents
const files: { name: string; path: string; content: string }[] = [];
// Find the root folder name
let rootFolderName = '';
zip.forEach((relativePath, zipEntry) => {
zip.forEach((relativePath) => {
if (!rootFolderName && relativePath.includes('/')) {
rootFolderName = relativePath.split('/')[0];
}
@ -61,13 +59,18 @@ export async function loader({ request }: { request: Request }) {
const zipEntry = zip.files[filename];
// Skip directories
if (zipEntry.dir) return null;
if (zipEntry.dir) {
return null;
}
// Skip the root folder itself
if (filename === rootFolderName) return null;
if (filename === rootFolderName) {
return null;
}
// Remove the root folder from the path
let normalizedPath = filename;
if (rootFolderName && filename.startsWith(rootFolderName + '/')) {
normalizedPath = filename.substring(rootFolderName.length + 1);
}

View File

@ -2,7 +2,6 @@ import ignore from 'ignore';
import type { ProviderInfo } from '~/types/model';
import type { Template } from '~/types/template';
import { STARTER_TEMPLATES } from './constants';
import Cookies from 'js-cookie';
const starterTemplateSelectionPrompt = (templates: Template[]) => `
You are an experienced developer who helps people choose the best starter template for their projects.
@ -111,10 +110,7 @@ export const selectStarterTemplate = async (options: { message: string; model: s
}
};
const getGitHubRepoContent = async (
repoName: string,
path: string = '',
): Promise<{ name: string; path: string; content: string }[]> => {
const getGitHubRepoContent = async (repoName: string): Promise<{ name: string; path: string; content: string }[]> => {
try {
// Instead of directly fetching from GitHub, use our own API endpoint as a proxy
const response = await fetch(`/api/github-template?repo=${encodeURIComponent(repoName)}`);
@ -124,7 +120,8 @@ const getGitHubRepoContent = async (
}
// 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;
} catch (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);
// exclude lock files
// WE NOW INCLUDE LOCK FILES FOR IMPROVED INSTALL TIMES
{/*const comminLockFiles = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml'];
filteredFiles = filteredFiles.filter((x) => comminLockFiles.includes(x.name) == false);*/}
/*
* exclude lock files
* WE NOW INCLUDE LOCK FILES FOR IMPROVED INSTALL TIMES
*/
{
/*
*const comminLockFiles = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml'];
*filteredFiles = filteredFiles.filter((x) => comminLockFiles.includes(x.name) == false);
*/
}
// exclude .bolt
filteredFiles = filteredFiles.filter((x) => x.path.startsWith('.bolt') == false);