@dexhq/canvas 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/README.md +5 -3
- package/app/canvas/activity-parts.tsx +50 -6
- package/app/canvas/activity.tsx +10 -18
- package/app/canvas/agent-changes.ts +18 -8
- package/app/canvas/anchoring.ts +15 -7
- package/app/canvas/canvas-context.tsx +6 -2
- package/app/canvas/canvas-input.ts +186 -14
- package/app/canvas/canvas-keys.ts +9 -0
- package/app/canvas/canvas-model.ts +7 -44
- package/app/canvas/canvas-panels.ts +1 -17
- package/app/canvas/canvas-scene.ts +250 -27
- package/app/canvas/canvas-ui.ts +13 -3
- package/app/canvas/canvas.css +147 -29
- package/app/canvas/change-notice.tsx +10 -1
- package/app/canvas/comment-layer.tsx +2 -1
- package/app/canvas/comments.tsx +270 -111
- package/app/canvas/element-link.ts +135 -0
- package/app/canvas/element-picker.ts +223 -27
- package/app/canvas/engine/canvas-gestures.ts +72 -17
- package/app/canvas/engine/canvas-store.ts +17 -1
- package/app/canvas/engine/engine.css +6 -3
- package/app/canvas/export-dialog.tsx +265 -0
- package/app/canvas/find-bar.tsx +817 -0
- package/app/canvas/find-model.ts +135 -0
- package/app/canvas/flow-canvas.tsx +83 -16
- package/app/canvas/follow-pin.ts +26 -6
- package/app/canvas/frame-context-menu.tsx +61 -7
- package/app/canvas/frame-node.tsx +19 -20
- package/app/canvas/imported-reviews.tsx +12 -22
- package/app/canvas/layout.ts +68 -22
- package/app/canvas/linked-element.tsx +196 -0
- package/app/canvas/live-page.ts +156 -19
- package/app/canvas/mentions.tsx +209 -0
- package/app/canvas/page-find.ts +220 -0
- package/app/canvas/page-style.ts +23 -0
- package/app/canvas/picked-box.tsx +21 -0
- package/app/canvas/removed-views-panel.tsx +4 -4
- package/app/canvas/request-node.tsx +151 -0
- package/app/canvas/review-panel.tsx +8 -3
- package/app/canvas/section-node.tsx +6 -133
- package/app/canvas/spec-margin.tsx +4 -1
- package/app/canvas/spec-threads.ts +24 -23
- package/app/canvas/teammates-layer.tsx +205 -0
- package/app/canvas/text-layer.tsx +103 -17
- package/app/canvas/thread-focus.tsx +14 -12
- package/app/canvas/tool-cursors.ts +7 -6
- package/app/canvas/tool-icons.tsx +24 -56
- package/app/canvas/typing.ts +12 -0
- package/app/canvas/use-activity.ts +0 -8
- package/app/canvas/use-agent-changes.tsx +40 -42
- package/app/canvas/use-canvas-clipboard.tsx +11 -14
- package/app/canvas/use-canvas-editor.ts +4 -2
- package/app/canvas/xray.ts +3 -12
- package/app/export/player-model.ts +159 -0
- package/app/export/player.tsx +198 -0
- package/app/export.html +31 -0
- package/app/export.tsx +9 -0
- package/app/frame/announce-refreshes.ts +21 -0
- package/app/frame/start-frame.tsx +50 -0
- package/app/frame/view-loads.ts +161 -0
- package/app/frame/views.ts +13 -49
- package/app/frame.tsx +2 -33
- package/app/i18n/locales/en/messages.po +233 -14
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +232 -13
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/dex-glyphs.tsx +219 -0
- package/app/icons/glyphs.tsx +80 -80
- package/app/kit/use-flow.ts +2 -1
- package/app/live/canvas-teammates.ts +90 -0
- package/app/live/studio-api.ts +30 -20
- package/app/main.tsx +3 -0
- package/app/pages/canvas.tsx +45 -14
- package/app/pages/commands-settings.tsx +17 -3
- package/app/pages/render.tsx +39 -11
- package/app/shell/bell.tsx +15 -5
- package/app/shell/feedback-form.tsx +10 -21
- package/app/shell/feedback-link.tsx +2 -1
- package/app/shell/presence.tsx +123 -26
- package/app/shell/scaled-frame.tsx +21 -9
- package/app/shell/thread-list.tsx +25 -8
- package/app/shell/working-on.tsx +35 -3
- package/app/types.ts +21 -205
- package/app/ui/file-drop.ts +128 -0
- package/app/ui/prompt-editor.tsx +39 -11
- package/app/ui/reference.tsx +21 -8
- package/app/ui/shadcn/input-group.tsx +2 -2
- package/bin/sudio.mjs +1 -1
- package/dist/cli/banner.d.mts +4 -2
- package/dist/cli/banner.mjs +34 -11
- package/dist/cli/commands/app.mjs +19 -11
- package/dist/cli/commands/create.d.mts +5 -5
- package/dist/cli/commands/create.mjs +4 -4
- package/dist/cli/commands/export.d.mts +40 -0
- package/dist/cli/commands/export.mjs +66 -0
- package/dist/cli/commands/hook.mjs +2 -1
- package/dist/cli/commands/init.d.mts +2 -2
- package/dist/cli/commands/upgrade.mjs +1 -1
- package/dist/cli/help.d.mts +1 -1
- package/dist/cli/help.mjs +13 -7
- package/dist/cli/main.d.mts +42 -5
- package/dist/cli/main.mjs +1 -0
- package/dist/config/load.mjs +14 -2
- package/dist/config/project-files.d.mts +11 -0
- package/dist/config/project-files.mjs +23 -2
- package/dist/config/renamed.d.mts +7 -2
- package/dist/config/renamed.mjs +13 -3
- package/dist/content/capture.d.mts +2 -2
- package/dist/content/capture.mjs +2 -2
- package/dist/content/commands.d.mts +11 -9
- package/dist/content/commands.mjs +22 -16
- package/dist/content/comments-log.mjs +2 -1
- package/dist/content/content.d.mts +13 -143
- package/dist/content/content.mjs +55 -76
- package/dist/content/element-words.d.mts +42 -0
- package/dist/content/element-words.mjs +112 -0
- package/dist/content/flow-specs.mjs +1 -1
- package/dist/content/hosted-person.d.mts +31 -0
- package/dist/content/hosted-person.mjs +68 -0
- package/dist/content/merge-rules.d.mts +5 -0
- package/dist/content/merge-rules.mjs +17 -1
- package/dist/content/prototype-summary.d.mts +3 -39
- package/dist/content/prototype-summary.mjs +2 -3
- package/dist/content/prototypes.mjs +1 -1
- package/dist/content/screenshot.mjs +9 -0
- package/dist/content/text-edit.d.mts +24 -14
- package/dist/content/text-edit.mjs +92 -81
- package/dist/content/text-replace.d.mts +30 -0
- package/dist/content/text-replace.mjs +285 -0
- package/dist/content/thread-module.d.mts +2 -4
- package/dist/content/thread-module.mjs +4 -5
- package/dist/content/threads.mjs +1 -1
- package/dist/paste/paste.mjs +1 -1
- package/dist/paths.d.mts +0 -2
- package/dist/paths.mjs +1 -3
- package/dist/server/agent-env.d.mts +5 -1
- package/dist/server/agent-env.mjs +7 -2
- package/dist/server/agent-session.d.mts +14 -1
- package/dist/server/agent-session.mjs +84 -19
- package/dist/server/agents.d.mts +10 -0
- package/dist/server/agents.mjs +21 -6
- package/dist/server/build-pictures.mjs +1 -1
- package/dist/server/canvas-presence.d.mts +22 -0
- package/dist/server/canvas-presence.mjs +160 -0
- package/dist/server/channel.d.mts +13 -24
- package/dist/server/channel.mjs +55 -37
- package/dist/server/claimed-presence.d.mts +3 -2
- package/dist/server/claimed-presence.mjs +15 -7
- package/dist/server/close-check.mjs +2 -2
- package/dist/server/command-settings.mjs +1 -1
- package/dist/server/comments/actions.d.mts +145 -0
- package/dist/server/comments/actions.mjs +146 -0
- package/dist/server/comments/routes.d.mts +25 -0
- package/dist/server/comments/routes.mjs +67 -0
- package/dist/server/comments/tools.d.mts +6 -0
- package/dist/server/comments/tools.mjs +154 -0
- package/dist/server/dev-server.mjs +59 -23
- package/dist/server/export/build.d.mts +15 -0
- package/dist/server/export/build.mjs +220 -0
- package/dist/server/export/page.d.mts +25 -0
- package/dist/server/export/page.mjs +40 -0
- package/dist/server/export/plugin.d.mts +31 -0
- package/dist/server/export/plugin.mjs +69 -0
- package/dist/server/export/run.d.mts +9 -0
- package/dist/server/export/run.mjs +61 -0
- package/dist/server/export/save.d.mts +7 -0
- package/dist/server/export/save.mjs +29 -0
- package/dist/server/file-lock.d.mts +2 -2
- package/dist/server/file-lock.mjs +130 -36
- package/dist/server/hosted.d.mts +8 -0
- package/dist/server/hosted.mjs +78 -0
- package/dist/server/live-mirror.mjs +66 -10
- package/dist/server/live.mjs +28 -1
- package/dist/server/mcp.d.mts +0 -2
- package/dist/server/mcp.mjs +9 -8
- package/dist/server/me.d.mts +3 -1
- package/dist/server/me.mjs +8 -2
- package/dist/server/notices.d.mts +1 -1
- package/dist/server/notices.mjs +1 -1
- package/dist/server/open-page.d.mts +22 -0
- package/dist/server/open-page.mjs +20 -2
- package/dist/server/outcome.d.mts +22 -0
- package/dist/server/outcome.mjs +8 -0
- package/dist/server/own-copies.mjs +1 -1
- package/dist/server/people.d.mts +8 -3
- package/dist/server/people.mjs +6 -2
- package/dist/server/pictures.d.mts +1 -1
- package/dist/server/pictures.mjs +2 -2
- package/dist/server/port.d.mts +12 -0
- package/dist/server/port.mjs +66 -14
- package/dist/server/prebundle.d.mts +32 -0
- package/dist/server/prebundle.mjs +115 -0
- package/dist/server/presence.d.mts +4 -1
- package/dist/server/presence.mjs +2 -2
- package/dist/server/problems.d.mts +8 -0
- package/dist/server/problems.mjs +13 -0
- package/dist/server/requests.d.mts +5 -1
- package/dist/server/requests.mjs +76 -78
- package/dist/server/source-stamp.d.mts +4 -3
- package/dist/server/source-stamp.mjs +60 -31
- package/dist/server/state.d.mts +19 -10
- package/dist/server/state.mjs +27 -18
- package/dist/server/studio-for.d.mts +5 -0
- package/dist/server/studio-for.mjs +17 -3
- package/dist/server/sync-install.d.mts +8 -12
- package/dist/server/sync-install.mjs +12 -30
- package/dist/server/thread-source.d.mts +8 -0
- package/dist/server/thread-source.mjs +25 -6
- package/dist/server/tools/describe.d.mts +1 -1
- package/dist/server/tools/describe.mjs +1 -1
- package/dist/server/tools/export.d.mts +5 -0
- package/dist/server/tools/export.mjs +35 -0
- package/dist/server/tools/feedback.d.mts +1 -1
- package/dist/server/tools/place-frame.mjs +16 -16
- package/dist/server/tools/reading.mjs +13 -4
- package/dist/server/tools/show.d.mts +1 -1
- package/dist/server/tools/snapshot.d.mts +1 -1
- package/dist/server/tools/thread-list.mjs +2 -2
- package/dist/server/tools/watch.mjs +5 -3
- package/dist/server/vite.d.mts +9 -4
- package/dist/server/vite.mjs +65 -63
- package/dist/server/web-app.mjs +4 -7
- package/dist/server/welcome.mjs +2 -1
- package/dist/server/work-groups.mjs +1 -1
- package/dist/setup/apply.d.mts +4 -0
- package/dist/setup/apply.mjs +5 -4
- package/dist/setup/create.d.mts +4 -2
- package/dist/setup/create.mjs +72 -22
- package/dist/setup/design-system-checks.mjs +3 -17
- package/dist/setup/desktop-app-script.mjs +4 -3
- package/dist/setup/desktop-app-start.d.mts +8 -2
- package/dist/setup/desktop-app-start.mjs +64 -29
- package/dist/setup/desktop-app.d.mts +8 -0
- package/dist/setup/desktop-app.mjs +19 -3
- package/dist/setup/detect/workspace.d.mts +10 -10
- package/dist/setup/detect/workspace.mjs +10 -12
- package/dist/setup/detect.d.mts +0 -2
- package/dist/setup/detect.mjs +1 -3
- package/dist/setup/doctor.d.mts +4 -1
- package/dist/setup/doctor.mjs +8 -6
- package/dist/setup/migrate/dex-folder.d.mts +61 -0
- package/dist/setup/migrate/dex-folder.mjs +544 -0
- package/dist/setup/migrate/files-folder.mjs +1 -1
- package/dist/setup/migrate/guides.mjs +1 -1
- package/dist/setup/migrate/migrations.mjs +4 -0
- package/dist/setup/migrate/row-titles.mjs +1 -1
- package/dist/setup/migrate/setup-files.d.mts +5 -0
- package/dist/setup/migrate/setup-files.mjs +115 -0
- package/dist/setup/migrate/studio-state.d.mts +2 -2
- package/dist/setup/migrate/studio-state.mjs +4 -4
- package/dist/setup/placement.d.mts +1 -1
- package/dist/setup/placement.mjs +5 -4
- package/dist/setup/plan.d.mts +5 -5
- package/dist/setup/plan.mjs +8 -12
- package/dist/setup/project.d.mts +6 -1
- package/dist/setup/project.mjs +10 -10
- package/dist/setup/prompts.d.mts +2 -1
- package/dist/setup/prompts.mjs +4 -3
- package/dist/setup/questions.mjs +3 -2
- package/dist/setup/starters.d.mts +3 -1
- package/dist/setup/starters.mjs +9 -3
- package/dist/setup/write.d.mts +15 -3
- package/dist/setup/write.mjs +23 -3
- package/dist/shared/annotations-core.mjs +1 -1
- package/dist/shared/canvas-core.d.mts +22 -7
- package/dist/shared/canvas-core.mjs +39 -11
- package/dist/shared/canvas-file.d.mts +201 -0
- package/dist/shared/canvas-file.mjs +1 -0
- package/dist/shared/comments/routes.d.mts +55 -0
- package/dist/shared/comments/routes.mjs +39 -0
- package/dist/shared/export-core.d.mts +62 -0
- package/dist/shared/export-core.mjs +101 -0
- package/dist/shared/feedback.d.mts +8 -0
- package/dist/shared/feedback.mjs +10 -2
- package/dist/shared/live-core.d.mts +2 -0
- package/dist/shared/live-core.mjs +6 -1
- package/dist/shared/live-presence.d.mts +57 -2
- package/dist/shared/live-presence.mjs +90 -4
- package/dist/shared/page-messages.d.mts +14 -1
- package/dist/shared/page-messages.mjs +30 -3
- package/dist/shared/page-review.d.mts +2 -11
- package/dist/shared/page-review.mjs +4 -13
- package/dist/shared/people-core.d.mts +28 -0
- package/dist/shared/people-core.mjs +27 -1
- package/dist/shared/presence-core.d.mts +13 -0
- package/dist/shared/presence-core.mjs +11 -2
- package/dist/shared/references-core.d.mts +4 -0
- package/dist/shared/references-core.mjs +12 -4
- package/dist/shared/review-file.d.mts +5 -0
- package/dist/shared/review-file.mjs +23 -13
- package/dist/shared/server-page.mjs +1 -1
- package/dist/shared/signup.d.mts +2 -5
- package/dist/shared/signup.mjs +2 -35
- package/dist/shared/studio-events.d.mts +0 -6
- package/dist/shared/studio-events.mjs +1 -5
- package/dist/shared/studio-files.d.mts +21 -0
- package/dist/shared/studio-files.mjs +16 -2
- package/dist/shared/studio-routes.d.mts +29 -63
- package/dist/shared/studio-routes.mjs +1 -69
- package/dist/shared/threads-core.d.mts +29 -6
- package/dist/shared/threads-core.mjs +68 -13
- package/extension/dist/feedback.js +104 -284
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +104 -284
- package/package.json +2 -2
- package/src/cli/banner.ts +45 -11
- package/src/cli/commands/app.ts +23 -8
- package/src/cli/commands/create.ts +4 -4
- package/src/cli/commands/export.ts +78 -0
- package/src/cli/commands/hook.ts +4 -1
- package/src/cli/commands/upgrade.ts +1 -1
- package/src/cli/help.ts +13 -7
- package/src/cli/main.ts +1 -0
- package/src/config/load.ts +26 -2
- package/src/config/project-files.ts +36 -6
- package/src/config/renamed.ts +19 -4
- package/src/content/capture.ts +6 -12
- package/src/content/commands.ts +30 -18
- package/src/content/comments-log.ts +4 -1
- package/src/content/content.ts +71 -257
- package/src/content/element-words.ts +175 -0
- package/src/content/flow-specs.ts +2 -1
- package/src/content/hosted-person.ts +107 -0
- package/src/content/merge-rules.ts +29 -0
- package/src/content/prototype-summary.ts +4 -44
- package/src/content/review-pages.ts +2 -1
- package/src/content/screenshot.ts +14 -0
- package/src/content/text-edit.ts +172 -105
- package/src/content/text-replace.ts +420 -0
- package/src/content/thread-module.ts +2 -4
- package/src/content/trash.ts +1 -1
- package/src/paths.ts +0 -8
- package/src/server/agent-env.ts +12 -2
- package/src/server/agent-session.ts +124 -34
- package/src/server/agents.ts +48 -17
- package/src/server/canvas-presence.ts +237 -0
- package/src/server/channel.ts +95 -53
- package/src/server/claimed-presence.ts +26 -10
- package/src/server/command-settings.ts +1 -1
- package/src/server/comments/actions.ts +333 -0
- package/src/server/comments/routes.ts +131 -0
- package/src/server/comments/tools.ts +317 -0
- package/src/server/dev-server.ts +94 -33
- package/src/server/export/build.ts +310 -0
- package/src/server/export/page.ts +85 -0
- package/src/server/export/plugin.ts +138 -0
- package/src/server/export/run.ts +79 -0
- package/src/server/export/save.ts +38 -0
- package/src/server/file-lock.ts +205 -54
- package/src/server/hosted.ts +113 -0
- package/src/server/live-mirror.ts +93 -8
- package/src/server/live.ts +46 -1
- package/src/server/machine-update.ts +3 -3
- package/src/server/mcp.ts +15 -14
- package/src/server/me.ts +12 -6
- package/src/server/notices.ts +2 -2
- package/src/server/open-page.ts +54 -4
- package/src/server/outcome.ts +26 -0
- package/src/server/people.ts +13 -3
- package/src/server/pictures.ts +2 -2
- package/src/server/port.ts +94 -20
- package/src/server/prebundle.ts +230 -0
- package/src/server/presence.ts +12 -4
- package/src/server/problems.ts +11 -0
- package/src/server/requests.ts +115 -110
- package/src/server/roster.ts +1 -1
- package/src/server/saved.ts +1 -1
- package/src/server/source-stamp.ts +118 -37
- package/src/server/state.ts +53 -31
- package/src/server/studio-for.ts +26 -2
- package/src/server/sync-install.ts +35 -26
- package/src/server/thread-place.ts +2 -4
- package/src/server/thread-source.ts +35 -3
- package/src/server/tools/export.ts +56 -0
- package/src/server/tools/place-frame.ts +23 -15
- package/src/server/tools/reading.ts +16 -3
- package/src/server/tools/thread-list.ts +1 -1
- package/src/server/tools/watch.ts +7 -7
- package/src/server/updates.ts +2 -2
- package/src/server/vite.ts +106 -110
- package/src/server/web-app.ts +11 -9
- package/src/server/welcome.ts +3 -1
- package/src/setup/apply.ts +8 -5
- package/src/setup/create.ts +101 -27
- package/src/setup/design-system-checks.ts +8 -21
- package/src/setup/desktop-app-script.ts +4 -3
- package/src/setup/desktop-app-start.ts +94 -26
- package/src/setup/desktop-app.ts +23 -2
- package/src/setup/detect/workspace.ts +20 -21
- package/src/setup/detect.ts +0 -4
- package/src/setup/doctor.ts +13 -6
- package/src/setup/migrate/dex-folder.ts +842 -0
- package/src/setup/migrate/files-folder.ts +1 -1
- package/src/setup/migrate/guides.ts +3 -1
- package/src/setup/migrate/migrations.ts +8 -2
- package/src/setup/migrate/setup-files.ts +198 -0
- package/src/setup/migrate/studio-state.ts +12 -10
- package/src/setup/own-app.ts +1 -1
- package/src/setup/placement.ts +7 -6
- package/src/setup/plan.ts +13 -18
- package/src/setup/project.ts +11 -10
- package/src/setup/prompts.ts +5 -4
- package/src/setup/questions.ts +6 -3
- package/src/setup/starters.ts +11 -4
- package/src/setup/write.ts +34 -3
- package/src/shared/canvas-core.ts +48 -9
- package/src/shared/canvas-file.ts +205 -0
- package/src/shared/comments/routes.ts +81 -0
- package/src/shared/export-core.ts +198 -0
- package/src/shared/feedback.ts +14 -4
- package/src/shared/live-core.ts +8 -0
- package/src/shared/live-presence.ts +171 -2
- package/src/shared/page-messages.ts +38 -2
- package/src/shared/page-review.ts +11 -16
- package/src/shared/people-core.ts +44 -0
- package/src/shared/presence-core.ts +18 -2
- package/src/shared/references-core.ts +22 -3
- package/src/shared/review-file.ts +28 -12
- package/src/shared/server-page.ts +2 -1
- package/src/shared/signup.ts +4 -28
- package/src/shared/studio-events.ts +0 -13
- package/src/shared/studio-files.ts +29 -1
- package/src/shared/studio-routes.ts +32 -65
- package/src/shared/threads-core.ts +134 -12
- package/templates/methods/explore.md +1 -1
- package/templates/methods/handoff.md +1 -1
- package/templates/methods/review.md +2 -1
- package/templates/rules/canvas-frames.md +6 -3
- package/templates/rules/commands.md +1 -0
- package/templates/rules/prototypes.md +1 -1
- package/templates/rules/studio.md +17 -11
- package/templates/skills/comprehend/SKILL.md +56 -0
- package/templates/skills/distill/SKILL.md +172 -0
- package/templates/skills/export-prototype/SKILL.md +35 -0
- package/templates/skills/riff/SKILL.md +21 -0
- package/templates/skills/riff-deep/SKILL.md +40 -0
- package/templates/skills/riff-max/SKILL.md +46 -0
- package/templates/skills/riff-state/SKILL.md +45 -0
- package/templates/skills/riff-up/SKILL.md +38 -0
- package/templates/skills/riff-wide/SKILL.md +40 -0
- package/templates/starters/standalone/README.md +1 -1
- package/templates/starters/turborepo/README.md +2 -2
- package/templates/starters/turborepo/apps/web/src/app.tsx +2 -2
- package/templates/starters/vite/README.md +1 -1
- package/dist/server/tools/close-reply.d.mts +0 -6
- package/dist/server/tools/close-reply.mjs +0 -138
- package/dist/server/tools/comment.d.mts +0 -6
- package/dist/server/tools/comment.mjs +0 -49
- package/src/server/tools/close-reply.ts +0 -271
- package/src/server/tools/comment.ts +0 -96
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
cp,
|
|
4
|
+
mkdir,
|
|
5
|
+
mkdtemp,
|
|
6
|
+
readdir,
|
|
7
|
+
readFile,
|
|
8
|
+
rm,
|
|
9
|
+
writeFile,
|
|
10
|
+
} from "node:fs/promises";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import type { InlineConfig, PluginOption } from "vite";
|
|
14
|
+
import { readCanvas } from "../../content/content.ts";
|
|
15
|
+
import { prototypeTitle, viewFiles } from "../../content/prototypes.ts";
|
|
16
|
+
import { APP_DIR } from "../../paths.ts";
|
|
17
|
+
import { frameTitle } from "../../shared/canvas-core.ts";
|
|
18
|
+
import {
|
|
19
|
+
type ExportChoice,
|
|
20
|
+
type ExportData,
|
|
21
|
+
type ExportedFrame,
|
|
22
|
+
exportedPath,
|
|
23
|
+
exportFileName,
|
|
24
|
+
exportSelection,
|
|
25
|
+
} from "../../shared/export-core.ts";
|
|
26
|
+
import { prototypeFiles, slugify } from "../../shared/prototypes-core.ts";
|
|
27
|
+
import { studioState } from "../state.ts";
|
|
28
|
+
import { frameStylesheet, type StudioProject, viteConfig } from "../vite.ts";
|
|
29
|
+
import { zipFolder } from "../zip.ts";
|
|
30
|
+
import {
|
|
31
|
+
APP_SCRIPT,
|
|
32
|
+
APP_STYLES,
|
|
33
|
+
CONTENT_SCRIPT,
|
|
34
|
+
contentScript,
|
|
35
|
+
exportPage,
|
|
36
|
+
} from "./page.ts";
|
|
37
|
+
import { type ExportFound, exportPlugin } from "./plugin.ts";
|
|
38
|
+
|
|
39
|
+
// Export prototype: the chosen frames of a file as a zip that opens by
|
|
40
|
+
// double-click, offline. The frame page (app/export.html, its player
|
|
41
|
+
// stepping as Play does) built as one classic script and one stylesheet,
|
|
42
|
+
// with only the exported views, none of Dex's interface, and none of the
|
|
43
|
+
// project's public folder: index.html, app.js and app.css, and per kind
|
|
44
|
+
// - pages: a page more for each frame, opening on it;
|
|
45
|
+
// - content: content.js, the words and data the views read from their
|
|
46
|
+
// content.json, to edit without building again, and the file's notes;
|
|
47
|
+
// - source: the prototype's files the bundle took, to build on.
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Dex's plugins an export leaves out: its web app's manifest and icons, and
|
|
51
|
+
* the project's public folder (copied whole).
|
|
52
|
+
*/
|
|
53
|
+
const LEFT_OUT = new Set(["studio-web-app", "dex:project-public"]);
|
|
54
|
+
|
|
55
|
+
const ENTRY = "export.html";
|
|
56
|
+
/** The frame page's stylesheet, as its entry imports it. */
|
|
57
|
+
const FRAME_CSS_RE = /^@studio-frame\.css$/;
|
|
58
|
+
/** What the build may write: the page, its script and its stylesheet. */
|
|
59
|
+
const BUILT = new Set([ENTRY, APP_SCRIPT, APP_STYLES]);
|
|
60
|
+
/** Dex's own files a build writes that an export has no use for. */
|
|
61
|
+
const DEX_FILES = new Set(["workspace-icon.svg", "workspace-icon.png"]);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Keep only what the page loads. Anything else the bundle needs, such as a
|
|
65
|
+
* worker or WebAssembly, can't load from a page opened by double-click: the
|
|
66
|
+
* export fails rather than open broken.
|
|
67
|
+
*/
|
|
68
|
+
async function keepBuilt(out: string) {
|
|
69
|
+
for (const file of await readdir(out)) {
|
|
70
|
+
if (DEX_FILES.has(file)) {
|
|
71
|
+
await rm(join(out, file));
|
|
72
|
+
} else if (!BUILT.has(file)) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`The prototype needs ${file}, which a page opened by double-click can't load (a worker or WebAssembly). Leave out the frames that use it, then export again.`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ExportResult {
|
|
81
|
+
/** The zip, as its file would hold it. */
|
|
82
|
+
bytes: Buffer;
|
|
83
|
+
/** What the zip is called: the file's title. */
|
|
84
|
+
name: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const flatten = (options: readonly unknown[]): unknown[] =>
|
|
88
|
+
options.flatMap((option) =>
|
|
89
|
+
Array.isArray(option) ? flatten(option) : [option]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const plugins = (options: PluginOption[] | undefined): PluginOption[] =>
|
|
93
|
+
flatten(options ?? []).filter((plugin) => {
|
|
94
|
+
const name =
|
|
95
|
+
plugin && typeof plugin === "object" && "name" in plugin
|
|
96
|
+
? plugin.name
|
|
97
|
+
: undefined;
|
|
98
|
+
return !(typeof name === "string" && LEFT_OUT.has(name));
|
|
99
|
+
}) as PluginOption[];
|
|
100
|
+
|
|
101
|
+
const exportedFrames = (data: ExportData): ExportedFrame[] =>
|
|
102
|
+
data.sections.flatMap((section) => section.rows.flatMap((row) => row.frames));
|
|
103
|
+
|
|
104
|
+
/** A page per frame, numbered in the canvas's order: "02-card-declined.html". */
|
|
105
|
+
const framePages = (data: ExportData) => {
|
|
106
|
+
const seen = new Set<string>();
|
|
107
|
+
return exportedFrames(data).flatMap((frame) => {
|
|
108
|
+
const start = exportedPath(data.slug, frame);
|
|
109
|
+
if (seen.has(start)) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
seen.add(start);
|
|
113
|
+
const number = String(seen.size).padStart(2, "0");
|
|
114
|
+
const name = slugify(frameTitle(frame)) || frame.view;
|
|
115
|
+
return [{ file: `${number}-${name}.html`, start }];
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
async function markdownIn(folder: string): Promise<string[]> {
|
|
120
|
+
const entries = await readdir(folder, { recursive: true }).catch(() => []);
|
|
121
|
+
return entries.filter((entry) => entry.endsWith(".md")).sort();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Write what each kind adds beside the bundle. */
|
|
125
|
+
async function writeKind(
|
|
126
|
+
out: string,
|
|
127
|
+
choice: ExportChoice,
|
|
128
|
+
context: {
|
|
129
|
+
data: ExportData;
|
|
130
|
+
found: ExportFound;
|
|
131
|
+
html: string;
|
|
132
|
+
people: string[];
|
|
133
|
+
prototypeDir: string;
|
|
134
|
+
}
|
|
135
|
+
) {
|
|
136
|
+
const { data, found, html, people, prototypeDir } = context;
|
|
137
|
+
const content = choice.kind === "content";
|
|
138
|
+
await writeFile(join(out, "index.html"), exportPage(html, { content, data }));
|
|
139
|
+
if (choice.kind === "pages") {
|
|
140
|
+
for (const page of framePages(data)) {
|
|
141
|
+
await writeFile(
|
|
142
|
+
join(out, page.file),
|
|
143
|
+
exportPage(html, { content, data, start: page.start })
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (content) {
|
|
148
|
+
if (found.content.size === 0) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
"None of these views reads its words from a content.json yet, so a content pack would have nothing to edit. Ask the agent to prepare one (/export-prototype content), then export again."
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
await writeFile(join(out, CONTENT_SCRIPT), contentScript(found.content));
|
|
154
|
+
// The file's notes and specs, as they are.
|
|
155
|
+
for (const person of people) {
|
|
156
|
+
const folder = join(prototypeDir, "people", person);
|
|
157
|
+
for (const file of await markdownIn(folder)) {
|
|
158
|
+
const to = join(out, "docs", file);
|
|
159
|
+
await mkdir(dirname(to), { recursive: true });
|
|
160
|
+
await cp(join(folder, file), to, { dereference: false });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (choice.kind === "source") {
|
|
165
|
+
for (const file of found.sources) {
|
|
166
|
+
const to = join(out, "source", file);
|
|
167
|
+
await mkdir(dirname(to), { recursive: true });
|
|
168
|
+
await cp(join(prototypeDir, file), to, { dereference: false });
|
|
169
|
+
}
|
|
170
|
+
await writeFile(
|
|
171
|
+
join(out, "source", "README.md"),
|
|
172
|
+
[
|
|
173
|
+
`# ${data.title}: source`,
|
|
174
|
+
"",
|
|
175
|
+
"The prototype's own files this export was built from: its views and",
|
|
176
|
+
"what they import. They render with the design system they were made",
|
|
177
|
+
"in, which is not included: build them where it is.",
|
|
178
|
+
"",
|
|
179
|
+
].join("\n")
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Run a build as production: React's JSX transform follows NODE_ENV, not
|
|
186
|
+
* Vite's mode, and in development (as under `dex dev`, or in tests) writes
|
|
187
|
+
* every element's file path into the bundle, people's names with them.
|
|
188
|
+
*/
|
|
189
|
+
async function productionBuild<T>(run: () => Promise<T>): Promise<T> {
|
|
190
|
+
const before = process.env.NODE_ENV;
|
|
191
|
+
process.env.NODE_ENV = "production";
|
|
192
|
+
try {
|
|
193
|
+
return await run();
|
|
194
|
+
} finally {
|
|
195
|
+
if (before === undefined) {
|
|
196
|
+
delete process.env.NODE_ENV;
|
|
197
|
+
} else {
|
|
198
|
+
process.env.NODE_ENV = before;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Export frames of a file, as `choice` says. Throws, saying why, when the
|
|
205
|
+
* choice names frames the file does not have or nothing that shows a view.
|
|
206
|
+
*/
|
|
207
|
+
export async function exportPrototype(
|
|
208
|
+
project: StudioProject,
|
|
209
|
+
slug: string,
|
|
210
|
+
choice: ExportChoice
|
|
211
|
+
): Promise<ExportResult> {
|
|
212
|
+
const files = prototypeFiles(slug);
|
|
213
|
+
if (!files) {
|
|
214
|
+
throw new Error(`"${slug}" is not a file's name.`);
|
|
215
|
+
}
|
|
216
|
+
const canvas = await readCanvas(slug, project.content);
|
|
217
|
+
const selection = exportSelection(canvas, choice);
|
|
218
|
+
const found = await viewFiles(project.content, slug);
|
|
219
|
+
const views = selection.views.map((name) => {
|
|
220
|
+
const view = found.get(name);
|
|
221
|
+
if (!view) {
|
|
222
|
+
throw new Error(`This file has no view "${name}".`);
|
|
223
|
+
}
|
|
224
|
+
return { name, file: view.file, person: view.person };
|
|
225
|
+
});
|
|
226
|
+
const people = [...new Set(views.map((view) => view.person))].sort();
|
|
227
|
+
const prototypeDir = join(project.content, files.folder);
|
|
228
|
+
const title = await prototypeTitle(project.content, slug);
|
|
229
|
+
const data: ExportData = {
|
|
230
|
+
flows: choice.flows ?? false,
|
|
231
|
+
slug,
|
|
232
|
+
sections: selection.sections,
|
|
233
|
+
title,
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const state = studioState(project.content);
|
|
237
|
+
const vite = await viteConfig(project, "production");
|
|
238
|
+
// Tailwind reads only the exported people's folders, not every file's.
|
|
239
|
+
const stylesheet = state.exportCss(randomUUID());
|
|
240
|
+
await writeFile(
|
|
241
|
+
stylesheet,
|
|
242
|
+
frameStylesheet(
|
|
243
|
+
project,
|
|
244
|
+
state.dir,
|
|
245
|
+
people.map((person) => join(prototypeDir, "people", person))
|
|
246
|
+
)
|
|
247
|
+
);
|
|
248
|
+
const out = await mkdtemp(join(tmpdir(), "dex-export-"));
|
|
249
|
+
const { found: bundled, plugin } = exportPlugin({
|
|
250
|
+
content: choice.kind === "content",
|
|
251
|
+
interfaceCss: state.entryCss,
|
|
252
|
+
people,
|
|
253
|
+
prototypeDir,
|
|
254
|
+
slug,
|
|
255
|
+
views,
|
|
256
|
+
});
|
|
257
|
+
try {
|
|
258
|
+
const config: InlineConfig = {
|
|
259
|
+
...vite,
|
|
260
|
+
base: "./",
|
|
261
|
+
logLevel: "warn",
|
|
262
|
+
publicDir: false,
|
|
263
|
+
plugins: [plugin, ...plugins(vite.plugins)],
|
|
264
|
+
resolve: {
|
|
265
|
+
...vite.resolve,
|
|
266
|
+
alias: [
|
|
267
|
+
{ find: FRAME_CSS_RE, replacement: stylesheet },
|
|
268
|
+
...((vite.resolve?.alias as { find: unknown }[] | undefined) ?? []),
|
|
269
|
+
] as never,
|
|
270
|
+
},
|
|
271
|
+
build: {
|
|
272
|
+
...vite.build,
|
|
273
|
+
outDir: out,
|
|
274
|
+
emptyOutDir: true,
|
|
275
|
+
copyPublicDir: false,
|
|
276
|
+
modulePreload: false,
|
|
277
|
+
cssCodeSplit: false,
|
|
278
|
+
// Fonts and images go inside app.css and app.js: a page opened by
|
|
279
|
+
// double-click can read nothing beside it but scripts and styles.
|
|
280
|
+
assetsInlineLimit: Number.MAX_SAFE_INTEGER,
|
|
281
|
+
chunkSizeWarningLimit: Number.MAX_SAFE_INTEGER,
|
|
282
|
+
rollupOptions: {
|
|
283
|
+
input: { export: join(APP_DIR, ENTRY) },
|
|
284
|
+
output: {
|
|
285
|
+
format: "iife",
|
|
286
|
+
inlineDynamicImports: true,
|
|
287
|
+
entryFileNames: APP_SCRIPT,
|
|
288
|
+
assetFileNames: APP_STYLES,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
const { build } = await import("vite");
|
|
294
|
+
await productionBuild(() => build(config));
|
|
295
|
+
await keepBuilt(out);
|
|
296
|
+
const html = await readFile(join(out, ENTRY), "utf8");
|
|
297
|
+
await rm(join(out, ENTRY));
|
|
298
|
+
await writeKind(out, choice, {
|
|
299
|
+
data,
|
|
300
|
+
found: bundled,
|
|
301
|
+
html,
|
|
302
|
+
people,
|
|
303
|
+
prototypeDir,
|
|
304
|
+
});
|
|
305
|
+
return { bytes: await zipFolder(out), name: exportFileName(title) };
|
|
306
|
+
} finally {
|
|
307
|
+
await rm(out, { recursive: true, force: true });
|
|
308
|
+
await rm(stylesheet, { force: true });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONTENT_GLOBAL,
|
|
3
|
+
EXPORT_GLOBAL,
|
|
4
|
+
type ExportData,
|
|
5
|
+
} from "../../shared/export-core.ts";
|
|
6
|
+
|
|
7
|
+
// An exported page's HTML, from the one Vite wrote: a page opened by
|
|
8
|
+
// double-click (file://) runs no module script and loads no stylesheet
|
|
9
|
+
// marked crossorigin, so its bundle becomes a classic script at the end of
|
|
10
|
+
// the body, after the export's data.
|
|
11
|
+
|
|
12
|
+
const MODULE_SCRIPT_RE =
|
|
13
|
+
/<script\b[^>]*\btype="module"[^>]*\bsrc="([^"]+)"[^>]*><\/script>\s*/g;
|
|
14
|
+
const CROSSORIGIN_RE = /\s+crossorigin(?:="[^"]*")?/g;
|
|
15
|
+
const TITLE_RE = /<title>[^<]*<\/title>/;
|
|
16
|
+
|
|
17
|
+
/** The JS the exported page runs, as the build names it. */
|
|
18
|
+
export const APP_SCRIPT = "app.js";
|
|
19
|
+
/** The stylesheet, as the build names it. */
|
|
20
|
+
export const APP_STYLES = "app.css";
|
|
21
|
+
/** A content pack's editable content. */
|
|
22
|
+
export const CONTENT_SCRIPT = "content.js";
|
|
23
|
+
|
|
24
|
+
/** JSON that can sit inside a <script>: no `</script>` or `<!--` in it. */
|
|
25
|
+
export const scriptJson = (value: unknown): string =>
|
|
26
|
+
JSON.stringify(value)
|
|
27
|
+
.replaceAll("<", "\\u003c")
|
|
28
|
+
.replaceAll("
", "\\u2028")
|
|
29
|
+
.replaceAll("
", "\\u2029");
|
|
30
|
+
|
|
31
|
+
const escapeHtml = (text: string) =>
|
|
32
|
+
text
|
|
33
|
+
.replaceAll("&", "&")
|
|
34
|
+
.replaceAll("<", "<")
|
|
35
|
+
.replaceAll(">", ">")
|
|
36
|
+
.replaceAll('"', """);
|
|
37
|
+
|
|
38
|
+
export interface PageOptions {
|
|
39
|
+
/** Load content.js before the bundle. */
|
|
40
|
+
content: boolean;
|
|
41
|
+
data: ExportData;
|
|
42
|
+
/** The frame the page opens on, when not the export's first. */
|
|
43
|
+
start?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* An exported page from Vite's HTML. Throws when the HTML is not what the
|
|
48
|
+
* build makes, rather than write a page that opens blank.
|
|
49
|
+
*/
|
|
50
|
+
export function exportPage(html: string, options: PageOptions): string {
|
|
51
|
+
const scripts = [...html.matchAll(MODULE_SCRIPT_RE)].map(([, src]) => src);
|
|
52
|
+
if (scripts.length !== 1 || scripts[0] !== `./${APP_SCRIPT}`) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`The export's page should load one script, ./${APP_SCRIPT}; it loads ${scripts.join(", ") || "none"}.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
const tail = [
|
|
58
|
+
...(options.start
|
|
59
|
+
? [
|
|
60
|
+
`<script>if (!location.hash) location.hash = ${scriptJson(options.start)};</script>`,
|
|
61
|
+
]
|
|
62
|
+
: []),
|
|
63
|
+
`<script>window.${EXPORT_GLOBAL} = ${scriptJson(options.data)};</script>`,
|
|
64
|
+
...(options.content ? [`<script src="./${CONTENT_SCRIPT}"></script>`] : []),
|
|
65
|
+
`<script src="./${APP_SCRIPT}"></script>`,
|
|
66
|
+
];
|
|
67
|
+
const page = html
|
|
68
|
+
.replace(MODULE_SCRIPT_RE, "")
|
|
69
|
+
.replace(CROSSORIGIN_RE, "")
|
|
70
|
+
.replace(TITLE_RE, `<title>${escapeHtml(options.data.title)}</title>`)
|
|
71
|
+
.replace("</body>", `${tail.join("\n")}\n</body>`);
|
|
72
|
+
if (page.includes('type="module"')) {
|
|
73
|
+
throw new Error("The export's page still has a module script.");
|
|
74
|
+
}
|
|
75
|
+
return page;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** content.js: the content.json files a content pack's views read, to edit. */
|
|
79
|
+
export const contentScript = (content: Map<string, unknown>): string =>
|
|
80
|
+
[
|
|
81
|
+
"// The words and data this prototype shows, by the file they came from.",
|
|
82
|
+
"// Edit them here, save, and open index.html again.",
|
|
83
|
+
`window.${CONTENT_GLOBAL} = ${JSON.stringify(Object.fromEntries(content), null, 2)};`,
|
|
84
|
+
"",
|
|
85
|
+
].join("\n");
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
3
|
+
import type { Plugin } from "vite";
|
|
4
|
+
import { APP_DIR, posix } from "../../paths.ts";
|
|
5
|
+
import { CONTENT_GLOBAL } from "../../shared/export-core.ts";
|
|
6
|
+
|
|
7
|
+
// What an export's build changes in the frame page's (export/build.ts):
|
|
8
|
+
// - the views it can show are the exported ones, keyed without whose they
|
|
9
|
+
// are, so nobody's name goes out in the bundle;
|
|
10
|
+
// - Dex's own sheets (studio-view.tsx: the components prototype, the note
|
|
11
|
+
// for no view) are left out, and with them the interface's stylesheet,
|
|
12
|
+
// which would restyle the design if it were bundled in;
|
|
13
|
+
// - a content pack's content.json files are read from content.js, so they
|
|
14
|
+
// can be edited without building again;
|
|
15
|
+
// - the prototype's files the bundle took are noted, for a source pack.
|
|
16
|
+
|
|
17
|
+
const VIEW_FILES = join(APP_DIR, "frame", "view-files.ts");
|
|
18
|
+
const STUDIO_VIEW = join(APP_DIR, "frame", "studio-view.tsx");
|
|
19
|
+
const CONTENT_FILE = "content.json";
|
|
20
|
+
const CONTENT_ID = "\0dex-export-content:";
|
|
21
|
+
// Not ".json" at the end, or Vite's JSON plugin reads the module as JSON.
|
|
22
|
+
const CONTENT_SUFFIX = ".content.js";
|
|
23
|
+
const contentFile = (id: string) =>
|
|
24
|
+
id.slice(CONTENT_ID.length, -CONTENT_SUFFIX.length);
|
|
25
|
+
|
|
26
|
+
/** A view the export shows, by name, and its file. */
|
|
27
|
+
export interface ExportedView {
|
|
28
|
+
file: string;
|
|
29
|
+
name: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ExportPluginOptions {
|
|
33
|
+
/** Read content.json from content.js. */
|
|
34
|
+
content: boolean;
|
|
35
|
+
/** The interface's stylesheet, which must never be in the bundle. */
|
|
36
|
+
interfaceCss: string;
|
|
37
|
+
/** The people whose views are exported, in order: content keys number them. */
|
|
38
|
+
people: string[];
|
|
39
|
+
/** The prototype's folder: what a source pack and content keys are relative to. */
|
|
40
|
+
prototypeDir: string;
|
|
41
|
+
slug: string;
|
|
42
|
+
views: ExportedView[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What the build found, for the export to write beside the bundle. */
|
|
46
|
+
export interface ExportFound {
|
|
47
|
+
/** Each content.json the bundle reads, by its path in the prototype. */
|
|
48
|
+
content: Map<string, unknown>;
|
|
49
|
+
/** The prototype's files the bundle took, relative to its folder. */
|
|
50
|
+
sources: string[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The module that lists the views, with only the exported ones in it. */
|
|
54
|
+
const viewFilesModule = (slug: string, views: ExportedView[]): string => {
|
|
55
|
+
const entries = views.map(
|
|
56
|
+
({ file, name }) =>
|
|
57
|
+
// views.ts reads a key's prototype and name, never its person.
|
|
58
|
+
` ${JSON.stringify(`/files/${slug}/people/_/views/${name}.tsx`)}: () => import(${JSON.stringify(posix(file))}),`
|
|
59
|
+
);
|
|
60
|
+
return `export const viewFiles = {\n${entries.join("\n")}\n};\n`;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const STUDIO_VIEW_STUB =
|
|
64
|
+
"// Left out of an export: only exported views show.\nexport default function StudioView() { return null; }\n";
|
|
65
|
+
|
|
66
|
+
const within = (folder: string, file: string) => {
|
|
67
|
+
const path = relative(folder, file);
|
|
68
|
+
return path && !path.startsWith("..") && !path.startsWith(sep)
|
|
69
|
+
? posix(path)
|
|
70
|
+
: undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A content.json's key in content.js: its path in the file, each person's
|
|
75
|
+
* folder numbered rather than named, so nobody's name goes out.
|
|
76
|
+
*/
|
|
77
|
+
const contentKey = (options: ExportPluginOptions, file: string): string => {
|
|
78
|
+
const path = within(options.prototypeDir, file) ?? "content.json";
|
|
79
|
+
const [people, person, ...rest] = path.split("/");
|
|
80
|
+
const number = options.people.indexOf(person ?? "") + 1;
|
|
81
|
+
return people === "people" && number > 0
|
|
82
|
+
? ["people", String(number), ...rest].join("/")
|
|
83
|
+
: path;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export function exportPlugin(options: ExportPluginOptions): {
|
|
87
|
+
found: ExportFound;
|
|
88
|
+
plugin: Plugin;
|
|
89
|
+
} {
|
|
90
|
+
const found: ExportFound = { content: new Map(), sources: [] };
|
|
91
|
+
const plugin: Plugin = {
|
|
92
|
+
name: "dex:export",
|
|
93
|
+
enforce: "pre",
|
|
94
|
+
async resolveId(source, importer) {
|
|
95
|
+
if (!(options.content && importer && source.endsWith(CONTENT_FILE))) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const resolved = await this.resolve(source, importer, { skipSelf: true });
|
|
99
|
+
const path = resolved && within(options.prototypeDir, resolved.id);
|
|
100
|
+
return path ? `${CONTENT_ID}${resolved.id}${CONTENT_SUFFIX}` : undefined;
|
|
101
|
+
},
|
|
102
|
+
async load(id) {
|
|
103
|
+
if (id === VIEW_FILES) {
|
|
104
|
+
return viewFilesModule(options.slug, options.views);
|
|
105
|
+
}
|
|
106
|
+
if (id === STUDIO_VIEW) {
|
|
107
|
+
return STUDIO_VIEW_STUB;
|
|
108
|
+
}
|
|
109
|
+
if (id.startsWith(CONTENT_ID)) {
|
|
110
|
+
const file = contentFile(id);
|
|
111
|
+
const key = contentKey(options, file);
|
|
112
|
+
found.content.set(key, JSON.parse(await readFile(file, "utf8")));
|
|
113
|
+
return `export default window[${JSON.stringify(CONTENT_GLOBAL)}][${JSON.stringify(key)}];\n`;
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
},
|
|
117
|
+
generateBundle() {
|
|
118
|
+
const ids = [...this.getModuleIds()];
|
|
119
|
+
if (ids.some((id) => id.split("?")[0] === options.interfaceCss)) {
|
|
120
|
+
this.error(
|
|
121
|
+
"Dex's own stylesheet ended up in the export, where it would restyle the design."
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
found.sources = ids
|
|
125
|
+
.map((id) =>
|
|
126
|
+
within(
|
|
127
|
+
options.prototypeDir,
|
|
128
|
+
id.startsWith(CONTENT_ID)
|
|
129
|
+
? contentFile(id)
|
|
130
|
+
: (id.split("?")[0] ?? id)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
.filter((path): path is string => Boolean(path))
|
|
134
|
+
.sort();
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
return { found, plugin };
|
|
138
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { basename, join } from "node:path";
|
|
5
|
+
import { PACKAGE_ROOT } from "../../paths.ts";
|
|
6
|
+
import {
|
|
7
|
+
type ExportChoice,
|
|
8
|
+
exportChoiceProblems,
|
|
9
|
+
} from "../../shared/export-core.ts";
|
|
10
|
+
import { Problems } from "../problems.ts";
|
|
11
|
+
import type { ExportResult } from "./build.ts";
|
|
12
|
+
|
|
13
|
+
// An export from Dex as it runs (the dialog's route, the MCP tool) runs
|
|
14
|
+
// `dex export` in a process of its own: a build takes seconds and much
|
|
15
|
+
// memory, which the development server and the agent's tools keep for
|
|
16
|
+
// themselves.
|
|
17
|
+
|
|
18
|
+
const DEX = join(PACKAGE_ROOT, "bin", "dex.mjs");
|
|
19
|
+
/** Longer than any export takes, so a stuck build gives up. */
|
|
20
|
+
const EXPORT_TIMEOUT_MS = 5 * 60_000;
|
|
21
|
+
const OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
22
|
+
|
|
23
|
+
const lastLine = (text: string) => text.trim().split("\n").at(-1) ?? "";
|
|
24
|
+
|
|
25
|
+
const flags = (choice: ExportChoice): string[] => [
|
|
26
|
+
"--kind",
|
|
27
|
+
choice.kind,
|
|
28
|
+
...(choice.frames?.length ? ["--frames", choice.frames.join(",")] : []),
|
|
29
|
+
...(choice.sections?.length ? ["--sections", choice.sections.join(",")] : []),
|
|
30
|
+
...(choice.flows ? ["--flows"] : []),
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Export a file's frames as `body` asks, in a process of its own. Throws
|
|
35
|
+
* Problems: 400 for a body that isn't an export's, 422 with why when the
|
|
36
|
+
* export can't be made.
|
|
37
|
+
*/
|
|
38
|
+
export async function exportInChild(
|
|
39
|
+
root: string,
|
|
40
|
+
slug: string,
|
|
41
|
+
body: unknown
|
|
42
|
+
): Promise<ExportResult> {
|
|
43
|
+
const problems = exportChoiceProblems(body);
|
|
44
|
+
if (problems.length > 0) {
|
|
45
|
+
throw new Problems(400, problems);
|
|
46
|
+
}
|
|
47
|
+
const out = await mkdtemp(join(tmpdir(), "dex-export-zip-"));
|
|
48
|
+
try {
|
|
49
|
+
const args = [
|
|
50
|
+
DEX,
|
|
51
|
+
"export",
|
|
52
|
+
"--slug",
|
|
53
|
+
slug,
|
|
54
|
+
...flags(body as ExportChoice),
|
|
55
|
+
"--out",
|
|
56
|
+
out,
|
|
57
|
+
"--json",
|
|
58
|
+
];
|
|
59
|
+
const stdout = await new Promise<string>((resolve, reject) => {
|
|
60
|
+
execFile(
|
|
61
|
+
process.execPath,
|
|
62
|
+
args,
|
|
63
|
+
{
|
|
64
|
+
cwd: root,
|
|
65
|
+
maxBuffer: OUTPUT_BYTES,
|
|
66
|
+
timeout: EXPORT_TIMEOUT_MS,
|
|
67
|
+
},
|
|
68
|
+
(error, output, errors) =>
|
|
69
|
+
error
|
|
70
|
+
? reject(new Problems(422, [lastLine(errors) || error.message]))
|
|
71
|
+
: resolve(output)
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
const { path } = JSON.parse(lastLine(stdout)) as { path: string };
|
|
75
|
+
return { name: basename(path), bytes: await readFile(path) };
|
|
76
|
+
} finally {
|
|
77
|
+
await rm(out, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { extname, join, resolve } from "node:path";
|
|
5
|
+
import type { ExportResult } from "./build.ts";
|
|
6
|
+
|
|
7
|
+
/** Downloads, where an export goes unless told otherwise; else here. */
|
|
8
|
+
export const downloadsFolder = (): string => {
|
|
9
|
+
const downloads = join(homedir(), "Downloads");
|
|
10
|
+
return existsSync(downloads) ? downloads : process.cwd();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** A name in `folder` nothing has yet: "board.zip", then "board (2).zip". */
|
|
14
|
+
const freeName = (folder: string, name: string): string => {
|
|
15
|
+
const extension = extname(name);
|
|
16
|
+
const stem = name.slice(0, name.length - extension.length);
|
|
17
|
+
for (let count = 1; ; count += 1) {
|
|
18
|
+
const path = join(
|
|
19
|
+
folder,
|
|
20
|
+
count === 1 ? name : `${stem} (${count})${extension}`
|
|
21
|
+
);
|
|
22
|
+
if (!existsSync(path)) {
|
|
23
|
+
return path;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Save an export in `folder` (Downloads by default), never over a file; returns its path. */
|
|
29
|
+
export async function saveExport(
|
|
30
|
+
exported: ExportResult,
|
|
31
|
+
folder: string = downloadsFolder()
|
|
32
|
+
): Promise<string> {
|
|
33
|
+
const into = resolve(folder);
|
|
34
|
+
await mkdir(into, { recursive: true });
|
|
35
|
+
const path = freeName(into, exported.name);
|
|
36
|
+
await writeFile(path, exported.bytes, { flag: "wx" });
|
|
37
|
+
return path;
|
|
38
|
+
}
|