Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions scripts/gen-example-sources.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const plugin = join(root, 'site/src/plugins/remark-port-code.mjs')
const { LANG_TO_PORT, checkoutFor, parseMeta } = await import(`file://${plugin}`)
const { landingCacheKey } = await import(`file://${join(root, 'site/src/lib/port-landing.ts')}`)
const { capabilityFiles } = await import(`file://${join(root, 'site/src/lib/core-capabilities.ts')}`)
const { capabilityApplies, capabilityFiles } = await import(`file://${join(root, 'site/src/lib/core-capabilities.ts')}`)

const CONTENT = join(root, 'site/src/content/docs')
const outArg = process.argv.indexOf('--out')
Expand Down Expand Up @@ -75,7 +75,9 @@ const CAPABILITIES = JSON.parse(readFileSync(join(root, 'site/src/data/core-capa
const choices = []
for (const [owner, capabilities] of Object.entries(CAPABILITIES)) {
for (const entry of Object.values(capabilities)) {
for (const files of capabilityFiles(entry)) {
const source = entry.revision && sourceOf(owner, undefined, join(root, `site/src/data/api/${owner}.json`))
if (!capabilityApplies(entry, source?.revision)) continue
for (const files of capabilityFiles(entry, owner)) {
if (files.length > 1) choices.push({ owner, files })
else wanted.set(`${owner}:${files[0]}`, { owner, file: files[0] })
}
Expand Down
11 changes: 3 additions & 8 deletions site/src/components/CoreHome.astro
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
---
import { Code } from 'astro-expressive-code/components'
import { coreShowcase } from '../lib/core-showcase'
import CoreShowcase from './CoreShowcase.astro'
import PackageInstall from './widgets/PackageInstall.astro'
import DocCard from './DocCard.astro'
import { PORT_BY_SLUG } from '../lib/ports'
import { CAPABILITY_GROUPS, coreLead, resolveCoreHome } from '../lib/core-home'
import { portCapabilities, type CapabilityTable } from '../lib/core-capabilities'
import { QUICKSTARTS } from '../lib/quickstarts'
import { registryFor } from '../lib/registry'
import { proseHref } from '../lib/docs-paths'
import { SITE_ROOT } from '../lib/site-root'
import CAPABILITY_TABLE from '../data/core-capabilities.json'
import SOURCES from '../data/example-sources.json'
import type { CachedSource } from '../lib/port-landing'

/**
* The body of a port's Core Library home, in the order of the Python front
Expand All @@ -32,8 +28,7 @@ interface Props {
const { port, version, cards } = Astro.props as Props
const info = PORT_BY_SLUG[port]
const home = resolveCoreHome(port, version)
const example = QUICKSTARTS[port]?.complete
const showcase = portCapabilities(port, CAPABILITY_TABLE as CapabilityTable, SOURCES as Record<string, CachedSource>)
const { quickstart, programs } = coreShowcase(port)

const released = registryFor(info).version ?? ''
const series = /^0\.(\d+)/.exec(released)?.[0]
Expand All @@ -55,7 +50,7 @@ const rest = (group: keyof typeof CAPABILITY_GROUPS) => home.capabilities[group]
<p>{coreLead(port)}</p>

<h2 id="what-it-does">What it does</h2>
{(example || showcase.length > 0) && <div class="not-prose"><CoreShowcase port={port} /></div>}
{(quickstart || programs.length > 0) && <div class="not-prose"><CoreShowcase port={port} /></div>}

{/* The installer follows the player (record 0059); the sections to go on to follow it. */}
<h2 id="install">Install</h2>
Expand Down
23 changes: 6 additions & 17 deletions site/src/components/CoreShowcase.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import { Code } from 'astro-expressive-code/components'
import HomeExample from './HomeExample.astro'
import CorePlayer from './core/CorePlayer.astro'
import { CAPABILITIES, capabilityCacheKey, portCapabilities, type CapabilityId, type CapabilityTable } from '../lib/core-capabilities'
import { HOME_VIEWS, QUICKSTARTS, homeProgram } from '../lib/quickstarts'
import { coreShowcase } from '../lib/core-showcase'
import { HOME_VIEWS, homeProgram } from '../lib/quickstarts'
import { capabilityExample, markersOnALine, playableCapability } from '../lib/core-player'
import { PORT_BY_SLUG } from '../lib/ports'
import { apisUsed, CORE_APIS } from '../lib/core-apis'
import { buildTarget } from '../lib/versions'
import TABLE from '../data/core-capabilities.json'
import SOURCES from '../data/example-sources.json'
import type { CachedSource } from '../lib/port-landing'
import { homeCodeColumns } from '../lib/quickstarts'

/**
Expand All @@ -37,11 +34,7 @@ interface Props {
links?: { href: string; label: string }[]
}
const { port, links = [] } = Astro.props as Props
const quickstart = QUICKSTARTS[port]?.complete
const quickstartCapability = CAPABILITIES.find((item) => item.id === (quickstart?.capability ?? 'typed-graph'))
if (!quickstartCapability) throw new Error(`CoreShowcase: ${port} names an unknown quickstart capability`)
// The quickstart is the panel for its capability, so a port table entry for the same capability is not a second panel: the script selects panels by id.
const programs = portCapabilities(port, TABLE as CapabilityTable, SOURCES as Record<string, CachedSource>).filter((item) => !quickstart || item.id !== quickstartCapability.id)
const { quickstart, capability: quickstartCapability, programs } = coreShowcase(port)
const quickstartCode = quickstart ? homeProgram(quickstart, 'full') : ''
// A recording of this program, run for real, makes the first capability a player; without one the program stands alone.
const player = quickstart ? await playableCapability(port, quickstartCapability.id, quickstartCode) : undefined
Expand All @@ -52,18 +45,13 @@ const hang = Math.max(
...(quickstart && player ? [markersOnALine(player.capability, HOME_VIEWS.map((view) => homeProgram(quickstart, view)), port)] : []),
...programs.flatMap((item) => {
const found = capabilityPlayers.get(item.id)
return found ? [markersOnALine(found.capability, [homeProgram(capabilityExample({ ...item, repository: '', revision: '' }), 'concise')], port)] : []
return found ? [markersOnALine(found.capability, [homeProgram(capabilityExample(item), 'concise')], port)] : []
}),
)
const shown = [
...(quickstart ? [{ ...quickstartCapability, quickstart: true as const, tmux: undefined as string | undefined }] : []),
...programs.map((item) => ({ ...item, quickstart: false as const })),
]
const cachedSource = (id: CapabilityId) => {
const entry = (TABLE as CapabilityTable)[port]![id]!
const cached = (SOURCES as Record<string, CachedSource>)[capabilityCacheKey(port, entry.file)]!
return { repository: cached.repository, revision: cached.revision }
}
const version = buildTarget(process.env).version
const apis = new Map(shown.map((item) => [item.id, apisUsed(port, CORE_APIS[port]?.[item.id] ?? [], item.quickstart ? quickstartCode : item.code, version, `${port}/${item.id}`)]))
---
Expand Down Expand Up @@ -103,9 +91,10 @@ const apis = new Map(shown.map((item) => [item.id, apisUsed(port, CORE_APIS[port
style={`--home-code-columns: ${homeCodeColumns(item.code)}`}>
{shown.length > 1 && <h3 class="core-showcase__panel-title">{item.label}</h3>}
{capabilityPlayers.get(item.id)
? <CorePlayer port={port} language={PORT_BY_SLUG[port]!.name} example={capabilityExample({ ...item, ...cachedSource(item.id) })} recording={capabilityPlayers.get(item.id)!.recording}
? <CorePlayer port={port} language={PORT_BY_SLUG[port]!.name} example={capabilityExample(item)} recording={capabilityPlayers.get(item.id)!.recording}
capability={capabilityPlayers.get(item.id)!.capability} capabilityId={item.id} options={false} run={false} hang={hang} />
: <Code code={item.code} lang={item.lang} title={item.file} frame="code" />}
{item.setupUrl && <p class="core-showcase__links"><a href={item.setupUrl}>Set up and run this example</a></p>}
{apis.get(item.id)!.shown.length > 0 && <div class="core-showcase__apis" data-core-apis>
<p class="core-showcase__apis-title">APIs used</p>
<ul class="core-showcase__apilist" data-apis-for={item.id} aria-label={`APIs used: ${item.label}`}>
Expand Down
23 changes: 23 additions & 0 deletions site/src/data/core-apis.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,28 @@
"LibTmux.Snapshot#v:lookupPane",
"LibTmux.Snapshot#v:labelText"
]
},
"lua": {
"typed-graph": [
"libtmux.Server:new_session",
"libtmux.Session:new_window",
"libtmux.Pane:split"
],
"watch": [
"libtmux.Server:observe",
"libtmux.Observation:watch_pane"
],
"send-keys": [
"libtmux.Pane:send_text",
"libtmux.Pane:send_keys",
"libtmux.Pane:wait_for_text"
],
"rename-windows": [
"libtmux.Window:rename"
],
"create-windows": [
"libtmux.Session:new_window",
"libtmux.Window:snapshot"
]
}
}
235 changes: 235 additions & 0 deletions site/src/data/core-capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,240 @@
}
]
}
},
"lua": {
"watch": {
"file": "examples/api/watch_pane.lua",
"lang": "lua",
"revision": "d8266f22bb7ddace64b597fc35899ab72c71cf9f",
"setup": "examples/api/README.md",
"tmux": "3.7+",
"ci": {
"workflow": ".github/workflows/ci.yml",
"job": "validate",
"step": "Run the ${{ matrix.gate }} gate",
"command": "luajit scripts/check/check.lua \"$CI_GATE\" --lua \"$TEST_LUA\" --nvim \".cache/toolchains/nvim-$CI_NVIM/bin/nvim\" 2>&1 | tee .cache/ci/check.log",
"matrix": {
"output": "matrix",
"cell": {
"name": "Outer current",
"gate": "outer",
"tmux": "3.8"
}
}
},
"checkedBy": [
{
"file": "examples/api/manifest.json",
"contains": "\"file\": \"examples/api/watch_pane.lua\",\n \"description\": \"Stream a pane's output from a control-mode observation and wait for typed text to arrive.\",\n \"min_tmux\": \"3.7\",\n \"stdout\": \"output: watched\\n\"\n }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ \"mid\", \"integration\", \"package\", \"types\" }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ ctx.luajit, \"scripts/package/main.lua\", \"--lua\", ctx.lua }"
},
{
"file": "scripts/package/package.lua",
"contains": "check_release(work, rocks, lua, rt, cache, options.output, options.public_tag, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "M.complete_api_examples(prefix, rt.version, lua, work, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "if code ~= 0 then\n refuse("
},
{
"file": "scripts/package/package.lua",
"contains": "if output ~= example.stdout then"
},
{
"file": ".github/workflows/ci.yml",
"contains": "defaults:\n run:\n shell: bash"
},
{
"file": ".github/workflows/ci.yml",
"contains": "CI_GATE: ${{ matrix.gate }}"
}
]
},
"send-keys": {
"file": "examples/api/send_keys.lua",
"lang": "lua",
"revision": "d8266f22bb7ddace64b597fc35899ab72c71cf9f",
"setup": "examples/api/README.md",
"ci": {
"workflow": ".github/workflows/ci.yml",
"job": "validate",
"step": "Run the ${{ matrix.gate }} gate",
"command": "luajit scripts/check/check.lua \"$CI_GATE\" --lua \"$TEST_LUA\" --nvim \".cache/toolchains/nvim-$CI_NVIM/bin/nvim\" 2>&1 | tee .cache/ci/check.log",
"matrix": {
"output": "matrix",
"cell": {
"name": "Outer current",
"gate": "outer",
"tmux": "3.8"
}
}
},
"checkedBy": [
{
"file": "examples/api/manifest.json",
"contains": "\"file\": \"examples/api/send_keys.lua\",\n \"description\": \"Send literal text and press Enter in a pane.\",\n \"stdout\": \"lua input ready\\n\"\n }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ \"mid\", \"integration\", \"package\", \"types\" }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ ctx.luajit, \"scripts/package/main.lua\", \"--lua\", ctx.lua }"
},
{
"file": "scripts/package/package.lua",
"contains": "check_release(work, rocks, lua, rt, cache, options.output, options.public_tag, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "M.complete_api_examples(prefix, rt.version, lua, work, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "if code ~= 0 then\n refuse("
},
{
"file": "scripts/package/package.lua",
"contains": "if output ~= example.stdout then"
},
{
"file": ".github/workflows/ci.yml",
"contains": "defaults:\n run:\n shell: bash"
},
{
"file": ".github/workflows/ci.yml",
"contains": "CI_GATE: ${{ matrix.gate }}"
}
]
},
"rename-windows": {
"file": "examples/api/refresh.lua",
"lang": "lua",
"revision": "d8266f22bb7ddace64b597fc35899ab72c71cf9f",
"setup": "examples/api/README.md",
"ci": {
"workflow": ".github/workflows/ci.yml",
"job": "validate",
"step": "Run the ${{ matrix.gate }} gate",
"command": "luajit scripts/check/check.lua \"$CI_GATE\" --lua \"$TEST_LUA\" --nvim \".cache/toolchains/nvim-$CI_NVIM/bin/nvim\" 2>&1 | tee .cache/ci/check.log",
"matrix": {
"output": "matrix",
"cell": {
"name": "Outer current",
"gate": "outer",
"tmux": "3.8"
}
}
},
"checkedBy": [
{
"file": "examples/api/manifest.json",
"contains": "\"file\": \"examples/api/refresh.lua\",\n \"description\": \"Read a window again after tmux renamed it, keeping the record read before.\",\n \"stdout\": \"editor build\\n\"\n }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ \"mid\", \"integration\", \"package\", \"types\" }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ ctx.luajit, \"scripts/package/main.lua\", \"--lua\", ctx.lua }"
},
{
"file": "scripts/package/package.lua",
"contains": "check_release(work, rocks, lua, rt, cache, options.output, options.public_tag, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "M.complete_api_examples(prefix, rt.version, lua, work, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "if code ~= 0 then\n refuse("
},
{
"file": "scripts/package/package.lua",
"contains": "if output ~= example.stdout then"
},
{
"file": ".github/workflows/ci.yml",
"contains": "defaults:\n run:\n shell: bash"
},
{
"file": ".github/workflows/ci.yml",
"contains": "CI_GATE: ${{ matrix.gate }}"
}
]
},
"create-windows": {
"file": "examples/api/new_window.lua",
"lang": "lua",
"revision": "d8266f22bb7ddace64b597fc35899ab72c71cf9f",
"setup": "examples/api/README.md",
"ci": {
"workflow": ".github/workflows/ci.yml",
"job": "validate",
"step": "Run the ${{ matrix.gate }} gate",
"command": "luajit scripts/check/check.lua \"$CI_GATE\" --lua \"$TEST_LUA\" --nvim \".cache/toolchains/nvim-$CI_NVIM/bin/nvim\" 2>&1 | tee .cache/ci/check.log",
"matrix": {
"output": "matrix",
"cell": {
"name": "Outer current",
"gate": "outer",
"tmux": "3.8"
}
}
},
"checkedBy": [
{
"file": "examples/api/manifest.json",
"contains": "\"file\": \"examples/api/new_window.lua\",\n \"description\": \"Create a named window in a particular session.\",\n \"stdout\": \"window: logs\\n\"\n }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ \"mid\", \"integration\", \"package\", \"types\" }"
},
{
"file": "scripts/check/gates.lua",
"contains": "{ ctx.luajit, \"scripts/package/main.lua\", \"--lua\", ctx.lua }"
},
{
"file": "scripts/package/package.lua",
"contains": "check_release(work, rocks, lua, rt, cache, options.output, options.public_tag, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "M.complete_api_examples(prefix, rt.version, lua, work, opts)"
},
{
"file": "scripts/package/package.lua",
"contains": "if code ~= 0 then\n refuse("
},
{
"file": "scripts/package/package.lua",
"contains": "if output ~= example.stdout then"
},
{
"file": ".github/workflows/ci.yml",
"contains": "defaults:\n run:\n shell: bash"
},
{
"file": ".github/workflows/ci.yml",
"contains": "CI_GATE: ${{ matrix.gate }}"
}
]
}
}
}
Loading
Loading