/ concept-collection / stan-web-ide
Sign in
concept-collection / stan-web-ide
Seed the GitHub workspace locally after publish
onPublished copies the published files and baseline into the per-repo workspace (transplantGitHubWorkspace) before navigating, instead of re-importing from GitHub.
Jeremy Magland <jmagland@flatironinstitute.org> committed commit 4e434baf11dc parent 8f06c18 Browse files
2 changed files+21−6
src/githubOpen.tsmodified+7−3View file
@@ -10,6 +10,12 @@ import './landing.css';
1010 // Source Control view tracking changes against the imported commit (and
1111 // offering "Reload from GitHub" to start fresh).
1212
13+/** The per-repo workspace database backing a #/github route. */
14+export function githubWorkspaceDbName(spec: { owner: string; repo: string; ref?: string; dir?: string }): string {
15+ return `stan-web-ide-gh-${spec.owner}-${spec.repo}${spec.ref ? `-${spec.ref}` : ''}${spec.dir ? `-${spec.dir}` : ''}`
16+ .toLowerCase().replace(/[^a-z0-9._-]/g, '-');
17+}
18+
1319 /** Handles a #/github/<spec> route. Returns a disposable view (the IDE, or an error screen). */
1420 export async function openGitHubRoute(container: HTMLElement, specText: string, theme: WorkbenchTheme): Promise<{ dispose(): void }> {
1521 let fs: Awaited<ReturnType<typeof createIndexedDBFileSystem>> | undefined;
@@ -18,10 +24,8 @@ export async function openGitHubRoute(container: HTMLElement, specText: string,
1824 const spec = parseGitHubSpec(specText);
1925 const name = `${spec.owner}/${spec.repo}`;
2026 document.title = `${name} — stan web IDE`;
21- const dbName = `stan-web-ide-gh-${spec.owner}-${spec.repo}${spec.ref ? `-${spec.ref}` : ''}${spec.dir ? `-${spec.dir}` : ''}`
22- .toLowerCase().replace(/[^a-z0-9._-]/g, '-');
2327
24- fs = await createIndexedDBFileSystem({ dbName });
28+ fs = await createIndexedDBFileSystem({ dbName: githubWorkspaceDbName(spec) });
2529 ide = await openStanWorkbench(container, fs, name, theme);
2630 ide.workbench.statusBar.removeItem('branding');
2731 ide.workbench.statusBar.setItem('project', 'left', 'Projects', {
src/ide.tsmodified+14−3View file
@@ -1,4 +1,5 @@
1-import { attachGitHubSourceControl, createWorkbench, type Workbench, type WorkbenchTheme, type WorkspaceFileSystem } from 'minwebide';
1+import { attachGitHubSourceControl, createIndexedDBFileSystem, createWorkbench, transplantGitHubWorkspace, type Workbench, type WorkbenchTheme, type WorkspaceFileSystem } from 'minwebide';
2+import { githubWorkspaceDbName } from './githubOpen';
23 import { createCsvTableProvider } from './csvTable';
34 import { openProjectFileSystem, touchProject, type ProjectInfo } from './projects';
45 import { createResultsViewProvider } from './stan/resultsView';
@@ -95,8 +96,18 @@ export async function openIde(container: HTMLElement, project: ProjectInfo, them
9596 const sourceControl = await attachGitHubSourceControl(ide.workbench, fs, {
9697 appName: 'stan web IDE',
9798 defaultRepoName: project.name,
98- // after publishing, the repo's own route is the canonical place to work
99- onPublished: ({ owner, repo }) => { location.hash = `#/github/${owner}/${repo}`; },
99+ // after publishing, seed the repo's own workspace from the local copy
100+ // (no re-download — the local state IS the pushed state) and make its
101+ // route the canonical place to work
102+ onPublished: async ({ owner, repo }) => {
103+ const ghFs = await createIndexedDBFileSystem({ dbName: githubWorkspaceDbName({ owner, repo }) });
104+ try {
105+ await transplantGitHubWorkspace(fs, ghFs);
106+ } finally {
107+ ghFs.dispose();
108+ }
109+ location.hash = `#/github/${owner}/${repo}`;
110+ },
100111 });
101112
102113 await openStartingFile(fs, ide.workbench);
moveopenescclose