@clarify-labs/cli 0.9.3 → 0.10.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.
Files changed (57) hide show
  1. package/output/cli/spawn.d.ts +1 -1
  2. package/output/cli.cjs +60 -128
  3. package/output/cli.cjs.map +1 -1
  4. package/output/cli.js +56 -124
  5. package/output/cli.js.map +1 -1
  6. package/output/core/adapters.d.ts +11 -0
  7. package/output/core/{config-schema.d.ts → config/config-schema.d.ts} +1 -10
  8. package/output/core/{config.d.ts → config/config.d.ts} +1 -1
  9. package/output/core/{options.d.ts → config/options.d.ts} +1 -1
  10. package/output/core/{user-config.d.ts → config/user-config.d.ts} +1 -1
  11. package/output/core/engine/context.d.ts +51 -0
  12. package/output/core/engine/engine.d.ts +68 -0
  13. package/output/core/engine/phases.d.ts +10 -0
  14. package/output/core/engine/types.d.ts +26 -0
  15. package/output/core/{builtin.d.ts → plugin/builtin.d.ts} +1 -1
  16. package/output/core/{hooks.d.ts → plugin/hooks.d.ts} +2 -1
  17. package/output/core/plugin/manager.d.ts +9 -0
  18. package/output/core/project/project-context.d.ts +16 -0
  19. package/output/core/{project-info.d.ts → project/project-info.d.ts} +3 -3
  20. package/output/core/{env-types.d.ts → runtime/env-types.d.ts} +1 -1
  21. package/output/core/runtime/html-template.d.ts +13 -0
  22. package/output/core/{ssg.d.ts → runtime/ssg.d.ts} +3 -3
  23. package/output/core/runtime/startup.d.ts +8 -0
  24. package/output/core/{virtual-modules.d.ts → runtime/virtual-modules.d.ts} +16 -13
  25. package/output/core/{vite-config.d.ts → runtime/vite-config.d.ts} +2 -1
  26. package/output/{plugin-poS3N83A.js → engine-3f5Tpa-6.js} +2403 -1804
  27. package/output/engine-3f5Tpa-6.js.map +1 -0
  28. package/output/{plugin-BUFe4vEb.cjs → engine-I04EZzjg.cjs} +2425 -1815
  29. package/output/engine-I04EZzjg.cjs.map +1 -0
  30. package/output/index.cjs +5 -3
  31. package/output/index.d.ts +6 -4
  32. package/output/index.js +2 -2
  33. package/output/parsers/content/content.d.ts +20 -0
  34. package/output/parsers/markdown/mdx.d.ts +37 -0
  35. package/output/{core → parsers/router}/dev-routes.d.ts +2 -2
  36. package/output/parsers/{routes.d.ts → routes/routes.d.ts} +2 -2
  37. package/output/parsers/{routes.test-utils.d.ts → routes/routes.test-utils.d.ts} +1 -1
  38. package/output/plugins/openapi/parser.d.ts +1 -1
  39. package/output/plugins/openapi/virtual-modules.d.ts +1 -4
  40. package/output/plugins/variables/index.d.ts +2 -1
  41. package/output/types.d.ts +40 -5
  42. package/package.json +12 -12
  43. package/output/core/content.d.ts +0 -5
  44. package/output/core/plugin.d.ts +0 -3
  45. package/output/core/site.d.ts +0 -17
  46. package/output/parsers/content.d.ts +0 -11
  47. package/output/parsers/mdx.d.ts +0 -13
  48. package/output/parsers/variables.d.ts +0 -2
  49. package/output/plugin-BUFe4vEb.cjs.map +0 -1
  50. package/output/plugin-poS3N83A.js.map +0 -1
  51. /package/output/core/{temp-dir.d.ts → project/temp-dir.d.ts} +0 -0
  52. /package/output/core/{log.d.ts → runtime/log.d.ts} +0 -0
  53. /package/output/core/{runtime-deps.d.ts → runtime/runtime-deps.d.ts} +0 -0
  54. /package/output/parsers/{frontmatter.d.ts → markdown/frontmatter.d.ts} +0 -0
  55. /package/output/{core → parsers/markdown}/utils.d.ts +0 -0
  56. /package/output/{core → parsers}/theme.d.ts +0 -0
  57. /package/output/{core → plugins/search-index}/search-language.d.ts +0 -0
