mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
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:
parent
63129a93cd
commit
76ed2bef69
@ -780,7 +780,7 @@ export const Preview = memo(() => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<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>
|
||||||
|
|||||||
@ -15,24 +15,25 @@ export async function loader({ request }: { request: Request }) {
|
|||||||
// 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) {
|
||||||
@ -45,12 +46,9 @@ export async function loader({ request }: { request: Request }) {
|
|||||||
// 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];
|
||||||
}
|
}
|
||||||
@ -61,13 +59,18 @@ export async function loader({ request }: { request: Request }) {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,10 +110,7 @@ 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)}`);
|
||||||
@ -124,7 +120,8 @@ const getGitHubRepoContent = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user