v0.3.2

Documentation version

v0.2.4v0.3.2
en

Documentation language

en

Search documentation

ESC

Documentation search

What are you working on?

Find a guide, configuration option, action, or ESH topic.

Browse documentation
DocsEveryinit npm package

Everyinit npm package

The everyinit npm package exposes framework-neutral helpers and a Vite integration for consuming the data generated by Evin's evin/docs@v1 action. It does not include a ready-made page renderer or documentation theme. Your frontend maps the page AST to its own components and controls routing presentation and styling.

Install and choose an entry point

npm install everyinit

The package requires Node.js 20 or later. everyinit/vite has an optional Vite peer dependency at version 6 or later. The Evin CLI must also be available to run the documentation build command configured for the Vite plugin.

ImportPurpose
everyinitRoute helpers, runtime construction, binary search decoding, and search.
everyinit/viteVite plugin that loads generated docs data and diagram SVGs.
virtual:evin/docsGenerated manifest, routes, pages, assets, and diagrams.
virtual:evin/searchLazy search-index loading and search.
everyinit/highlightFlow, ESH, and JSON code tokenization.

For a guided setup from source pages through a Vite site, see Build a documentation site.

Vite integration

Register the plugin in vite.config.js:

import { defineConfig } from "vite";
import evinDocs from "everyinit/vite";

export default defineConfig({
  plugins: [
    evinDocs({
      command: ["evin", "run", "docs:build"],
      cwd: "../..",
      watch: ["../../docs"],
    }),
  ],
});

The plugin runs the command when Vite starts and before a production build. During development, edits under the watched directories rerun the command and invalidate virtual:evin/docs.

OptionTypeDefaultMeaning
commandstring[]['evin', 'run', 'docs:build']Executable and arguments used to generate docs data. An empty array skips the command.
cwdstringVite project rootWorking directory for the command, manifest, and watched paths.
manifeststringdist/docs-data/manifest.jsonManifest path relative to cwd.
watchstring[]['docs']Source paths relative to cwd that trigger regeneration.

The command must produce the manifest, page files, and asset map before the plugin can load. It rejects an unsupported manifest schema, missing page data, or paths that escape the generated output directory.

Generated docs module

virtual:evin/docs exports named values and the same runtime as its default export:

import docs, {
  manifest,
  routes,
  pages,
  assets,
  diagrams,
  resolveRoute,
  counterpart,
  routeForPage,
} from "virtual:evin/docs";

const route = resolveRoute(window.location.pathname);
if (route) {
  const page = route.page;
  const pageAssets = assets[page.id] ?? {};
  const pageDiagrams = diagrams[page.id] ?? {};
  // Render page.page.ast with your framework's components.
}

resolveRoute normalizes leading and trailing slashes and ignores query and fragment text. It returns a route with its page data, or null when no route matches. Use generated route records rather than rebuilding routes from source filenames.

Each route contains path, page_id, page_file, version, locale, content_locale, is_fallback, navigation_order, and counterparts. When a localized page falls back to another locale, content_locale identifies the language of the actual page content. counterparts maps a version/locale pair to an equivalent page ID, or null when no equivalent exists.

The manifest is available as docs.manifest:

FieldMeaning
schema, format_versionManifest contract identifier; the current schema is evin.docs.manifest/v1.
latest_version, default_localeVersion and locale used for unqualified routes.
versions, localesConfigured version and locale inventories. Each version has an id and latest flag.
routesRoute records described above.
assetsRelative path to the generated asset map file.
search_indexesSearch artifact descriptors with version, locale, path, byte length, and SHA-256.
diagnosticsBuild findings with severity, code, message, version, locale, and route.

pages is keyed by stable page ID. Each page includes metadata, format, source path, route, table of contents, reference data, and a serialized document AST. assets[pageId] maps source media paths to imported asset URLs. diagrams[pageId][diagramId] contains imported SVG source strings. Embed a diagram as inline SVG to retain its authored ID and let site CSS style it; an img element does not expose the SVG's internal nodes to page styles.