@@ -0,0 +1,68 @@
1
+ import { ConfigEnv, Plugin } from 'vite';
2
+ import { ClarifyEmitAsset, ClarifyHtmlTransformInput, ClarifyPlugin, ContentRoute, NavigationTree, ClarifyProjectContext } from '../../types.js';
3
+ import { ClarifyBuildOptions } from '../config/options.js';
4
+ import { runDevConfigureServerHooks } from '../plugin/hooks.js';
5
+ import { VirtualModules } from '../runtime/virtual-modules.js';
6
+ import { ClarifyContext } from './context.js';
7
+ import { ClarifyEngineRuntime, PrepareOptions } from './types.js';
8
+ export type { ClarifyEngineMode, ClarifyEngineRuntime, PrepareOptions } from './types.js';
9
+ export declare class ClarifyEngine {
10
+ readonly options: ClarifyBuildOptions;
11
+ readonly root: string;
12
+ configFilePath?: string;
13
+ readonly ctx: ClarifyContext;
14
+ private runtime;
15
+ private virtualModules;
16
+ private buildEnabled;
17
+ private initializedOptions?;
18
+ constructor(options?: ClarifyBuildOptions);
19
+ configureRuntime(runtime: Partial<ClarifyEngineRuntime>): void;
20
+ initialize(env?: ConfigEnv, options?: ClarifyBuildOptions, prepareOptions?: PrepareOptions): Promise<ClarifyBuildOptions>;
21
+ /**
22
+ * Runs the full pre-build/pre-dev preparation: initialize (config load +
23
+ * resolve + plugins:load), site discovery (routes + navigation), and module
24
+ * building. This is the single entry point that prepares the engine before
25
+ * handing it to a Vite adapter or running a check, so callers never need to
26
+ * call initialize/discoverSite separately.
27
+ *
28
+ * Options:
29
+ * - `force`: re-run even if already prepared (config-file hot reload).
30
+ * - `htmlShell`: toggle the HTML shell builtin plugin (default true).
31
+ * - `skipModules`: skip `buildModules()` (check command).
32
+ * - `skipHints`: skip `logStartupHints()` (check command).
33
+ *
34
+ * Idempotent: calling prepare() again with the same env is a no-op unless
35
+ * `force` is set.
36
+ */
37
+ prepare(env?: ConfigEnv, options?: ClarifyBuildOptions, prepareOptions?: PrepareOptions): Promise<ClarifyBuildOptions>;
38
+ get projectConfig(): ClarifyContext['projectConfig'];
39
+ get generateOptions(): ClarifyContext['generateOptions'];
40
+ get contentRoot(): string;
41
+ get routes(): ContentRoute[];
42
+ get navigation(): NavigationTree;
43
+ get plugins(): ClarifyPlugin[];
44
+ get modules(): VirtualModules;
45
+ loadModule(id: string): string | null;
46
+ discoverSite(): Promise<void>;
47
+ logStartupHints(): void;
48
+ buildModules(): Promise<void>;
49
+ writeEnvTypes(): void;
50
+ hasContentRouteForFile(filePath: string): boolean;
51
+ collectBuildAssets(): Promise<ClarifyEmitAsset[]>;
52
+ beginBuild(): Promise<boolean>;
53
+ endBuild(): Promise<void>;
54
+ shouldRunBuild(): boolean;
55
+ configureDevServer(server: Parameters<typeof runDevConfigureServerHooks>[1]): Promise<void>;
56
+ runBuildDone(): Promise<void>;
57
+ runSSG(): Promise<void>;
58
+ refresh(): Promise<void>;
59
+ /**
60
+ * Runs the `html:transform` pipeline hook and returns the transformed
61
+ * input. Adapters call this from their `transformIndexHtml` hook instead
62
+ * of invoking `runHooks` directly, keeping hook execution inside Engine.
63
+ */
64
+ transformHtml(input: ClarifyHtmlTransformInput): Promise<ClarifyHtmlTransformInput>;
65
+ runtimeContext(): ClarifyProjectContext;
66
+ createSSGVirtualPlugin(): Plugin;
67
+ }
68
+ export declare function createClarifyEngine(options?: ClarifyBuildOptions): ClarifyEngine;
@@ -0,0 +1,10 @@
1
+ import { ClarifyHookContext, ClarifyPlugin } from '../../types.js';
2
+ export type PhaseName = 'config:load' | 'config:resolve' | 'plugins:load' | 'site:discover' | 'content:process' | 'modules:build' | 'build' | 'ssg' | 'dev:server';
3
+ export type TapPhaseName = `before:${PhaseName}` | `after:${PhaseName}`;
4
+ export type TapHook = (ctx: ClarifyHookContext) => Promise<void> | void;
5
+ export type InterceptHook = (ctx: ClarifyHookContext) => Promise<boolean> | boolean;
6
+ export type PipelineHook<Input> = (input: Input, ctx: ClarifyHookContext) => Promise<Input> | Input;
7
+ export type CollectorHook<Result> = (ctx: ClarifyHookContext) => Promise<Result> | Result;
8
+ export declare function runTapHooks(plugins: ClarifyPlugin[], hookName: TapPhaseName, ctx: ClarifyHookContext): Promise<void>;
9
+ export declare function runInterceptHooks(plugins: ClarifyPlugin[], hookName: 'build:shouldRun' | 'ssg:shouldRun', ctx: ClarifyHookContext): Promise<boolean>;
10
+ export declare function runPhase<T>(plugins: ClarifyPlugin[], phase: PhaseName, ctx: ClarifyHookContext, task: () => Promise<T> | T): Promise<T>;
@@ -0,0 +1,26 @@
1
+ import { Plugin } from 'vite';
2
+ export type ClarifyEngineMode = 'development' | 'production';
3
+ export type PrepareOptions = {
4
+ /** Force re-initialization even if already prepared (used by config-file hot reload). */
5
+ force?: boolean;
6
+ /** Toggle the HTML shell builtin plugin (default: true). */
7
+ htmlShell?: boolean;
8
+ /** Skip building virtual modules (used by check command). */
9
+ skipModules?: boolean;
10
+ /** Skip startup hints logging (used by check command). */
11
+ skipHints?: boolean;
12
+ };
13
+ export type BuildSSRBundleOptions = {
14
+ root: string;
15
+ ssrEntry: string;
16
+ ssrOutDir: string;
17
+ plugins: Plugin[];
18
+ };
19
+ export type ClarifyEngineRuntime = {
20
+ command: 'build' | 'serve';
21
+ mode: ClarifyEngineMode | string;
22
+ themeEditor?: boolean;
23
+ outputDirectory?: string;
24
+ ssrPlugins?: Plugin[];
25
+ buildSSRBundle?: (options: BuildSSRBundleOptions) => Promise<void>;
26
+ };
@@ -1,4 +1,4 @@
1
- import { ClarifyPlugin } from '../types.js';
1
+ import { ClarifyPlugin } from '../../types.js';
2
2
  export type BuiltinPluginOptions = {
3
3
  htmlShell?: boolean;
4
4
  };
