refactor: rename @open-pencil/codegen to @open-pencil/emit (#822)
* refactor: rename @open-pencil/codegen to @open-pencil/emit In design tools codegen means design-to-code, which is dom-css's job and Core's codegen tools'. The package builds and prints the syntax trees exporters emit, so name it for that. It has not been released yet. * fix: alias @open-pencil/emit to its source in Vite The rename missed the escaped regex, so Vite resolved the package through its built dist output.
This commit is contained in:
parent
46c678e18f
commit
3e4e3d0b8b
|
|
@ -26,7 +26,7 @@ RUN apt-get update \
|
|||
/workspace/open-pencil/packages/core/node_modules \
|
||||
/workspace/open-pencil/packages/dom-css/node_modules \
|
||||
/workspace/open-pencil/packages/design-jsx/node_modules \
|
||||
/workspace/open-pencil/packages/codegen/node_modules \
|
||||
/workspace/open-pencil/packages/emit/node_modules \
|
||||
/workspace/open-pencil/packages/vue/node_modules \
|
||||
/workspace/open-pencil/packages/cli/node_modules \
|
||||
/workspace/open-pencil/packages/mcp/node_modules \
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
"source=open-pencil-core-modules-${devcontainerId},target=/workspace/open-pencil/packages/core/node_modules,type=volume",
|
||||
"source=open-pencil-dom-css-modules-${devcontainerId},target=/workspace/open-pencil/packages/dom-css/node_modules,type=volume",
|
||||
"source=open-pencil-design-jsx-modules-${devcontainerId},target=/workspace/open-pencil/packages/design-jsx/node_modules,type=volume",
|
||||
"source=open-pencil-codegen-modules-${devcontainerId},target=/workspace/open-pencil/packages/codegen/node_modules,type=volume",
|
||||
"source=open-pencil-emit-modules-${devcontainerId},target=/workspace/open-pencil/packages/emit/node_modules,type=volume",
|
||||
"source=open-pencil-vue-modules-${devcontainerId},target=/workspace/open-pencil/packages/vue/node_modules,type=volume",
|
||||
"source=open-pencil-cli-modules-${devcontainerId},target=/workspace/open-pencil/packages/cli/node_modules,type=volume",
|
||||
"source=open-pencil-mcp-modules-${devcontainerId},target=/workspace/open-pencil/packages/mcp/node_modules,type=volume",
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ This file holds the repository map and the rules that apply everywhere. Rules fo
|
|||
| `packages/kiwi` | SceneGraph-independent Kiwi schema/runtime, codecs, containers, parse helpers | `packages/fig/AGENTS.md` |
|
||||
| `packages/fig` | `.fig` archives, SceneGraph conversion, metadata policy, component/instance interpretation, Figma clipboard | `packages/fig/AGENTS.md` |
|
||||
| `packages/core` | Renderer, layout, editor, Figma API, tools, clipboard, vector conversion, document I/O; depends on scene-graph and the format packages (pen, kiwi, fig, dom-css, design-jsx); no browser DOM | `packages/core/AGENTS.md` |
|
||||
| `packages/dom-css` | DOM/CSS/HTML/JSX/Tailwind projection and browser/headless adapters; depends only on scene-graph and codegen, and takes engine services such as web-font resolution as injected options | `packages/dom-css/AGENTS.md` |
|
||||
| `packages/codegen` | Syntax-tree code generation for exporters: ESTree and JSX builders, template filling, and esrap printing, with the literal rules that keep exported strings from being reinterpreted | — |
|
||||
| `packages/dom-css` | DOM/CSS/HTML/JSX/Tailwind projection and browser/headless adapters; depends only on scene-graph and emit, and takes engine services such as web-font resolution as injected options | `packages/dom-css/AGENTS.md` |
|
||||
| `packages/emit` | Source emission for exporters: ESTree and JSX builders, template filling, and esrap printing, with the literal rules that keep exported strings from being reinterpreted | — |
|
||||
| `packages/design-jsx` | OpenPencil design JSX: elements, paint/effect helpers, variables, schema and authoring reference, JSX export, and a renderer that takes icons, SVG, and layout as injected services | `packages/design-jsx/AGENTS.md` |
|
||||
| `packages/vue` | Headless Vue 3 SDK primitives, composables, commands, i18n, menu model | `packages/vue/AGENTS.md` |
|
||||
| `packages/cli` | Headless `.fig` inspection, export, linting, `eval` | `packages/cli/AGENTS.md` |
|
||||
|
|
@ -45,7 +45,7 @@ Before a PR run `bun run check`, `bun run format`, `bun run test:unit`, and `bun
|
|||
|
||||
- Across package/app boundaries import the owning package's public exports, never workspace internals or forwarding-only shims. `@open-pencil/scene-graph` owns graph types and primitives; `@open-pencil/kiwi` owns low-level Kiwi/FIG helpers; `@open-pencil/core` provides the compatibility barrel plus the subpaths listed in `packages/core/package.json`.
|
||||
- `bun run check:arch` enforces: public workspace exports, framework-neutral Core, no app services in views or shared UI, property-panel internals scoped to that panel.
|
||||
- Package aliases are `#core/*`, `#fig/*`, `#vue/*`, `#cli/*`, `#mcp/*`, `#dom-css/*`, `#design-jsx/*`, `#codegen/*`; a package's own tests use `#core-tests/*` and `#fig-tests/*`; the app uses `@/`. Prefer clear relative imports nearby. Never escape an alias root with `../` (for example `#tests/../vite`); fix module ownership instead.
|
||||
- Package aliases are `#core/*`, `#fig/*`, `#vue/*`, `#cli/*`, `#mcp/*`, `#dom-css/*`, `#design-jsx/*`, `#emit/*`; a package's own tests use `#core-tests/*` and `#fig-tests/*`; the app uses `@/`. Prefer clear relative imports nearby. Never escape an alias root with `../` (for example `#tests/../vite`); fix module ownership instead.
|
||||
- Never drill with `../../`: one `../` to a sibling folder is fine, two or more means an alias. This holds in tests as much as in source — a test reaches its package's source through `#<pkg>/*` and its own helpers through `#<pkg>-tests/*`. `open-pencil/no-deep-parent-relative-imports` enforces it; a new test directory must be added to `lint:structure` so the rule reaches it.
|
||||
- Reuse named types from `@open-pencil/scene-graph`; do not respell `Color`, `Vector`, `SceneNode`, `Effect`, `Fill`, or `Stroke`.
|
||||
|
||||
|
|
|
|||
36
bun.lock
36
bun.lock
|
|
@ -187,20 +187,6 @@
|
|||
"@types/bun": "^1.3.14",
|
||||
},
|
||||
},
|
||||
"packages/codegen": {
|
||||
"name": "@open-pencil/codegen",
|
||||
"version": "0.15.1",
|
||||
"dependencies": {
|
||||
"@sveltejs/acorn-typescript": "^1.0.13",
|
||||
"acorn": "^8.18.0",
|
||||
"esrap": "^2.3.11",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.3.14",
|
||||
"tsdown": "^0.22.14",
|
||||
"typescript": "~5.8.3",
|
||||
},
|
||||
},
|
||||
"packages/core": {
|
||||
"name": "@open-pencil/core",
|
||||
"version": "0.15.1",
|
||||
|
|
@ -261,7 +247,7 @@
|
|||
"dependencies": {
|
||||
"@lezer/common": "^1.5.2",
|
||||
"@lezer/javascript": "^1.5.4",
|
||||
"@open-pencil/codegen": "workspace:*",
|
||||
"@open-pencil/emit": "workspace:*",
|
||||
"acorn": "^8.18.0",
|
||||
"dedent": "^1.7.2",
|
||||
"entities": "^8.0.0",
|
||||
|
|
@ -300,7 +286,7 @@
|
|||
"version": "0.15.1",
|
||||
"dependencies": {
|
||||
"@acemir/cssom": "^0.9.31",
|
||||
"@open-pencil/codegen": "workspace:*",
|
||||
"@open-pencil/emit": "workspace:*",
|
||||
"dedent": "^1.7.2",
|
||||
"es-toolkit": "^1.51.0",
|
||||
"js-base64": "^3.9.3",
|
||||
|
|
@ -318,6 +304,20 @@
|
|||
"@open-pencil/scene-graph": "workspace:*",
|
||||
},
|
||||
},
|
||||
"packages/emit": {
|
||||
"name": "@open-pencil/emit",
|
||||
"version": "0.15.1",
|
||||
"dependencies": {
|
||||
"@sveltejs/acorn-typescript": "^1.0.13",
|
||||
"acorn": "^8.18.0",
|
||||
"esrap": "^2.3.11",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.3.14",
|
||||
"tsdown": "^0.22.14",
|
||||
"typescript": "~5.8.3",
|
||||
},
|
||||
},
|
||||
"packages/fig": {
|
||||
"name": "@open-pencil/fig",
|
||||
"version": "0.15.1",
|
||||
|
|
@ -1457,8 +1457,6 @@
|
|||
|
||||
"@open-pencil/cli": ["@open-pencil/cli@workspace:packages/cli"],
|
||||
|
||||
"@open-pencil/codegen": ["@open-pencil/codegen@workspace:packages/codegen"],
|
||||
|
||||
"@open-pencil/core": ["@open-pencil/core@workspace:packages/core"],
|
||||
|
||||
"@open-pencil/design-jsx": ["@open-pencil/design-jsx@workspace:packages/design-jsx"],
|
||||
|
|
@ -1471,6 +1469,8 @@
|
|||
|
||||
"@open-pencil/dom-css": ["@open-pencil/dom-css@workspace:packages/dom-css"],
|
||||
|
||||
"@open-pencil/emit": ["@open-pencil/emit@workspace:packages/emit"],
|
||||
|
||||
"@open-pencil/fig": ["@open-pencil/fig@workspace:packages/fig"],
|
||||
|
||||
"@open-pencil/harness": ["@open-pencil/harness@workspace:packages/harness"],
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -11,7 +11,7 @@
|
|||
"packages/core",
|
||||
"packages/dom-css",
|
||||
"packages/design-jsx",
|
||||
"packages/codegen",
|
||||
"packages/emit",
|
||||
"packages/vue",
|
||||
"packages/cli",
|
||||
"packages/mcp",
|
||||
|
|
@ -51,9 +51,9 @@
|
|||
"build:native-test": "bun run generate:icons --target desktop && bun run build:packages && bun tauri build --debug --no-bundle --features native-test --config desktop/tauri.native-test.conf.json",
|
||||
"benchmark:navigation": "bun tools/dev/navigation-benchmark/src/cli.ts run",
|
||||
"test:native": "bun run build:native-test && wdio run wdio.conf.ts",
|
||||
"lint": "bun run lint:structure && oxlint -c oxlint.json --type-aware --type-check src/ packages/scene-graph/src/ packages/core/src/ packages/vue/src/ packages/cli/src/ packages/mcp/src/ packages/harness/src/ packages/dom-css/src/ packages/pen/src/ packages/design-jsx/src/ packages/codegen/src/ packages/kiwi/src/ packages/fig/src/",
|
||||
"lint:structure": "oxlint -c oxlint.json commitlint.config.ts vite.config.ts vite/ .storybook/ src/ packages/scene-graph/src/ packages/scene-graph/scripts/ packages/core/src/ packages/vue/src/ packages/cli/src/ packages/mcp/src/ packages/harness/src/ packages/harness/tests/ packages/dom-css/src/ packages/dom-css/tests/ packages/dom-css/scripts/ packages/pen/src/ packages/pen/scripts/ packages/design-jsx/src/ packages/design-jsx/tests/ packages/design-jsx/scripts/ packages/codegen/src/ packages/codegen/tests/ packages/codegen/scripts/ packages/kiwi/src/ packages/kiwi/tests/ packages/kiwi/scripts/ packages/fig/src/ packages/fig/tests/ packages/fig/scripts/ packages/core/tests/ packages/cli/tests/ packages/scene-graph/tests/ packages/vue/tests/ tests/ scripts/ tools/",
|
||||
"format": "oxfmt --write .oxfmtrc.json commitlint.config.ts vite.config.ts vite/ .storybook/ src/ packages/scene-graph/src/ packages/scene-graph/scripts/ packages/core/src/ packages/cli/src/ packages/mcp/src/ packages/harness/src/ packages/harness/tests/ packages/vue/src/ packages/dom-css/src/ packages/dom-css/tests/ packages/dom-css/scripts/ packages/pen/src/ packages/pen/scripts/ packages/design-jsx/src/ packages/design-jsx/tests/ packages/design-jsx/scripts/ packages/codegen/src/ packages/codegen/tests/ packages/codegen/scripts/ packages/kiwi/src/ packages/kiwi/tests/ packages/kiwi/scripts/ packages/fig/src/ packages/fig/tests/ packages/fig/scripts/ tests scripts/ tools/",
|
||||
"lint": "bun run lint:structure && oxlint -c oxlint.json --type-aware --type-check src/ packages/scene-graph/src/ packages/core/src/ packages/vue/src/ packages/cli/src/ packages/mcp/src/ packages/harness/src/ packages/dom-css/src/ packages/pen/src/ packages/design-jsx/src/ packages/emit/src/ packages/kiwi/src/ packages/fig/src/",
|
||||
"lint:structure": "oxlint -c oxlint.json commitlint.config.ts vite.config.ts vite/ .storybook/ src/ packages/scene-graph/src/ packages/scene-graph/scripts/ packages/core/src/ packages/vue/src/ packages/cli/src/ packages/mcp/src/ packages/harness/src/ packages/harness/tests/ packages/dom-css/src/ packages/dom-css/tests/ packages/dom-css/scripts/ packages/pen/src/ packages/pen/scripts/ packages/design-jsx/src/ packages/design-jsx/tests/ packages/design-jsx/scripts/ packages/emit/src/ packages/emit/tests/ packages/emit/scripts/ packages/kiwi/src/ packages/kiwi/tests/ packages/kiwi/scripts/ packages/fig/src/ packages/fig/tests/ packages/fig/scripts/ packages/core/tests/ packages/cli/tests/ packages/scene-graph/tests/ packages/vue/tests/ tests/ scripts/ tools/",
|
||||
"format": "oxfmt --write .oxfmtrc.json commitlint.config.ts vite.config.ts vite/ .storybook/ src/ packages/scene-graph/src/ packages/scene-graph/scripts/ packages/core/src/ packages/cli/src/ packages/mcp/src/ packages/harness/src/ packages/harness/tests/ packages/vue/src/ packages/dom-css/src/ packages/dom-css/tests/ packages/dom-css/scripts/ packages/pen/src/ packages/pen/scripts/ packages/design-jsx/src/ packages/design-jsx/tests/ packages/design-jsx/scripts/ packages/emit/src/ packages/emit/tests/ packages/emit/scripts/ packages/kiwi/src/ packages/kiwi/tests/ packages/kiwi/scripts/ packages/fig/src/ packages/fig/tests/ packages/fig/scripts/ tests scripts/ tools/",
|
||||
"format:check": "bun run format && status=$(git status --porcelain -uall) && test -z \"$status\" || (echo \"$status\" && exit 1)",
|
||||
"check": "bun run check:icons && bun run build:packages && bun run lint && tsgo --noEmit && bun run check:vue && bun run check:native-test && bun run check:i18n && bun run check:docs && bun run check:changelog && bun run check:packages && bun run check:deps && bun run check:audit && bun run check:secrets && bun run check:monorepo && bun run check:arch && bun run check:test-homes && bun run test:type-shapes && bun run check:tools && bun run test:tools && bun run test:dupes",
|
||||
"check:commits": "commitlint",
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
"test:coverage": "bun tools/dev/unit-tests/src/run.ts all --include-heavy -- --coverage",
|
||||
"test:type-shapes": "bun tools/checks/type-shapes/src/index.ts",
|
||||
"test:tools": "bun --filter '@open-pencil/*-tools' test && bun --filter @open-pencil/harness test",
|
||||
"test:dupes": "jscpd packages/scene-graph/src packages/pen/src packages/design-jsx/src packages/codegen/src packages/core/src packages/cli/src packages/dom-css/src packages/fig/src src --min-lines 5 --min-tokens 50 --format typescript --threshold 0",
|
||||
"test:dupes": "jscpd packages/scene-graph/src packages/pen/src packages/design-jsx/src packages/emit/src packages/core/src packages/cli/src packages/dom-css/src packages/fig/src src --min-lines 5 --min-tokens 50 --format typescript --threshold 0",
|
||||
"test:packages": "bun tools/checks/package-quality/src/cli.ts verify",
|
||||
"build:packages": "bun tools/release/package-artifacts/src/build.ts",
|
||||
"open-pencil": "bun packages/cli/src/index.ts",
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ OpenPencil's design JSX: the elements (`Frame`, `Text`, …) and the trees they
|
|||
|
||||
Rules:
|
||||
|
||||
- Depend only on `@open-pencil/scene-graph` and `@open-pencil/codegen`. Engine work the renderer needs — icon lookup, SVG path conversion, vector node creation, and layout — comes in through `DesignJSXServices` (`src/services.ts`). Core binds them in `packages/core/src/design-jsx/renderer.ts` and exports the bound `renderJSX` and `renderTree` from `@open-pencil/core/design-jsx`.
|
||||
- Depend only on `@open-pencil/scene-graph` and `@open-pencil/emit`. Engine work the renderer needs — icon lookup, SVG path conversion, vector node creation, and layout — comes in through `DesignJSXServices` (`src/services.ts`). Core binds them in `packages/core/src/design-jsx/renderer.ts` and exports the bound `renderJSX` and `renderTree` from `@open-pencil/core/design-jsx`.
|
||||
- `src/streaming/` parses JSX as it streams in and projects the static subset into trees without evaluating expressions; Core's `packages/core/src/design-jsx/preview/` stages and records those trees on the canvas.
|
||||
- JSX export (`src/export/`) collects typed props in `props.ts` and prints them with `@open-pencil/codegen`'s JSX builders; never build JSX from string fragments.
|
||||
- JSX export (`src/export/`) collects typed props in `props.ts` and prints them with `@open-pencil/emit`'s JSX builders; never build JSX from string fragments.
|
||||
- `src/reference/authoring.md` is the source of the shared authoring reference. Run `bun run generate:authoring-reference` after changing it or the schema; never edit the generated copies.
|
||||
- Tests that need icons, layout, or the bound renderer live in `packages/core/tests/design-jsx` (existing ones still in `tests/engine/render/jsx`); tests of trees, parsing, schema, and export live in `packages/design-jsx/tests`.
|
||||
|
|
|
|||
|
|
@ -27,4 +27,4 @@ import { renderJSX } from '@open-pencil/core/design-jsx'
|
|||
await renderJSX(graph, '<Frame w={320} p={16} bg="#FFFFFF"><Text>Hello</Text></Frame>')
|
||||
```
|
||||
|
||||
This package depends only on `@open-pencil/scene-graph` and `@open-pencil/codegen`. Rendering needs icons, SVG conversion, and layout, which `@open-pencil/core/design-jsx` provides; other engines can supply their own through `createDesignJSXRenderer(services)`.
|
||||
This package depends only on `@open-pencil/scene-graph` and `@open-pencil/emit`. Rendering needs icons, SVG conversion, and layout, which `@open-pencil/core/design-jsx` provides; other engines can supply their own through `createDesignJSXRenderer(services)`.
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
"dependencies": {
|
||||
"@lezer/common": "^1.5.2",
|
||||
"@lezer/javascript": "^1.5.4",
|
||||
"@open-pencil/codegen": "workspace:*",
|
||||
"@open-pencil/emit": "workspace:*",
|
||||
"acorn": "^8.18.0",
|
||||
"dedent": "^1.7.2",
|
||||
"entities": "^8.0.0",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { jsx, type SyntaxNode } from '@open-pencil/codegen'
|
||||
import { jsx, type SyntaxNode } from '@open-pencil/emit'
|
||||
import type { SceneGraph, SceneNode } from '@open-pencil/scene-graph'
|
||||
|
||||
import { collectProps, NODE_TYPE_TO_TAG, type JSXProp } from './props'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { es, jsx, type SyntaxNode } from '@open-pencil/codegen'
|
||||
import { es, jsx, type SyntaxNode } from '@open-pencil/emit'
|
||||
|
||||
/** A paint, effect, or variable helper call inside a prop value, such as `solid("#FF0000")`. */
|
||||
export class HelperCall {
|
||||
|
|
@ -52,7 +52,7 @@ export function plainValue(value: unknown): JSXValue {
|
|||
throw new TypeError(`Cannot write a ${typeof value} value as JSX`)
|
||||
}
|
||||
|
||||
/** The expression for a value, printed through the codegen builders. */
|
||||
/** The expression for a value, printed through the emit builders. */
|
||||
export function valueSyntax(value: JSXValue): SyntaxNode {
|
||||
if (value === null) return { type: 'Literal', value: null }
|
||||
if (value instanceof HelperCall) return es.call(value.helper, value.args.map(valueSyntax))
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ DOM, CSS, HTML, JSX, and Tailwind projection between documents and SceneGraph, w
|
|||
|
||||
Rules:
|
||||
|
||||
- Depend only on `@open-pencil/scene-graph` and `@open-pencil/codegen`. Engine services such as web-font resolution come in as options; Core registers the HTML and Tailwind JSX formats (`packages/core/AGENTS.md`).
|
||||
- Depend only on `@open-pencil/scene-graph` and `@open-pencil/emit`. Engine services such as web-font resolution come in as options; Core registers the HTML and Tailwind JSX formats (`packages/core/AGENTS.md`).
|
||||
- Keep the `./export` entry browser-safe: load `node:*` modules and the headless CSS object model lazily inside the functions that need them, so the app never bundles them.
|
||||
- Build generated code as syntax trees with `@open-pencil/codegen` (`es` for TypeScript modules, `jsx` for JSX), not string fragments.
|
||||
- Build generated code as syntax trees with `@open-pencil/emit` (`es` for TypeScript modules, `jsx` for JSX), not string fragments.
|
||||
- Imported documents are untrusted: check Base64 with `js-base64`'s `isValid` before decoding.
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@acemir/cssom": "^0.9.31",
|
||||
"@open-pencil/codegen": "workspace:*",
|
||||
"@open-pencil/emit": "workspace:*",
|
||||
"dedent": "^1.7.2",
|
||||
"es-toolkit": "^1.51.0",
|
||||
"js-base64": "^3.9.3",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import dedent from 'dedent'
|
||||
|
||||
import { es } from '@open-pencil/codegen'
|
||||
import { es } from '@open-pencil/emit'
|
||||
|
||||
export const STORYBOOK_FRAMEWORKS = ['react', 'vue', 'html'] as const
|
||||
export type StorybookFramework = (typeof STORYBOOK_FRAMEWORKS)[number]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { jsx, type SyntaxNode } from '@open-pencil/codegen'
|
||||
import { jsx, type SyntaxNode } from '@open-pencil/emit'
|
||||
import type { SceneGraph } from '@open-pencil/scene-graph'
|
||||
|
||||
import type { DesignDocument, DesignElement, DesignNode } from '../types'
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
# @open-pencil/codegen
|
||||
# @open-pencil/emit
|
||||
|
||||
Syntax-tree code generation for OpenPencil's exporters. Build JavaScript, TypeScript, and JSX as ESTree nodes and print them with [esrap](https://github.com/sveltejs/esrap), instead of concatenating strings.
|
||||
How OpenPencil's exporters emit source code. Build JavaScript, TypeScript, and JSX as ESTree nodes and print them with [esrap](https://github.com/sveltejs/esrap), instead of concatenating strings.
|
||||
|
||||
```ts
|
||||
import { jsx } from '@open-pencil/codegen'
|
||||
import { jsx } from '@open-pencil/emit'
|
||||
|
||||
const card = jsx.element(
|
||||
'Card',
|
||||
|
|
@ -20,7 +20,7 @@ jsx.printJSX(card) // <Card title={"Fish & chips"}>Hello</Card>
|
|||
`es` parses TypeScript templates, fills `$name` placeholders, and prints modules:
|
||||
|
||||
```ts
|
||||
import { es } from '@open-pencil/codegen'
|
||||
import { es } from '@open-pencil/emit'
|
||||
|
||||
const module = es.fill(es.parseModule("export const title = '$title'"), {
|
||||
$title: es.string('Checkout')
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"name": "@open-pencil/codegen",
|
||||
"name": "@open-pencil/emit",
|
||||
"version": "0.15.1",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"description": "Syntax-tree code generation for OpenPencil exporters: JavaScript, TypeScript, and JSX built as ESTree and printed with esrap.",
|
||||
"description": "How OpenPencil exporters emit source: JavaScript, TypeScript, and JSX built as ESTree and printed with esrap.",
|
||||
"imports": {
|
||||
"#codegen/*": {
|
||||
"#emit/*": {
|
||||
"types": "./src/*",
|
||||
"bun": "./src/*",
|
||||
"default": "./dist/*"
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/open-pencil/open-pencil.git",
|
||||
"directory": "packages/codegen"
|
||||
"directory": "packages/emit"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
|
|
@ -7,5 +7,5 @@ const card = jsx.printJSX(
|
|||
)
|
||||
const module = es.printModule(es.parseModule('export const answer = 42'))
|
||||
if (card !== '<Card title={"a \\"quoted\\" title"} />' || !module.includes('answer = 42')) {
|
||||
throw new Error('Expected built codegen package to print JSX and modules')
|
||||
throw new Error('Expected built emit package to print JSX and modules')
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { describe, expect, test } from 'bun:test'
|
||||
|
||||
import { jsx } from '#codegen/index'
|
||||
import { jsx } from '#emit/index'
|
||||
|
||||
const card = (attributes: ReturnType<typeof jsx.attribute>[], children = [jsx.text('Hi')]) =>
|
||||
jsx.printJSX(jsx.element('Card', attributes, children, 0, true))
|
||||
|
|
@ -15,8 +15,8 @@
|
|||
"resolveJsonModule": true,
|
||||
"types": ["bun"],
|
||||
"paths": {
|
||||
"#codegen/*": ["./src/*"],
|
||||
"@open-pencil/codegen": ["./src/index.ts"]
|
||||
"#emit/*": ["./src/*"],
|
||||
"@open-pencil/emit": ["./src/index.ts"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
|
|
@ -33,8 +33,8 @@ export const runtimeScenarios: RuntimeScenario[] = [
|
|||
code: "const { parsePenFile } = await import('@open-pencil/pen'); const graph = parsePenFile(JSON.stringify({ version: '1', children: [{ id: 'frame', type: 'frame', width: 100, height: 50 }] })); if (graph.getPages()[0].childIds.length !== 1) throw new Error('Pen package smoke failed')"
|
||||
},
|
||||
{
|
||||
name: 'Codegen package',
|
||||
code: "const { jsx } = await import('@open-pencil/codegen'); const code = jsx.printJSX(jsx.element('Card', [jsx.attribute('wide', null)], [], 0)); if (code !== '<Card wide />') throw new Error('Codegen package smoke failed: ' + code)"
|
||||
name: 'Emit package',
|
||||
code: "const { jsx } = await import('@open-pencil/emit'); const code = jsx.printJSX(jsx.element('Card', [jsx.attribute('wide', null)], [], 0)); if (code !== '<Card wide />') throw new Error('Codegen package smoke failed: ' + code)"
|
||||
},
|
||||
{
|
||||
name: 'Design JSX package',
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export const UNIT_TEST_GROUPS = {
|
|||
'tests/engine/vector'
|
||||
],
|
||||
dom: [
|
||||
'packages/codegen/tests',
|
||||
'packages/emit/tests',
|
||||
'packages/design-jsx/tests',
|
||||
'packages/dom-css/tests',
|
||||
'packages/pen/tests',
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ test('canonical destinations are registered before they hold files', async () =>
|
|||
'kiwi',
|
||||
'dom-css',
|
||||
'design-jsx',
|
||||
'codegen',
|
||||
'emit',
|
||||
'pen',
|
||||
'cli',
|
||||
'mcp'
|
||||
|
|
|
|||
|
|
@ -80,11 +80,11 @@
|
|||
"@open-pencil/scene-graph/*": [
|
||||
"./packages/scene-graph/src/*"
|
||||
],
|
||||
"#codegen/*": [
|
||||
"./packages/codegen/src/*"
|
||||
"#emit/*": [
|
||||
"./packages/emit/src/*"
|
||||
],
|
||||
"@open-pencil/codegen": [
|
||||
"./packages/codegen/src/index.ts"
|
||||
"@open-pencil/emit": [
|
||||
"./packages/emit/src/index.ts"
|
||||
],
|
||||
"#design-jsx/*": [
|
||||
"./packages/design-jsx/src/*"
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ export function createOpenPencilAliases(rootDir: string) {
|
|||
replacement: resolve(rootDir, 'packages/scene-graph/src/index.ts')
|
||||
},
|
||||
{ find: '@open-pencil/scene-graph', replacement: resolve(rootDir, 'packages/scene-graph/src') },
|
||||
{ find: '#codegen', replacement: resolve(rootDir, 'packages/codegen/src') },
|
||||
{ find: '#emit', replacement: resolve(rootDir, 'packages/emit/src') },
|
||||
{
|
||||
find: /^@open-pencil\/codegen$/,
|
||||
replacement: resolve(rootDir, 'packages/codegen/src/index.ts')
|
||||
find: /^@open-pencil\/emit$/,
|
||||
replacement: resolve(rootDir, 'packages/emit/src/index.ts')
|
||||
},
|
||||
{ find: '#design-jsx', replacement: resolve(rootDir, 'packages/design-jsx/src') },
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue