Home / Function/ download_stackblitz_project() — svelte Function Reference

download_stackblitz_project() — svelte Function Reference

Architecture documentation for the download_stackblitz_project() function in download.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  cf80c23c_24c2_ac05_1b36_16e9c691f676["download_stackblitz_project()"]
  65d20932_41e6_eeee_7338_5dd0682e5e42["download.js"]
  cf80c23c_24c2_ac05_1b36_16e9c691f676 -->|defined in| 65d20932_41e6_eeee_7338_5dd0682e5e42
  style cf80c23c_24c2_ac05_1b36_16e9c691f676 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

playgrounds/sandbox/scripts/download.js lines 137–195

async function download_stackblitz_project(url, target_dir) {
	console.log(`Downloading StackBlitz project via browser automation...`);
	console.log(`URL: ${url.href}`);

	const browser = await chromium.launch({ headless: true });
	const context = await browser.newContext({ acceptDownloads: true });
	const page = await context.newPage();

	try {
		// Navigate to the StackBlitz project
		console.log('Loading StackBlitz project (this may take a moment)...');
		await page.goto(url.href, { waitUntil: 'domcontentloaded', timeout: 20000 });

		// Set up download handler
		const downloadPromise = page.waitForEvent('download', { timeout: 30000 });
		await page.locator('button[aria-label*="Download Project" i]', { timeout: 30000 }).click();
		console.log('Triggering download...');

		// Wait for the download to start
		const download = await downloadPromise;

		// Save the downloaded file
		const zip_path = path.join(target_dir, 'project.zip');
		await download.saveAs(zip_path);

		console.log('Download complete, extracting...');

		// Extract the zip file
		if (process.platform === 'win32') {
			execSync(
				`powershell -Command "Expand-Archive -Path '${zip_path}' -DestinationPath '${target_dir}' -Force"`,
				{ stdio: 'inherit' }
			);
		} else {
			execSync(`unzip -o "${zip_path}" -d "${target_dir}"`, { stdio: 'inherit' });
		}

		// Remove the zip file
		fs.unlinkSync(zip_path);

		// Check if files were extracted into a subdirectory
		const entries = fs.readdirSync(target_dir);
		if (entries.length === 1) {
			const subdir = path.join(target_dir, entries[0]);
			if (fs.statSync(subdir).isDirectory()) {
				// Move files from subdirectory to target_dir
				const subentries = fs.readdirSync(subdir);
				for (const entry of subentries) {
					fs.renameSync(path.join(subdir, entry), path.join(target_dir, entry));
				}
				fs.rmdirSync(subdir);
			}
		}

		console.log('StackBlitz project downloaded successfully');
	} finally {
		await browser.close();
	}
}

Domain

Subdomains

Frequently Asked Questions

What does download_stackblitz_project() do?
download_stackblitz_project() is a function in the svelte codebase, defined in playgrounds/sandbox/scripts/download.js.
Where is download_stackblitz_project() defined?
download_stackblitz_project() is defined in playgrounds/sandbox/scripts/download.js at line 137.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free