@@ -1,6 +1,7 @@
1
1
  import { ViteDevServer } from 'vite';
2
- import { ClarifyEmitAsset, ClarifyHookContext, ClarifyHooks, ClarifyPlugin } from '../types.js';
2
+ import { ClarifyEmitAsset, ClarifyHookContext, ClarifyHooks, ClarifyPlugin } from '../../types.js';
3
3
  export declare function runHooks<K extends Exclude<keyof ClarifyHooks, 'build:assets' | 'build:done' | 'dev:configureServer'>>(plugins: ClarifyPlugin[], hookName: K, input: Parameters<NonNullable<ClarifyHooks[K]>>[0], ctx: ClarifyHookContext): Promise<Parameters<NonNullable<ClarifyHooks[K]>>[0]>;
4
4
  export declare function runDevConfigureServerHooks(plugins: ClarifyPlugin[], server: ViteDevServer, ctx: ClarifyHookContext): Promise<void>;
5
+ export declare function runCollectorHooks<T>(plugins: ClarifyPlugin[], hookName: string, ctx: ClarifyHookContext): Promise<T[]>;
5
6
  export declare function runBuildAssetsHooks(plugins: ClarifyPlugin[], ctx: ClarifyHookContext): Promise<ClarifyEmitAsset[]>;
