Skip to content

Commit fb938f8

Browse files
committed
move here
1 parent a000bb6 commit fb938f8

File tree

6 files changed

+53
-52
lines changed

6 files changed

+53
-52
lines changed

apps/svelte.dev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"ansi-to-html": "^0.7.2",
3636
"base64-js": "^1.5.1",
3737
"cookie": "^0.7.0",
38+
"do-not-zip": "^1.0.0",
3839
"d3-geo": "^3.1.0",
3940
"d3-geo-projection": "^4.0.0",
4041
"editor": "workspace:*",

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
// @ts-expect-error no types
3+
import * as doNotZip from 'do-not-zip';
24
import { browser } from '$app/environment';
35
import { afterNavigate, goto, replaceState } from '$app/navigation';
46
import type { Gist } from '$lib/db/types';
@@ -113,6 +115,44 @@
113115
}
114116
}
115117
118+
async function download() {
119+
const { files: components, imports } = repl.toJSON();
120+
121+
const files: Array<{ path: string; data: string }> =
122+
await // TODO this is a bit of a cyclic dependency: we assume that the site
123+
// does provide a template at this position which matches our expectations
124+
(await fetch('/svelte-template.json')).json();
125+
126+
if (imports.length > 0) {
127+
const idx = files.findIndex(({ path }) => path === 'package.json');
128+
const pkg = JSON.parse(files[idx].data);
129+
const { devDependencies } = pkg;
130+
imports.forEach((mod) => {
131+
const match = /^(@[^/]+\/)?[^@/]+/.exec(mod)!;
132+
devDependencies[match[0]] = 'latest';
133+
});
134+
pkg.devDependencies = devDependencies;
135+
files[idx].data = JSON.stringify(pkg, null, ' ');
136+
}
137+
138+
files.push(
139+
...components.map((component) => ({
140+
path: `src/routes/${component.name}`,
141+
data: (component as File).contents
142+
}))
143+
);
144+
145+
const url = URL.createObjectURL(doNotZip.toBlob(files));
146+
const link = document.createElement('a');
147+
link.href = url;
148+
link.download = 'svelte-app.zip';
149+
link.style.display = 'none';
150+
document.body.appendChild(link);
151+
link.click();
152+
URL.revokeObjectURL(url);
153+
link.remove();
154+
}
155+
116156
async function update_hash() {
117157
// Only change hash when necessary to avoid polluting everyone's browser history
118158
if (modified) {
@@ -200,6 +240,7 @@
200240
{can_escape}
201241
injectedJS={mapbox_setup}
202242
{onchange}
243+
{download}
203244
previewTheme={$theme.current}
204245
/>
205246
</div>

packages/repl/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"@sveltejs/site-kit": "workspace:*",
8181
"@sveltejs/svelte-json-tree": "^2.2.1",
8282
"acorn": "^8.11.3",
83-
"do-not-zip": "^1.0.0",
8483
"editor": "workspace:*",
8584
"esm-env": "^1.0.0",
8685
"esrap": "^1.2.2",

packages/repl/src/lib/Input/ComponentSelector.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
workspace: Workspace;
1111
can_migrate: boolean;
1212
migrate: () => void;
13-
download: () => void;
13+
download?: () => void;
1414
}
1515
1616
let { runes, onchange, workspace, can_migrate, migrate, download }: Props = $props();
@@ -171,7 +171,10 @@
171171
</label>
172172

173173
<button disabled={!can_migrate} onclick={migrate}>Migrate to Svelte 5, if possible</button>
174-
<button onclick={download}>Download app</button>
174+
175+
{#if download}
176+
<button onclick={download}>Download app</button>
177+
{/if}
175178
</Toolbox>
176179
</div>
177180
</div>

packages/repl/src/lib/Repl.svelte

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import * as doNotZip from 'do-not-zip';
32
import { SplitPane } from '@rich_harris/svelte-split-pane';
43
import { ScreenToggle } from '@sveltejs/site-kit/components';
54
import { BROWSER } from 'esm-env';
@@ -24,6 +23,7 @@
2423
injectedCSS?: string;
2524
previewTheme?: 'light' | 'dark';
2625
onchange?: () => void;
26+
download?: () => void;
2727
}
2828
2929
let {
@@ -38,7 +38,8 @@
3838
injectedJS = '',
3939
injectedCSS = '',
4040
previewTheme = 'light',
41-
onchange = () => {}
41+
onchange = () => {},
42+
download
4243
}: Props = $props();
4344
4445
// TODO pass in real data
@@ -108,50 +109,6 @@
108109
rebundle();
109110
}
110111
111-
async function download() {
112-
const { files: components, imports } = toJSON();
113-
114-
const files: Array<{ path: string; data: string }> =
115-
await // TODO this is a bit of a cyclic dependency: we assume that the site
116-
// does provide a template at this position which matches our expectations
117-
(
118-
await fetch('/svelte-template.json')
119-
).json();
120-
121-
if (imports.length > 0) {
122-
const idx = files.findIndex(({ path }) => path === 'package.json');
123-
const pkg = JSON.parse(files[idx].data);
124-
const { devDependencies } = pkg;
125-
imports.forEach((mod) => {
126-
const match = /^(@[^/]+\/)?[^@/]+/.exec(mod)!;
127-
devDependencies[match[0]] = 'latest';
128-
});
129-
pkg.devDependencies = devDependencies;
130-
files[idx].data = JSON.stringify(pkg, null, ' ');
131-
}
132-
133-
files.push(
134-
...components.map((component) => ({
135-
path: `src/routes/${component.name}`,
136-
data: (component as File).contents
137-
}))
138-
);
139-
140-
const downloadBlob = (blob: any, filename: string) => {
141-
const url = URL.createObjectURL(blob);
142-
const link = document.createElement('a');
143-
link.href = url;
144-
link.download = filename;
145-
link.style.display = 'none';
146-
document.body.appendChild(link);
147-
link.click();
148-
URL.revokeObjectURL(url);
149-
link.remove();
150-
};
151-
152-
downloadBlob(doNotZip.toBlob(files), 'svelte-app.zip');
153-
}
154-
155112
let width = $state(0);
156113
let show_output = $state(false);
157114
let status: string | null = $state(null);

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)