Each EvinDocsPage has schema, id, version, locale, content_locale, source_path, route, is_fallback, and navigation_order fields. Its nested page record contains the source slug and format, metadata, the formal reference when present, a toc array of heading level/text/anchor records, and the serialized ast. The AST is the content contract; render its nodes with your framework rather than treating page data as prebuilt HTML.

Use counterpart(route, version, locale) to find the equivalent page when it exists, then routeForPage(page) to find its route. createRouteTable(docs, render) maps the runtime's route list to { path, element, handle } records for router adapters.

Framework-neutral runtime

When you load the generated manifest and page JSON files yourself, construct the runtime with createDocsRuntime:

import { createDocsRuntime, normalizeDocsPath, createRouteTable } from "everyinit";

const docs = createDocsRuntime(manifest, pages, assets);
const path = normalizeDocsPath("guide/?mode=print"); // "/guide"
const route = docs.resolveRoute(path);
const routeTable = createRouteTable(docs, (entry) => renderPage(entry.page));

createDocsRuntime verifies the manifest schema and that each route refers to the matching page ID. It throws TypeError when these inputs are invalid. normalizeDocsPath accepts a path string, strips query and fragment text, normalizes slash direction, and ensures a leading slash.

In a Vite app, load the selected version and locale's binary search artifact only when search is opened:

import { loadSearchIndex, searchDocs } from "virtual:evin/search";

const index = await loadSearchIndex(route.version, route.locale);
const results = searchDocs(index, "workspace configuration", {
  limit: 8,
  allowFuzzy: true,
});

loadSearchIndex(version, locale) caches the decoded result and checks its size and SHA-256 digest when Web Crypto is available. searchDocs(index, query, options) requires all query terms to match. It supports term prefixes and, when no prefix matches, optional one-edit fuzzy matching for longer terms. The module's default export contains these same two functions. limit defaults to 10 and is clamped to at least 1. Results include the page ID, route with an optional heading anchor, title, section, snippet, reference ID, result kind, and score.

Each result is an EvinDocsSearchRecord with pageId, route, pageTitle, title, sectionTitle, anchor, referenceId, snippet, kind, and score. A page result has an empty anchor; a section result can link to its heading. EvinDocsSearchIndex.records contains the searchable records, while terms and termList hold the decoded lookup tables.

Without Vite, import decodeSearchIndex and searchDocs from everyinit and fetch or load the binary file with your own runtime. decodeSearchIndex accepts an ArrayBuffer or Uint8Array and returns the index expected by searchDocs.

Code highlighting

everyinit/highlight tokenizes Flow, ESH, and JSON with the same TextMate grammars as the VS Code extension:

import { createCodeHighlighter } from "everyinit/highlight";

const highlighter = await createCodeHighlighter();
const tokens = highlighter.tokenizeCode('workspace:\n  name: "site"\n', "flow");
highlighter.dispose();

The canonical language IDs are flow, esh, and json. Flow and ESH also accept evin-flow, evin-esh, and leading-dot file extensions such as .flow. resolveCodeLanguage(language) returns the canonical ID or null; supportedCodeLanguages lists the canonical IDs.

Each token contains its source text, most specific scope (or null), and full TextMate scopes stack. Unknown language IDs return the original source as one unscoped token. Initialize one highlighter per app and reuse it; call dispose() when that app no longer needs it. The convenience tokenizeCode function is asynchronous and shares a lazily initialized highlighter.

Exported types

The root entry exports TypeScript interfaces for EvinDocsManifest, EvinDocsRoute, EvinDocsRouteData, EvinDocsPage, EvinDocsRuntime, EvinDocsSearchArtifact, EvinDocsSearchIndex, and EvinDocsSearchRecord. The highlighter subpath exports EvinCodeLanguage, EvinCodeToken, and EvinCodeHighlighter types. The Vite subpath exports EvinDocsViteOptions. The virtual module types are included with everyinit/vite; add /// <reference types="everyinit/vite" /> to a TypeScript app's environment declaration if its editor does not discover the virtual modules automatically.

Page source: reference/80.everyinit-package.5200.md