6
7
  export declare function runBuildDoneHooks(plugins: ClarifyPlugin[], ctx: ClarifyHookContext): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { ClarifyPlugin } from '../../types.js';
2
+ import { ClarifyBuildOptions } from '../config/options.js';
3
+ import { BuiltinPluginOptions } from './builtin.js';
4
+ export type LoadPluginsOptions = BuiltinPluginOptions & {
5
+ userPlugins?: ClarifyPlugin[];
6
+ };
7
+ export declare function sortPlugins(plugins: ClarifyPlugin[]): ClarifyPlugin[];
8
+ export declare function loadPlugins(options?: LoadPluginsOptions): ClarifyPlugin[];
9
+ export declare function loadBuildPlugins(options?: ClarifyBuildOptions, pluginOptions?: BuiltinPluginOptions): ClarifyPlugin[];
@@ -0,0 +1,16 @@
1
+ import { ConfigEnv } from 'vite';
2
+ import { ClarifyProjectContext } from '../../types.js';
3
+ import { resolveProjectConfig } from '../config/config.js';
4
+ import { ClarifyBuildOptions, ResolvedBuildOptions } from '../config/options.js';
5
+ import { ClarifyConfig } from '../config/user-config.js';
6
+ export type ResolvedProjectContext = {
7
+ projectRoot: string;
8
+ contentRoot: string;
9
+ config: ClarifyConfig;
10
+ configFilePath?: string;
11
+ buildOptions: ResolvedBuildOptions;
12
+ resolvedOptions: ClarifyBuildOptions;
13
+ projectContext: ClarifyProjectContext;
14
+ projectConfig: ReturnType<typeof resolveProjectConfig>;
15
+ };
16
+ export declare function resolveProjectContext(options?: ClarifyBuildOptions, env?: ConfigEnv): Promise<ResolvedProjectContext>;
@@ -1,5 +1,5 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
- import { ResolvedProjectConfig } from '../types.js';
2
+ import { ClarifyProjectContext } from '../../types.js';
3
3
  /**
4
4
  * Dev-only HTTP endpoint that exposes project metadata so external tooling
5
5
  * (e.g. the VS Code extension) can discover which files Clarify recognizes
@@ -34,9 +34,9 @@ export type ProjectInfoResponse = {
34
34
  /**
35
35
  * Build the project-info response payload from the resolved plugin state.
36
36
  */
37
- export declare function buildProjectInfo(projectRoot: string, contentRoot: string, projectConfig: ResolvedProjectConfig): ProjectInfoResponse;
37
+ export declare function buildProjectInfo(context: ClarifyProjectContext): ProjectInfoResponse;
38
38
  /**
39
39
  * Handle a request to the project-info endpoint. Responds to any method
40
40
  * (GET is typical) with the JSON payload — there is no request body to parse.
41
41
  */
42
- export declare function handleProjectInfoRequest(_req: IncomingMessage, res: ServerResponse, projectRoot: string, contentRoot: string, projectConfig: ResolvedProjectConfig): void;
42
+ export declare function handleProjectInfoRequest(_req: IncomingMessage, res: ServerResponse, context: ClarifyProjectContext): void;
@@ -1,4 +1,4 @@
1
- import { ClarifyPlugin } from '../types.js';
1
+ import { ClarifyPlugin } from '../../types.js';
2
2
  export declare function generateClarifyEnvDts(_plugins: ClarifyPlugin[]): string;
