@kubb/fabric-core 0.13.2 → 0.14.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/dist/{Fabric-BOjvMvNC.d.ts → Fabric-CFkgoZwY.d.ts} +4 -1
- package/dist/chunk-MlS0t1Af.cjs +53 -0
- package/dist/chunk-O_arW02_.js +17 -0
- package/dist/defaultParser-D0_-Uy2Z.cjs +19 -0
- package/dist/{defaultParser-BAgmtMo_.cjs.map → defaultParser-D0_-Uy2Z.cjs.map} +1 -1
- package/dist/{defaultParser-C1atU7yU.js → defaultParser-iCpMSYCp.js} +4 -4
- package/dist/{defaultParser-C1atU7yU.js.map → defaultParser-iCpMSYCp.js.map} +1 -1
- package/dist/{getRelativePath-BcieQL5M.js → getRelativePath-NAm_Y-vp.js} +3 -5
- package/dist/{getRelativePath-BcieQL5M.js.map → getRelativePath-NAm_Y-vp.js.map} +1 -1
- package/dist/{getRelativePath-DVG8dIzW.cjs → getRelativePath-WX4HB169.cjs} +18 -21
- package/dist/{getRelativePath-DVG8dIzW.cjs.map → getRelativePath-WX4HB169.cjs.map} +1 -1
- package/dist/index.cjs +75 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +54 -54
- package/dist/index.js +71 -88
- package/dist/index.js.map +1 -1
- package/dist/{onProcessExit-DENCUkMz.cjs → onProcessExit-C2AuepQI.cjs} +213 -227
- package/dist/onProcessExit-C2AuepQI.cjs.map +1 -0
- package/dist/{onProcessExit-B0rJqX4s.js → onProcessExit-Cput7j2c.js} +124 -137
- package/dist/onProcessExit-Cput7j2c.js.map +1 -0
- package/dist/parsers/typescript.cjs +4 -5
- package/dist/parsers/typescript.cjs.map +1 -1
- package/dist/parsers/typescript.d.ts +2 -1
- package/dist/parsers/typescript.js +3 -3
- package/dist/parsers/typescript.js.map +1 -1
- package/dist/parsers.cjs +6 -6
- package/dist/parsers.cjs.map +1 -1
- package/dist/parsers.d.ts +2 -1
- package/dist/parsers.js +4 -4
- package/dist/plugins.cjs +7 -13
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.ts +5 -4
- package/dist/plugins.js +6 -11
- package/dist/plugins.js.map +1 -1
- package/dist/{RootContext-BQHfIhhC.d.ts → types-BwR3_cUx.d.ts} +10 -4
- package/dist/types.cjs +13 -15
- package/dist/types.d.ts +4 -11
- package/dist/types.js +2 -3
- package/dist/{useNodeTree-Brj-fAVZ.d.ts → useNodeTree-Wc1WxA05.d.ts} +3 -2
- package/package.json +4 -3
- package/src/components/{App.ts → Fabric.ts} +8 -8
- package/src/composables/{useApp.ts → useFabric.ts} +4 -4
- package/src/contexts/{AppContext.ts → FabricContext.ts} +2 -2
- package/src/index.ts +4 -6
- package/src/plugins/fsxPlugin/fsxPlugin.ts +4 -4
- package/dist/Fabric-w9Y9duM6.d.ts +0 -516
- package/dist/RootContext-Cbs-UQXM.d.ts +0 -26
- package/dist/chunk-BYypO7fO.js +0 -18
- package/dist/chunk-uaV2rQ02.cjs +0 -53
- package/dist/defaultParser-BAgmtMo_.cjs +0 -20
- package/dist/onProcessExit-B0rJqX4s.js.map +0 -1
- package/dist/onProcessExit-DENCUkMz.cjs.map +0 -1
- package/dist/useNodeTree-6ZhDpI13.d.ts +0 -58
- package/src/components/__snapshots__/arrow_function_with_generics.ts +0 -3
- package/src/components/__snapshots__/async_arrow_function.ts +0 -3
- package/src/components/__snapshots__/async_function.ts +0 -3
- package/src/components/__snapshots__/async_function_with_Promise_return_type.ts +0 -3
- package/src/components/__snapshots__/basic_arrow_function.ts +0 -3
- package/src/components/__snapshots__/basic_const.ts +0 -1
- package/src/components/__snapshots__/basic_export.ts +0 -1
- package/src/components/__snapshots__/basic_function.ts +0 -3
- package/src/components/__snapshots__/basic_import.ts +0 -1
- package/src/components/__snapshots__/basic_type.ts +0 -1
- package/src/components/__snapshots__/const_with_JSDoc.ts +0 -4
- package/src/components/__snapshots__/const_with_as_const.ts +0 -1
- package/src/components/__snapshots__/const_with_type.ts +0 -1
- package/src/components/__snapshots__/default_exported_arrow_function.ts +0 -3
- package/src/components/__snapshots__/default_exported_function.ts +0 -3
- package/src/components/__snapshots__/exported_arrow_function.ts +0 -3
- package/src/components/__snapshots__/exported_const.ts +0 -1
- package/src/components/__snapshots__/exported_function.ts +0 -3
- package/src/components/__snapshots__/exported_type.ts +0 -1
- package/src/components/__snapshots__/function_with_JSDoc.ts +0 -6
- package/src/components/__snapshots__/function_with_generics.ts +0 -3
- package/src/components/__snapshots__/function_with_parameters.ts +0 -3
- package/src/components/__snapshots__/function_with_return_type.ts +0 -3
- package/src/components/__snapshots__/matches_with_root_import.ts +0 -1
- package/src/components/__snapshots__/named_export.ts +0 -1
- package/src/components/__snapshots__/named_export_(object_advanced).ts +0 -1
- package/src/components/__snapshots__/named_import.ts +0 -1
- package/src/components/__snapshots__/named_import_(object).ts +0 -1
- package/src/components/__snapshots__/named_import_(object_advanced).ts +0 -1
- package/src/components/__snapshots__/named_typed_export.ts +0 -1
- package/src/components/__snapshots__/named_typed_import.ts +0 -1
- package/src/components/__snapshots__/single_line_arrow_function.ts +0 -1
- package/src/components/__snapshots__/type_with_JSDoc.ts +0 -4
- package/src/components/__snapshots__/typed_export.ts +0 -1
- package/src/components/__snapshots__/typed_import.ts +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["inject","NodeTreeContext","createContext","createComponent","RootContext","NodeTreeContext","createComponent","createIntrinsic","createComponent","NodeTreeContext","renderIntrinsic","createComponent","createIntrinsic","createContext","RootContext","createComponent","NodeTreeContext","renderIntrinsic","print","createExport","createImport","createComponent","createIntrinsic","createComponent","NodeTreeContext","createComponent","NodeTreeContext","renderIntrinsic","RootContext","AsyncEventEmitter","FileManager"],"sources":["../src/composables/useContext.ts","../src/composables/useNodeTree.ts","../src/contexts/AppContext.ts","../src/components/App.ts","../src/components/Br.ts","../src/utils/createJSDoc.ts","../src/components/Const.ts","../src/components/Dedent.ts","../src/contexts/FileContext.ts","../src/composables/useFile.ts","../src/composables/useFileManager.ts","../src/components/File.ts","../src/components/Indent.ts","../src/components/Function.ts","../src/components/Type.ts","../src/composables/useApp.ts","../src/composables/useLifecycle.ts","../src/createFabric.ts"],"sourcesContent":["import type { Context } from '../context.ts'\nimport { inject } from '../context.ts'\n\n/**\n * React-style alias for inject\n *\n * @example\n * ```ts\n * const theme = useContext(ThemeContext) // type is inferred from ThemeContext\n * ```\n */\nexport function useContext<T>(key: Context<T>): T\nexport function useContext<T, TValue = T>(key: Context<T>, defaultValue: TValue): NonNullable<T> | TValue\nexport function useContext<T>(key: Context<T>, defaultValue?: T): T {\n return inject(key, defaultValue)\n}\n","import { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport type { TreeNode } from '../utils/TreeNode.ts'\nimport { useContext } from './useContext.ts'\n\nexport type ComponentNode = {\n type: string\n props: Record<string, unknown>\n}\n\n/**\n * Accesses the current node tree for tracking component hierarchy.\n *\n * Use this composable to inspect or manipulate the component tree structure.\n * Returns null if not within a component that provides NodeTreeContext.\n *\n * @returns The current TreeNode or null\n *\n * @example\n * ```ts\n * const nodeTree = useNodeTree()\n * if (nodeTree) {\n * const childTree = nodeTree.addChild({ type: 'MyComponent', props: {} })\n * }\n * ```\n */\nexport function useNodeTree(): TreeNode<ComponentNode> | null {\n return useContext(NodeTreeContext)\n}\n","import { createContext } from '../context.ts'\n\nexport type AppContextProps<TMeta extends object = object> = {\n /**\n * Exit (unmount)\n */\n exit: (error?: Error) => void\n meta: TMeta\n}\n\n/**\n * Provides app-level metadata and lifecycle hooks (like `exit`) to\n * components and composables within a Fabric runtime.\n */\nexport const AppContext = createContext<AppContextProps>({\n exit: () => {},\n meta: {},\n})\n","import { useContext } from '../composables/useContext.ts'\nimport { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { AppContext } from '../contexts/AppContext.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { RootContext } from '../contexts/RootContext.ts'\nimport { createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\n\nexport type AppProps<TMeta extends Object = Object> = {\n /**\n * Metadata attached to the App context.\n *\n * Use this to pass custom data to child components via useApp.\n */\n meta?: TMeta\n /**\n * Child components.\n */\n children?: FabricNode\n}\n\n/**\n * Container component providing App context with metadata and lifecycle.\n *\n * Use this component to wrap your application and provide shared metadata\n * that can be accessed by child components using the useApp composable.\n *\n * @example\n * ```tsx\n * <App meta={{ version: '1.0.0', author: 'John Doe' }}>\n * <File baseName=\"user.ts\" path=\"./user.ts\">\n * <File.Source>export type User = {}</File.Source>\n * </File>\n * </App>\n * ```\n */\nexport const App = createComponent('App', ({ children, ...props }: AppProps) => {\n const { meta = {} } = props\n\n const { exit } = useContext(RootContext)\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'App', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n provide(AppContext, { exit, meta })\n\n return children\n})\n\nApp.displayName = 'App'\n","import { createComponent } from '../createComponent.ts'\nimport { createIntrinsic } from '../intrinsic.ts'\n\n/**\n * Generates a line break in the output.\n *\n * Use this component to add newlines in generated code.\n *\n * @example\n * ```tsx\n * <>\n * const x = 1\n * <Br />\n * const y = 2\n * </>\n * ```\n */\nexport const Br = createComponent('br', () => {\n return createIntrinsic('br')\n})\n\nBr.displayName = 'Br'\n","/**\n * Create JSDoc comment block from comments array\n */\nexport function createJSDoc({ comments }: { comments: string[] }): string {\n if (!comments || comments.length === 0) return ''\n\n const lines = comments\n .flatMap((c) => String(c ?? '').split(/\\r?\\n/))\n .map((l) => l.replace(/\\*\\//g, '*\\\\/').replace(/\\r/g, ''))\n .filter((l) => l.trim().length > 0)\n\n if (lines.length === 0) return ''\n\n return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\\n')\n}\n","import { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport { renderIntrinsic } from '../intrinsic.ts'\nimport type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type ConstProps = {\n /**\n * Name of the constant.\n */\n name: string\n /**\n * Export this constant.\n * - `true` generates `export const`\n * - `false` generates internal const\n * @default false\n */\n export?: boolean\n /**\n * TypeScript type annotation.\n *\n * @example 'string' or 'User[]'\n */\n type?: string\n /**\n * JSDoc comments for the constant.\n */\n JSDoc?: JSDoc\n /**\n * Use const assertion.\n * - `true` adds `as const` for deep readonly\n * - `false` uses inferred or explicit type\n * @default false\n */\n asConst?: boolean\n /**\n * Constant value.\n */\n children?: FabricNode\n}\n\n/**\n * Generates a TypeScript constant declaration.\n *\n * @example\n * ```tsx\n * <Const name=\"API_URL\" export type=\"string\">\n * 'https://api.example.com'\n * </Const>\n * ```\n */\nexport const Const = createComponent('Const', ({ children, ...props }: ConstProps) => {\n const { name, export: canExport, type, JSDoc, asConst } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Const', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const value = renderIntrinsic(children)\n\n let result = ''\n\n if (JSDoc?.comments) {\n result += createJSDoc({ comments: JSDoc.comments })\n result += '\\n'\n }\n\n if (canExport) {\n result += 'export '\n }\n\n result += `const ${name}`\n\n if (type) {\n result += `: ${type}`\n }\n\n result += ` = ${children ? value : ''}`\n\n if (asConst) {\n result += ' as const'\n }\n\n return result\n})\n\nConst.displayName = 'Const'\n","import { createComponent } from '../createComponent.ts'\nimport { createIntrinsic } from '../intrinsic.ts'\n\n/**\n * Decreases indentation level in the output.\n *\n * Use this component to reduce indentation after an indented code block.\n * Typically paired with Indent to control indentation levels.\n *\n * @example\n * ```tsx\n * <>\n * function example() {'{'}<Br />\n * <Indent />\n * return true<Br />\n * <Dedent />\n * {'}'}\n * </>\n * ```\n */\nexport const Dedent = createComponent('dedent', () => {\n return createIntrinsic('dedent')\n})\nDedent.displayName = 'Dedent'\n","import { createContext } from '../context.ts'\nimport type * as KubbFile from '../KubbFile.ts'\n\n/**\n * Provides app-level metadata and lifecycle hooks (like `exit`) to\n * components and composables within a Fabric runtime.\n */\nexport const FileContext = createContext<KubbFile.ResolvedFile | null>(null)\n","import { FileContext } from '../contexts/FileContext.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses the current File context.\n *\n * Use this composable to access or modify the current file's properties,\n * sources, imports, or exports.\n *\n * @returns The current file object or null if not within a File component\n *\n * @example\n * ```ts\n * const file = useFile()\n * if (file) {\n * console.log(file.path)\n * file.sources.push({ value: 'export const x = 1', isExportable: true })\n * }\n * ```\n */\nexport function useFile(): KubbFile.ResolvedFile | null {\n return useContext(FileContext)\n}\n","import { RootContext } from '../contexts/RootContext.ts'\nimport type { FileManager } from '../FileManager.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses the FileManager from the Root context.\n *\n * Use this composable to interact with the FileManager directly,\n * such as adding, retrieving, or managing files.\n *\n * @returns The current FileManager instance\n *\n * @example\n * ```ts\n * const fileManager = useFileManager()\n * fileManager.add({\n * baseName: 'user.ts',\n * path: './generated/user.ts',\n * sources: []\n * })\n * ```\n */\nexport function useFileManager(): FileManager {\n const { fileManager } = useContext(RootContext)\n\n return fileManager\n}\n","import { useFile } from '../composables/useFile.ts'\nimport { useFileManager } from '../composables/useFileManager.ts'\nimport { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { FileContext } from '../contexts/FileContext.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { type ComponentBuilder, createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport { renderIntrinsic } from '../intrinsic.ts'\nimport { createExport, createImport, print } from '../parsers/typescriptParser.ts'\nimport type { KubbFile } from '../types.ts'\n\nexport type FileProps<TMeta extends object = object> = {\n /**\n * File name with extension.\n *\n * @example 'user.ts'\n */\n baseName: KubbFile.BaseName\n /**\n * Full path to the file including directory and file name.\n *\n * The path must include the baseName at the end.\n *\n * @example './generated/types/user.ts'\n */\n path: KubbFile.Path\n /**\n * Optional metadata attached to the file.\n *\n * Use this to store custom information about the file.\n */\n meta?: TMeta\n /**\n * Optional banner text added at the top of the file.\n */\n banner?: string\n /**\n * Optional footer text added at the bottom of the file.\n */\n footer?: string\n /**\n * Child components (File.Source, File.Import, File.Export).\n */\n children?: FabricNode\n}\n\n/**\n * Component for generating files with sources, imports, and exports.\n *\n * Creates files in the FileManager that can be written to disk.\n *\n * @example\n * ```tsx\n * <File baseName=\"user.ts\" path=\"./generated/user.ts\">\n * <File.Source isExportable>\n * export type User = {{ '{' }} id: number {{ '}' }}\n * </File.Source>\n * </File>\n * ```\n */\nexport const File = createComponent('File', ({ children, ...props }: FileProps) => {\n const { baseName, path, meta = {}, footer, banner } = props\n\n const fileManager = useFileManager()\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'File', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const file: KubbFile.File = {\n baseName,\n path,\n meta,\n banner,\n footer,\n sources: [],\n imports: [],\n exports: [],\n }\n\n const [resolvedFile] = fileManager.add(file)\n provide(FileContext, resolvedFile)\n\n return children\n}) as ComponentBuilder<FileProps<object>> & { Source: typeof FileSource; Import: typeof FileImport; Export: typeof FileExport }\n\ntype FileSourceProps = Omit<KubbFile.Source, 'value'> & {\n /**\n * Source code content.\n */\n children?: FabricNode\n}\n\n/**\n * Adds source code to a file.\n *\n * Use this component inside a File component to add code blocks.\n *\n * @example\n * ```tsx\n * <File.Source isExportable name=\"User\">\n * export type User = {{ '{' }} id: number {{ '}' }}\n * </File.Source>\n * ```\n */\nexport const FileSource = createComponent('FileSource', ({ children, ...props }: FileSourceProps) => {\n const { name, isExportable, isIndexable, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileSource', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const value = renderIntrinsic(children)\n\n if (file) {\n file.sources.push({\n name,\n isExportable,\n isIndexable,\n isTypeOnly,\n value,\n })\n }\n\n return value\n})\n\nexport type FileExportProps = KubbFile.Export\n\n/**\n * Adds export statements to a file.\n *\n * Use this component to create re-exports from other files.\n *\n * @example\n * ```tsx\n * <File.Export name=\"User\" path=\"./types/user\" isTypeOnly />\n * ```\n */\nexport const FileExport = createComponent('FileExport', (props: FileExportProps) => {\n const { name, path, isTypeOnly, asAlias } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileExport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.exports.push({\n name,\n path,\n asAlias,\n isTypeOnly,\n })\n }\n\n return print(createExport({ name, path, isTypeOnly, asAlias }))\n})\n\nexport type FileImportProps = KubbFile.Import\n\n/**\n * Adds import statements to a file.\n *\n * Use this component to import types or values from other files.\n *\n * @example\n * ```tsx\n * <File.Import name=\"User\" path=\"./types/user\" isTypeOnly />\n * ```\n */\nexport const FileImport = createComponent('FileImport', (props: FileImportProps) => {\n const { name, path, root, isNameSpace, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileImport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.imports.push({\n name,\n path,\n root,\n isNameSpace,\n isTypeOnly,\n })\n }\n\n return print(createImport({ name, path, root, isNameSpace, isTypeOnly }))\n})\n\nFile.Source = FileSource\nFile.Import = FileImport\nFile.Export = FileExport\n","import { createComponent } from '../createComponent.ts'\nimport { createIntrinsic } from '../intrinsic.ts'\n\n/**\n * Increases indentation level in the output.\n *\n * Use this component to add indentation for nested code blocks.\n * Typically paired with Dedent to control indentation levels.\n *\n * @example\n * ```tsx\n * <>\n * function example() {'{'}<Br />\n * <Indent />\n * return true<Br />\n * <Dedent />\n * {'}'}\n * </>\n * ```\n */\nexport const Indent = createComponent('indent', () => {\n return createIntrinsic('indent')\n})\nIndent.displayName = 'Indent'\n","import { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { type ComponentBuilder, createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\nimport { Br } from './Br.ts'\nimport { Dedent } from './Dedent.ts'\nimport { Indent } from './Indent.ts'\n\ntype FunctionProps = {\n /**\n * Name of the function.\n */\n name: string\n /**\n * Export with default keyword.\n * - `true` generates `export default function`\n * - `false` generates named export or no export\n * @default false\n */\n default?: boolean\n /**\n * Function parameters.\n *\n * @example 'id: number, name: string'\n */\n params?: string\n /**\n * Export this function.\n * - `true` generates `export function`\n * - `false` generates internal function\n * @default false\n */\n export?: boolean\n /**\n * Make the function async.\n * - `true` adds async keyword and wraps return type in Promise\n * - `false` generates synchronous function\n * @default false\n */\n async?: boolean\n /**\n * TypeScript generics.\n *\n * @example 'T' or ['T', 'U']\n */\n generics?: string | string[]\n /**\n * Return type of the function.\n *\n * When async is true, this is automatically wrapped in Promise.\n */\n returnType?: string\n /**\n * JSDoc comments for the function.\n */\n JSDoc?: JSDoc\n /**\n * Function body.\n */\n children?: FabricNode\n}\n\n/**\n * Generates a TypeScript function declaration.\n *\n * @example\n * ```tsx\n * <Function\n * name=\"getUser\"\n * export\n * async\n * params=\"id: number\"\n * returnType=\"User\"\n * >\n * return fetch(`/users/${id}`).then(r => r.json())\n * </Function>\n * ```\n */\nexport const Function = createComponent('Function', ({ children, ...props }: FunctionProps) => {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Function', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const parts: string[] = []\n\n if (JSDoc?.comments) {\n parts.push(createJSDoc({ comments: JSDoc.comments }))\n parts.push('\\n')\n }\n\n if (canExport) {\n parts.push('export ')\n }\n\n if (isDefault) {\n parts.push('default ')\n }\n\n if (async) {\n parts.push('async ')\n }\n\n parts.push(`function ${name}`)\n\n if (generics) {\n parts.push('<')\n parts.push(Array.isArray(generics) ? generics.join(', ').trim() : generics)\n parts.push('>')\n }\n\n parts.push(`(${params || ''})`)\n\n if (returnType && !async) {\n parts.push(`: ${returnType}`)\n }\n\n if (returnType && async) {\n parts.push(`: Promise<${returnType}>`)\n }\n\n parts.push(' {')\n\n if (children) {\n return [parts.join(''), Br(), Indent(), children, Br(), Dedent(), '}']\n }\n\n return [parts.join(''), '}']\n}) as ComponentBuilder<FunctionProps> & { Arrow: typeof ArrowFunction }\n\nFunction.displayName = 'Function'\n\ntype ArrowFunctionProps = FunctionProps & {\n /**\n * Create Arrow function in one line\n */\n singleLine?: boolean\n}\n\n/**\n * ArrowFunction\n *\n * Builds an arrow function declaration string for the fsx renderer. Supports\n * the same options as `Function`. Use `singleLine` to produce a one-line\n * arrow expression.\n */\nconst ArrowFunction = createComponent('ArrowFunction', ({ children, ...props }: ArrowFunctionProps) => {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'ArrowFunction', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const parts: string[] = []\n\n if (JSDoc?.comments) {\n parts.push(createJSDoc({ comments: JSDoc.comments }))\n parts.push('\\n')\n }\n\n if (canExport) {\n parts.push('export ')\n }\n\n if (isDefault) {\n parts.push('default ')\n }\n\n parts.push(`const ${name} = `)\n\n if (async) {\n parts.push('async ')\n }\n\n if (generics) {\n parts.push('<')\n parts.push(Array.isArray(generics) ? generics.join(', ').trim() : generics)\n parts.push('>')\n }\n\n parts.push(`(${params || ''})`)\n\n if (returnType && !async) {\n parts.push(`: ${returnType}`)\n }\n\n if (returnType && async) {\n parts.push(`: Promise<${returnType}>`)\n }\n\n if (singleLine) {\n parts.push(` => ${children || ''}\\n`)\n return parts.join('')\n }\n\n if (children) {\n return [parts.join(''), ' => {', Br(), Indent(), children, Br(), Dedent(), '}']\n }\n\n return [parts.join(''), ' => {}']\n})\n\nArrowFunction.displayName = 'ArrowFunction'\nFunction.Arrow = ArrowFunction\n","import { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport { renderIntrinsic } from '../intrinsic.ts'\nimport type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type TypeProps = {\n /**\n * Name of the type (must start with a capital letter).\n */\n name: string\n /**\n * Export this type.\n * - `true` generates `export type`\n * - `false` generates internal type\n * @default false\n */\n export?: boolean\n /**\n * JSDoc comments for the type.\n */\n JSDoc?: JSDoc\n /**\n * Type definition.\n */\n children?: FabricNode\n}\n\n/**\n * Generates a TypeScript type declaration.\n *\n * @example\n * ```tsx\n * <Type name=\"User\" export>\n * {'{'} id: number; name: string {'}'}\n * </Type>\n * ```\n */\nexport const Type = createComponent('Type', ({ children, ...props }: TypeProps) => {\n const { name, export: canExport, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Type', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (name.charAt(0).toUpperCase() !== name.charAt(0)) {\n throw new Error('Name should start with a capital letter (see TypeScript types)')\n }\n\n const value = renderIntrinsic(children)\n\n let result = ''\n\n if (JSDoc?.comments) {\n result += createJSDoc({ comments: JSDoc.comments })\n result += '\\n'\n }\n\n if (canExport) {\n result += 'export '\n }\n\n result += `type ${name} = ${value || ''}`\n\n return result\n})\n\nType.displayName = 'Type'\n","import { AppContext, type AppContextProps } from '../contexts/AppContext.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses the App context with metadata and exit function.\n *\n * Use this composable to access metadata defined in the App component\n * or to exit the rendering process early.\n *\n * @throws Error when no AppContext is available\n *\n * @example\n * ```ts\n * const { meta, exit } = useApp<{ version: string }>()\n * console.log(meta.version)\n * ```\n */\nexport function useApp<TMeta extends object = object>(): AppContextProps<TMeta> {\n return useContext(AppContext) as AppContextProps<TMeta>\n}\n","import { RootContext } from '../contexts/RootContext.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses lifecycle helpers for controlling generation flow.\n *\n * Use this composable to exit the rendering process early or perform\n * cleanup operations.\n *\n * @returns Object with lifecycle methods (exit)\n *\n * @example\n * ```ts\n * const { exit } = useLifecycle()\n *\n * // Stop generation on error\n * if (invalidData) {\n * exit(new Error('Invalid data'))\n * }\n * ```\n */\nexport function useLifecycle() {\n const { exit } = useContext(RootContext)\n\n return {\n exit,\n }\n}\n","import { isFunction } from 'remeda'\nimport type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\nimport { FileManager } from './FileManager.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport type { Parser } from './parsers/types.ts'\nimport type { Plugin } from './plugins/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\n/**\n * Creates a new Fabric instance for file generation.\n *\n * The Fabric instance provides methods for registering plugins,\n * adding files, and triggering file generation.\n *\n * @param config - Optional configuration object\n * @returns A new Fabric instance\n *\n * @example\n * ```ts\n * import { createFabric } from '@kubb/fabric-core'\n * import { fsPlugin } from '@kubb/fabric-core/plugins'\n * import { typescriptParser } from '@kubb/fabric-core/parsers'\n *\n * const fabric = createFabric()\n * fabric.use(fsPlugin)\n * fabric.use(typescriptParser)\n *\n * await fabric.addFile({\n * baseName: 'user.ts',\n * path: './generated/user.ts',\n * sources: [{ value: 'export type User = {}', isExportable: true }],\n * imports: [],\n * exports: [],\n * })\n *\n * await fabric.write({ extension: { '.ts': '.ts' } })\n * ```\n */\nexport function createFabric<T extends FabricOptions>(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Map<KubbFile.Extname, Parser<any>>()\n const installedParserNames = new Set<string>()\n const fileManager = new FileManager({ events })\n\n const context: FabricContext<T> = {\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n await fileManager.add(...files)\n },\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n on: events.on.bind(events),\n off: events.off.bind(events),\n onOnce: events.onOnce.bind(events),\n removeAll: events.removeAll.bind(events),\n emit: events.emit.bind(events),\n } as FabricContext<T>\n\n const fabric: Fabric<T> = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n fileManager.add(...files)\n },\n async upsertFile(...files) {\n fileManager.upsert(...files)\n },\n unmount(_error?: Error | number | null) {\n events.removeAll()\n },\n async use(pluginOrParser, ...options) {\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn(`Plugin \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const injected = (injecter as any)(context, ...options)\n Object.assign(fabric, injected)\n }\n }\n\n if (pluginOrParser.type === 'parser') {\n if (installedParserNames.has(pluginOrParser.name)) {\n console.warn(`Parser \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedParserNames.add(pluginOrParser.name)\n }\n\n if (pluginOrParser.extNames) {\n for (const extName of pluginOrParser.extNames) {\n const existing = installedParsers.get(extName)\n if (existing && existing.name !== pluginOrParser.name) {\n console.warn(`Parser \"${pluginOrParser.name}\" is overriding parser \"${existing.name}\" for extension \"${extName}\".`)\n }\n installedParsers.set(extName, pluginOrParser)\n }\n }\n }\n\n if (isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(context, ...options)\n }\n\n return fabric\n },\n } as Fabric<T>\n\n return fabric\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,WAAc,KAAiB,cAAqB;AAClE,QAAOA,6BAAO,KAAK,aAAa;;;;;;;;;;;;;;;;;;;;;ACWlC,SAAgB,cAA8C;AAC5D,QAAO,WAAWC,sCAAgB;;;;;;;;;ACZpC,MAAa,aAAaC,oCAA+B;CACvD,YAAY;CACZ,MAAM,EAAE;CACT,CAAC;;;;;;;;;;;;;;;;;;;ACoBF,MAAa,MAAMC,sCAAgB,QAAQ,EAAE,UAAU,GAAG,YAAsB;CAC9E,MAAM,EAAE,OAAO,EAAE,KAAK;CAEtB,MAAM,EAAE,SAAS,WAAWC,kCAAY;CAExC,MAAM,WAAW,aAAa;AAE9B,KAAI,SAGF,+BAAQC,uCAFU,SAAS,SAAS;EAAE,MAAM;EAAO;EAAO,CAAC,CAExB;AAGrC,+BAAQ,YAAY;EAAE;EAAM;EAAM,CAAC;AAEnC,QAAO;EACP;AAEF,IAAI,cAAc;;;;;;;;;;;;;;;;;;ACtClB,MAAa,KAAKC,sCAAgB,YAAY;AAC5C,QAAOC,sCAAgB,KAAK;EAC5B;AAEF,GAAG,cAAc;;;;;;;AClBjB,SAAgB,YAAY,EAAE,YAA4C;AACxE,KAAI,CAAC,YAAY,SAAS,WAAW,EAAG,QAAO;CAE/C,MAAM,QAAQ,SACX,SAAS,MAAM,OAAO,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,CAC9C,KAAK,MAAM,EAAE,QAAQ,SAAS,OAAO,CAAC,QAAQ,OAAO,GAAG,CAAC,CACzD,QAAQ,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE;AAErC,KAAI,MAAM,WAAW,EAAG,QAAO;AAE/B,QAAO;EAAC;EAAO,GAAG,MAAM,KAAK,MAAM,MA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"version":3,"file":"index.cjs","names":["createComponent","createIntrinsic","inject","NodeTreeContext","createComponent","NodeTreeContext","renderIntrinsic","createComponent","createIntrinsic","createContext","createComponent","RootContext","NodeTreeContext","createContext","RootContext","createComponent","NodeTreeContext","renderIntrinsic","print","createExport","createImport","createComponent","createIntrinsic","createComponent","NodeTreeContext","createComponent","NodeTreeContext","renderIntrinsic","RootContext","AsyncEventEmitter","FileManager"],"sources":["../src/components/Br.ts","../src/composables/useContext.ts","../src/composables/useNodeTree.ts","../src/utils/createJSDoc.ts","../src/components/Const.ts","../src/components/Dedent.ts","../src/contexts/FabricContext.ts","../src/components/Fabric.ts","../src/contexts/FileContext.ts","../src/composables/useFile.ts","../src/composables/useFileManager.ts","../src/components/File.ts","../src/components/Indent.ts","../src/components/Function.ts","../src/components/Type.ts","../src/composables/useFabric.ts","../src/composables/useLifecycle.ts","../src/createFabric.ts"],"sourcesContent":["import { createComponent } from '../createComponent.ts'\nimport { createIntrinsic } from '../intrinsic.ts'\n\n/**\n * Generates a line break in the output.\n *\n * Use this component to add newlines in generated code.\n *\n * @example\n * ```tsx\n * <>\n * const x = 1\n * <Br />\n * const y = 2\n * </>\n * ```\n */\nexport const Br = createComponent('br', () => {\n return createIntrinsic('br')\n})\n\nBr.displayName = 'Br'\n","import type { Context } from '../context.ts'\nimport { inject } from '../context.ts'\n\n/**\n * React-style alias for inject\n *\n * @example\n * ```ts\n * const theme = useContext(ThemeContext) // type is inferred from ThemeContext\n * ```\n */\nexport function useContext<T>(key: Context<T>): T\nexport function useContext<T, TValue = T>(key: Context<T>, defaultValue: TValue): NonNullable<T> | TValue\nexport function useContext<T>(key: Context<T>, defaultValue?: T): T {\n return inject(key, defaultValue)\n}\n","import { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport type { TreeNode } from '../utils/TreeNode.ts'\nimport { useContext } from './useContext.ts'\n\nexport type ComponentNode = {\n type: string\n props: Record<string, unknown>\n}\n\n/**\n * Accesses the current node tree for tracking component hierarchy.\n *\n * Use this composable to inspect or manipulate the component tree structure.\n * Returns null if not within a component that provides NodeTreeContext.\n *\n * @returns The current TreeNode or null\n *\n * @example\n * ```ts\n * const nodeTree = useNodeTree()\n * if (nodeTree) {\n * const childTree = nodeTree.addChild({ type: 'MyComponent', props: {} })\n * }\n * ```\n */\nexport function useNodeTree(): TreeNode<ComponentNode> | null {\n return useContext(NodeTreeContext)\n}\n","/**\n * Create JSDoc comment block from comments array\n */\nexport function createJSDoc({ comments }: { comments: string[] }): string {\n if (!comments || comments.length === 0) return ''\n\n const lines = comments\n .flatMap((c) => String(c ?? '').split(/\\r?\\n/))\n .map((l) => l.replace(/\\*\\//g, '*\\\\/').replace(/\\r/g, ''))\n .filter((l) => l.trim().length > 0)\n\n if (lines.length === 0) return ''\n\n return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\\n')\n}\n","import { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport { renderIntrinsic } from '../intrinsic.ts'\nimport type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type ConstProps = {\n /**\n * Name of the constant.\n */\n name: string\n /**\n * Export this constant.\n * - `true` generates `export const`\n * - `false` generates internal const\n * @default false\n */\n export?: boolean\n /**\n * TypeScript type annotation.\n *\n * @example 'string' or 'User[]'\n */\n type?: string\n /**\n * JSDoc comments for the constant.\n */\n JSDoc?: JSDoc\n /**\n * Use const assertion.\n * - `true` adds `as const` for deep readonly\n * - `false` uses inferred or explicit type\n * @default false\n */\n asConst?: boolean\n /**\n * Constant value.\n */\n children?: FabricNode\n}\n\n/**\n * Generates a TypeScript constant declaration.\n *\n * @example\n * ```tsx\n * <Const name=\"API_URL\" export type=\"string\">\n * 'https://api.example.com'\n * </Const>\n * ```\n */\nexport const Const = createComponent('Const', ({ children, ...props }: ConstProps) => {\n const { name, export: canExport, type, JSDoc, asConst } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Const', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const value = renderIntrinsic(children)\n\n let result = ''\n\n if (JSDoc?.comments) {\n result += createJSDoc({ comments: JSDoc.comments })\n result += '\\n'\n }\n\n if (canExport) {\n result += 'export '\n }\n\n result += `const ${name}`\n\n if (type) {\n result += `: ${type}`\n }\n\n result += ` = ${children ? value : ''}`\n\n if (asConst) {\n result += ' as const'\n }\n\n return result\n})\n\nConst.displayName = 'Const'\n","import { createComponent } from '../createComponent.ts'\nimport { createIntrinsic } from '../intrinsic.ts'\n\n/**\n * Decreases indentation level in the output.\n *\n * Use this component to reduce indentation after an indented code block.\n * Typically paired with Indent to control indentation levels.\n *\n * @example\n * ```tsx\n * <>\n * function example() {'{'}<Br />\n * <Indent />\n * return true<Br />\n * <Dedent />\n * {'}'}\n * </>\n * ```\n */\nexport const Dedent = createComponent('dedent', () => {\n return createIntrinsic('dedent')\n})\nDedent.displayName = 'Dedent'\n","import { createContext } from '../context.ts'\n\nexport type FabricContextProps<TMeta extends object = object> = {\n /**\n * Exit (unmount)\n */\n exit: (error?: Error) => void\n meta: TMeta\n}\n\n/**\n * Provides app-level metadata and lifecycle hooks (like `exit`) to\n * components and composables within a Fabric runtime.\n */\nexport const FabricContext = createContext<FabricContextProps>({\n exit: () => {},\n meta: {},\n})\n","import { useContext } from '../composables/useContext.ts'\nimport { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { FabricContext } from '../contexts/FabricContext.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { RootContext } from '../contexts/RootContext.ts'\nimport { createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\n\nexport type FabricProps<TMeta extends Object = Object> = {\n /**\n * Metadata attached to the App context.\n *\n * Use this to pass custom data to child components via useApp.\n */\n meta?: TMeta\n /**\n * Child components.\n */\n children?: FabricNode\n}\n\n/**\n * Container component providing App context with metadata and lifecycle.\n *\n * Use this component to wrap your application and provide shared metadata\n * that can be accessed by child components using the useApp composable.\n *\n * @example\n * ```tsx\n * <Fabric meta={{ version: '1.0.0', author: 'John Doe' }}>\n * <File baseName=\"user.ts\" path=\"./user.ts\">\n * <File.Source>export type User = {}</File.Source>\n * </File>\n * </Fabric>\n * ```\n */\nexport const Fabric = createComponent('Fabric', ({ children, ...props }: FabricProps) => {\n const { meta = {} } = props\n\n const { exit } = useContext(RootContext)\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Fabric', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n provide(FabricContext, { exit, meta })\n\n return children\n})\n\nFabric.displayName = 'Fabric'\n","import { createContext } from '../context.ts'\nimport type * as KubbFile from '../KubbFile.ts'\n\n/**\n * Provides app-level metadata and lifecycle hooks (like `exit`) to\n * components and composables within a Fabric runtime.\n */\nexport const FileContext = createContext<KubbFile.ResolvedFile | null>(null)\n","import { FileContext } from '../contexts/FileContext.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses the current File context.\n *\n * Use this composable to access or modify the current file's properties,\n * sources, imports, or exports.\n *\n * @returns The current file object or null if not within a File component\n *\n * @example\n * ```ts\n * const file = useFile()\n * if (file) {\n * console.log(file.path)\n * file.sources.push({ value: 'export const x = 1', isExportable: true })\n * }\n * ```\n */\nexport function useFile(): KubbFile.ResolvedFile | null {\n return useContext(FileContext)\n}\n","import { RootContext } from '../contexts/RootContext.ts'\nimport type { FileManager } from '../FileManager.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses the FileManager from the Root context.\n *\n * Use this composable to interact with the FileManager directly,\n * such as adding, retrieving, or managing files.\n *\n * @returns The current FileManager instance\n *\n * @example\n * ```ts\n * const fileManager = useFileManager()\n * fileManager.add({\n * baseName: 'user.ts',\n * path: './generated/user.ts',\n * sources: []\n * })\n * ```\n */\nexport function useFileManager(): FileManager {\n const { fileManager } = useContext(RootContext)\n\n return fileManager\n}\n","import { useFile } from '../composables/useFile.ts'\nimport { useFileManager } from '../composables/useFileManager.ts'\nimport { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { FileContext } from '../contexts/FileContext.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { type ComponentBuilder, createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport { renderIntrinsic } from '../intrinsic.ts'\nimport { createExport, createImport, print } from '../parsers/typescriptParser.ts'\nimport type { KubbFile } from '../types.ts'\n\nexport type FileProps<TMeta extends object = object> = {\n /**\n * File name with extension.\n *\n * @example 'user.ts'\n */\n baseName: KubbFile.BaseName\n /**\n * Full path to the file including directory and file name.\n *\n * The path must include the baseName at the end.\n *\n * @example './generated/types/user.ts'\n */\n path: KubbFile.Path\n /**\n * Optional metadata attached to the file.\n *\n * Use this to store custom information about the file.\n */\n meta?: TMeta\n /**\n * Optional banner text added at the top of the file.\n */\n banner?: string\n /**\n * Optional footer text added at the bottom of the file.\n */\n footer?: string\n /**\n * Child components (File.Source, File.Import, File.Export).\n */\n children?: FabricNode\n}\n\n/**\n * Component for generating files with sources, imports, and exports.\n *\n * Creates files in the FileManager that can be written to disk.\n *\n * @example\n * ```tsx\n * <File baseName=\"user.ts\" path=\"./generated/user.ts\">\n * <File.Source isExportable>\n * export type User = {{ '{' }} id: number {{ '}' }}\n * </File.Source>\n * </File>\n * ```\n */\nexport const File = createComponent('File', ({ children, ...props }: FileProps) => {\n const { baseName, path, meta = {}, footer, banner } = props\n\n const fileManager = useFileManager()\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'File', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const file: KubbFile.File = {\n baseName,\n path,\n meta,\n banner,\n footer,\n sources: [],\n imports: [],\n exports: [],\n }\n\n const [resolvedFile] = fileManager.add(file)\n provide(FileContext, resolvedFile)\n\n return children\n}) as ComponentBuilder<FileProps<object>> & { Source: typeof FileSource; Import: typeof FileImport; Export: typeof FileExport }\n\ntype FileSourceProps = Omit<KubbFile.Source, 'value'> & {\n /**\n * Source code content.\n */\n children?: FabricNode\n}\n\n/**\n * Adds source code to a file.\n *\n * Use this component inside a File component to add code blocks.\n *\n * @example\n * ```tsx\n * <File.Source isExportable name=\"User\">\n * export type User = {{ '{' }} id: number {{ '}' }}\n * </File.Source>\n * ```\n */\nexport const FileSource = createComponent('FileSource', ({ children, ...props }: FileSourceProps) => {\n const { name, isExportable, isIndexable, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileSource', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const value = renderIntrinsic(children)\n\n if (file) {\n file.sources.push({\n name,\n isExportable,\n isIndexable,\n isTypeOnly,\n value,\n })\n }\n\n return value\n})\n\nexport type FileExportProps = KubbFile.Export\n\n/**\n * Adds export statements to a file.\n *\n * Use this component to create re-exports from other files.\n *\n * @example\n * ```tsx\n * <File.Export name=\"User\" path=\"./types/user\" isTypeOnly />\n * ```\n */\nexport const FileExport = createComponent('FileExport', (props: FileExportProps) => {\n const { name, path, isTypeOnly, asAlias } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileExport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.exports.push({\n name,\n path,\n asAlias,\n isTypeOnly,\n })\n }\n\n return print(createExport({ name, path, isTypeOnly, asAlias }))\n})\n\nexport type FileImportProps = KubbFile.Import\n\n/**\n * Adds import statements to a file.\n *\n * Use this component to import types or values from other files.\n *\n * @example\n * ```tsx\n * <File.Import name=\"User\" path=\"./types/user\" isTypeOnly />\n * ```\n */\nexport const FileImport = createComponent('FileImport', (props: FileImportProps) => {\n const { name, path, root, isNameSpace, isTypeOnly } = props\n\n const nodeTree = useNodeTree()\n const file = useFile()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'FileImport', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (file) {\n file.imports.push({\n name,\n path,\n root,\n isNameSpace,\n isTypeOnly,\n })\n }\n\n return print(createImport({ name, path, root, isNameSpace, isTypeOnly }))\n})\n\nFile.Source = FileSource\nFile.Import = FileImport\nFile.Export = FileExport\n","import { createComponent } from '../createComponent.ts'\nimport { createIntrinsic } from '../intrinsic.ts'\n\n/**\n * Increases indentation level in the output.\n *\n * Use this component to add indentation for nested code blocks.\n * Typically paired with Dedent to control indentation levels.\n *\n * @example\n * ```tsx\n * <>\n * function example() {'{'}<Br />\n * <Indent />\n * return true<Br />\n * <Dedent />\n * {'}'}\n * </>\n * ```\n */\nexport const Indent = createComponent('indent', () => {\n return createIntrinsic('indent')\n})\nIndent.displayName = 'Indent'\n","import { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { type ComponentBuilder, createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\nimport { Br } from './Br.ts'\nimport { Dedent } from './Dedent.ts'\nimport { Indent } from './Indent.ts'\n\ntype FunctionProps = {\n /**\n * Name of the function.\n */\n name: string\n /**\n * Export with default keyword.\n * - `true` generates `export default function`\n * - `false` generates named export or no export\n * @default false\n */\n default?: boolean\n /**\n * Function parameters.\n *\n * @example 'id: number, name: string'\n */\n params?: string\n /**\n * Export this function.\n * - `true` generates `export function`\n * - `false` generates internal function\n * @default false\n */\n export?: boolean\n /**\n * Make the function async.\n * - `true` adds async keyword and wraps return type in Promise\n * - `false` generates synchronous function\n * @default false\n */\n async?: boolean\n /**\n * TypeScript generics.\n *\n * @example 'T' or ['T', 'U']\n */\n generics?: string | string[]\n /**\n * Return type of the function.\n *\n * When async is true, this is automatically wrapped in Promise.\n */\n returnType?: string\n /**\n * JSDoc comments for the function.\n */\n JSDoc?: JSDoc\n /**\n * Function body.\n */\n children?: FabricNode\n}\n\n/**\n * Generates a TypeScript function declaration.\n *\n * @example\n * ```tsx\n * <Function\n * name=\"getUser\"\n * export\n * async\n * params=\"id: number\"\n * returnType=\"User\"\n * >\n * return fetch(`/users/${id}`).then(r => r.json())\n * </Function>\n * ```\n */\nexport const Function = createComponent('Function', ({ children, ...props }: FunctionProps) => {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Function', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const parts: string[] = []\n\n if (JSDoc?.comments) {\n parts.push(createJSDoc({ comments: JSDoc.comments }))\n parts.push('\\n')\n }\n\n if (canExport) {\n parts.push('export ')\n }\n\n if (isDefault) {\n parts.push('default ')\n }\n\n if (async) {\n parts.push('async ')\n }\n\n parts.push(`function ${name}`)\n\n if (generics) {\n parts.push('<')\n parts.push(Array.isArray(generics) ? generics.join(', ').trim() : generics)\n parts.push('>')\n }\n\n parts.push(`(${params || ''})`)\n\n if (returnType && !async) {\n parts.push(`: ${returnType}`)\n }\n\n if (returnType && async) {\n parts.push(`: Promise<${returnType}>`)\n }\n\n parts.push(' {')\n\n if (children) {\n return [parts.join(''), Br(), Indent(), children, Br(), Dedent(), '}']\n }\n\n return [parts.join(''), '}']\n}) as ComponentBuilder<FunctionProps> & { Arrow: typeof ArrowFunction }\n\nFunction.displayName = 'Function'\n\ntype ArrowFunctionProps = FunctionProps & {\n /**\n * Create Arrow function in one line\n */\n singleLine?: boolean\n}\n\n/**\n * ArrowFunction\n *\n * Builds an arrow function declaration string for the fsx renderer. Supports\n * the same options as `Function`. Use `singleLine` to produce a one-line\n * arrow expression.\n */\nconst ArrowFunction = createComponent('ArrowFunction', ({ children, ...props }: ArrowFunctionProps) => {\n const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'ArrowFunction', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n const parts: string[] = []\n\n if (JSDoc?.comments) {\n parts.push(createJSDoc({ comments: JSDoc.comments }))\n parts.push('\\n')\n }\n\n if (canExport) {\n parts.push('export ')\n }\n\n if (isDefault) {\n parts.push('default ')\n }\n\n parts.push(`const ${name} = `)\n\n if (async) {\n parts.push('async ')\n }\n\n if (generics) {\n parts.push('<')\n parts.push(Array.isArray(generics) ? generics.join(', ').trim() : generics)\n parts.push('>')\n }\n\n parts.push(`(${params || ''})`)\n\n if (returnType && !async) {\n parts.push(`: ${returnType}`)\n }\n\n if (returnType && async) {\n parts.push(`: Promise<${returnType}>`)\n }\n\n if (singleLine) {\n parts.push(` => ${children || ''}\\n`)\n return parts.join('')\n }\n\n if (children) {\n return [parts.join(''), ' => {', Br(), Indent(), children, Br(), Dedent(), '}']\n }\n\n return [parts.join(''), ' => {}']\n})\n\nArrowFunction.displayName = 'ArrowFunction'\nFunction.Arrow = ArrowFunction\n","import { useNodeTree } from '../composables/useNodeTree.ts'\nimport { provide } from '../context.ts'\nimport { NodeTreeContext } from '../contexts/NodeTreeContext.ts'\nimport { createComponent } from '../createComponent.ts'\nimport type { FabricNode } from '../Fabric.ts'\nimport { renderIntrinsic } from '../intrinsic.ts'\nimport type { JSDoc } from '../types.ts'\nimport { createJSDoc } from '../utils/createJSDoc.ts'\n\nexport type TypeProps = {\n /**\n * Name of the type (must start with a capital letter).\n */\n name: string\n /**\n * Export this type.\n * - `true` generates `export type`\n * - `false` generates internal type\n * @default false\n */\n export?: boolean\n /**\n * JSDoc comments for the type.\n */\n JSDoc?: JSDoc\n /**\n * Type definition.\n */\n children?: FabricNode\n}\n\n/**\n * Generates a TypeScript type declaration.\n *\n * @example\n * ```tsx\n * <Type name=\"User\" export>\n * {'{'} id: number; name: string {'}'}\n * </Type>\n * ```\n */\nexport const Type = createComponent('Type', ({ children, ...props }: TypeProps) => {\n const { name, export: canExport, JSDoc } = props\n\n const nodeTree = useNodeTree()\n\n if (nodeTree) {\n const childTree = nodeTree.addChild({ type: 'Type', props })\n\n provide(NodeTreeContext, childTree)\n }\n\n if (name.charAt(0).toUpperCase() !== name.charAt(0)) {\n throw new Error('Name should start with a capital letter (see TypeScript types)')\n }\n\n const value = renderIntrinsic(children)\n\n let result = ''\n\n if (JSDoc?.comments) {\n result += createJSDoc({ comments: JSDoc.comments })\n result += '\\n'\n }\n\n if (canExport) {\n result += 'export '\n }\n\n result += `type ${name} = ${value || ''}`\n\n return result\n})\n\nType.displayName = 'Type'\n","import { FabricContext, type FabricContextProps } from '../contexts/FabricContext.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses the App context with metadata and exit function.\n *\n * Use this composable to access metadata defined in the App component\n * or to exit the rendering process early.\n *\n * @throws Error when no AppContext is available\n *\n * @example\n * ```ts\n * const { meta, exit } = useFabric<{ version: string }>()\n * console.log(meta.version)\n * ```\n */\nexport function useFabric<TMeta extends object = object>(): FabricContextProps<TMeta> {\n return useContext(FabricContext) as FabricContextProps<TMeta>\n}\n","import { RootContext } from '../contexts/RootContext.ts'\nimport { useContext } from './useContext.ts'\n\n/**\n * Accesses lifecycle helpers for controlling generation flow.\n *\n * Use this composable to exit the rendering process early or perform\n * cleanup operations.\n *\n * @returns Object with lifecycle methods (exit)\n *\n * @example\n * ```ts\n * const { exit } = useLifecycle()\n *\n * // Stop generation on error\n * if (invalidData) {\n * exit(new Error('Invalid data'))\n * }\n * ```\n */\nexport function useLifecycle() {\n const { exit } = useContext(RootContext)\n\n return {\n exit,\n }\n}\n","import { isFunction } from 'remeda'\nimport type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\nimport { FileManager } from './FileManager.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport type { Parser } from './parsers/types.ts'\nimport type { Plugin } from './plugins/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\n/**\n * Creates a new Fabric instance for file generation.\n *\n * The Fabric instance provides methods for registering plugins,\n * adding files, and triggering file generation.\n *\n * @param config - Optional configuration object\n * @returns A new Fabric instance\n *\n * @example\n * ```ts\n * import { createFabric } from '@kubb/fabric-core'\n * import { fsPlugin } from '@kubb/fabric-core/plugins'\n * import { typescriptParser } from '@kubb/fabric-core/parsers'\n *\n * const fabric = createFabric()\n * fabric.use(fsPlugin)\n * fabric.use(typescriptParser)\n *\n * await fabric.addFile({\n * baseName: 'user.ts',\n * path: './generated/user.ts',\n * sources: [{ value: 'export type User = {}', isExportable: true }],\n * imports: [],\n * exports: [],\n * })\n *\n * await fabric.write({ extension: { '.ts': '.ts' } })\n * ```\n */\nexport function createFabric<T extends FabricOptions>(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Map<KubbFile.Extname, Parser<any>>()\n const installedParserNames = new Set<string>()\n const fileManager = new FileManager({ events })\n\n const context: FabricContext<T> = {\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n await fileManager.add(...files)\n },\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n on: events.on.bind(events),\n off: events.off.bind(events),\n onOnce: events.onOnce.bind(events),\n removeAll: events.removeAll.bind(events),\n emit: events.emit.bind(events),\n } as FabricContext<T>\n\n const fabric: Fabric<T> = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...files) {\n fileManager.add(...files)\n },\n async upsertFile(...files) {\n fileManager.upsert(...files)\n },\n unmount(_error?: Error | number | null) {\n events.removeAll()\n },\n async use(pluginOrParser, ...options) {\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn(`Plugin \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const injected = (injecter as any)(context, ...options)\n Object.assign(fabric, injected)\n }\n }\n\n if (pluginOrParser.type === 'parser') {\n if (installedParserNames.has(pluginOrParser.name)) {\n console.warn(`Parser \"${pluginOrParser.name}\" already applied.`)\n } else {\n installedParserNames.add(pluginOrParser.name)\n }\n\n if (pluginOrParser.extNames) {\n for (const extName of pluginOrParser.extNames) {\n const existing = installedParsers.get(extName)\n if (existing && existing.name !== pluginOrParser.name) {\n console.warn(`Parser \"${pluginOrParser.name}\" is overriding parser \"${existing.name}\" for extension \"${extName}\".`)\n }\n installedParsers.set(extName, pluginOrParser)\n }\n }\n }\n\n if (isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(context, ...options)\n }\n\n return fabric\n },\n } as Fabric<T>\n\n return fabric\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiBA,MAAa,KAAKA,sBAAAA,gBAAgB,YAAY;AAC5C,QAAOC,sBAAAA,gBAAgB,KAAK;EAC5B;AAEF,GAAG,cAAc;;;ACRjB,SAAgB,WAAc,KAAiB,cAAqB;AAClE,QAAOC,sBAAAA,OAAO,KAAK,aAAa;;;;;;;;;;;;;;;;;;;;ACWlC,SAAgB,cAA8C;AAC5D,QAAO,WAAWC,sBAAAA,gBAAgB;;;;;;;ACvBpC,SAAgB,YAAY,EAAE,YAA4C;AACxE,KAAI,CAAC,YAAY,SAAS,WAAW,EAAG,QAAO;CAE/C,MAAM,QAAQ,SACX,SAAS,MAAM,OAAO,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,CAC9C,KAAK,MAAM,EAAE,QAAQ,SAAS,OAAO,CAAC,QAAQ,OAAO,GAAG,CAAC,CACzD,QAAQ,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE;AAErC,KAAI,MAAM,WAAW,EAAG,QAAO;AAE/B,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C,OAAI,eAAe,SAAS,UAAU;AACpC,QAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,WAAW,eAAe,KAAK,oBAAoB;QAEhE,kBAAiB,IAAI,eAAe;AAGtC,SAAA,GAAA,OAAA,YAAe,eAAe,OAAO,EAAE;KACrC,MAAM,WAAW,eAAe;KAEhC,MAAM,WAAY,SAAiB,SAAS,GAAG,QAAQ;AACvD,YAAO,OAAO,QAAQ,SAAS;;;AAInC,OAAI,eAAe,SAAS,UAAU;AACpC,QAAI,qBAAqB,IAAI,eAAe,KAAK,CAC/C,SAAQ,KAAK,WAAW,eAAe,KAAK,oBAAoB;QAEhE,sBAAqB,IAAI,eAAe,KAAK;AAG/C,QAAI,eAAe,SACjB,MAAK,MAAM,WAAW,eAAe,UAAU;KAC7C,MAAM,WAAW,iBAAiB,IAAI,QAAQ;AAC9C,SAAI,YAAY,SAAS,SAAS,eAAe,KAC/C,SAAQ,KAAK,WAAW,eAAe,KAAK,0BAA0B,SAAS,KAAK,mBAAmB,QAAQ,IAAI;AAErH,sBAAiB,IAAI,SAAS,eAAe;;;AAKnD,QAAA,GAAA,OAAA,YAAe,eAAe,QAAQ,EAAE;IACtC,MAAM,YAAY,eAAe;AAEjC,UAAO,UAAkB,SAAS,GAAG,QAAQ;;AAG/C,UAAO;;EAEV;AAED,QAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
3
|
-
import { t as
|
|
4
|
-
import { JSDoc } from "./types.js";
|
|
1
|
+
import { n as __name } from "./chunk-O_arW02_.js";
|
|
2
|
+
import { A as Path, D as File$1, M as Source, O as Import, T as Export, _ as inject, b as FileManager, c as FabricOptions, d as renderIndent, f as renderIntrinsic, g as createContext, h as Context, j as ResolvedFile, n as FabricComponent, p as RenderContext, r as FabricConfig, s as FabricNode, t as Fabric$1, v as provide, w as BaseName, x as FileProcessor, y as unprovide } from "./Fabric-CFkgoZwY.js";
|
|
3
|
+
import { n as useNodeTree, r as TreeNode, t as ComponentNode } from "./useNodeTree-Wc1WxA05.js";
|
|
4
|
+
import { n as RootContext, t as JSDoc } from "./types-BwR3_cUx.js";
|
|
5
5
|
|
|
6
6
|
//#region src/createComponent.d.ts
|
|
7
7
|
type MakeChildrenOptional<T extends object> = T extends {
|
|
@@ -13,36 +13,6 @@ type ComponentBuilder<T extends object> = {
|
|
|
13
13
|
};
|
|
14
14
|
declare function createComponent<TProps extends object>(type: string, Component: (props: TProps) => FabricNode): ComponentBuilder<TProps>;
|
|
15
15
|
//#endregion
|
|
16
|
-
//#region src/components/App.d.ts
|
|
17
|
-
type AppProps<TMeta extends Object = Object> = {
|
|
18
|
-
/**
|
|
19
|
-
* Metadata attached to the App context.
|
|
20
|
-
*
|
|
21
|
-
* Use this to pass custom data to child components via useApp.
|
|
22
|
-
*/
|
|
23
|
-
meta?: TMeta;
|
|
24
|
-
/**
|
|
25
|
-
* Child components.
|
|
26
|
-
*/
|
|
27
|
-
children?: FabricNode;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Container component providing App context with metadata and lifecycle.
|
|
31
|
-
*
|
|
32
|
-
* Use this component to wrap your application and provide shared metadata
|
|
33
|
-
* that can be accessed by child components using the useApp composable.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```tsx
|
|
37
|
-
* <App meta={{ version: '1.0.0', author: 'John Doe' }}>
|
|
38
|
-
* <File baseName="user.ts" path="./user.ts">
|
|
39
|
-
* <File.Source>export type User = {}</File.Source>
|
|
40
|
-
* </File>
|
|
41
|
-
* </App>
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
declare const App: ComponentBuilder<AppProps<Object>>;
|
|
45
|
-
//#endregion
|
|
46
16
|
//#region src/components/Br.d.ts
|
|
47
17
|
/**
|
|
48
18
|
* Generates a line break in the output.
|
|
@@ -127,6 +97,36 @@ declare const Const: ComponentBuilder<ConstProps>;
|
|
|
127
97
|
*/
|
|
128
98
|
declare const Dedent: ComponentBuilder<object>;
|
|
129
99
|
//#endregion
|
|
100
|
+
//#region src/components/Fabric.d.ts
|
|
101
|
+
type FabricProps<TMeta extends Object = Object> = {
|
|
102
|
+
/**
|
|
103
|
+
* Metadata attached to the App context.
|
|
104
|
+
*
|
|
105
|
+
* Use this to pass custom data to child components via useApp.
|
|
106
|
+
*/
|
|
107
|
+
meta?: TMeta;
|
|
108
|
+
/**
|
|
109
|
+
* Child components.
|
|
110
|
+
*/
|
|
111
|
+
children?: FabricNode;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Container component providing App context with metadata and lifecycle.
|
|
115
|
+
*
|
|
116
|
+
* Use this component to wrap your application and provide shared metadata
|
|
117
|
+
* that can be accessed by child components using the useApp composable.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```tsx
|
|
121
|
+
* <Fabric meta={{ version: '1.0.0', author: 'John Doe' }}>
|
|
122
|
+
* <File baseName="user.ts" path="./user.ts">
|
|
123
|
+
* <File.Source>export type User = {}</File.Source>
|
|
124
|
+
* </File>
|
|
125
|
+
* </Fabric>
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare const Fabric: ComponentBuilder<FabricProps<Object>>;
|
|
129
|
+
//#endregion
|
|
130
130
|
//#region src/components/File.d.ts
|
|
131
131
|
type FileProps<TMeta extends object = object> = {
|
|
132
132
|
/**
|
|
@@ -419,8 +419,20 @@ type TypeProps = {
|
|
|
419
419
|
*/
|
|
420
420
|
declare const Type: ComponentBuilder<TypeProps>;
|
|
421
421
|
//#endregion
|
|
422
|
-
//#region src/
|
|
423
|
-
|
|
422
|
+
//#region src/composables/useContext.d.ts
|
|
423
|
+
/**
|
|
424
|
+
* React-style alias for inject
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* const theme = useContext(ThemeContext) // type is inferred from ThemeContext
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
declare function useContext<T>(key: Context<T>): T;
|
|
432
|
+
declare function useContext<T, TValue = T>(key: Context<T>, defaultValue: TValue): NonNullable<T> | TValue;
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region src/contexts/FabricContext.d.ts
|
|
435
|
+
type FabricContextProps<TMeta extends object = object> = {
|
|
424
436
|
/**
|
|
425
437
|
* Exit (unmount)
|
|
426
438
|
*/
|
|
@@ -431,9 +443,9 @@ type AppContextProps<TMeta extends object = object> = {
|
|
|
431
443
|
* Provides app-level metadata and lifecycle hooks (like `exit`) to
|
|
432
444
|
* components and composables within a Fabric runtime.
|
|
433
445
|
*/
|
|
434
|
-
declare const
|
|
446
|
+
declare const FabricContext: Context<FabricContextProps<object>>;
|
|
435
447
|
//#endregion
|
|
436
|
-
//#region src/composables/
|
|
448
|
+
//#region src/composables/useFabric.d.ts
|
|
437
449
|
/**
|
|
438
450
|
* Accesses the App context with metadata and exit function.
|
|
439
451
|
*
|
|
@@ -444,23 +456,11 @@ declare const AppContext: Context<AppContextProps<object>>;
|
|
|
444
456
|
*
|
|
445
457
|
* @example
|
|
446
458
|
* ```ts
|
|
447
|
-
* const { meta, exit } =
|
|
459
|
+
* const { meta, exit } = useFabric<{ version: string }>()
|
|
448
460
|
* console.log(meta.version)
|
|
449
461
|
* ```
|
|
450
462
|
*/
|
|
451
|
-
declare function
|
|
452
|
-
//#endregion
|
|
453
|
-
//#region src/composables/useContext.d.ts
|
|
454
|
-
/**
|
|
455
|
-
* React-style alias for inject
|
|
456
|
-
*
|
|
457
|
-
* @example
|
|
458
|
-
* ```ts
|
|
459
|
-
* const theme = useContext(ThemeContext) // type is inferred from ThemeContext
|
|
460
|
-
* ```
|
|
461
|
-
*/
|
|
462
|
-
declare function useContext<T>(key: Context<T>): T;
|
|
463
|
-
declare function useContext<T, TValue = T>(key: Context<T>, defaultValue: TValue): NonNullable<T> | TValue;
|
|
463
|
+
declare function useFabric<TMeta extends object = object>(): FabricContextProps<TMeta>;
|
|
464
464
|
//#endregion
|
|
465
465
|
//#region src/composables/useFile.d.ts
|
|
466
466
|
/**
|
|
@@ -570,7 +570,7 @@ declare const NodeTreeContext: Context<TreeNode<ComponentNode> | null>;
|
|
|
570
570
|
* await fabric.write({ extension: { '.ts': '.ts' } })
|
|
571
571
|
* ```
|
|
572
572
|
*/
|
|
573
|
-
declare function createFabric<T extends FabricOptions>(config?: FabricConfig<T>): Fabric<T>;
|
|
573
|
+
declare function createFabric<T extends FabricOptions>(config?: FabricConfig<T>): Fabric$1<T>;
|
|
574
574
|
//#endregion
|
|
575
575
|
//#region src/createFile.d.ts
|
|
576
576
|
/**
|
|
@@ -601,5 +601,5 @@ declare function getRelativePath(rootDir?: string | null, filePath?: string | nu
|
|
|
601
601
|
*/
|
|
602
602
|
declare function onProcessExit(callback: (code: number | null) => void): () => void;
|
|
603
603
|
//#endregion
|
|
604
|
-
export {
|
|
604
|
+
export { Br, Const, Dedent, Fabric, FabricContext, File, FileContext, FileManager, FileProcessor, Function, Indent, NodeTreeContext, RenderContext, Root, RootContext, TreeNode, Type, createComponent, createContext, createFabric, createFile, createJSDoc, getRelativePath, inject, onProcessExit, provide, renderIndent, renderIntrinsic, unprovide, useContext, useFabric, useFile, useFileManager, useLifecycle, useNodeTree };
|
|
605
605
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as
|
|
1
|
+
import "./chunk-O_arW02_.js";
|
|
2
|
+
import { _ as provide, a as FileManager, c as createFile, d as createIntrinsic, f as renderIndent, g as inject, h as createContext, i as TreeNode, l as NodeTreeContext, m as RenderContext, n as Root, o as FileProcessor, p as renderIntrinsic, r as RootContext, s as AsyncEventEmitter, t as onProcessExit, u as createComponent, v as unprovide } from "./onProcessExit-Cput7j2c.js";
|
|
3
|
+
import { t as getRelativePath } from "./getRelativePath-NAm_Y-vp.js";
|
|
3
4
|
import { createExport, createImport, print } from "./parsers/typescript.js";
|
|
4
5
|
import { isFunction } from "remeda";
|
|
5
|
-
|
|
6
|
+
//#region src/components/Br.ts
|
|
7
|
+
/**
|
|
8
|
+
* Generates a line break in the output.
|
|
9
|
+
*
|
|
10
|
+
* Use this component to add newlines in generated code.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* <>
|
|
15
|
+
* const x = 1
|
|
16
|
+
* <Br />
|
|
17
|
+
* const y = 2
|
|
18
|
+
* </>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const Br = createComponent("br", () => {
|
|
22
|
+
return createIntrinsic("br");
|
|
23
|
+
});
|
|
24
|
+
Br.displayName = "Br";
|
|
25
|
+
//#endregion
|
|
6
26
|
//#region src/composables/useContext.ts
|
|
7
27
|
function useContext(key, defaultValue) {
|
|
8
28
|
return inject(key, defaultValue);
|
|
9
29
|
}
|
|
10
|
-
|
|
11
30
|
//#endregion
|
|
12
31
|
//#region src/composables/useNodeTree.ts
|
|
13
32
|
/**
|
|
@@ -29,72 +48,6 @@ function useContext(key, defaultValue) {
|
|
|
29
48
|
function useNodeTree() {
|
|
30
49
|
return useContext(NodeTreeContext);
|
|
31
50
|
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/contexts/AppContext.ts
|
|
35
|
-
/**
|
|
36
|
-
* Provides app-level metadata and lifecycle hooks (like `exit`) to
|
|
37
|
-
* components and composables within a Fabric runtime.
|
|
38
|
-
*/
|
|
39
|
-
const AppContext = createContext({
|
|
40
|
-
exit: () => {},
|
|
41
|
-
meta: {}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/components/App.ts
|
|
46
|
-
/**
|
|
47
|
-
* Container component providing App context with metadata and lifecycle.
|
|
48
|
-
*
|
|
49
|
-
* Use this component to wrap your application and provide shared metadata
|
|
50
|
-
* that can be accessed by child components using the useApp composable.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```tsx
|
|
54
|
-
* <App meta={{ version: '1.0.0', author: 'John Doe' }}>
|
|
55
|
-
* <File baseName="user.ts" path="./user.ts">
|
|
56
|
-
* <File.Source>export type User = {}</File.Source>
|
|
57
|
-
* </File>
|
|
58
|
-
* </App>
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
const App = createComponent("App", ({ children, ...props }) => {
|
|
62
|
-
const { meta = {} } = props;
|
|
63
|
-
const { exit } = useContext(RootContext);
|
|
64
|
-
const nodeTree = useNodeTree();
|
|
65
|
-
if (nodeTree) provide(NodeTreeContext, nodeTree.addChild({
|
|
66
|
-
type: "App",
|
|
67
|
-
props
|
|
68
|
-
}));
|
|
69
|
-
provide(AppContext, {
|
|
70
|
-
exit,
|
|
71
|
-
meta
|
|
72
|
-
});
|
|
73
|
-
return children;
|
|
74
|
-
});
|
|
75
|
-
App.displayName = "App";
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/components/Br.ts
|
|
79
|
-
/**
|
|
80
|
-
* Generates a line break in the output.
|
|
81
|
-
*
|
|
82
|
-
* Use this component to add newlines in generated code.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```tsx
|
|
86
|
-
* <>
|
|
87
|
-
* const x = 1
|
|
88
|
-
* <Br />
|
|
89
|
-
* const y = 2
|
|
90
|
-
* </>
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
const Br = createComponent("br", () => {
|
|
94
|
-
return createIntrinsic("br");
|
|
95
|
-
});
|
|
96
|
-
Br.displayName = "Br";
|
|
97
|
-
|
|
98
51
|
//#endregion
|
|
99
52
|
//#region src/utils/createJSDoc.ts
|
|
100
53
|
/**
|
|
@@ -110,7 +63,6 @@ function createJSDoc({ comments }) {
|
|
|
110
63
|
" */"
|
|
111
64
|
].join("\n");
|
|
112
65
|
}
|
|
113
|
-
|
|
114
66
|
//#endregion
|
|
115
67
|
//#region src/components/Const.ts
|
|
116
68
|
/**
|
|
@@ -144,7 +96,6 @@ const Const = createComponent("Const", ({ children, ...props }) => {
|
|
|
144
96
|
return result;
|
|
145
97
|
});
|
|
146
98
|
Const.displayName = "Const";
|
|
147
|
-
|
|
148
99
|
//#endregion
|
|
149
100
|
//#region src/components/Dedent.ts
|
|
150
101
|
/**
|
|
@@ -168,7 +119,48 @@ const Dedent = createComponent("dedent", () => {
|
|
|
168
119
|
return createIntrinsic("dedent");
|
|
169
120
|
});
|
|
170
121
|
Dedent.displayName = "Dedent";
|
|
171
|
-
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/contexts/FabricContext.ts
|
|
124
|
+
/**
|
|
125
|
+
* Provides app-level metadata and lifecycle hooks (like `exit`) to
|
|
126
|
+
* components and composables within a Fabric runtime.
|
|
127
|
+
*/
|
|
128
|
+
const FabricContext = createContext({
|
|
129
|
+
exit: () => {},
|
|
130
|
+
meta: {}
|
|
131
|
+
});
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/components/Fabric.ts
|
|
134
|
+
/**
|
|
135
|
+
* Container component providing App context with metadata and lifecycle.
|
|
136
|
+
*
|
|
137
|
+
* Use this component to wrap your application and provide shared metadata
|
|
138
|
+
* that can be accessed by child components using the useApp composable.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```tsx
|
|
142
|
+
* <Fabric meta={{ version: '1.0.0', author: 'John Doe' }}>
|
|
143
|
+
* <File baseName="user.ts" path="./user.ts">
|
|
144
|
+
* <File.Source>export type User = {}</File.Source>
|
|
145
|
+
* </File>
|
|
146
|
+
* </Fabric>
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
const Fabric = createComponent("Fabric", ({ children, ...props }) => {
|
|
150
|
+
const { meta = {} } = props;
|
|
151
|
+
const { exit } = useContext(RootContext);
|
|
152
|
+
const nodeTree = useNodeTree();
|
|
153
|
+
if (nodeTree) provide(NodeTreeContext, nodeTree.addChild({
|
|
154
|
+
type: "Fabric",
|
|
155
|
+
props
|
|
156
|
+
}));
|
|
157
|
+
provide(FabricContext, {
|
|
158
|
+
exit,
|
|
159
|
+
meta
|
|
160
|
+
});
|
|
161
|
+
return children;
|
|
162
|
+
});
|
|
163
|
+
Fabric.displayName = "Fabric";
|
|
172
164
|
//#endregion
|
|
173
165
|
//#region src/contexts/FileContext.ts
|
|
174
166
|
/**
|
|
@@ -176,7 +168,6 @@ Dedent.displayName = "Dedent";
|
|
|
176
168
|
* components and composables within a Fabric runtime.
|
|
177
169
|
*/
|
|
178
170
|
const FileContext = createContext(null);
|
|
179
|
-
|
|
180
171
|
//#endregion
|
|
181
172
|
//#region src/composables/useFile.ts
|
|
182
173
|
/**
|
|
@@ -199,7 +190,6 @@ const FileContext = createContext(null);
|
|
|
199
190
|
function useFile() {
|
|
200
191
|
return useContext(FileContext);
|
|
201
192
|
}
|
|
202
|
-
|
|
203
193
|
//#endregion
|
|
204
194
|
//#region src/composables/useFileManager.ts
|
|
205
195
|
/**
|
|
@@ -224,7 +214,6 @@ function useFileManager() {
|
|
|
224
214
|
const { fileManager } = useContext(RootContext);
|
|
225
215
|
return fileManager;
|
|
226
216
|
}
|
|
227
|
-
|
|
228
217
|
//#endregion
|
|
229
218
|
//#region src/components/File.ts
|
|
230
219
|
/**
|
|
@@ -360,7 +349,6 @@ const FileImport = createComponent("FileImport", (props) => {
|
|
|
360
349
|
File.Source = FileSource;
|
|
361
350
|
File.Import = FileImport;
|
|
362
351
|
File.Export = FileExport;
|
|
363
|
-
|
|
364
352
|
//#endregion
|
|
365
353
|
//#region src/components/Indent.ts
|
|
366
354
|
/**
|
|
@@ -384,7 +372,6 @@ const Indent = createComponent("indent", () => {
|
|
|
384
372
|
return createIntrinsic("indent");
|
|
385
373
|
});
|
|
386
374
|
Indent.displayName = "Indent";
|
|
387
|
-
|
|
388
375
|
//#endregion
|
|
389
376
|
//#region src/components/Function.ts
|
|
390
377
|
/**
|
|
@@ -489,7 +476,6 @@ const ArrowFunction = createComponent("ArrowFunction", ({ children, ...props })
|
|
|
489
476
|
});
|
|
490
477
|
ArrowFunction.displayName = "ArrowFunction";
|
|
491
478
|
Function.Arrow = ArrowFunction;
|
|
492
|
-
|
|
493
479
|
//#endregion
|
|
494
480
|
//#region src/components/Type.ts
|
|
495
481
|
/**
|
|
@@ -521,9 +507,8 @@ const Type = createComponent("Type", ({ children, ...props }) => {
|
|
|
521
507
|
return result;
|
|
522
508
|
});
|
|
523
509
|
Type.displayName = "Type";
|
|
524
|
-
|
|
525
510
|
//#endregion
|
|
526
|
-
//#region src/composables/
|
|
511
|
+
//#region src/composables/useFabric.ts
|
|
527
512
|
/**
|
|
528
513
|
* Accesses the App context with metadata and exit function.
|
|
529
514
|
*
|
|
@@ -534,14 +519,13 @@ Type.displayName = "Type";
|
|
|
534
519
|
*
|
|
535
520
|
* @example
|
|
536
521
|
* ```ts
|
|
537
|
-
* const { meta, exit } =
|
|
522
|
+
* const { meta, exit } = useFabric<{ version: string }>()
|
|
538
523
|
* console.log(meta.version)
|
|
539
524
|
* ```
|
|
540
525
|
*/
|
|
541
|
-
function
|
|
542
|
-
return useContext(
|
|
526
|
+
function useFabric() {
|
|
527
|
+
return useContext(FabricContext);
|
|
543
528
|
}
|
|
544
|
-
|
|
545
529
|
//#endregion
|
|
546
530
|
//#region src/composables/useLifecycle.ts
|
|
547
531
|
/**
|
|
@@ -566,7 +550,6 @@ function useLifecycle() {
|
|
|
566
550
|
const { exit } = useContext(RootContext);
|
|
567
551
|
return { exit };
|
|
568
552
|
}
|
|
569
|
-
|
|
570
553
|
//#endregion
|
|
571
554
|
//#region src/createFabric.ts
|
|
572
555
|
/**
|
|
@@ -664,7 +647,7 @@ function createFabric(config = { mode: "sequential" }) {
|
|
|
664
647
|
};
|
|
665
648
|
return fabric;
|
|
666
649
|
}
|
|
667
|
-
|
|
668
650
|
//#endregion
|
|
669
|
-
export {
|
|
651
|
+
export { Br, Const, Dedent, Fabric, FabricContext, File, FileContext, FileManager, FileProcessor, Function, Indent, NodeTreeContext, RenderContext, Root, RootContext, TreeNode, Type, createComponent, createContext, createFabric, createFile, createJSDoc, getRelativePath, inject, onProcessExit, provide, renderIndent, renderIntrinsic, unprovide, useContext, useFabric, useFile, useFileManager, useLifecycle, useNodeTree };
|
|
652
|
+
|
|
670
653
|
//# sourceMappingURL=index.js.map
|