Files
feuerwerk/tools/lib/builders.mjs
T
rootandClaude Opus 5 d54a620ebd Add ESLint and Prettier, and close the node test gaps
Tooling:
- Prettier as the single formatting authority (110 columns, single quotes,
  measured against the existing style); Markdown excluded because table-cell
  padding turns the README glossary into 1000-character lines.
- Type-aware ESLint ending in eslint-config-prettier, so a rule always means
  "this is a bug", never "this looks different".
- .editorconfig and an `npm run check` that runs typecheck, lint, format and
  tests in one go.

Findings fixed on the first run: three more duplicate imports, four
String(unknown) calls (parameter types narrowed instead of casts), two dead
initialisers, two redundant casts, a console.log for a real error. Two
warnings were false here and are disabled with a reason in place.

Tests 132 -> 269:
- node-catalog.test.ts covers every node with a run(), with a guard that fails
  when a new node has no row.
- behavior-events.test.ts covers the ten event nodes through a running World,
  checking timing rather than existence.
- Input's state machine (press/release/releaseAll) is reachable without DOM
  events now; the DOM handlers are thin adapters.

Compare fell back to == without a configured operator although the schema
default is <; aligned.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 10:02:22 +02:00

63 lines
2.2 KiB
JavaScript

/**
* Small factories for writing project documents by hand (the seed scripts). They produce the
* exact shape `src/core/store/serialize.ts` reads; optional fields get their defaults.
*/
/** A scene object (also a container template entry). Position defaults to the origin. */
export const sceneObject = (
id,
assetId,
{ name = '', x = 0, y = 0, z = 0, overrides = {}, parentId = '', templateId = '', editorOffset } = {},
) => ({
id,
assetId,
name,
position: { x, y, z },
overrides,
parentId,
templateId,
...(editorOffset ? { editorOffset } : {}),
});
/** A graph edge from `from.fromPort` to `to.toPort`. */
export const edge = (id, from, fromPort, to, toPort) => ({
id,
from: { node: from, port: fromPort },
to: { node: to, port: toPort },
});
/** A graph node; `params` holds settings and inline input values alike. */
export const node = (id, type, x, y, params = {}) => ({ id, type, x, y, params });
/** A behavior variable declaration. */
export const variable = (key, kind, value) => ({ key, label: key, kind, default: value });
/**
* Instantiation of container templates the way the editor does it (`instantiateContainer`):
* `templates` maps container asset ids to their template objects.
*
* expand(assetId, hostId) copies of the template, parented below `hostId`
* instantiate(id, assetId, options) the container object plus its expanded content
*
* A template object that is itself a container is expanded in turn, unless the template already
* spells its content out. Copies remember their template id.
*/
export function containerFactory(templates) {
const expand = (assetId, hostId) => {
const template = templates[assetId];
const objects = [];
for (const t of template) {
const id = `${hostId}-${t.id}`;
objects.push({ ...t, id, parentId: t.parentId ? `${hostId}-${t.parentId}` : hostId, templateId: t.id });
if (templates[t.assetId] && !template.some((o) => o.parentId === t.id))
objects.push(...expand(t.assetId, id));
}
return objects;
};
const instantiate = (id, assetId, options = {}) => [
sceneObject(id, assetId, options),
...expand(assetId, id),
];
return { expand, instantiate };
}