3
3
  /**
4
4
  * Writes `clarify-env.d.ts` into the project root. Only rewrites when content
@@ -0,0 +1,13 @@
1
+ import { ClarifyProjectContext, ContentRoute, ResolvedProjectConfig } from '../../types.js';
2
+ /** Inject `lang` (and optional `dir`) onto the `<html>` tag for the route locale. */
3
+ export declare function injectHtmlLocaleAttributes(html: string, contextOrConfig: ClarifyProjectContext | ResolvedProjectConfig, route?: ContentRoute): string;
4
+ /** Set, replace, or remove a `<meta name="...">` tag in `<head>`. */
5
+ export declare function setNamedMeta(html: string, name: string, content: string | undefined): string;
6
+ /** Remove any existing canonical link and (if a URL is resolved) inject a fresh one. */
7
+ export declare function injectCanonicalUrl(html: string, contextOrConfig: ClarifyProjectContext | ResolvedProjectConfig, route?: ContentRoute): string;
8
+ /**
9
+ * Render the SSR result into the built HTML template: set `<title>`, the
10
+ * description/keywords meta, the canonical link, the `<html lang/dir>`, and
11
+ * replace the `#root` content with the rendered app HTML.
12
+ */
13
+ export declare function injectSSRIntoTemplate(template: string, appHtml: string, contextOrConfig: ClarifyProjectContext | ResolvedProjectConfig, route?: ContentRoute): string;
@@ -1,10 +1,10 @@
1
1
  import { Plugin } from 'vite';
2
- import { ResolvedProjectConfig, ContentRoute } from '../types.js';
2
+ import { ClarifyProjectContext, ContentRoute, ResolvedProjectConfig } from '../../types.js';
3
+ export { injectSSRIntoTemplate } from './html-template.js';
3
4
  export declare function readIndexHtml(outputDirectory: string): string | undefined;
4
- export declare function injectSSRIntoTemplate(template: string, appHtml: string, projectConfig: ResolvedProjectConfig, route?: ContentRoute): string;
5
5
  export declare function isNotFoundRoute(route: ContentRoute): boolean;
6
6
  export declare function routeOutputFiles(outputDirectory: string, route: ContentRoute): string[];
7
7
  export declare const SSR_ENTRY_CODE = "import { renderToHTML } from '@clarify-labs/renderer/server';\nimport { routes, navigation } from 'virtual:clarify/routes/server';\nimport { config } from 'virtual:clarify/config';\nimport { openApis } from 'virtual:clarify/openapi';\nimport { runtimeSlots } from 'virtual:clarify/slots';\n\nexport async function render(url) {\n // Pre-resolve every slot component factory so renderToString can use\n // them synchronously (renderToString has no Suspense support).\n const entries = Object.values(runtimeSlots).flat()\n await Promise.all(entries.map(async (entry) => {\n const mod = await entry.component()\n entry._resolved = mod.default\n }))\n return renderToHTML({ config, routes, navigation, openApis, runtimeSlots, url, themeEditor: config.theme.editor });\n}";
8
8
  export declare function createTempEntryFile(content: string): string;
9
9
  export declare function buildSSRBundle(root: string, ssrEntry: string, ssrOutDir: string, plugins: Plugin[]): Promise<void>;
10
- export declare function renderSSGRoutes(routes: ContentRoute[], projectConfig: ResolvedProjectConfig, outputDirectory: string, ssrBundlePath: string, failOnError?: boolean): Promise<void>;
10
+ export declare function renderSSGRoutes(routes: ContentRoute[], contextOrConfig: ClarifyProjectContext | ResolvedProjectConfig, outputDirectory: string, ssrBundlePath: string, failOnError?: boolean): Promise<void>;
@@ -0,0 +1,8 @@
1
+ export type StartupHintOptions = {
2
+ projectRoot: string;
3
+ contentRoot: string;
4
+ contentDirExists: boolean;
5
+ hasRoutes: boolean;
6
+ };
7
+ export declare function getStartupHints(options: StartupHintOptions): string[];
8
+ export declare function logStartupHints(options: StartupHintOptions): void;
@@ -1,4 +1,4 @@
1
- import { ClarifyPlugin, ContentRoute, NavigationTree, ResolvedBuildOptions, ResolvedProjectConfig } from '../types.js';
1
+ import { ClarifyPlugin, ContentDiagnostic, ContentRoute, NavigationTree, ResolvedBuildOptions, ResolvedProjectConfig } from '../../types.js';
2
2
  export declare const VIRTUAL_CONFIG = "virtual:clarify/config";
3
3
  export declare const VIRTUAL_ROUTES = "virtual:clarify/routes";
4
4
  export declare const VIRTUAL_SERVER_ROUTES = "virtual:clarify/routes/server";
