Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Add a simple UI to the build server
  • Loading branch information
cdata committed May 22, 2024
commit aae56e8924449cee911919e94bd24ecc1dd0e6c0
155 changes: 155 additions & 0 deletions typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions typescript/packages/usuba-sw/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ self.addEventListener('install', (_event) => {
});

self.addEventListener('fetch', async (event: FetchEvent) => {
console.log('Usuba sees a fetch event!');
if (event.request.method !== 'GET') {
return;
}

const requestUrl = new URL(event.request.url);

if (requestUrl.pathname.startsWith('/module/transpiled')) {
console.log('Pulling generated artifact from cache...');
event.respondWith(
(async () => {
const cache = await caches.open('v0/modules/transpiled');
Expand All @@ -26,6 +26,7 @@ self.addEventListener('fetch', async (event: FetchEvent) => {
})()
);
} else if (requestUrl.pathname.startsWith('/module/on-demand')) {
console.log('On-demand module generation detected...');
requestUrl.pathname.split('/').slice(2);

const [ext, witBase64, sourceCodeBase64] = requestUrl.pathname
Expand Down Expand Up @@ -90,7 +91,7 @@ self.addEventListener('fetch', async (event: FetchEvent) => {
});

for (const [filename, bytes] of files) {
console.log(filename);
console.log('Caching artifact:', filename);
const blob = new Blob([bytes], {
type: filename.endsWith('.wasm')
? 'application/wasm'
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/usuba-sw/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

48 changes: 19 additions & 29 deletions typescript/packages/usuba-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,27 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Usuba</title>
<link rel="stylesheet" href="/shoelace/dist/themes/light.css" />
<link rel="stylesheet" href="/shoelace/dist/themes/dark.css" />
<link rel="stylesheet" href="/styles.css" />
</head>

<body>
<section id="specifier">
<sl-select aria-label="Language" label="Language" value="js">
<sl-option aria-selected="true" value="js">JavaScript</sl-option>
<sl-option disabled value="py">Python</sl-option>
<sl-option disabled value="rs">Rust</sl-option>
</sl-select>
<sl-input aria-readonly="true" readonly label="Module specifier"></sl-input>
<sl-copy-button label="Copy to smizmar"></sl-copy-button>
</section>
<section id="code">
<sl-textarea label="WIT" resize="none" rows="16" spellcheck="false">
</sl-textarea>
<sl-textarea label="Source Code" resize="none" rows="16" spellcheck="false">
</sl-textarea>
</section>

<script type="module">
if ("serviceWorker" in navigator) {
Expand All @@ -29,35 +47,7 @@
}
</script>

<script type="module">
// Example component IDL
const witComponentDefinition = `
package example:hello;
world hello {
export hello: func() -> string;
}`;

// JavaScript implementation
const javascriptSourceCode = `
export function hello() {
return 'Hello, ShmavaScript!'
}`;

// Base64-encode all sources
const witBase64 = btoa(witComponentDefinition);
const javascriptBase64 = btoa(javascriptSourceCode);

console.log(witBase64);

const { hello } = await import(
/* @vite-ignore */
`/module/on-demand/js/${witBase64}/${javascriptBase64}`
);

// Prints "Hello, JavaScript!" to the console
console.log("Message from a JavaScript Wasm Component:", hello());
</script>

<script type="module" src="./src/index.ts"></script>
</body>

</html>
6 changes: 4 additions & 2 deletions typescript/packages/usuba-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"url": "https://github.com/commontoolsinc/labs/issues"
},
"homepage": "https://github.com/commontoolsinc/labs#readme",
"dependencies": {},
"dependencies": {
"@shoelace-style/shoelace": "^2.15.1"
},
"devDependencies": {
"@commontools/usuba-sw": "^0.0.1",
"typescript": "^5.2.2",
Expand All @@ -32,4 +34,4 @@
"command": "vite build"
}
}
}
}
1 change: 1 addition & 0 deletions typescript/packages/usuba-ui/public/shoelace
36 changes: 36 additions & 0 deletions typescript/packages/usuba-ui/public/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
body {
font-family: var(--sl-font-sans, sans-serif);
padding: 1em;
}

* {
box-sizing: border-box;
}

sl-textarea {
min-height: 360px;
flex: 1;
}
sl-textarea::part(textarea) {
font-family: var(--sl-font-mono, mono);
font-size: 0.85rem;
}

sl-input {
flex: 1;
}

#specifier {
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 1em;
gap: 1em;
margin-right: 1em;
}

#code {
display: flex;
flex-direction: row;
gap: 1em;
}
Loading