@@ -6,14 +6,14 @@ export declare const VIRTUAL_OPENAPI = "virtual:clarify/openapi";
6
6
  export declare const VIRTUAL_SLOTS = "virtual:clarify/slots";
7
7
  export declare const VIRTUAL_SLOT = "virtual:clarify/slot";
8
8
  export declare const VIRTUAL_CLIENT_ENTRY = "virtual:clarify/entry-client";
9
- export declare const RESOLVED_CLIENT_ENTRY: string;
10
9
  export type VirtualModules = Map<string, string>;
11
10
  type BuildVirtualModulesArgs = {
12
- projectConfig: ResolvedProjectConfig;
13
11
  generateOptions: ResolvedBuildOptions;
12
+ projectConfig: ResolvedProjectConfig;
14
13
  routes: ContentRoute[];
15
- navigation?: NavigationTree;
14
+ version?: string;
16
15
  plugins?: ClarifyPlugin[];
16
+ navigation: NavigationTree;
17
17
  themeEditor?: boolean;
18
18
  };
19
19
  type CreateClientEntryModuleOptions = {
@@ -21,8 +21,17 @@ type CreateClientEntryModuleOptions = {
21
21
  };
22
22
  export declare function resolveVirtualId(id: string): string;
23
23
  export declare function stripVirtualPrefix(id: string): string;
24
- export declare function generateConfigModule(projectConfig: ResolvedProjectConfig, buildOptions: ResolvedBuildOptions): string;
25
- export declare function generateRoutesModule(routes: ContentRoute[], resolvedNavigation?: NavigationTree, projectConfig?: ResolvedProjectConfig, mode?: 'client' | 'server'): string;
24
+ /**
25
+ * Shared `resolveId` logic for all Clarify virtual modules. Used by both the
26
+ * Vite core plugin (dev + build) and the SSG virtual plugin so the ID-to-
27
+ * resolved-ID mapping has a single source of truth.
28
+ *
29
+ * Returns the resolved ID (with `\0` prefix per Vite convention) or `null`
30
+ * if the ID is not a Clarify virtual module.
31
+ */
32
+ export declare function resolveVirtualModuleId(id: string, modules: VirtualModules, routes: readonly ContentRoute[]): string | null;
33
+ export declare function generateConfigModule(projectConfig: ResolvedProjectConfig, buildOptions: ResolvedBuildOptions, version?: string): string;
34
+ export declare function generateRoutesModule(routes: ContentRoute[], navigation: NavigationTree, mode?: 'client' | 'server'): string;
26
35
  export declare function createClientEntryModule(options?: CreateClientEntryModuleOptions): string;
27
36
  /**
28
37
  * Collect every plugin's `slots` declarations into a single runtime registry
@@ -37,12 +46,6 @@ export declare function createClientEntryModule(options?: CreateClientEntryModul
37
46
  * type — no runtime validation is needed.
38
47
  */
39
48
  export declare function createRuntimeSlotsModule(plugins?: ClarifyPlugin[], root?: string): string;
40
- /**
41
- * Re-exports the slot context hook from the renderer so plugin components can
42
- * `import { useSlot } from 'virtual:clarify/slot'` without depending on
43
- * renderer internals directly.
44
- */
45
- export declare function createSlotModule(): string;
49
+ export declare function generateMdxErrorModule(diagnostic: ContentDiagnostic): string;
46
50
  export declare function buildVirtualModules(args: BuildVirtualModulesArgs): VirtualModules;
47
- export declare function generateOpenApiModule(): string;
48
51
  export {};
@@ -1,4 +1,5 @@
1
1
  import { ConfigEnv, InlineConfig } from 'vite';
2
+ import { ClarifyEngine } from '../engine/engine.js';
2
3
  export type ClarifyViteConfigOptions = {
3
4
  root: string;
4
5
  content: string;
@@ -7,4 +8,4 @@ export type ClarifyViteConfigOptions = {
7
8
  port?: number;
8
9
  open?: boolean | string;
9
10
  };
10
- export declare function createViteConfig(options: ClarifyViteConfigOptions, env: ConfigEnv): Promise<InlineConfig>;
11
+ export declare function createViteConfig(options: ClarifyViteConfigOptions, env: ConfigEnv, engine: ClarifyEngine): Promise<InlineConfig>;