@fumadocs/cli 1.3.0 → 1.3.2
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/build/index.d.ts +1 -1
- package/dist/build/index.js +2 -1
- package/dist/build/index.js.map +1 -1
- package/dist/{config-DH5Ggyir.js → config-BYrMmXOw.js} +3 -3
- package/dist/{config-DH5Ggyir.js.map → config-BYrMmXOw.js.map} +1 -1
- package/dist/{config-ndMKrpJz.d.ts → config-Dyass4D9.d.ts} +3 -3
- package/dist/{config-ndMKrpJz.d.ts.map → config-Dyass4D9.d.ts.map} +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/index.js +278 -62
- package/dist/index.js.map +1 -1
- package/dist/{installer-BS70ExnQ.js → installer-B3-my9zN.js} +2 -2
- package/dist/{installer-BS70ExnQ.js.map → installer-B3-my9zN.js.map} +1 -1
- package/dist/registry/client.d.ts +14 -4
- package/dist/registry/client.d.ts.map +1 -1
- package/dist/registry/installer/index.d.ts +1 -1
- package/dist/registry/installer/index.js +1 -1
- package/dist/registry/schema.d.ts +1 -1
- package/dist/registry/schema.js +2 -1
- package/dist/registry/schema.js.map +1 -1
- package/dist/schema/default.json +1 -1
- package/dist/schema/src.json +1 -1
- package/dist/{schema-CKNbRBjk.d.ts → schema-DrgqlhpT.d.ts} +9 -4
- package/dist/{schema-CKNbRBjk.d.ts.map → schema-DrgqlhpT.d.ts.map} +1 -1
- package/package.json +2 -2
package/dist/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { p as registryInfoSchema, s as NamespaceType, t as CompiledComponent } from "../schema-
|
|
1
|
+
import { p as registryInfoSchema, s as NamespaceType, t as CompiledComponent } from "../schema-DrgqlhpT.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { ResolverFactory } from "oxc-resolver";
|
|
4
4
|
|
package/dist/build/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var RegistryCompiler = class {
|
|
|
22
22
|
name: registry.name,
|
|
23
23
|
info: {
|
|
24
24
|
indexes: [],
|
|
25
|
+
unlistedIndexes: [],
|
|
25
26
|
env: registry.env,
|
|
26
27
|
variables: registry.variables
|
|
27
28
|
},
|
|
@@ -31,7 +32,7 @@ var RegistryCompiler = class {
|
|
|
31
32
|
return [component, await new ComponentCompiler(this, component).build()];
|
|
32
33
|
}));
|
|
33
34
|
for (const [input, comp] of builtComps) {
|
|
34
|
-
|
|
35
|
+
(input.unlisted ? output.info.unlistedIndexes : output.info.indexes).push({
|
|
35
36
|
name: input.name,
|
|
36
37
|
title: input.title,
|
|
37
38
|
description: input.description
|
package/dist/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fs","path","fs","path"],"sources":["../../src/build/compiler.ts","../../src/build/index.ts"],"sourcesContent":["import * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type {\n CompiledComponent,\n CompiledFile,\n httpSubComponent,\n NamespaceType,\n registryInfoSchema,\n} from '@/registry/schema';\nimport type { z } from 'zod';\nimport { parse } from 'oxc-parser';\nimport { ResolverFactory } from 'oxc-resolver';\nimport MagicString from 'magic-string';\nimport { transformSpecifiers } from '@/utils/ast';\nimport { isRelative } from '@/utils/fs';\n\nexport type OnResolve = (\n reference: SourceReference,\n from: { component: Component; file: ComponentFile },\n) => Reference;\n\nexport interface CompiledRegistry {\n name: string;\n components: CompiledComponent[];\n info: z.output<typeof registryInfoSchema>;\n}\n\nexport interface ComponentFile {\n type: NamespaceType;\n path: string;\n target?: string;\n}\n\nexport interface Component {\n name: string;\n title?: string;\n description?: string;\n files: ComponentFile[];\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n\n /**\n * Don't list the component in registry index file\n */\n unlisted?: boolean;\n\n /**\n * Map imported file paths, inherit from registry if not defined.\n */\n onResolve?: OnResolve;\n}\n\nexport interface PackageJson {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n}\n\nexport interface Registry extends Omit<z.input<typeof registryInfoSchema>, 'indexes'> {\n name: string;\n packageJson: string | PackageJson;\n tsconfigPath: string;\n components: Component[];\n\n /**\n * The directory of registry, used to resolve relative paths\n */\n dir: string;\n\n /**\n * Map import paths of components\n */\n onResolve?: OnResolve;\n /**\n * When a referenced file is not found in component files, this function is called.\n * @returns file, or `false` to mark as external.\n */\n onUnknownFile?: (absolutePath: string) => ComponentFile | false | undefined;\n\n dependencies?: Record<string, string | null>;\n devDependencies?: Record<string, string | null>;\n}\n\nexport class RegistryCompiler {\n readonly raw: Registry;\n resolver!: RegistryResolver;\n\n constructor(registry: Registry) {\n this.raw = registry;\n }\n\n private async readPackageJson(): Promise<PackageJson | undefined> {\n if (typeof this.raw.packageJson !== 'string') return this.raw.packageJson;\n\n return fs\n .readFile(path.join(this.raw.dir, this.raw.packageJson))\n .then((res) => JSON.parse(res.toString()) as PackageJson)\n .catch(() => undefined);\n }\n\n async compile(): Promise<CompiledRegistry> {\n const registry = this.raw;\n this.resolver = new RegistryResolver(this, await this.readPackageJson());\n const output: CompiledRegistry = {\n name: registry.name,\n info: {\n indexes: [],\n env: registry.env,\n variables: registry.variables,\n },\n components: [],\n };\n\n const builtComps = await Promise.all(\n registry.components.map(async (component) => {\n const compiler = new ComponentCompiler(this, component);\n\n return [component, await compiler.build()] as [Component, CompiledComponent];\n }),\n );\n\n for (const [input, comp] of builtComps) {\n if (!input.unlisted) {\n output.info.indexes.push({\n name: input.name,\n title: input.title,\n description: input.description,\n });\n }\n\n output.components.push(comp);\n }\n\n return output;\n }\n}\n\nclass RegistryResolver {\n private readonly deps: Record<string, string | null>;\n private readonly devDeps: Record<string, string | null>;\n private readonly fileToComponent = new Map<string, [Component, ComponentFile]>();\n readonly oxc: ResolverFactory;\n\n constructor(\n private readonly compiler: RegistryCompiler,\n packageJson: PackageJson = {},\n ) {\n const registry = compiler.raw;\n\n for (const comp of registry.components) {\n for (const file of comp.files) {\n if (this.fileToComponent.has(file.path))\n console.warn(\n `the same file ${file.path} exists in multiple component, you should make the shared file a separate component.`,\n );\n this.fileToComponent.set(file.path, [comp, file]);\n }\n }\n\n this.deps = {\n ...packageJson?.dependencies,\n ...registry.dependencies,\n };\n\n this.devDeps = {\n ...packageJson?.devDependencies,\n ...registry.devDependencies,\n };\n\n // resolve anything possible\n this.oxc = new ResolverFactory({\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.node'],\n conditionNames: ['node', 'import', 'require', 'default', 'types'],\n tsconfig: {\n configFile: path.join(registry.dir, registry.tsconfigPath),\n },\n });\n }\n\n getDepFromSpecifier(specifier: string) {\n return specifier.startsWith('@')\n ? specifier.split('/').slice(0, 2).join('/')\n : specifier.split('/')[0];\n }\n\n getDepInfo(name: string):\n | {\n type: 'runtime' | 'dev';\n name: string;\n version: string | null;\n }\n | undefined {\n if (name in this.deps)\n return {\n name,\n type: 'runtime',\n version: this.deps[name],\n };\n\n if (name in this.devDeps)\n return {\n name,\n type: 'dev',\n version: this.devDeps[name],\n };\n\n console.warn(`dep info for ${name} cannot be found`);\n }\n\n getComponentByName(name: string): Component | undefined {\n return this.compiler.raw.components.find((comp) => comp.name === name);\n }\n\n getSubComponent(file: string) {\n const relativeFile = path.relative(this.compiler.raw.dir, file);\n const comp = this.fileToComponent.get(relativeFile);\n\n if (!comp) return;\n return {\n component: comp[0],\n file: comp[1],\n };\n }\n}\n\nexport type SourceReference =\n | {\n type: 'file';\n /**\n * Absolute path\n */\n file: string;\n }\n | {\n type: 'dependency';\n dep: string;\n specifier: string;\n }\n | {\n type: 'sub-component';\n resolved:\n | {\n type: 'local';\n component: Component;\n file: ComponentFile;\n }\n | {\n type: 'remote';\n component: Component;\n file: ComponentFile;\n registryName: string;\n };\n }\n | {\n type: 'unknown-specifier';\n specifier: string;\n };\n\nexport type Reference =\n | SourceReference\n | {\n type: 'custom';\n specifier: string;\n };\n\nexport class ComponentCompiler {\n private readonly processedFiles = new Set<string>();\n private readonly registry: Registry;\n private readonly subComponents = new Map<string, string | z.input<typeof httpSubComponent>>();\n private readonly devDependencies = new Map<string, string | null>();\n private readonly dependencies = new Map<string, string | null>();\n\n constructor(\n private readonly compiler: RegistryCompiler,\n private readonly component: Component,\n ) {\n this.registry = compiler.raw;\n }\n\n private toImportPath(file: ComponentFile): string {\n let filePath = file.target ?? file.path;\n\n if (filePath.startsWith('./')) filePath = filePath.slice(2);\n\n return `@/${filePath.replaceAll(path.sep, '/')}`;\n }\n\n async build(): Promise<CompiledComponent> {\n const files = (\n await Promise.all(this.component.files.map((file) => this.onBuildFile(file)))\n ).flat();\n const dependencies = Object.fromEntries(this.dependencies);\n const devDependencies = Object.fromEntries(this.devDependencies);\n\n if (this.component.dependencies) {\n Object.assign(dependencies, this.component.dependencies);\n }\n if (this.component.devDependencies) {\n Object.assign(devDependencies, this.component.devDependencies);\n }\n\n return {\n name: this.component.name,\n title: this.component.title,\n description: this.component.description,\n files,\n subComponents: Array.from(this.subComponents.values()),\n dependencies,\n devDependencies,\n };\n }\n\n private async onBuildFile(file: ComponentFile): Promise<CompiledFile[]> {\n if (this.processedFiles.has(file.path)) return [];\n this.processedFiles.add(file.path);\n const resolver = this.compiler.resolver;\n\n const queue: ComponentFile[] = [];\n const result = await this.buildFile(file, (reference) => {\n if (reference.type === 'unknown-specifier') {\n if (!reference.specifier.startsWith('node:')) {\n console.warn(`Unknown specifier ${reference.specifier}, skipping for now`);\n }\n\n return reference.specifier;\n }\n\n if (reference.type === 'custom') return reference.specifier;\n\n if (reference.type === 'file') {\n const refFile = this.registry.onUnknownFile?.(reference.file);\n if (refFile) {\n queue.push(refFile);\n return this.toImportPath(refFile);\n }\n\n if (refFile === false) return;\n\n throw new Error(`Unknown file ${reference.file} referenced by ${file.path}`);\n }\n\n if (reference.type === 'sub-component') {\n const resolved = reference.resolved;\n if (resolved.component.name === this.component.name)\n return this.toImportPath(resolved.file);\n\n if (resolved.type === 'remote') {\n this.subComponents.set(`${resolved.registryName}:${resolved.component.name}`, {\n type: 'http',\n baseUrl: resolved.registryName,\n component: resolved.component.name,\n });\n } else {\n this.subComponents.set(resolved.component.name, resolved.component.name);\n }\n\n return this.toImportPath(resolved.file);\n }\n\n const dep = resolver.getDepInfo(reference.dep);\n if (dep) {\n const map = dep.type === 'dev' ? this.devDependencies : this.dependencies;\n map.set(dep.name, dep.version);\n }\n\n return reference.specifier;\n });\n\n return [result, ...(await Promise.all(queue.map((file) => this.onBuildFile(file)))).flat()];\n }\n\n private async buildFile(\n file: ComponentFile,\n /**\n * write references back to import specifiers\n *\n * keep original one if `undefined`\n */\n writeReference: (reference: Reference) => string | undefined,\n ): Promise<CompiledFile> {\n const sourceFilePath = path.join(this.registry.dir, file.path);\n const astTypes: Record<string, 'js' | 'ts' | undefined> = {\n '.ts': 'ts',\n '.tsx': 'ts',\n '.js': 'js',\n '.jsx': 'js',\n };\n const astType = astTypes[path.extname(file.path)];\n const content = (await fs.readFile(sourceFilePath)).toString();\n\n if (!astType)\n return {\n content,\n path: file.path,\n type: file.type,\n target: file.target,\n };\n\n const resolver = this.compiler.resolver;\n\n const ast = await parse(sourceFilePath, content, {\n astType,\n });\n\n if (ast.errors.length > 0) {\n throw new Error(`failed to parse file ${sourceFilePath}: \\n${ast.errors.join('\\n')}`);\n }\n\n const s = new MagicString(content);\n const ctx = { component: this.component, file };\n // Process import paths\n transformSpecifiers(ast.program, s, (specifier) => {\n let resolved: Reference = {\n type: 'unknown-specifier',\n specifier: specifier,\n };\n const onResolve = this.component.onResolve ?? this.registry.onResolve;\n const resolvedSpecifier = resolver.oxc.resolveFileSync(sourceFilePath, specifier);\n if (resolvedSpecifier.error || !resolvedSpecifier.path) {\n return writeReference(onResolve ? onResolve(resolved, ctx) : resolved);\n }\n\n resolved = {\n type: 'file',\n file: resolvedSpecifier.path,\n };\n\n // outside of registry dir\n if (!isRelative(this.registry.dir, resolvedSpecifier.path)) {\n resolved = {\n type: 'dependency',\n dep: resolver.getDepFromSpecifier(specifier),\n specifier,\n };\n } else {\n const sub = resolver.getSubComponent(resolvedSpecifier.path);\n if (sub) {\n resolved = {\n type: 'sub-component',\n resolved: {\n type: 'local',\n component: sub.component,\n file: sub.file,\n },\n };\n }\n }\n\n return writeReference(onResolve ? onResolve(resolved, ctx) : resolved);\n });\n\n return {\n content: s.toString(),\n type: file.type,\n path: file.path,\n target: file.target,\n };\n }\n}\n\nexport function resolveFromRemote(\n r: Registry,\n component: string,\n selectFile: (file: ComponentFile) => boolean,\n): Reference | undefined {\n const comp = r.components.find((comp) => comp.name === component);\n if (!comp) return;\n const file = comp.files.find(selectFile);\n if (!file) return;\n\n return {\n type: 'sub-component',\n resolved: {\n type: 'remote',\n registryName: r.name,\n component: comp,\n file,\n },\n };\n}\n","import * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport picocolors from 'picocolors';\nimport type { CompiledRegistry } from '@/build/compiler';\n\nexport * from './compiler';\n\nexport interface MonoRegistry extends CompiledRegistry {\n registries: CompiledRegistry[];\n}\n\nexport function combineRegistry(\n root: CompiledRegistry,\n ...items: CompiledRegistry[]\n): MonoRegistry {\n return {\n ...root,\n info: {\n ...root.info,\n registries: items.map((item) => item.name),\n },\n registries: items,\n };\n}\n\nexport async function writeFumadocsRegistry(\n out: CompiledRegistry | MonoRegistry,\n options: {\n dir: string;\n\n /**\n * Remove previous outputs\n *\n * @defaultValue false\n */\n cleanDir?: boolean;\n\n log?: boolean;\n },\n): Promise<void> {\n const { dir, cleanDir = false, log = true } = options;\n\n if (cleanDir) {\n await fs.rm(dir, {\n recursive: true,\n force: true,\n });\n console.log(picocolors.bold(picocolors.greenBright('Cleaned directory')));\n }\n\n async function writeInfo() {\n const file = path.join(dir, '_registry.json');\n const json = JSON.stringify(out.info, null, 2);\n\n await writeFile(file, json, log);\n }\n\n const write = out.components.map(async (comp) => {\n const file = path.join(dir, `${comp.name}.json`);\n const json = JSON.stringify(comp, null, 2);\n\n await writeFile(file, json, log);\n });\n\n write.push(writeInfo());\n if ('registries' in out) {\n for (const child of out.registries) {\n write.push(\n writeFumadocsRegistry(child, {\n dir: path.join(dir, child.name),\n log: options.log,\n }),\n );\n }\n }\n\n await Promise.all(write);\n}\n\nasync function writeFile(file: string, content: string, log = true): Promise<void> {\n await fs.mkdir(path.dirname(file), { recursive: true });\n await fs.writeFile(file, content);\n\n if (log) {\n const size = (Buffer.byteLength(content) / 1024).toFixed(2);\n\n console.log(\n `${picocolors.greenBright('+')} ${path.relative(process.cwd(), file)} ${picocolors.dim(`${size} KB`)}`,\n );\n }\n}\n"],"mappings":";;;;;;;;;AAkFA,IAAa,mBAAb,MAA8B;CAI5B,YAAY,UAAoB;AAC9B,OAAK,MAAM;;CAGb,MAAc,kBAAoD;AAChE,MAAI,OAAO,KAAK,IAAI,gBAAgB,SAAU,QAAO,KAAK,IAAI;AAE9D,SAAOA,KACJ,SAASC,OAAK,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,YAAY,CAAC,CACvD,MAAM,QAAQ,KAAK,MAAM,IAAI,UAAU,CAAC,CAAgB,CACxD,YAAY,KAAA,EAAU;;CAG3B,MAAM,UAAqC;EACzC,MAAM,WAAW,KAAK;AACtB,OAAK,WAAW,IAAI,iBAAiB,MAAM,MAAM,KAAK,iBAAiB,CAAC;EACxE,MAAM,SAA2B;GAC/B,MAAM,SAAS;GACf,MAAM;IACJ,SAAS,EAAE;IACX,KAAK,SAAS;IACd,WAAW,SAAS;IACrB;GACD,YAAY,EAAE;GACf;EAED,MAAM,aAAa,MAAM,QAAQ,IAC/B,SAAS,WAAW,IAAI,OAAO,cAAc;AAG3C,UAAO,CAAC,WAAW,MAFF,IAAI,kBAAkB,MAAM,UAAU,CAErB,OAAO,CAAC;IAC1C,CACH;AAED,OAAK,MAAM,CAAC,OAAO,SAAS,YAAY;AACtC,OAAI,CAAC,MAAM,SACT,QAAO,KAAK,QAAQ,KAAK;IACvB,MAAM,MAAM;IACZ,OAAO,MAAM;IACb,aAAa,MAAM;IACpB,CAAC;AAGJ,UAAO,WAAW,KAAK,KAAK;;A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B,eAAe,UAAU,MAAc,SAAiB,MAAM,MAAqB;AACjF,OAAMD,KAAG,MAAMC,OAAK,QAAQ,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,OAAMD,KAAG,UAAU,MAAM,QAAQ;AAEjC,KAAI,KAAK;EACP,MAAM,QAAQ,OAAO,WAAW,QAAQ,GAAG,MAAM,QAAQ,EAAE;AAE3D,UAAQ,IACN,GAAG,WAAW,YAAY,IAAI,CAAC,GAAGC,OAAK,SAAS,QAAQ,KAAK,EAAE,KAAK,CAAC,GAAG,WAAW,IAAI,GAAG,KAAK,KAAK,GACrG"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fs","path","fs","path"],"sources":["../../src/build/compiler.ts","../../src/build/index.ts"],"sourcesContent":["import * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type {\n CompiledComponent,\n CompiledFile,\n httpSubComponent,\n NamespaceType,\n registryInfoSchema,\n} from '@/registry/schema';\nimport type { z } from 'zod';\nimport { parse } from 'oxc-parser';\nimport { ResolverFactory } from 'oxc-resolver';\nimport MagicString from 'magic-string';\nimport { transformSpecifiers } from '@/utils/ast';\nimport { isRelative } from '@/utils/fs';\n\nexport type OnResolve = (\n reference: SourceReference,\n from: { component: Component; file: ComponentFile },\n) => Reference;\n\nexport interface CompiledRegistry {\n name: string;\n components: CompiledComponent[];\n info: z.output<typeof registryInfoSchema>;\n}\n\nexport interface ComponentFile {\n type: NamespaceType;\n path: string;\n target?: string;\n}\n\nexport interface Component {\n name: string;\n title?: string;\n description?: string;\n files: ComponentFile[];\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n\n /**\n * Don't list the component in registry index file\n */\n unlisted?: boolean;\n\n /**\n * Map imported file paths, inherit from registry if not defined.\n */\n onResolve?: OnResolve;\n}\n\nexport interface PackageJson {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n}\n\nexport interface Registry extends Omit<z.input<typeof registryInfoSchema>, 'indexes'> {\n name: string;\n packageJson: string | PackageJson;\n tsconfigPath: string;\n components: Component[];\n\n /**\n * The directory of registry, used to resolve relative paths\n */\n dir: string;\n\n /**\n * Map import paths of components\n */\n onResolve?: OnResolve;\n /**\n * When a referenced file is not found in component files, this function is called.\n * @returns file, or `false` to mark as external.\n */\n onUnknownFile?: (absolutePath: string) => ComponentFile | false | undefined;\n\n dependencies?: Record<string, string | null>;\n devDependencies?: Record<string, string | null>;\n}\n\nexport class RegistryCompiler {\n readonly raw: Registry;\n resolver!: RegistryResolver;\n\n constructor(registry: Registry) {\n this.raw = registry;\n }\n\n private async readPackageJson(): Promise<PackageJson | undefined> {\n if (typeof this.raw.packageJson !== 'string') return this.raw.packageJson;\n\n return fs\n .readFile(path.join(this.raw.dir, this.raw.packageJson))\n .then((res) => JSON.parse(res.toString()) as PackageJson)\n .catch(() => undefined);\n }\n\n async compile(): Promise<CompiledRegistry> {\n const registry = this.raw;\n this.resolver = new RegistryResolver(this, await this.readPackageJson());\n const output: CompiledRegistry = {\n name: registry.name,\n info: {\n indexes: [],\n unlistedIndexes: [],\n env: registry.env,\n variables: registry.variables,\n },\n components: [],\n };\n\n const builtComps = await Promise.all(\n registry.components.map(async (component) => {\n const compiler = new ComponentCompiler(this, component);\n\n return [component, await compiler.build()] as [Component, CompiledComponent];\n }),\n );\n\n for (const [input, comp] of builtComps) {\n const arr = input.unlisted ? output.info.unlistedIndexes : output.info.indexes;\n\n arr.push({\n name: input.name,\n title: input.title,\n description: input.description,\n });\n output.components.push(comp);\n }\n\n return output;\n }\n}\n\nclass RegistryResolver {\n private readonly deps: Record<string, string | null>;\n private readonly devDeps: Record<string, string | null>;\n private readonly fileToComponent = new Map<string, [Component, ComponentFile]>();\n readonly oxc: ResolverFactory;\n\n constructor(\n private readonly compiler: RegistryCompiler,\n packageJson: PackageJson = {},\n ) {\n const registry = compiler.raw;\n\n for (const comp of registry.components) {\n for (const file of comp.files) {\n if (this.fileToComponent.has(file.path))\n console.warn(\n `the same file ${file.path} exists in multiple component, you should make the shared file a separate component.`,\n );\n this.fileToComponent.set(file.path, [comp, file]);\n }\n }\n\n this.deps = {\n ...packageJson?.dependencies,\n ...registry.dependencies,\n };\n\n this.devDeps = {\n ...packageJson?.devDependencies,\n ...registry.devDependencies,\n };\n\n // resolve anything possible\n this.oxc = new ResolverFactory({\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.node'],\n conditionNames: ['node', 'import', 'require', 'default', 'types'],\n tsconfig: {\n configFile: path.join(registry.dir, registry.tsconfigPath),\n },\n });\n }\n\n getDepFromSpecifier(specifier: string) {\n return specifier.startsWith('@')\n ? specifier.split('/').slice(0, 2).join('/')\n : specifier.split('/')[0];\n }\n\n getDepInfo(name: string):\n | {\n type: 'runtime' | 'dev';\n name: string;\n version: string | null;\n }\n | undefined {\n if (name in this.deps)\n return {\n name,\n type: 'runtime',\n version: this.deps[name],\n };\n\n if (name in this.devDeps)\n return {\n name,\n type: 'dev',\n version: this.devDeps[name],\n };\n\n console.warn(`dep info for ${name} cannot be found`);\n }\n\n getComponentByName(name: string): Component | undefined {\n return this.compiler.raw.components.find((comp) => comp.name === name);\n }\n\n getSubComponent(file: string) {\n const relativeFile = path.relative(this.compiler.raw.dir, file);\n const comp = this.fileToComponent.get(relativeFile);\n\n if (!comp) return;\n return {\n component: comp[0],\n file: comp[1],\n };\n }\n}\n\nexport type SourceReference =\n | {\n type: 'file';\n /**\n * Absolute path\n */\n file: string;\n }\n | {\n type: 'dependency';\n dep: string;\n specifier: string;\n }\n | {\n type: 'sub-component';\n resolved:\n | {\n type: 'local';\n component: Component;\n file: ComponentFile;\n }\n | {\n type: 'remote';\n component: Component;\n file: ComponentFile;\n registryName: string;\n };\n }\n | {\n type: 'unknown-specifier';\n specifier: string;\n };\n\nexport type Reference =\n | SourceReference\n | {\n type: 'custom';\n specifier: string;\n };\n\nexport class ComponentCompiler {\n private readonly processedFiles = new Set<string>();\n private readonly registry: Registry;\n private readonly subComponents = new Map<string, string | z.input<typeof httpSubComponent>>();\n private readonly devDependencies = new Map<string, string | null>();\n private readonly dependencies = new Map<string, string | null>();\n\n constructor(\n private readonly compiler: RegistryCompiler,\n private readonly component: Component,\n ) {\n this.registry = compiler.raw;\n }\n\n private toImportPath(file: ComponentFile): string {\n let filePath = file.target ?? file.path;\n\n if (filePath.startsWith('./')) filePath = filePath.slice(2);\n\n return `@/${filePath.replaceAll(path.sep, '/')}`;\n }\n\n async build(): Promise<CompiledComponent> {\n const files = (\n await Promise.all(this.component.files.map((file) => this.onBuildFile(file)))\n ).flat();\n const dependencies = Object.fromEntries(this.dependencies);\n const devDependencies = Object.fromEntries(this.devDependencies);\n\n if (this.component.dependencies) {\n Object.assign(dependencies, this.component.dependencies);\n }\n if (this.component.devDependencies) {\n Object.assign(devDependencies, this.component.devDependencies);\n }\n\n return {\n name: this.component.name,\n title: this.component.title,\n description: this.component.description,\n files,\n subComponents: Array.from(this.subComponents.values()),\n dependencies,\n devDependencies,\n };\n }\n\n private async onBuildFile(file: ComponentFile): Promise<CompiledFile[]> {\n if (this.processedFiles.has(file.path)) return [];\n this.processedFiles.add(file.path);\n const resolver = this.compiler.resolver;\n\n const queue: ComponentFile[] = [];\n const result = await this.buildFile(file, (reference) => {\n if (reference.type === 'unknown-specifier') {\n if (!reference.specifier.startsWith('node:')) {\n console.warn(`Unknown specifier ${reference.specifier}, skipping for now`);\n }\n\n return reference.specifier;\n }\n\n if (reference.type === 'custom') return reference.specifier;\n\n if (reference.type === 'file') {\n const refFile = this.registry.onUnknownFile?.(reference.file);\n if (refFile) {\n queue.push(refFile);\n return this.toImportPath(refFile);\n }\n\n if (refFile === false) return;\n\n throw new Error(`Unknown file ${reference.file} referenced by ${file.path}`);\n }\n\n if (reference.type === 'sub-component') {\n const resolved = reference.resolved;\n if (resolved.component.name === this.component.name)\n return this.toImportPath(resolved.file);\n\n if (resolved.type === 'remote') {\n this.subComponents.set(`${resolved.registryName}:${resolved.component.name}`, {\n type: 'http',\n baseUrl: resolved.registryName,\n component: resolved.component.name,\n });\n } else {\n this.subComponents.set(resolved.component.name, resolved.component.name);\n }\n\n return this.toImportPath(resolved.file);\n }\n\n const dep = resolver.getDepInfo(reference.dep);\n if (dep) {\n const map = dep.type === 'dev' ? this.devDependencies : this.dependencies;\n map.set(dep.name, dep.version);\n }\n\n return reference.specifier;\n });\n\n return [result, ...(await Promise.all(queue.map((file) => this.onBuildFile(file)))).flat()];\n }\n\n private async buildFile(\n file: ComponentFile,\n /**\n * write references back to import specifiers\n *\n * keep original one if `undefined`\n */\n writeReference: (reference: Reference) => string | undefined,\n ): Promise<CompiledFile> {\n const sourceFilePath = path.join(this.registry.dir, file.path);\n const astTypes: Record<string, 'js' | 'ts' | undefined> = {\n '.ts': 'ts',\n '.tsx': 'ts',\n '.js': 'js',\n '.jsx': 'js',\n };\n const astType = astTypes[path.extname(file.path)];\n const content = (await fs.readFile(sourceFilePath)).toString();\n\n if (!astType)\n return {\n content,\n path: file.path,\n type: file.type,\n target: file.target,\n };\n\n const resolver = this.compiler.resolver;\n\n const ast = await parse(sourceFilePath, content, {\n astType,\n });\n\n if (ast.errors.length > 0) {\n throw new Error(`failed to parse file ${sourceFilePath}: \\n${ast.errors.join('\\n')}`);\n }\n\n const s = new MagicString(content);\n const ctx = { component: this.component, file };\n // Process import paths\n transformSpecifiers(ast.program, s, (specifier) => {\n let resolved: Reference = {\n type: 'unknown-specifier',\n specifier: specifier,\n };\n const onResolve = this.component.onResolve ?? this.registry.onResolve;\n const resolvedSpecifier = resolver.oxc.resolveFileSync(sourceFilePath, specifier);\n if (resolvedSpecifier.error || !resolvedSpecifier.path) {\n return writeReference(onResolve ? onResolve(resolved, ctx) : resolved);\n }\n\n resolved = {\n type: 'file',\n file: resolvedSpecifier.path,\n };\n\n // outside of registry dir\n if (!isRelative(this.registry.dir, resolvedSpecifier.path)) {\n resolved = {\n type: 'dependency',\n dep: resolver.getDepFromSpecifier(specifier),\n specifier,\n };\n } else {\n const sub = resolver.getSubComponent(resolvedSpecifier.path);\n if (sub) {\n resolved = {\n type: 'sub-component',\n resolved: {\n type: 'local',\n component: sub.component,\n file: sub.file,\n },\n };\n }\n }\n\n return writeReference(onResolve ? onResolve(resolved, ctx) : resolved);\n });\n\n return {\n content: s.toString(),\n type: file.type,\n path: file.path,\n target: file.target,\n };\n }\n}\n\nexport function resolveFromRemote(\n r: Registry,\n component: string,\n selectFile: (file: ComponentFile) => boolean,\n): Reference | undefined {\n const comp = r.components.find((comp) => comp.name === component);\n if (!comp) return;\n const file = comp.files.find(selectFile);\n if (!file) return;\n\n return {\n type: 'sub-component',\n resolved: {\n type: 'remote',\n registryName: r.name,\n component: comp,\n file,\n },\n };\n}\n","import * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport picocolors from 'picocolors';\nimport type { CompiledRegistry } from '@/build/compiler';\n\nexport * from './compiler';\n\nexport interface MonoRegistry extends CompiledRegistry {\n registries: CompiledRegistry[];\n}\n\nexport function combineRegistry(\n root: CompiledRegistry,\n ...items: CompiledRegistry[]\n): MonoRegistry {\n return {\n ...root,\n info: {\n ...root.info,\n registries: items.map((item) => item.name),\n },\n registries: items,\n };\n}\n\nexport async function writeFumadocsRegistry(\n out: CompiledRegistry | MonoRegistry,\n options: {\n dir: string;\n\n /**\n * Remove previous outputs\n *\n * @defaultValue false\n */\n cleanDir?: boolean;\n\n log?: boolean;\n },\n): Promise<void> {\n const { dir, cleanDir = false, log = true } = options;\n\n if (cleanDir) {\n await fs.rm(dir, {\n recursive: true,\n force: true,\n });\n console.log(picocolors.bold(picocolors.greenBright('Cleaned directory')));\n }\n\n async function writeInfo() {\n const file = path.join(dir, '_registry.json');\n const json = JSON.stringify(out.info, null, 2);\n\n await writeFile(file, json, log);\n }\n\n const write = out.components.map(async (comp) => {\n const file = path.join(dir, `${comp.name}.json`);\n const json = JSON.stringify(comp, null, 2);\n\n await writeFile(file, json, log);\n });\n\n write.push(writeInfo());\n if ('registries' in out) {\n for (const child of out.registries) {\n write.push(\n writeFumadocsRegistry(child, {\n dir: path.join(dir, child.name),\n log: options.log,\n }),\n );\n }\n }\n\n await Promise.all(write);\n}\n\nasync function writeFile(file: string, content: string, log = true): Promise<void> {\n await fs.mkdir(path.dirname(file), { recursive: true });\n await fs.writeFile(file, content);\n\n if (log) {\n const size = (Buffer.byteLength(content) / 1024).toFixed(2);\n\n console.log(\n `${picocolors.greenBright('+')} ${path.relative(process.cwd(), file)} ${picocolors.dim(`${size} KB`)}`,\n );\n }\n}\n"],"mappings":";;;;;;;;;AAkFA,IAAa,mBAAb,MAA8B;CAI5B,YAAY,UAAoB;AAC9B,OAAK,MAAM;;CAGb,MAAc,kBAAoD;AAChE,MAAI,OAAO,KAAK,IAAI,gBAAgB,SAAU,QAAO,KAAK,IAAI;AAE9D,SAAOA,KACJ,SAASC,OAAK,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,YAAY,CAAC,CACvD,MAAM,QAAQ,KAAK,MAAM,IAAI,UAAU,CAAC,CAAgB,CACxD,YAAY,KAAA,EAAU;;CAG3B,MAAM,UAAqC;EACzC,MAAM,WAAW,KAAK;AACtB,OAAK,WAAW,IAAI,iBAAiB,MAAM,MAAM,KAAK,iBAAiB,CAAC;EACxE,MAAM,SAA2B;GAC/B,MAAM,SAAS;GACf,MAAM;IACJ,SAAS,EAAE;IACX,iBAAiB,EAAE;IACnB,KAAK,SAAS;IACd,WAAW,SAAS;IACrB;GACD,YAAY,EAAE;GACf;EAED,MAAM,aAAa,MAAM,QAAQ,IAC/B,SAAS,WAAW,IAAI,OAAO,cAAc;AAG3C,UAAO,CAAC,WAAW,MAFF,IAAI,kBAAkB,MAAM,UAAU,CAErB,OAAO,CAAC;IAC1C,CACH;AAED,OAAK,MAAM,CAAC,OAAO,SAAS,YAAY;AAGtC,IAFY,MAAM,WAAW,OAAO,KAAK,kBAAkB,OAAO,KAAK,SAEnE,KAAK;IACP,MAAM,MAAM;IACZ,OAAO,MAAM;IACb,aAAa,MAAM;IACpB,CAAC;AACF,UAAO,WAAW,KAAK,KAAK;;AAG9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AAe,UAAU,MAAc,SAAiB,MAAM,MAAqB;AACjF,OAAMD,KAAG,MAAMC,OAAK,QAAQ,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,OAAMD,KAAG,UAAU,MAAM,QAAQ;AAEjC,KAAI,KAAK;EACP,MAAM,QAAQ,OAAO,WAAW,QAAQ,GAAG,MAAM,QAAQ,EAAE;AAE3D,UAAQ,IACN,GAAG,WAAW,YAAY,IAAI,CAAC,GAAGC,OAAK,SAAS,QAAQ,KAAK,EAAE,KAAK,CAAC,GAAG,WAAW,IAAI,GAAG,KAAK,KAAK,GACrG"}
|
|
@@ -11,7 +11,7 @@ function createConfigSchema(isSrc) {
|
|
|
11
11
|
const defaultAliases = {
|
|
12
12
|
uiDir: "./components/ui",
|
|
13
13
|
componentsDir: "./components",
|
|
14
|
-
|
|
14
|
+
layoutDir: "./layouts",
|
|
15
15
|
cssDir: "./styles",
|
|
16
16
|
libDir: "./lib"
|
|
17
17
|
};
|
|
@@ -20,7 +20,7 @@ function createConfigSchema(isSrc) {
|
|
|
20
20
|
aliases: z.object({
|
|
21
21
|
uiDir: z.string().default(defaultAliases.uiDir),
|
|
22
22
|
componentsDir: z.string().default(defaultAliases.uiDir),
|
|
23
|
-
|
|
23
|
+
layoutDir: z.string().default(defaultAliases.layoutDir),
|
|
24
24
|
cssDir: z.string().default(defaultAliases.componentsDir),
|
|
25
25
|
libDir: z.string().default(defaultAliases.libDir)
|
|
26
26
|
}).default(defaultAliases),
|
|
@@ -52,4 +52,4 @@ async function getDefaultConfig(src) {
|
|
|
52
52
|
//#endregion
|
|
53
53
|
export { initConfig as i, createOrLoadConfig as n, getDefaultConfig as r, createConfigSchema as t };
|
|
54
54
|
|
|
55
|
-
//# sourceMappingURL=config-
|
|
55
|
+
//# sourceMappingURL=config-BYrMmXOw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-
|
|
1
|
+
{"version":3,"file":"config-BYrMmXOw.js","names":[],"sources":["../src/utils/is-src.ts","../src/config.ts"],"sourcesContent":["import { exists } from '@/utils/fs';\n\nexport async function isSrc(): Promise<boolean> {\n return exists('./src');\n}\n","import fs from 'node:fs/promises';\nimport { isSrc } from '@/utils/is-src';\nimport { z } from 'zod';\n\nexport function createConfigSchema(isSrc: boolean) {\n const defaultAliases = {\n uiDir: './components/ui',\n componentsDir: './components',\n layoutDir: './layouts',\n cssDir: './styles',\n libDir: './lib',\n };\n\n return z.object({\n $schema: z\n .string()\n .default(\n isSrc\n ? 'node_modules/@fumadocs/cli/dist/schema/src.json'\n : 'node_modules/@fumadocs/cli/dist/schema/default.json',\n )\n .optional(),\n aliases: z\n .object({\n uiDir: z.string().default(defaultAliases.uiDir),\n componentsDir: z.string().default(defaultAliases.uiDir),\n layoutDir: z.string().default(defaultAliases.layoutDir),\n cssDir: z.string().default(defaultAliases.componentsDir),\n libDir: z.string().default(defaultAliases.libDir),\n })\n .default(defaultAliases),\n\n baseDir: z.string().default(isSrc ? 'src' : ''),\n uiLibrary: z.enum(['radix-ui', 'base-ui']).default('radix-ui'),\n\n commands: z\n .object({\n /**\n * command to format output code automatically\n */\n format: z.string().optional(),\n })\n .default({}),\n });\n}\n\ntype ConfigSchema = ReturnType<typeof createConfigSchema>;\n\nexport type ConfigInput = z.input<ConfigSchema>;\nexport type LoadedConfig = z.output<ConfigSchema>;\n\nexport async function createOrLoadConfig(file = './cli.json'): Promise<LoadedConfig> {\n const inited = await initConfig(file);\n if (inited) return inited;\n\n const content = (await fs.readFile(file)).toString();\n const src = await isSrc();\n const configSchema = createConfigSchema(src);\n\n return configSchema.parse(JSON.parse(content));\n}\n\n/**\n * Write new config, skip if a config already exists\n *\n * @returns the created config, `undefined` if not created\n */\nexport async function initConfig(\n file = './cli.json',\n src?: boolean,\n): Promise<LoadedConfig | undefined> {\n if (\n await fs\n .stat(file)\n .then(() => true)\n .catch(() => false)\n ) {\n return;\n }\n\n const defaultConfig = await getDefaultConfig(src);\n await fs.writeFile(file, JSON.stringify(defaultConfig, null, 2));\n return defaultConfig;\n}\n\nexport async function getDefaultConfig(src?: boolean) {\n return createConfigSchema(src ?? (await isSrc())).parse({} satisfies ConfigInput);\n}\n"],"mappings":";;;;AAEA,eAAsB,QAA0B;AAC9C,QAAO,OAAO,QAAQ;;;;ACCxB,SAAgB,mBAAmB,OAAgB;CACjD,MAAM,iBAAiB;EACrB,OAAO;EACP,eAAe;EACf,WAAW;EACX,QAAQ;EACR,QAAQ;EACT;AAED,QAAO,EAAE,OAAO;EACd,SAAS,EACN,QAAQ,CACR,QACC,QACI,oDACA,sDACL,CACA,UAAU;EACb,SAAS,EACN,OAAO;GACN,OAAO,EAAE,QAAQ,CAAC,QAAQ,eAAe,MAAM;GAC/C,eAAe,EAAE,QAAQ,CAAC,QAAQ,eAAe,MAAM;GACvD,WAAW,EAAE,QAAQ,CAAC,QAAQ,eAAe,UAAU;GACvD,QAAQ,EAAE,QAAQ,CAAC,QAAQ,eAAe,cAAc;GACxD,QAAQ,EAAE,QAAQ,CAAC,QAAQ,eAAe,OAAO;GAClD,CAAC,CACD,QAAQ,eAAe;EAE1B,SAAS,EAAE,QAAQ,CAAC,QAAQ,QAAQ,QAAQ,GAAG;EAC/C,WAAW,EAAE,KAAK,CAAC,YAAY,UAAU,CAAC,CAAC,QAAQ,WAAW;EAE9D,UAAU,EACP,OAAO,EAIN,QAAQ,EAAE,QAAQ,CAAC,UAAU,EAC9B,CAAC,CACD,QAAQ,EAAE,CAAC;EACf,CAAC;;AAQJ,eAAsB,mBAAmB,OAAO,cAAqC;CACnF,MAAM,SAAS,MAAM,WAAW,KAAK;AACrC,KAAI,OAAQ,QAAO;CAEnB,MAAM,WAAW,MAAM,GAAG,SAAS,KAAK,EAAE,UAAU;AAIpD,QAFqB,mBADT,MAAM,OAAO,CACmB,CAExB,MAAM,KAAK,MAAM,QAAQ,CAAC;;;;;;;AAQhD,eAAsB,WACpB,OAAO,cACP,KACmC;AACnC,KACE,MAAM,GACH,KAAK,KAAK,CACV,WAAW,KAAK,CAChB,YAAY,MAAM,CAErB;CAGF,MAAM,gBAAgB,MAAM,iBAAiB,IAAI;AACjD,OAAM,GAAG,UAAU,MAAM,KAAK,UAAU,eAAe,MAAM,EAAE,CAAC;AAChE,QAAO;;AAGT,eAAsB,iBAAiB,KAAe;AACpD,QAAO,mBAAmB,OAAQ,MAAM,OAAO,CAAE,CAAC,MAAM,EAAE,CAAuB"}
|
|
@@ -6,7 +6,7 @@ declare function createConfigSchema(isSrc: boolean): z.ZodObject<{
|
|
|
6
6
|
aliases: z.ZodDefault<z.ZodObject<{
|
|
7
7
|
uiDir: z.ZodDefault<z.ZodString>;
|
|
8
8
|
componentsDir: z.ZodDefault<z.ZodString>;
|
|
9
|
-
|
|
9
|
+
layoutDir: z.ZodDefault<z.ZodString>;
|
|
10
10
|
cssDir: z.ZodDefault<z.ZodString>;
|
|
11
11
|
libDir: z.ZodDefault<z.ZodString>;
|
|
12
12
|
}, z.core.$strip>>;
|
|
@@ -33,7 +33,7 @@ declare function getDefaultConfig(src?: boolean): Promise<{
|
|
|
33
33
|
aliases: {
|
|
34
34
|
uiDir: string;
|
|
35
35
|
componentsDir: string;
|
|
36
|
-
|
|
36
|
+
layoutDir: string;
|
|
37
37
|
cssDir: string;
|
|
38
38
|
libDir: string;
|
|
39
39
|
};
|
|
@@ -46,4 +46,4 @@ declare function getDefaultConfig(src?: boolean): Promise<{
|
|
|
46
46
|
}>;
|
|
47
47
|
//#endregion
|
|
48
48
|
export { getDefaultConfig as a, createOrLoadConfig as i, LoadedConfig as n, initConfig as o, createConfigSchema as r, ConfigInput as t };
|
|
49
|
-
//# sourceMappingURL=config-
|
|
49
|
+
//# sourceMappingURL=config-Dyass4D9.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-
|
|
1
|
+
{"version":3,"file":"config-Dyass4D9.d.ts","names":[],"sources":["../src/config.ts"],"mappings":";;;iBAIgB,kBAAA,CAAmB,KAAA,YAAc,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;KA0C5C,YAAA,GAAe,UAAA,QAAkB,kBAAA;AAAA,KAE1B,WAAA,GAAc,CAAA,CAAE,KAAA,CAAM,YAAA;AAAA,KACtB,YAAA,GAAe,CAAA,CAAE,MAAA,CAAO,YAAA;AAAA,iBAEd,kBAAA,CAAmB,IAAA,YAAsB,OAAA,CAAQ,YAAA;;;;;;iBAgBjD,UAAA,CACpB,IAAA,WACA,GAAA,aACC,OAAA,CAAQ,YAAA;AAAA,iBAeW,gBAAA,CAAiB,GAAA,aAAa,OAAA"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as getDefaultConfig, i as createOrLoadConfig, n as LoadedConfig, o as initConfig, r as createConfigSchema, t as ConfigInput } from "./config-
|
|
1
|
+
import { a as getDefaultConfig, i as createOrLoadConfig, n as LoadedConfig, o as initConfig, r as createConfigSchema, t as ConfigInput } from "./config-Dyass4D9.js";
|
|
2
2
|
export { ConfigInput, LoadedConfig, createConfigSchema, createOrLoadConfig, getDefaultConfig, initConfig };
|
package/dist/config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as initConfig, n as createOrLoadConfig, r as getDefaultConfig, t as createConfigSchema } from "./config-
|
|
1
|
+
import { i as initConfig, n as createOrLoadConfig, r as getDefaultConfig, t as createConfigSchema } from "./config-BYrMmXOw.js";
|
|
2
2
|
export { createConfigSchema, createOrLoadConfig, getDefaultConfig, initConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as exists } from "./fs-CigSthjp.js";
|
|
3
|
-
import { i as initConfig, n as createOrLoadConfig } from "./config-
|
|
3
|
+
import { i as initConfig, n as createOrLoadConfig } from "./config-BYrMmXOw.js";
|
|
4
4
|
import { n as transformSpecifiers } from "./ast-BRNdmLn5.js";
|
|
5
5
|
import { n as LocalRegistryClient, t as HttpRegistryClient } from "./client-YTcWP1iz.js";
|
|
6
|
-
import { t as ComponentInstaller } from "./installer-
|
|
6
|
+
import { t as ComponentInstaller } from "./installer-B3-my9zN.js";
|
|
7
7
|
import fs from "node:fs/promises";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { Command } from "commander";
|
|
@@ -63,7 +63,7 @@ async function runTree(args) {
|
|
|
63
63
|
}
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region package.json
|
|
66
|
-
var version = "1.3.
|
|
66
|
+
var version = "1.3.2";
|
|
67
67
|
//#endregion
|
|
68
68
|
//#region src/commands/shared.ts
|
|
69
69
|
const UIRegistries = {
|
|
@@ -73,7 +73,7 @@ const UIRegistries = {
|
|
|
73
73
|
//#endregion
|
|
74
74
|
//#region src/registry/plugins/preserve.ts
|
|
75
75
|
/**
|
|
76
|
-
* keep references to `fumadocs-ui/layouts/*` components as original, unless the user is installing them
|
|
76
|
+
* keep references to `fumadocs-ui/layouts/*` components as original, unless the user is installing them directly.
|
|
77
77
|
*/
|
|
78
78
|
function pluginPreserveLayouts() {
|
|
79
79
|
const layoutNames = [
|
|
@@ -84,20 +84,20 @@ function pluginPreserveLayouts() {
|
|
|
84
84
|
"layouts/shared"
|
|
85
85
|
];
|
|
86
86
|
const layoutComps = {
|
|
87
|
-
"@/<dir>/
|
|
88
|
-
"@/<dir>/
|
|
89
|
-
"@/<dir>/
|
|
90
|
-
"@/<dir>/
|
|
91
|
-
"@/<dir>/
|
|
92
|
-
"@/<dir>/
|
|
93
|
-
"@/<dir>/
|
|
94
|
-
"@/<dir>/
|
|
95
|
-
"@/<dir>/
|
|
96
|
-
"@/<dir>/
|
|
97
|
-
"@/<dir>/
|
|
98
|
-
"@/<dir>/
|
|
99
|
-
"@/<dir>/
|
|
100
|
-
"@/<dir>/
|
|
87
|
+
"@/<dir>/home/index.tsx": "layouts/home",
|
|
88
|
+
"@/<dir>/shared/index.tsx": "layouts/shared",
|
|
89
|
+
"@/<dir>/shared/client.tsx": "layouts/shared",
|
|
90
|
+
"@/<dir>/notebook/index.tsx": "layouts/notebook",
|
|
91
|
+
"@/<dir>/notebook/client.tsx": "layouts/notebook",
|
|
92
|
+
"@/<dir>/notebook/page/index.tsx": "layouts/notebook/page",
|
|
93
|
+
"@/<dir>/notebook/page/client.tsx": "layouts/notebook/page",
|
|
94
|
+
"@/<dir>/docs/index.tsx": "layouts/docs",
|
|
95
|
+
"@/<dir>/docs/client.tsx": "layouts/docs",
|
|
96
|
+
"@/<dir>/docs/page/index.tsx": "layouts/docs/page",
|
|
97
|
+
"@/<dir>/docs/page/client.tsx": "layouts/docs/page",
|
|
98
|
+
"@/<dir>/flux/index.tsx": "layouts/flux",
|
|
99
|
+
"@/<dir>/flux/page/index.tsx": "layouts/flux/page",
|
|
100
|
+
"@/<dir>/flux/page/client.tsx": "layouts/flux/page"
|
|
101
101
|
};
|
|
102
102
|
const layoutNameSet = new Set(layoutNames);
|
|
103
103
|
return {
|
|
@@ -211,59 +211,119 @@ async function customise(client) {
|
|
|
211
211
|
const config = client.config;
|
|
212
212
|
const installer = new ComponentInstaller(client, { plugins: [pluginPreserveLayouts()] });
|
|
213
213
|
const registry = UIRegistries[config.uiLibrary];
|
|
214
|
+
const info = await client.createLinkedRegistryClient(registry).fetchRegistryInfo();
|
|
214
215
|
const target = (await group({
|
|
215
216
|
layout: () => select({
|
|
216
217
|
message: "What do you want to customise?",
|
|
217
|
-
options: [
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
218
|
+
options: [
|
|
219
|
+
{
|
|
220
|
+
label: "Docs Layout",
|
|
221
|
+
value: {
|
|
222
|
+
id: "docs",
|
|
223
|
+
target: [`${registry}/layouts/docs`],
|
|
224
|
+
print() {
|
|
225
|
+
printLayout(["fumadocs-ui/layouts/docs", "@/layouts/docs"], ["fumadocs-ui/layouts/docs/page", "@/layouts/docs/page"]);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
hint: "the default docs layout"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
label: "Notebook Layout",
|
|
232
|
+
value: {
|
|
233
|
+
id: "notebook",
|
|
234
|
+
target: [`${registry}/layouts/notebook`],
|
|
235
|
+
print() {
|
|
236
|
+
printLayout(["fumadocs-ui/layouts/notebook", "@/layouts/notebook"], ["fumadocs-ui/layouts/notebook/page", "@/layouts/notebook/page"]);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
hint: "a more compact version of docs layout"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
label: "Flux Layout",
|
|
243
|
+
value: {
|
|
244
|
+
id: "flux",
|
|
245
|
+
target: [`${registry}/layouts/flux`],
|
|
246
|
+
print() {
|
|
247
|
+
printLayout(["fumadocs-ui/layouts/flux", "@/layouts/flux"], ["fumadocs-ui/layouts/flux/page", "@/layouts/flux/page"]);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
hint: "the experimental variant of docs layout"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
label: "Home Layout",
|
|
254
|
+
value: {
|
|
255
|
+
id: "home",
|
|
256
|
+
target: [`${registry}/layouts/home`],
|
|
257
|
+
print() {
|
|
258
|
+
printLayout(["fumadocs-ui/layouts/home", `@/layouts/home`]);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
hint: "the layout for other non-docs pages"
|
|
262
|
+
}
|
|
263
|
+
]
|
|
226
264
|
}),
|
|
227
265
|
target: (v) => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
replace: [["fumadocs-ui/layouts/home", `@/components/layout/home`]]
|
|
231
|
-
});
|
|
266
|
+
const selected = v.results.layout;
|
|
267
|
+
if (selected.id === "home") return Promise.resolve(selected);
|
|
232
268
|
return select({
|
|
233
|
-
message: "Which
|
|
269
|
+
message: "Which part do you want to customise?",
|
|
234
270
|
options: [
|
|
235
271
|
{
|
|
236
|
-
label: "
|
|
237
|
-
hint: "
|
|
238
|
-
value:
|
|
239
|
-
target: ["layouts/docs-min"],
|
|
240
|
-
replace: [["fumadocs-ui/layouts/docs", "@/components/layout/docs"], ["fumadocs-ui/layouts/docs/page", "@/components/layout/docs/page"]]
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
label: "Start from default layout",
|
|
245
|
-
value: {
|
|
246
|
-
target: [`${registry}/layouts/docs`],
|
|
247
|
-
replace: [["fumadocs-ui/layouts/docs", "@/components/layout/docs"], ["fumadocs-ui/layouts/docs/page", "@/components/layout/docs/page"]]
|
|
248
|
-
},
|
|
249
|
-
hint: "useful for adjusting small details."
|
|
272
|
+
label: "All",
|
|
273
|
+
hint: "install the entire layout",
|
|
274
|
+
value: selected
|
|
250
275
|
},
|
|
251
276
|
{
|
|
252
|
-
label: "
|
|
277
|
+
label: "Replace & rewrite from minimal styles",
|
|
278
|
+
hint: "for those who want to build their own UI from ground up",
|
|
253
279
|
value: {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
280
|
+
id: "docs-min",
|
|
281
|
+
target: ["layouts/docs-min"],
|
|
282
|
+
print() {
|
|
283
|
+
printLayout(["fumadocs-ui/layouts/docs", "@/layouts/docs"], ["fumadocs-ui/layouts/docs/page", "@/layouts/docs/page"]);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
258
286
|
},
|
|
259
|
-
{
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
287
|
+
...info.unlistedIndexes.flatMap((index) => {
|
|
288
|
+
const prefix = `slots/${selected.id}`;
|
|
289
|
+
if (!index.name.startsWith(prefix)) return [];
|
|
290
|
+
let name = index.name.slice(prefix.length + 1);
|
|
291
|
+
if (name.startsWith("page/")) {
|
|
292
|
+
name = name.slice(5);
|
|
293
|
+
return {
|
|
294
|
+
label: `Page: ${name}`,
|
|
295
|
+
hint: "only replace a part of layout's page, useful for adjusting details",
|
|
296
|
+
value: {
|
|
297
|
+
id: index.name,
|
|
298
|
+
target: [`${registry}/${index.name}`],
|
|
299
|
+
print() {
|
|
300
|
+
printSlot({
|
|
301
|
+
at: `@/layouts/${selected.id}/page/slots/${name}`,
|
|
302
|
+
layoutId: selected.id,
|
|
303
|
+
name,
|
|
304
|
+
isPage: true
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
label: `Layout: ${name}`,
|
|
312
|
+
hint: "only replace a part of layout, useful for adjusting details",
|
|
313
|
+
value: {
|
|
314
|
+
id: index.name,
|
|
315
|
+
target: [`${registry}/${index.name}`],
|
|
316
|
+
print() {
|
|
317
|
+
printSlot({
|
|
318
|
+
at: `@/layouts/${selected.id}/slots/${name}`,
|
|
319
|
+
layoutId: selected.id,
|
|
320
|
+
name,
|
|
321
|
+
isPage: false
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
})
|
|
267
327
|
]
|
|
268
328
|
});
|
|
269
329
|
}
|
|
@@ -272,18 +332,174 @@ async function customise(client) {
|
|
|
272
332
|
process.exit(0);
|
|
273
333
|
} })).target;
|
|
274
334
|
await install(target.target, installer);
|
|
275
|
-
|
|
335
|
+
target.print?.();
|
|
276
336
|
outro(picocolors.bold("Have fun!"));
|
|
277
337
|
}
|
|
278
|
-
function
|
|
338
|
+
function printLayout(...maps) {
|
|
279
339
|
intro(picocolors.bold("What is Next?"));
|
|
280
340
|
log.info([
|
|
281
|
-
"You can check the installed
|
|
341
|
+
"You can check the installed layouts in `layouts` folder.",
|
|
282
342
|
picocolors.dim("---"),
|
|
283
343
|
"Open your `layout.tsx` files, replace the imports of components:",
|
|
284
344
|
...maps.map(([from, to]) => picocolors.greenBright(`"${from}" -> "${to}"`))
|
|
285
345
|
].join("\n"));
|
|
286
346
|
}
|
|
347
|
+
function printSlot({ at, layoutId, name, isPage }) {
|
|
348
|
+
intro(picocolors.bold("What is Next?"));
|
|
349
|
+
log.info(`You can check the installed layout slot in "${at}".`);
|
|
350
|
+
const code = getSlotCode({
|
|
351
|
+
at,
|
|
352
|
+
layoutId,
|
|
353
|
+
name,
|
|
354
|
+
isPage
|
|
355
|
+
});
|
|
356
|
+
if (code) if (isPage) log.info(`${picocolors.bold("At your <DocsPage /> component, update your \"slots\" prop:")}\n\n${code}`);
|
|
357
|
+
else log.info(`${picocolors.bold("At your <DocsLayout /> component, update your \"slots\" prop:")}\n\n${code}`);
|
|
358
|
+
}
|
|
359
|
+
function getSlotCode({ at, layoutId, name, isPage }) {
|
|
360
|
+
if (isPage) switch (name) {
|
|
361
|
+
case "toc":
|
|
362
|
+
if (layoutId === "flux") return `import { TOCProvider, TOC } from '${at}';
|
|
363
|
+
|
|
364
|
+
return (
|
|
365
|
+
<DocsPage
|
|
366
|
+
slots={{
|
|
367
|
+
toc: {
|
|
368
|
+
provider: TOCProvider,
|
|
369
|
+
main: TOC,
|
|
370
|
+
},
|
|
371
|
+
}}
|
|
372
|
+
>
|
|
373
|
+
...
|
|
374
|
+
</DocsPage>
|
|
375
|
+
);`;
|
|
376
|
+
return `import { TOCProvider, TOC, TOCPopover } from '${at}';
|
|
377
|
+
|
|
378
|
+
return (
|
|
379
|
+
<DocsPage
|
|
380
|
+
slots={{
|
|
381
|
+
toc: {
|
|
382
|
+
provider: TOCProvider,
|
|
383
|
+
main: TOC,
|
|
384
|
+
popover: TOCPopover,
|
|
385
|
+
},
|
|
386
|
+
}}
|
|
387
|
+
>
|
|
388
|
+
...
|
|
389
|
+
</DocsPage>
|
|
390
|
+
);`;
|
|
391
|
+
case "container": return `import { Container } from '${at}';
|
|
392
|
+
|
|
393
|
+
return (
|
|
394
|
+
<DocsPage
|
|
395
|
+
slots={{
|
|
396
|
+
container: Container,
|
|
397
|
+
}}
|
|
398
|
+
>
|
|
399
|
+
...
|
|
400
|
+
</DocsPage>
|
|
401
|
+
);`;
|
|
402
|
+
case "footer": return `import { Footer } from '${at}';
|
|
403
|
+
|
|
404
|
+
return (
|
|
405
|
+
<DocsPage
|
|
406
|
+
slots={{
|
|
407
|
+
footer: Footer,
|
|
408
|
+
}}
|
|
409
|
+
>
|
|
410
|
+
...
|
|
411
|
+
</DocsPage>
|
|
412
|
+
);`;
|
|
413
|
+
case "breadcrumb": return `import { Breadcrumb } from '${at}';
|
|
414
|
+
|
|
415
|
+
return (
|
|
416
|
+
<DocsPage
|
|
417
|
+
slots={{
|
|
418
|
+
breadcrumb: Breadcrumb,
|
|
419
|
+
}}
|
|
420
|
+
>
|
|
421
|
+
...
|
|
422
|
+
</DocsPage>
|
|
423
|
+
);`;
|
|
424
|
+
default: return;
|
|
425
|
+
}
|
|
426
|
+
switch (name) {
|
|
427
|
+
case "sidebar":
|
|
428
|
+
if (layoutId === "notebook") return `import {
|
|
429
|
+
SidebarProvider,
|
|
430
|
+
Sidebar,
|
|
431
|
+
SidebarTrigger,
|
|
432
|
+
SidebarCollapseTrigger,
|
|
433
|
+
useSidebar,
|
|
434
|
+
} from '${at}';
|
|
435
|
+
|
|
436
|
+
return (
|
|
437
|
+
<DocsLayout
|
|
438
|
+
slots={{
|
|
439
|
+
sidebar: {
|
|
440
|
+
provider: SidebarProvider,
|
|
441
|
+
root: Sidebar,
|
|
442
|
+
trigger: SidebarTrigger,
|
|
443
|
+
collapseTrigger: SidebarCollapseTrigger,
|
|
444
|
+
useSidebar: useSidebar,
|
|
445
|
+
},
|
|
446
|
+
}}
|
|
447
|
+
>
|
|
448
|
+
...
|
|
449
|
+
</DocsLayout>
|
|
450
|
+
);`;
|
|
451
|
+
return `import { SidebarProvider, Sidebar, SidebarTrigger, useSidebar } from '${at}';
|
|
452
|
+
|
|
453
|
+
return (
|
|
454
|
+
<DocsLayout
|
|
455
|
+
slots={{
|
|
456
|
+
sidebar: {
|
|
457
|
+
provider: SidebarProvider,
|
|
458
|
+
root: Sidebar,
|
|
459
|
+
trigger: SidebarTrigger,
|
|
460
|
+
useSidebar: useSidebar,
|
|
461
|
+
},
|
|
462
|
+
}}
|
|
463
|
+
>
|
|
464
|
+
...
|
|
465
|
+
</DocsLayout>
|
|
466
|
+
);`;
|
|
467
|
+
case "container": return `import { Container } from '${at}';
|
|
468
|
+
|
|
469
|
+
return (
|
|
470
|
+
<DocsLayout
|
|
471
|
+
slots={{
|
|
472
|
+
container: Container,
|
|
473
|
+
}}
|
|
474
|
+
>
|
|
475
|
+
...
|
|
476
|
+
</DocsLayout>
|
|
477
|
+
);`;
|
|
478
|
+
case "header": return `import { Header } from '${at}';
|
|
479
|
+
|
|
480
|
+
return (
|
|
481
|
+
<DocsLayout
|
|
482
|
+
slots={{
|
|
483
|
+
header: Header,
|
|
484
|
+
}}
|
|
485
|
+
>
|
|
486
|
+
...
|
|
487
|
+
</DocsLayout>
|
|
488
|
+
);`;
|
|
489
|
+
case "tab-dropdown": return `import { TabDropdown } from '${at}';
|
|
490
|
+
|
|
491
|
+
return (
|
|
492
|
+
<DocsLayout
|
|
493
|
+
slots={{
|
|
494
|
+
tabDropdown: TabDropdown,
|
|
495
|
+
}}
|
|
496
|
+
>
|
|
497
|
+
...
|
|
498
|
+
</DocsLayout>
|
|
499
|
+
);`;
|
|
500
|
+
default: return;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
287
503
|
//#endregion
|
|
288
504
|
//#region src/commands/export-epub.ts
|
|
289
505
|
const execAsync = promisify(exec);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["packageJson.version"],"sources":["../src/commands/file-tree.ts","../src/utils/file-tree/run-tree.ts","../package.json","../src/commands/shared.ts","../src/registry/plugins/preserve.ts","../src/commands/add.ts","../src/commands/customise.ts","../src/commands/export-epub.ts","../src/index.ts"],"sourcesContent":["export type JsonTreeNode =\n | {\n type: 'file';\n name: string;\n }\n | {\n type: 'directory';\n name: string;\n contents: JsonTreeNode[];\n }\n | {\n type: 'report';\n }\n | {\n type: 'link';\n name: string;\n };\n\nconst scanned = ['file', 'directory', 'link'];\n\nexport function treeToMdx(input: JsonTreeNode[], noRoot = false): string {\n function toNode(item: JsonTreeNode): string {\n if (item.type === 'file' || item.type === 'link') {\n return `<File name=${JSON.stringify(item.name)} />`;\n }\n\n if (item.type === 'directory') {\n if (item.contents.length === 1 && 'name' in item.contents[0]) {\n const child = item.contents[0];\n\n return toNode({\n ...child,\n name: `${item.name}/${child.name}`,\n });\n }\n\n return `<Folder name=${JSON.stringify(item.name)}>\n${item.contents.map(toNode).filter(Boolean).join('\\n')}\n</Folder>`;\n }\n\n return '';\n }\n\n let children = input.filter((v) => scanned.includes(v.type));\n\n if (noRoot && children.length === 1 && input[0].type === 'directory') {\n children = input[0].contents;\n }\n\n return `<Files>\n${children.map(toNode).filter(Boolean).join('\\n')}\n</Files>`;\n}\n\nexport function treeToJavaScript(\n input: JsonTreeNode[],\n noRoot?: boolean,\n importName = 'fumadocs-ui/components/files',\n): string {\n return `import { File, Files, Folder } from ${JSON.stringify(importName)}\n\nexport default (${treeToMdx(input, noRoot)})`;\n}\n","import { x } from 'tinyexec';\nimport type { JsonTreeNode } from '@/commands/file-tree';\n\nexport async function runTree(args: string): Promise<JsonTreeNode[]> {\n const out = await x('tree', [args, '--gitignore', '--prune', '-J']);\n\n try {\n return JSON.parse(out.stdout) as JsonTreeNode[];\n } catch (e) {\n throw new Error('failed to run `tree` command', {\n cause: e,\n });\n }\n}\n","","export const UIRegistries = {\n 'base-ui': 'fumadocs/base-ui',\n 'radix-ui': 'fumadocs/radix-ui',\n};\n","import { transformSpecifiers } from '@/utils/ast';\nimport type { ComponentInstallerPlugin } from '../installer';\n\n/**\n * keep references to `fumadocs-ui/layouts/*` components as original, unless the user is installing them direclty.\n */\nexport function pluginPreserveLayouts(): ComponentInstallerPlugin {\n const layoutNames = [\n 'layouts/home',\n 'layouts/flux',\n 'layouts/notebook',\n 'layouts/docs',\n 'layouts/shared',\n ];\n // original specifier -> new specifier\n const layoutComps: Record<string, string> = {\n '@/<dir>/layout/home/index.tsx': 'layouts/home',\n '@/<dir>/layout/shared/index.tsx': 'layouts/shared',\n '@/<dir>/layout/shared/client.tsx': 'layouts/shared',\n '@/<dir>/layout/notebook/index.tsx': 'layouts/notebook',\n '@/<dir>/layout/notebook/client.tsx': 'layouts/notebook',\n '@/<dir>/layout/notebook/page/index.tsx': 'layouts/notebook/page',\n '@/<dir>/layout/notebook/page/client.tsx': 'layouts/notebook/page',\n '@/<dir>/layout/docs/index.tsx': 'layouts/docs',\n '@/<dir>/layout/docs/client.tsx': 'layouts/docs',\n '@/<dir>/layout/docs/page/index.tsx': 'layouts/docs/page',\n '@/<dir>/layout/docs/page/client.tsx': 'layouts/docs/page',\n '@/<dir>/layout/flux/index.tsx': 'layouts/flux',\n '@/<dir>/layout/flux/page/index.tsx': 'layouts/flux/page',\n '@/<dir>/layout/flux/page/client.tsx': 'layouts/flux/page',\n };\n const layoutNameSet = new Set(layoutNames);\n\n return {\n beforeInstall(comp, { stack }) {\n const isDirectInstall = layoutNameSet.has(stack[0].name);\n if (isDirectInstall) return;\n\n return {\n ...comp,\n $subComponents: comp.$subComponents.filter((child) => !layoutNameSet.has(child.name)),\n };\n },\n beforeTransform({ parsed, s, stack }) {\n const isDirectInstall = layoutNameSet.has(stack[0].name);\n if (isDirectInstall) return;\n\n transformSpecifiers(parsed.program, s, (specifier) => {\n // skip if unrelated to layout component\n if (!(specifier in layoutComps)) return specifier;\n\n return `fumadocs-ui/${layoutComps[specifier]}`;\n });\n },\n };\n}\n","import {\n isCancel,\n autocompleteMultiselect,\n outro,\n spinner,\n confirm,\n box,\n log,\n} from '@clack/prompts';\nimport picocolors from 'picocolors';\nimport { ComponentInstaller } from '@/registry/installer';\nimport type { RegistryClient } from '@/registry/client';\nimport { UIRegistries } from '@/commands/shared';\nimport { pluginPreserveLayouts } from '@/registry/plugins/preserve';\n\nexport async function add(input: string[], client: RegistryClient) {\n const config = client.config;\n let target: string[];\n const installer = new ComponentInstaller(client, {\n plugins: [pluginPreserveLayouts()],\n });\n const registry = UIRegistries[config.uiLibrary];\n\n if (input.length === 0) {\n const spin = spinner();\n spin.start('fetching registry');\n const info = await client.fetchRegistryInfo();\n const options: {\n label: string;\n value: string;\n hint?: string;\n }[] = [];\n\n for (const item of info.indexes) {\n options.push({\n label: item.title ?? item.name,\n value: item.name,\n hint: item.description,\n });\n }\n const { indexes } = await client.createLinkedRegistryClient(registry).fetchRegistryInfo();\n\n for (const item of indexes) {\n options.push({\n label: item.title ?? item.name,\n value: `${registry}/${item.name}`,\n hint: item.description,\n });\n }\n\n spin.stop(picocolors.bold(picocolors.greenBright('registry fetched')));\n const value = await autocompleteMultiselect({\n message: 'Select components to install',\n options,\n });\n\n if (isCancel(value)) {\n outro('Ended');\n return;\n }\n\n target = value;\n } else {\n target = await Promise.all(\n input.map(async (item) => ((await client.hasComponent(item)) ? item : `${registry}/${item}`)),\n );\n }\n\n await install(target, installer);\n}\n\nexport async function install(target: string[], installer: ComponentInstaller) {\n for (const name of target) {\n const spin = spinner();\n spin.start(picocolors.bold(picocolors.cyanBright(`Installing ${name}`)));\n\n try {\n await installer.install(name, {\n onWarn(message) {\n spin.message(message);\n },\n async confirmFileOverride(options) {\n spin.clear();\n const value = await confirm({\n message: `Do you want to override ${options.path}?`,\n initialValue: false,\n });\n if (isCancel(value)) {\n outro('Installation terminated');\n process.exit(0);\n }\n spin.start(picocolors.bold(picocolors.cyanBright(`Installing ${name}`)));\n return value;\n },\n onFileDownloaded(options) {\n spin.message(options.path);\n },\n });\n spin.stop(picocolors.bold(picocolors.greenBright(`${name} installed`)));\n } catch (e) {\n spin.error(e instanceof Error ? e.message : String(e));\n process.exit(-1);\n }\n }\n\n const deps = await installer.deps();\n if (deps.hasRequired()) {\n log.message();\n box([...deps.dependencies, ...deps.devDependencies].join('\\n'), 'New Dependencies');\n const value = await confirm({\n message: `Do you want to install with ${deps.packageManager}?`,\n });\n\n if (isCancel(value)) {\n outro('Installation terminated');\n process.exit(0);\n }\n\n if (value) {\n const spin = spinner({\n errorMessage: 'Failed to install dependencies',\n });\n spin.start('Installing dependencies');\n await deps.installRequired();\n spin.stop('Dependencies installed');\n }\n }\n\n await installer.onEnd();\n outro(picocolors.bold(picocolors.greenBright('Successful')));\n}\n","import { cancel, group, intro, log, outro, select } from '@clack/prompts';\nimport picocolors from 'picocolors';\nimport { install } from '@/commands/add';\nimport type { RegistryClient } from '@/registry/client';\nimport { ComponentInstaller } from '@/registry/installer';\nimport { UIRegistries } from '@/commands/shared';\nimport { pluginPreserveLayouts } from '@/registry/plugins/preserve';\n\ninterface TargetInfo {\n target: string[];\n replace: [string, string][];\n}\n\nexport async function customise(client: RegistryClient) {\n intro(picocolors.bgBlack(picocolors.whiteBright('Customise Fumadocs UI')));\n const config = client.config;\n const installer = new ComponentInstaller(client, {\n plugins: [pluginPreserveLayouts()],\n });\n const registry = UIRegistries[config.uiLibrary];\n\n const result = await group(\n {\n layout: () =>\n select({\n message: 'What do you want to customise?',\n options: [\n {\n label: 'Docs Layout',\n value: 'docs',\n hint: 'main UI of your docs',\n },\n {\n label: 'Home Layout',\n value: 'home',\n hint: 'the navbar for your other pages',\n },\n ],\n }),\n target: (v): Promise<TargetInfo | symbol> => {\n if (v.results.layout !== 'docs')\n return Promise.resolve({\n target: [`${registry}/layouts/home`],\n replace: [['fumadocs-ui/layouts/home', `@/components/layout/home`]],\n });\n\n return select<TargetInfo>({\n message: 'Which variant do you want to start from?',\n options: [\n {\n label: 'Start from minimal styles',\n hint: 'for those who want to build their own variant from ground up.',\n value: {\n target: ['layouts/docs-min'],\n replace: [\n ['fumadocs-ui/layouts/docs', '@/components/layout/docs'],\n ['fumadocs-ui/layouts/docs/page', '@/components/layout/docs/page'],\n ],\n },\n },\n {\n label: 'Start from default layout',\n value: {\n target: [`${registry}/layouts/docs`],\n replace: [\n ['fumadocs-ui/layouts/docs', '@/components/layout/docs'],\n ['fumadocs-ui/layouts/docs/page', '@/components/layout/docs/page'],\n ],\n },\n hint: 'useful for adjusting small details.',\n },\n {\n label: 'Start from Notebook layout',\n value: {\n target: [`${registry}/layouts/notebook`],\n replace: [\n ['fumadocs-ui/layouts/notebook', '@/components/layout/notebook'],\n ['fumadocs-ui/layouts/notebook/page', '@/components/layout/notebook/page'],\n ],\n },\n hint: 'useful for adjusting small details.',\n },\n {\n label: 'Start from Flux layout',\n value: {\n target: [`${registry}/layouts/flux`],\n replace: [\n ['fumadocs-ui/layouts/flux', '@/components/layout/flux'],\n ['fumadocs-ui/layouts/flux/page', '@/components/layout/flux/page'],\n ],\n },\n hint: 'useful for adjusting small details.',\n },\n ],\n });\n },\n },\n {\n onCancel: () => {\n cancel('Installation Stopped.');\n process.exit(0);\n },\n },\n );\n\n const target = result.target as TargetInfo;\n await install(target.target, installer);\n printNext(...target.replace);\n\n outro(picocolors.bold('Have fun!'));\n}\n\nfunction printNext(...maps: [from: string, to: string][]) {\n intro(picocolors.bold('What is Next?'));\n\n log.info(\n [\n 'You can check the installed components in `components`.',\n picocolors.dim('---'),\n 'Open your `layout.tsx` files, replace the imports of components:',\n ...maps.map(([from, to]) => picocolors.greenBright(`\"${from}\" -> \"${to}\"`)),\n ].join('\\n'),\n );\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { exists } from '@/utils/fs';\nimport picocolors from 'picocolors';\nimport { spinner } from '@clack/prompts';\nimport { exec } from 'node:child_process';\nimport { promisify } from 'node:util';\n\nconst execAsync = promisify(exec);\n\ninterface PackageJson {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n}\n\nasync function readPackageJson(cwd: string): Promise<PackageJson | null> {\n try {\n const raw = await fs.readFile(path.join(cwd, 'package.json'), 'utf-8');\n return JSON.parse(raw) as PackageJson;\n } catch {\n return null;\n }\n}\n\n/** Path of pre-rendered EPUB, choose one according to your React framework. Next.js fetches from the running server instead. */\nconst EPUB_BUILD_PATHS: Record<string, string> = {\n next: '', // Fetched from /export/epub at runtime; route handlers don't produce static files\n 'tanstack-start': '.output/public/export/epub',\n 'tanstack-start-spa': 'dist/client/export/epub',\n 'react-router': 'build/client/export/epub',\n 'react-router-spa': 'build/client/export/epub',\n waku: 'dist/public/export/epub',\n};\n\nconst API_ROUTE_TEMPLATE = `import { source } from '@/lib/source';\nimport { exportEpub } from 'fumadocs-epub';\n\nexport const revalidate = false;\n\nexport async function GET(request: Request): Promise<Response> {\n // Require EXPORT_SECRET to prevent unauthenticated abuse. Pass via Authorization: Bearer <secret>\n const secret = process.env.EXPORT_SECRET;\n if (!secret) {\n return new Response('EXPORT_SECRET is not configured. Set it in your environment to protect this endpoint.', { status: 503 });\n }\n const authHeader = request.headers.get('authorization');\n const token = authHeader?.replace(/^Bearer\\\\s+/i, '') ?? '';\n if (token !== secret) {\n return new Response('Unauthorized', { status: authHeader ? 403 : 401 });\n }\n const buffer = await exportEpub({\n source,\n title: 'Documentation',\n author: 'Your Team',\n description: 'Exported documentation',\n cover: '/cover.png',\n });\n return new Response(new Uint8Array(buffer), {\n headers: {\n 'Content-Type': 'application/epub+zip',\n 'Content-Disposition': 'attachment; filename=\"docs.epub\"',\n },\n });\n}\n`;\n\nasync function findAppDir(cwd: string): Promise<string | null> {\n const appPaths = ['app', 'src/app'];\n for (const appPath of appPaths) {\n const fullPath = path.join(cwd, appPath);\n if (await exists(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\nasync function scaffoldEpubRoute(cwd: string): Promise<boolean> {\n const appDir = await findAppDir(cwd);\n if (!appDir) {\n console.error(picocolors.red('Could not find app directory (app/ or src/app/)'));\n return false;\n }\n\n const routePath = path.join(appDir, 'export', 'epub', 'route.ts');\n if (await exists(routePath)) {\n console.log(picocolors.yellow('EPUB route already exists at'), routePath);\n return true;\n }\n\n await fs.mkdir(path.dirname(routePath), { recursive: true });\n await fs.writeFile(routePath, API_ROUTE_TEMPLATE);\n console.log(picocolors.green('Created EPUB route at'), routePath);\n return true;\n}\n\nexport async function exportEpub(options: {\n output?: string;\n framework: string;\n scaffoldOnly?: boolean;\n}) {\n const cwd = process.cwd();\n const outputPath = path.resolve(cwd, options.output ?? 'docs.epub');\n const framework = options.framework;\n\n const spin = spinner();\n\n const buildPath = EPUB_BUILD_PATHS[framework];\n if (!(framework in EPUB_BUILD_PATHS)) {\n const valid = Object.keys(EPUB_BUILD_PATHS).join(', ');\n console.error(picocolors.red(`Invalid --framework \"${framework}\". Must be one of: ${valid}`));\n process.exit(1);\n }\n\n // Check for Next.js when scaffolding (only Next.js scaffold is implemented)\n const pkg = await readPackageJson(cwd);\n const hasNextConfig =\n (await exists(path.join(cwd, 'next.config.js'))) ||\n (await exists(path.join(cwd, 'next.config.ts'))) ||\n (await exists(path.join(cwd, 'next.config.mjs')));\n const nextDeps = pkg\n ? { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies }\n : {};\n const hasNextInPkg = !!nextDeps?.next;\n const hasAppOrPages =\n (await exists(path.join(cwd, 'app'))) ||\n (await exists(path.join(cwd, 'pages'))) ||\n (await exists(path.join(cwd, 'src', 'app'))) ||\n (await exists(path.join(cwd, 'src', 'pages')));\n const hasNext = hasNextConfig || (hasNextInPkg && hasAppOrPages);\n\n if (!hasNext && framework === 'next') {\n console.error(\n picocolors.red(\n 'Next.js project not found. Run this command from a Fumadocs Next.js project root.',\n ),\n );\n process.exit(1);\n }\n\n // Scaffold EPUB route (Next.js only for now)\n if (framework === 'next') {\n spin.start('Scaffolding EPUB route');\n const scaffolded = await scaffoldEpubRoute(cwd);\n spin.stop(scaffolded ? 'EPUB route ready' : 'Scaffolding failed');\n\n if (!scaffolded) {\n process.exit(1);\n }\n }\n\n if (options.scaffoldOnly) {\n console.log(picocolors.cyan('\\nTo export:'));\n console.log(' 1. Add fumadocs-epub to your dependencies: pnpm add fumadocs-epub');\n console.log(' 2. Ensure includeProcessedMarkdown: true in your docs collection config');\n if (framework === 'next') {\n console.log(\n ' 3. Set EXPORT_SECRET in your environment to protect the /export/epub endpoint',\n );\n console.log(' 4. Run production build: pnpm build');\n console.log(' 5. Start the server (e.g. pnpm start) and keep it running');\n console.log(' 6. Run: fumadocs export epub --framework next');\n } else {\n console.log(` 3. Add a prerender route that outputs EPUB to ${buildPath}`);\n console.log(' 4. Run production build: pnpm build');\n console.log(` 5. Run: fumadocs export epub --framework ${framework}`);\n }\n return;\n }\n\n // Check for fumadocs-epub dependency\n if (!pkg) {\n console.error(\n picocolors.red('Cannot read or parse package.json. Ensure it exists and is valid JSON.'),\n );\n process.exit(1);\n }\n const deps = { ...pkg.dependencies, ...pkg.devDependencies };\n if (!deps['fumadocs-epub']) {\n console.log(picocolors.yellow('\\nInstalling fumadocs-epub...'));\n const packageManager = process.env.npm_execpath?.includes('pnpm')\n ? 'pnpm'\n : process.env.npm_execpath?.includes('bun')\n ? 'bun'\n : 'npm';\n const installCmd = `${packageManager} add fumadocs-epub`;\n try {\n await execAsync(installCmd, { cwd });\n } catch (err: unknown) {\n const stderr =\n err && typeof err === 'object' && 'stderr' in err\n ? String((err as { stderr?: string }).stderr)\n : '';\n console.error(picocolors.red(`Failed to install fumadocs-epub. Command: ${installCmd}`));\n if (stderr) console.error(stderr);\n process.exit(1);\n }\n }\n\n if (framework === 'next') {\n const secret = process.env.EXPORT_SECRET;\n if (!secret) {\n console.error(\n picocolors.red('EXPORT_SECRET is required for Next.js export. Set it in your environment.'),\n );\n process.exit(1);\n }\n const port = process.env.PORT || '3000';\n const url = `http://localhost:${port}/export/epub`;\n spin.start('Fetching EPUB from server');\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), 30_000);\n try {\n const res = await fetch(url, {\n headers: { Authorization: `Bearer ${secret}` },\n signal: controller.signal,\n });\n if (!res.ok) {\n if (res.status === 401 || res.status === 403) {\n console.error(\n picocolors.red('Auth failed. Check that EXPORT_SECRET matches the value in your app.'),\n );\n } else {\n console.error(\n picocolors.red(\n `Server returned ${res.status}. Ensure the app is running (e.g. pnpm start) on port ${port}.`,\n ),\n );\n }\n process.exit(1);\n }\n const buffer = Buffer.from(await res.arrayBuffer());\n await fs.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.writeFile(outputPath, buffer);\n spin.stop(picocolors.green(`EPUB saved to ${outputPath}`));\n } catch (err: unknown) {\n if (err instanceof Error && err.name === 'AbortError') {\n console.error(picocolors.red('Request timed out after 30 seconds.'));\n } else {\n const msg = err instanceof Error ? err.message : String(err);\n console.error(picocolors.red(`Could not fetch EPUB: ${msg}`));\n }\n console.error(\n picocolors.yellow(`Ensure the server is running (e.g. pnpm start) on port ${port}.`),\n );\n process.exit(1);\n } finally {\n clearTimeout(timeoutId);\n }\n return;\n }\n\n const fullBuildPath = path.join(cwd, buildPath);\n if (!(await exists(fullBuildPath))) {\n console.error(\n picocolors.red(\n `EPUB not found at ${buildPath}. Run production build first (e.g. pnpm build).`,\n ),\n );\n process.exit(1);\n }\n\n spin.start('Copying EPUB');\n await fs.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.copyFile(fullBuildPath, outputPath);\n spin.stop(picocolors.green(`EPUB saved to ${outputPath}`));\n}\n","#!/usr/bin/env node\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { Command } from 'commander';\nimport picocolors from 'picocolors';\nimport { createOrLoadConfig, initConfig, type LoadedConfig } from '@/config';\nimport { type JsonTreeNode, treeToJavaScript, treeToMdx } from '@/commands/file-tree';\nimport { runTree } from '@/utils/file-tree/run-tree';\nimport packageJson from '../package.json';\nimport { customise } from '@/commands/customise';\nimport { add } from '@/commands/add';\nimport { exportEpub } from '@/commands/export-epub';\nimport { HttpRegistryClient, LocalRegistryClient } from '@/registry/client';\n\nconst program = new Command().option('--config <string>');\n\nprogram\n .name('fumadocs')\n .description('CLI to setup Fumadocs, init a config')\n .version(packageJson.version)\n .action(async () => {\n if (await initConfig()) {\n console.log(picocolors.green('Initialized a `./cli.json` config file.'));\n } else {\n console.log(picocolors.redBright('A config file already exists.'));\n }\n });\n\nprogram\n .command('customise')\n .alias('customize')\n .description('simple way to customise layouts with Fumadocs UI')\n .option('--dir <string>', 'the root url or directory to resolve registry')\n .action(async (options: { config?: string; dir?: string }) => {\n await customise(createClientFromDir(options.dir, await createOrLoadConfig(options.config)));\n });\n\nconst dirShortcuts: Record<string, string> = {\n ':preview': 'https://preview.fumadocs.dev/registry',\n ':dev': 'http://localhost:3000/registry',\n};\n\nprogram\n .command('add')\n .description('add a new component to your docs')\n .argument('[components...]', 'components to download')\n .option('--dir <string>', 'the root url or directory to resolve registry')\n .action(async (input: string[], options: { config?: string; dir?: string }) => {\n const client = createClientFromDir(options.dir, await createOrLoadConfig(options.config));\n await add(input, client);\n });\n\nconst exportCmd = program.command('export').description('export documentation to various formats');\n\nexportCmd\n .command('epub')\n .description('export documentation to EPUB format (run after production build)')\n .requiredOption('--framework <name>', 'React framework: next, tanstack-start, react-router, waku')\n .option('--output <path>', 'output file path', 'docs.epub')\n .option('--scaffold-only', 'only scaffold the EPUB route, do not copy')\n .action(async (options: { output?: string; framework: string; scaffoldOnly?: boolean }) => {\n await exportEpub({\n output: options.output,\n framework: options.framework,\n scaffoldOnly: options.scaffoldOnly,\n });\n });\n\nprogram\n .command('tree')\n .argument('[json_or_args]', 'JSON output of `tree` command or arguments for the `tree` command')\n .argument('[output]', 'output path of file')\n .option('--js', 'output as JavaScript file')\n .option('--no-root', 'remove the root node')\n .option('--import-name <name>', 'where to import components (JS only)')\n .action(\n async (\n str: string | undefined,\n output: string | undefined,\n { js, root, importName }: { js: boolean; root: boolean; importName?: string },\n ) => {\n const jsExtensions = ['.js', '.tsx', '.jsx'];\n const noRoot = !root;\n let nodes: JsonTreeNode[];\n\n try {\n nodes = JSON.parse(str ?? '') as JsonTreeNode[];\n } catch {\n nodes = await runTree(str ?? './');\n }\n\n const out =\n js || (output && jsExtensions.includes(path.extname(output)))\n ? treeToJavaScript(nodes, noRoot, importName)\n : treeToMdx(nodes, noRoot);\n\n if (output) {\n await fs.mkdir(path.dirname(output), { recursive: true });\n await fs.writeFile(output, out);\n } else {\n console.log(out);\n }\n },\n );\n\nfunction createClientFromDir(dir = 'https://fumadocs.dev/registry', config: LoadedConfig) {\n if (dir in dirShortcuts) dir = dirShortcuts[dir];\n\n return dir.startsWith('http://') || dir.startsWith('https://')\n ? new HttpRegistryClient(dir, config)\n : new LocalRegistryClient(dir, config);\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAM,UAAU;CAAC;CAAQ;CAAa;CAAO;AAE7C,SAAgB,UAAU,OAAuB,SAAS,OAAe;CACvE,SAAS,OAAO,MAA4B;AAC1C,MAAI,KAAK,SAAS,UAAU,KAAK,SAAS,OACxC,QAAO,cAAc,KAAK,UAAU,KAAK,KAAK,CAAC;AAGjD,MAAI,KAAK,SAAS,aAAa;AAC7B,OAAI,KAAK,SAAS,WAAW,KAAK,UAAU,KAAK,SAAS,IAAI;IAC5D,MAAM,QAAQ,KAAK,SAAS;AAE5B,WAAO,OAAO;KACZ,GAAG;KACH,MAAM,GAAG,KAAK,KAAK,GAAG,MAAM;KAC7B,CAAC;;AAGJ,UAAO,gBAAgB,KAAK,UAAU,KAAK,KAAK,CAAC;EACrD,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,QAAQ,CAAC,KAAK,KAAK,CAAC;;;AAInD,SAAO;;CAGT,IAAI,WAAW,MAAM,QAAQ,MAAM,QAAQ,SAAS,EAAE,KAAK,CAAC;AAE5D,KAAI,UAAU,SAAS,WAAW,KAAK,MAAM,GAAG,SAAS,YACvD,YAAW,MAAM,GAAG;AAGtB,QAAO;EACP,SAAS,IAAI,OAAO,CAAC,OAAO,QAAQ,CAAC,KAAK,KAAK,CAAC;;;AAIlD,SAAgB,iBACd,OACA,QACA,aAAa,gCACL;AACR,QAAO,uCAAuC,KAAK,UAAU,WAAW,CAAC;;kBAEzD,UAAU,OAAO,OAAO,CAAC;;;;AC3D3C,eAAsB,QAAQ,MAAuC;CACnE,MAAM,MAAM,MAAM,EAAE,QAAQ;EAAC;EAAM;EAAe;EAA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ChB,IAAI;AAEJ,KAAI;AACF,UAAQ,KAAK,MAAM,OAAO,GAAG;SACvB;AACN,UAAQ,MAAM,QAAQ,OAAO,KAAK;;CAGpC,MAAM,MACJ,MAAO,UAAU,aAAa,SAAS,KAAK,QAAQ,OAAO,CAAC,GACxD,iBAAiB,OAAO,QAAQ,WAAW,GAC3C,UAAU,OAAO,OAAO;AAE9B,KAAI,QAAQ;AACV,QAAM,GAAG,MAAM,KAAK,QAAQ,OAAO,EAAE,EAAE,WAAW,MAAM,CAAC;AACzD,QAAM,GAAG,UAAU,QAAQ,IAAI;OAE/B,SAAQ,IAAI,IAAI;EAGrB;AAEH,SAAS,oBAAoB,MAAM,iCAAiC,QAAsB;AACxF,KAAI,OAAO,aAAc,OAAM,aAAa;AAE5C,QAAO,IAAI,WAAW,UAAU,IAAI,IAAI,WAAW,WAAW,GAC1D,IAAI,mBAAmB,KAAK,OAAO,GACnC,IAAI,oBAAoB,KAAK,OAAO;;AAG1C,QAAQ,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["packageJson.version"],"sources":["../src/commands/file-tree.ts","../src/utils/file-tree/run-tree.ts","../package.json","../src/commands/shared.ts","../src/registry/plugins/preserve.ts","../src/commands/add.ts","../src/commands/customise.ts","../src/commands/export-epub.ts","../src/index.ts"],"sourcesContent":["export type JsonTreeNode =\n | {\n type: 'file';\n name: string;\n }\n | {\n type: 'directory';\n name: string;\n contents: JsonTreeNode[];\n }\n | {\n type: 'report';\n }\n | {\n type: 'link';\n name: string;\n };\n\nconst scanned = ['file', 'directory', 'link'];\n\nexport function treeToMdx(input: JsonTreeNode[], noRoot = false): string {\n function toNode(item: JsonTreeNode): string {\n if (item.type === 'file' || item.type === 'link') {\n return `<File name=${JSON.stringify(item.name)} />`;\n }\n\n if (item.type === 'directory') {\n if (item.contents.length === 1 && 'name' in item.contents[0]) {\n const child = item.contents[0];\n\n return toNode({\n ...child,\n name: `${item.name}/${child.name}`,\n });\n }\n\n return `<Folder name=${JSON.stringify(item.name)}>\n${item.contents.map(toNode).filter(Boolean).join('\\n')}\n</Folder>`;\n }\n\n return '';\n }\n\n let children = input.filter((v) => scanned.includes(v.type));\n\n if (noRoot && children.length === 1 && input[0].type === 'directory') {\n children = input[0].contents;\n }\n\n return `<Files>\n${children.map(toNode).filter(Boolean).join('\\n')}\n</Files>`;\n}\n\nexport function treeToJavaScript(\n input: JsonTreeNode[],\n noRoot?: boolean,\n importName = 'fumadocs-ui/components/files',\n): string {\n return `import { File, Files, Folder } from ${JSON.stringify(importName)}\n\nexport default (${treeToMdx(input, noRoot)})`;\n}\n","import { x } from 'tinyexec';\nimport type { JsonTreeNode } from '@/commands/file-tree';\n\nexport async function runTree(args: string): Promise<JsonTreeNode[]> {\n const out = await x('tree', [args, '--gitignore', '--prune', '-J']);\n\n try {\n return JSON.parse(out.stdout) as JsonTreeNode[];\n } catch (e) {\n throw new Error('failed to run `tree` command', {\n cause: e,\n });\n }\n}\n","","export const UIRegistries = {\n 'base-ui': 'fumadocs/base-ui',\n 'radix-ui': 'fumadocs/radix-ui',\n};\n","import { transformSpecifiers } from '@/utils/ast';\nimport type { ComponentInstallerPlugin } from '../installer';\n\n/**\n * keep references to `fumadocs-ui/layouts/*` components as original, unless the user is installing them directly.\n */\nexport function pluginPreserveLayouts(): ComponentInstallerPlugin {\n const layoutNames = [\n 'layouts/home',\n 'layouts/flux',\n 'layouts/notebook',\n 'layouts/docs',\n 'layouts/shared',\n ];\n // original specifier -> new specifier\n const layoutComps: Record<string, string> = {\n '@/<dir>/home/index.tsx': 'layouts/home',\n '@/<dir>/shared/index.tsx': 'layouts/shared',\n '@/<dir>/shared/client.tsx': 'layouts/shared',\n '@/<dir>/notebook/index.tsx': 'layouts/notebook',\n '@/<dir>/notebook/client.tsx': 'layouts/notebook',\n '@/<dir>/notebook/page/index.tsx': 'layouts/notebook/page',\n '@/<dir>/notebook/page/client.tsx': 'layouts/notebook/page',\n '@/<dir>/docs/index.tsx': 'layouts/docs',\n '@/<dir>/docs/client.tsx': 'layouts/docs',\n '@/<dir>/docs/page/index.tsx': 'layouts/docs/page',\n '@/<dir>/docs/page/client.tsx': 'layouts/docs/page',\n '@/<dir>/flux/index.tsx': 'layouts/flux',\n '@/<dir>/flux/page/index.tsx': 'layouts/flux/page',\n '@/<dir>/flux/page/client.tsx': 'layouts/flux/page',\n };\n const layoutNameSet = new Set(layoutNames);\n\n return {\n beforeInstall(comp, { stack }) {\n const isDirectInstall = layoutNameSet.has(stack[0].name);\n if (isDirectInstall) return;\n\n return {\n ...comp,\n $subComponents: comp.$subComponents.filter((child) => !layoutNameSet.has(child.name)),\n };\n },\n beforeTransform({ parsed, s, stack }) {\n const isDirectInstall = layoutNameSet.has(stack[0].name);\n if (isDirectInstall) return;\n\n transformSpecifiers(parsed.program, s, (specifier) => {\n // skip if unrelated to layout component\n if (!(specifier in layoutComps)) return specifier;\n\n return `fumadocs-ui/${layoutComps[specifier]}`;\n });\n },\n };\n}\n","import {\n isCancel,\n autocompleteMultiselect,\n outro,\n spinner,\n confirm,\n box,\n log,\n} from '@clack/prompts';\nimport picocolors from 'picocolors';\nimport { ComponentInstaller } from '@/registry/installer';\nimport type { RegistryClient } from '@/registry/client';\nimport { UIRegistries } from '@/commands/shared';\nimport { pluginPreserveLayouts } from '@/registry/plugins/preserve';\n\nexport async function add(input: string[], client: RegistryClient) {\n const config = client.config;\n let target: string[];\n const installer = new ComponentInstaller(client, {\n plugins: [pluginPreserveLayouts()],\n });\n const registry = UIRegistries[config.uiLibrary];\n\n if (input.length === 0) {\n const spin = spinner();\n spin.start('fetching registry');\n const info = await client.fetchRegistryInfo();\n const options: {\n label: string;\n value: string;\n hint?: string;\n }[] = [];\n\n for (const item of info.indexes) {\n options.push({\n label: item.title ?? item.name,\n value: item.name,\n hint: item.description,\n });\n }\n const { indexes } = await client.createLinkedRegistryClient(registry).fetchRegistryInfo();\n\n for (const item of indexes) {\n options.push({\n label: item.title ?? item.name,\n value: `${registry}/${item.name}`,\n hint: item.description,\n });\n }\n\n spin.stop(picocolors.bold(picocolors.greenBright('registry fetched')));\n const value = await autocompleteMultiselect({\n message: 'Select components to install',\n options,\n });\n\n if (isCancel(value)) {\n outro('Ended');\n return;\n }\n\n target = value;\n } else {\n target = await Promise.all(\n input.map(async (item) => ((await client.hasComponent(item)) ? item : `${registry}/${item}`)),\n );\n }\n\n await install(target, installer);\n}\n\nexport async function install(target: string[], installer: ComponentInstaller) {\n for (const name of target) {\n const spin = spinner();\n spin.start(picocolors.bold(picocolors.cyanBright(`Installing ${name}`)));\n\n try {\n await installer.install(name, {\n onWarn(message) {\n spin.message(message);\n },\n async confirmFileOverride(options) {\n spin.clear();\n const value = await confirm({\n message: `Do you want to override ${options.path}?`,\n initialValue: false,\n });\n if (isCancel(value)) {\n outro('Installation terminated');\n process.exit(0);\n }\n spin.start(picocolors.bold(picocolors.cyanBright(`Installing ${name}`)));\n return value;\n },\n onFileDownloaded(options) {\n spin.message(options.path);\n },\n });\n spin.stop(picocolors.bold(picocolors.greenBright(`${name} installed`)));\n } catch (e) {\n spin.error(e instanceof Error ? e.message : String(e));\n process.exit(-1);\n }\n }\n\n const deps = await installer.deps();\n if (deps.hasRequired()) {\n log.message();\n box([...deps.dependencies, ...deps.devDependencies].join('\\n'), 'New Dependencies');\n const value = await confirm({\n message: `Do you want to install with ${deps.packageManager}?`,\n });\n\n if (isCancel(value)) {\n outro('Installation terminated');\n process.exit(0);\n }\n\n if (value) {\n const spin = spinner({\n errorMessage: 'Failed to install dependencies',\n });\n spin.start('Installing dependencies');\n await deps.installRequired();\n spin.stop('Dependencies installed');\n }\n }\n\n await installer.onEnd();\n outro(picocolors.bold(picocolors.greenBright('Successful')));\n}\n","import { cancel, group, intro, log, outro, select } from '@clack/prompts';\nimport picocolors from 'picocolors';\nimport { install } from '@/commands/add';\nimport type { RegistryClient } from '@/registry/client';\nimport { ComponentInstaller } from '@/registry/installer';\nimport { UIRegistries } from '@/commands/shared';\nimport { pluginPreserveLayouts } from '@/registry/plugins/preserve';\n\ninterface TargetInfo {\n target: string[];\n id: string;\n print?: () => void;\n}\n\ninterface SlotPrintInfo {\n at: string;\n layoutId: string;\n name: string;\n isPage: boolean;\n}\n\nexport async function customise(client: RegistryClient) {\n intro(picocolors.bgBlack(picocolors.whiteBright('Customise Fumadocs UI')));\n const config = client.config;\n const installer = new ComponentInstaller(client, {\n plugins: [pluginPreserveLayouts()],\n });\n const registry = UIRegistries[config.uiLibrary];\n const info = await client.createLinkedRegistryClient(registry).fetchRegistryInfo();\n\n const result = await group(\n {\n layout: (): Promise<TargetInfo | symbol> =>\n select({\n message: 'What do you want to customise?',\n options: [\n {\n label: 'Docs Layout',\n value: {\n id: 'docs',\n target: [`${registry}/layouts/docs`],\n print() {\n printLayout(\n ['fumadocs-ui/layouts/docs', '@/layouts/docs'],\n ['fumadocs-ui/layouts/docs/page', '@/layouts/docs/page'],\n );\n },\n },\n hint: 'the default docs layout',\n },\n {\n label: 'Notebook Layout',\n value: {\n id: 'notebook',\n target: [`${registry}/layouts/notebook`],\n print() {\n printLayout(\n ['fumadocs-ui/layouts/notebook', '@/layouts/notebook'],\n ['fumadocs-ui/layouts/notebook/page', '@/layouts/notebook/page'],\n );\n },\n },\n hint: 'a more compact version of docs layout',\n },\n {\n label: 'Flux Layout',\n value: {\n id: 'flux',\n target: [`${registry}/layouts/flux`],\n print() {\n printLayout(\n ['fumadocs-ui/layouts/flux', '@/layouts/flux'],\n ['fumadocs-ui/layouts/flux/page', '@/layouts/flux/page'],\n );\n },\n },\n hint: 'the experimental variant of docs layout',\n },\n {\n label: 'Home Layout',\n value: {\n id: 'home',\n target: [`${registry}/layouts/home`],\n print() {\n printLayout(['fumadocs-ui/layouts/home', `@/layouts/home`]);\n },\n },\n hint: 'the layout for other non-docs pages',\n },\n ],\n }),\n target: (v): Promise<TargetInfo | symbol> => {\n const selected = v.results.layout!;\n if (selected.id === 'home') return Promise.resolve(selected);\n\n return select<TargetInfo>({\n message: 'Which part do you want to customise?',\n options: [\n {\n label: 'All',\n hint: 'install the entire layout',\n value: selected,\n },\n {\n label: 'Replace & rewrite from minimal styles',\n hint: 'for those who want to build their own UI from ground up',\n value: {\n id: 'docs-min',\n target: ['layouts/docs-min'],\n print() {\n printLayout(\n ['fumadocs-ui/layouts/docs', '@/layouts/docs'],\n ['fumadocs-ui/layouts/docs/page', '@/layouts/docs/page'],\n );\n },\n },\n },\n ...info.unlistedIndexes.flatMap((index) => {\n const prefix = `slots/${selected.id}`;\n if (!index.name.startsWith(prefix)) return [];\n let name = index.name.slice(prefix.length + 1);\n\n if (name.startsWith('page/')) {\n name = name.slice('page/'.length);\n\n return {\n label: `Page: ${name}`,\n hint: \"only replace a part of layout's page, useful for adjusting details\",\n value: {\n id: index.name,\n target: [`${registry}/${index.name}`],\n print() {\n printSlot({\n at: `@/layouts/${selected.id}/page/slots/${name}`,\n layoutId: selected.id,\n name,\n isPage: true,\n });\n },\n } as TargetInfo,\n };\n }\n\n return {\n label: `Layout: ${name}`,\n hint: 'only replace a part of layout, useful for adjusting details',\n value: {\n id: index.name,\n target: [`${registry}/${index.name}`],\n print() {\n printSlot({\n at: `@/layouts/${selected.id}/slots/${name}`,\n layoutId: selected.id,\n name,\n isPage: false,\n });\n },\n } as TargetInfo,\n };\n }),\n ],\n });\n },\n },\n {\n onCancel: () => {\n cancel('Installation Stopped.');\n process.exit(0);\n },\n },\n );\n\n const target = result.target as TargetInfo;\n await install(target.target, installer);\n target.print?.();\n\n outro(picocolors.bold('Have fun!'));\n}\n\nfunction printLayout(...maps: [from: string, to: string][]) {\n intro(picocolors.bold('What is Next?'));\n\n log.info(\n [\n 'You can check the installed layouts in `layouts` folder.',\n picocolors.dim('---'),\n 'Open your `layout.tsx` files, replace the imports of components:',\n ...maps.map(([from, to]) => picocolors.greenBright(`\"${from}\" -> \"${to}\"`)),\n ].join('\\n'),\n );\n}\n\nfunction printSlot({ at, layoutId, name, isPage }: SlotPrintInfo) {\n intro(picocolors.bold('What is Next?'));\n\n log.info(`You can check the installed layout slot in \"${at}\".`);\n\n const code = getSlotCode({ at, layoutId, name, isPage });\n\n if (code) {\n if (isPage) {\n log.info(\n `${picocolors.bold('At your <DocsPage /> component, update your \"slots\" prop:')}\\n\\n${code}`,\n );\n } else {\n log.info(\n `${picocolors.bold('At your <DocsLayout /> component, update your \"slots\" prop:')}\\n\\n${code}`,\n );\n }\n }\n}\n\nfunction getSlotCode({ at, layoutId, name, isPage }: SlotPrintInfo): string | undefined {\n if (isPage) {\n switch (name) {\n case 'toc':\n if (layoutId === 'flux') {\n return `import { TOCProvider, TOC } from '${at}';\n\nreturn (\n <DocsPage\n slots={{\n toc: {\n provider: TOCProvider,\n main: TOC,\n },\n }}\n >\n ...\n </DocsPage>\n);`;\n }\n\n return `import { TOCProvider, TOC, TOCPopover } from '${at}';\n\nreturn (\n <DocsPage\n slots={{\n toc: {\n provider: TOCProvider,\n main: TOC,\n popover: TOCPopover,\n },\n }}\n >\n ...\n </DocsPage>\n);`;\n case 'container': {\n return `import { Container } from '${at}';\n\nreturn (\n <DocsPage\n slots={{\n container: Container,\n }}\n >\n ...\n </DocsPage>\n);`;\n }\n case 'footer': {\n return `import { Footer } from '${at}';\n\nreturn (\n <DocsPage\n slots={{\n footer: Footer,\n }}\n >\n ...\n </DocsPage>\n);`;\n }\n case 'breadcrumb': {\n return `import { Breadcrumb } from '${at}';\n\nreturn (\n <DocsPage\n slots={{\n breadcrumb: Breadcrumb,\n }}\n >\n ...\n </DocsPage>\n);`;\n }\n default:\n return;\n }\n }\n\n switch (name) {\n case 'sidebar': {\n if (layoutId === 'notebook') {\n return `import {\n SidebarProvider,\n Sidebar,\n SidebarTrigger,\n SidebarCollapseTrigger,\n useSidebar,\n} from '${at}';\n\nreturn (\n <DocsLayout\n slots={{\n sidebar: {\n provider: SidebarProvider,\n root: Sidebar,\n trigger: SidebarTrigger,\n collapseTrigger: SidebarCollapseTrigger,\n useSidebar: useSidebar,\n },\n }}\n >\n ...\n </DocsLayout>\n);`;\n }\n\n return `import { SidebarProvider, Sidebar, SidebarTrigger, useSidebar } from '${at}';\n\nreturn (\n <DocsLayout\n slots={{\n sidebar: {\n provider: SidebarProvider,\n root: Sidebar,\n trigger: SidebarTrigger,\n useSidebar: useSidebar,\n },\n }}\n >\n ...\n </DocsLayout>\n);`;\n }\n case 'container': {\n return `import { Container } from '${at}';\n\nreturn (\n <DocsLayout\n slots={{\n container: Container,\n }}\n >\n ...\n </DocsLayout>\n);`;\n }\n case 'header': {\n return `import { Header } from '${at}';\n\nreturn (\n <DocsLayout\n slots={{\n header: Header,\n }}\n >\n ...\n </DocsLayout>\n);`;\n }\n case 'tab-dropdown': {\n return `import { TabDropdown } from '${at}';\n\nreturn (\n <DocsLayout\n slots={{\n tabDropdown: TabDropdown,\n }}\n >\n ...\n </DocsLayout>\n);`;\n }\n default:\n return;\n }\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { exists } from '@/utils/fs';\nimport picocolors from 'picocolors';\nimport { spinner } from '@clack/prompts';\nimport { exec } from 'node:child_process';\nimport { promisify } from 'node:util';\n\nconst execAsync = promisify(exec);\n\ninterface PackageJson {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n}\n\nasync function readPackageJson(cwd: string): Promise<PackageJson | null> {\n try {\n const raw = await fs.readFile(path.join(cwd, 'package.json'), 'utf-8');\n return JSON.parse(raw) as PackageJson;\n } catch {\n return null;\n }\n}\n\n/** Path of pre-rendered EPUB, choose one according to your React framework. Next.js fetches from the running server instead. */\nconst EPUB_BUILD_PATHS: Record<string, string> = {\n next: '', // Fetched from /export/epub at runtime; route handlers don't produce static files\n 'tanstack-start': '.output/public/export/epub',\n 'tanstack-start-spa': 'dist/client/export/epub',\n 'react-router': 'build/client/export/epub',\n 'react-router-spa': 'build/client/export/epub',\n waku: 'dist/public/export/epub',\n};\n\nconst API_ROUTE_TEMPLATE = `import { source } from '@/lib/source';\nimport { exportEpub } from 'fumadocs-epub';\n\nexport const revalidate = false;\n\nexport async function GET(request: Request): Promise<Response> {\n // Require EXPORT_SECRET to prevent unauthenticated abuse. Pass via Authorization: Bearer <secret>\n const secret = process.env.EXPORT_SECRET;\n if (!secret) {\n return new Response('EXPORT_SECRET is not configured. Set it in your environment to protect this endpoint.', { status: 503 });\n }\n const authHeader = request.headers.get('authorization');\n const token = authHeader?.replace(/^Bearer\\\\s+/i, '') ?? '';\n if (token !== secret) {\n return new Response('Unauthorized', { status: authHeader ? 403 : 401 });\n }\n const buffer = await exportEpub({\n source,\n title: 'Documentation',\n author: 'Your Team',\n description: 'Exported documentation',\n cover: '/cover.png',\n });\n return new Response(new Uint8Array(buffer), {\n headers: {\n 'Content-Type': 'application/epub+zip',\n 'Content-Disposition': 'attachment; filename=\"docs.epub\"',\n },\n });\n}\n`;\n\nasync function findAppDir(cwd: string): Promise<string | null> {\n const appPaths = ['app', 'src/app'];\n for (const appPath of appPaths) {\n const fullPath = path.join(cwd, appPath);\n if (await exists(fullPath)) {\n return fullPath;\n }\n }\n return null;\n}\n\nasync function scaffoldEpubRoute(cwd: string): Promise<boolean> {\n const appDir = await findAppDir(cwd);\n if (!appDir) {\n console.error(picocolors.red('Could not find app directory (app/ or src/app/)'));\n return false;\n }\n\n const routePath = path.join(appDir, 'export', 'epub', 'route.ts');\n if (await exists(routePath)) {\n console.log(picocolors.yellow('EPUB route already exists at'), routePath);\n return true;\n }\n\n await fs.mkdir(path.dirname(routePath), { recursive: true });\n await fs.writeFile(routePath, API_ROUTE_TEMPLATE);\n console.log(picocolors.green('Created EPUB route at'), routePath);\n return true;\n}\n\nexport async function exportEpub(options: {\n output?: string;\n framework: string;\n scaffoldOnly?: boolean;\n}) {\n const cwd = process.cwd();\n const outputPath = path.resolve(cwd, options.output ?? 'docs.epub');\n const framework = options.framework;\n\n const spin = spinner();\n\n const buildPath = EPUB_BUILD_PATHS[framework];\n if (!(framework in EPUB_BUILD_PATHS)) {\n const valid = Object.keys(EPUB_BUILD_PATHS).join(', ');\n console.error(picocolors.red(`Invalid --framework \"${framework}\". Must be one of: ${valid}`));\n process.exit(1);\n }\n\n // Check for Next.js when scaffolding (only Next.js scaffold is implemented)\n const pkg = await readPackageJson(cwd);\n const hasNextConfig =\n (await exists(path.join(cwd, 'next.config.js'))) ||\n (await exists(path.join(cwd, 'next.config.ts'))) ||\n (await exists(path.join(cwd, 'next.config.mjs')));\n const nextDeps = pkg\n ? { ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies }\n : {};\n const hasNextInPkg = !!nextDeps?.next;\n const hasAppOrPages =\n (await exists(path.join(cwd, 'app'))) ||\n (await exists(path.join(cwd, 'pages'))) ||\n (await exists(path.join(cwd, 'src', 'app'))) ||\n (await exists(path.join(cwd, 'src', 'pages')));\n const hasNext = hasNextConfig || (hasNextInPkg && hasAppOrPages);\n\n if (!hasNext && framework === 'next') {\n console.error(\n picocolors.red(\n 'Next.js project not found. Run this command from a Fumadocs Next.js project root.',\n ),\n );\n process.exit(1);\n }\n\n // Scaffold EPUB route (Next.js only for now)\n if (framework === 'next') {\n spin.start('Scaffolding EPUB route');\n const scaffolded = await scaffoldEpubRoute(cwd);\n spin.stop(scaffolded ? 'EPUB route ready' : 'Scaffolding failed');\n\n if (!scaffolded) {\n process.exit(1);\n }\n }\n\n if (options.scaffoldOnly) {\n console.log(picocolors.cyan('\\nTo export:'));\n console.log(' 1. Add fumadocs-epub to your dependencies: pnpm add fumadocs-epub');\n console.log(' 2. Ensure includeProcessedMarkdown: true in your docs collection config');\n if (framework === 'next') {\n console.log(\n ' 3. Set EXPORT_SECRET in your environment to protect the /export/epub endpoint',\n );\n console.log(' 4. Run production build: pnpm build');\n console.log(' 5. Start the server (e.g. pnpm start) and keep it running');\n console.log(' 6. Run: fumadocs export epub --framework next');\n } else {\n console.log(` 3. Add a prerender route that outputs EPUB to ${buildPath}`);\n console.log(' 4. Run production build: pnpm build');\n console.log(` 5. Run: fumadocs export epub --framework ${framework}`);\n }\n return;\n }\n\n // Check for fumadocs-epub dependency\n if (!pkg) {\n console.error(\n picocolors.red('Cannot read or parse package.json. Ensure it exists and is valid JSON.'),\n );\n process.exit(1);\n }\n const deps = { ...pkg.dependencies, ...pkg.devDependencies };\n if (!deps['fumadocs-epub']) {\n console.log(picocolors.yellow('\\nInstalling fumadocs-epub...'));\n const packageManager = process.env.npm_execpath?.includes('pnpm')\n ? 'pnpm'\n : process.env.npm_execpath?.includes('bun')\n ? 'bun'\n : 'npm';\n const installCmd = `${packageManager} add fumadocs-epub`;\n try {\n await execAsync(installCmd, { cwd });\n } catch (err: unknown) {\n const stderr =\n err && typeof err === 'object' && 'stderr' in err\n ? String((err as { stderr?: string }).stderr)\n : '';\n console.error(picocolors.red(`Failed to install fumadocs-epub. Command: ${installCmd}`));\n if (stderr) console.error(stderr);\n process.exit(1);\n }\n }\n\n if (framework === 'next') {\n const secret = process.env.EXPORT_SECRET;\n if (!secret) {\n console.error(\n picocolors.red('EXPORT_SECRET is required for Next.js export. Set it in your environment.'),\n );\n process.exit(1);\n }\n const port = process.env.PORT || '3000';\n const url = `http://localhost:${port}/export/epub`;\n spin.start('Fetching EPUB from server');\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), 30_000);\n try {\n const res = await fetch(url, {\n headers: { Authorization: `Bearer ${secret}` },\n signal: controller.signal,\n });\n if (!res.ok) {\n if (res.status === 401 || res.status === 403) {\n console.error(\n picocolors.red('Auth failed. Check that EXPORT_SECRET matches the value in your app.'),\n );\n } else {\n console.error(\n picocolors.red(\n `Server returned ${res.status}. Ensure the app is running (e.g. pnpm start) on port ${port}.`,\n ),\n );\n }\n process.exit(1);\n }\n const buffer = Buffer.from(await res.arrayBuffer());\n await fs.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.writeFile(outputPath, buffer);\n spin.stop(picocolors.green(`EPUB saved to ${outputPath}`));\n } catch (err: unknown) {\n if (err instanceof Error && err.name === 'AbortError') {\n console.error(picocolors.red('Request timed out after 30 seconds.'));\n } else {\n const msg = err instanceof Error ? err.message : String(err);\n console.error(picocolors.red(`Could not fetch EPUB: ${msg}`));\n }\n console.error(\n picocolors.yellow(`Ensure the server is running (e.g. pnpm start) on port ${port}.`),\n );\n process.exit(1);\n } finally {\n clearTimeout(timeoutId);\n }\n return;\n }\n\n const fullBuildPath = path.join(cwd, buildPath);\n if (!(await exists(fullBuildPath))) {\n console.error(\n picocolors.red(\n `EPUB not found at ${buildPath}. Run production build first (e.g. pnpm build).`,\n ),\n );\n process.exit(1);\n }\n\n spin.start('Copying EPUB');\n await fs.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.copyFile(fullBuildPath, outputPath);\n spin.stop(picocolors.green(`EPUB saved to ${outputPath}`));\n}\n","#!/usr/bin/env node\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { Command } from 'commander';\nimport picocolors from 'picocolors';\nimport { createOrLoadConfig, initConfig, type LoadedConfig } from '@/config';\nimport { type JsonTreeNode, treeToJavaScript, treeToMdx } from '@/commands/file-tree';\nimport { runTree } from '@/utils/file-tree/run-tree';\nimport packageJson from '../package.json';\nimport { customise } from '@/commands/customise';\nimport { add } from '@/commands/add';\nimport { exportEpub } from '@/commands/export-epub';\nimport { HttpRegistryClient, LocalRegistryClient } from '@/registry/client';\n\nconst program = new Command().option('--config <string>');\n\nprogram\n .name('fumadocs')\n .description('CLI to setup Fumadocs, init a config')\n .version(packageJson.version)\n .action(async () => {\n if (await initConfig()) {\n console.log(picocolors.green('Initialized a `./cli.json` config file.'));\n } else {\n console.log(picocolors.redBright('A config file already exists.'));\n }\n });\n\nprogram\n .command('customise')\n .alias('customize')\n .description('simple way to customise layouts with Fumadocs UI')\n .option('--dir <string>', 'the root url or directory to resolve registry')\n .action(async (options: { config?: string; dir?: string }) => {\n await customise(createClientFromDir(options.dir, await createOrLoadConfig(options.config)));\n });\n\nconst dirShortcuts: Record<string, string> = {\n ':preview': 'https://preview.fumadocs.dev/registry',\n ':dev': 'http://localhost:3000/registry',\n};\n\nprogram\n .command('add')\n .description('add a new component to your docs')\n .argument('[components...]', 'components to download')\n .option('--dir <string>', 'the root url or directory to resolve registry')\n .action(async (input: string[], options: { config?: string; dir?: string }) => {\n const client = createClientFromDir(options.dir, await createOrLoadConfig(options.config));\n await add(input, client);\n });\n\nconst exportCmd = program.command('export').description('export documentation to various formats');\n\nexportCmd\n .command('epub')\n .description('export documentation to EPUB format (run after production build)')\n .requiredOption('--framework <name>', 'React framework: next, tanstack-start, react-router, waku')\n .option('--output <path>', 'output file path', 'docs.epub')\n .option('--scaffold-only', 'only scaffold the EPUB route, do not copy')\n .action(async (options: { output?: string; framework: string; scaffoldOnly?: boolean }) => {\n await exportEpub({\n output: options.output,\n framework: options.framework,\n scaffoldOnly: options.scaffoldOnly,\n });\n });\n\nprogram\n .command('tree')\n .argument('[json_or_args]', 'JSON output of `tree` command or arguments for the `tree` command')\n .argument('[output]', 'output path of file')\n .option('--js', 'output as JavaScript file')\n .option('--no-root', 'remove the root node')\n .option('--import-name <name>', 'where to import components (JS only)')\n .action(\n async (\n str: string | undefined,\n output: string | undefined,\n { js, root, importName }: { js: boolean; root: boolean; importName?: string },\n ) => {\n const jsExtensions = ['.js', '.tsx', '.jsx'];\n const noRoot = !root;\n let nodes: JsonTreeNode[];\n\n try {\n nodes = JSON.parse(str ?? '') as JsonTreeNode[];\n } catch {\n nodes = await runTree(str ?? './');\n }\n\n const out =\n js || (output && jsExtensions.includes(path.extname(output)))\n ? treeToJavaScript(nodes, noRoot, importName)\n : treeToMdx(nodes, noRoot);\n\n if (output) {\n await fs.mkdir(path.dirname(output), { recursive: true });\n await fs.writeFile(output, out);\n } else {\n console.log(out);\n }\n },\n );\n\nfunction createClientFromDir(dir = 'https://fumadocs.dev/registry', config: LoadedConfig) {\n if (dir in dirShortcuts) dir = dirShortcuts[dir];\n\n return dir.startsWith('http://') || dir.startsWith('https://')\n ? new HttpRegistryClient(dir, config)\n : new LocalRegistryClient(dir, config);\n}\n\nprogram.parse();\n"],"mappings":";;;;;;;;;;;;;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G,OAAO,mBAAmB,oBAAoB,YAAY,CAC1D,OAAO,mBAAmB,4CAA4C,CACtE,OAAO,OAAO,YAA4E;AACzF,OAAM,WAAW;EACf,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB,cAAc,QAAQ;EACvB,CAAC;EACF;AAEJ,QACG,QAAQ,OAAO,CACf,SAAS,kBAAkB,oEAAoE,CAC/F,SAAS,YAAY,sBAAsB,CAC3C,OAAO,QAAQ,4BAA4B,CAC3C,OAAO,aAAa,uBAAuB,CAC3C,OAAO,wBAAwB,uCAAuC,CACtE,OACC,OACE,KACA,QACA,EAAE,IAAI,MAAM,iBACT;CACH,MAAM,eAAe;EAAC;EAAO;EAAQ;EAAO;CAC5C,MAAM,SAAS,CAAC;CAChB,IAAI;AAEJ,KAAI;AACF,UAAQ,KAAK,MAAM,OAAO,GAAG;SACvB;AACN,UAAQ,MAAM,QAAQ,OAAO,KAAK;;CAGpC,MAAM,MACJ,MAAO,UAAU,aAAa,SAAS,KAAK,QAAQ,OAAO,CAAC,GACxD,iBAAiB,OAAO,QAAQ,WAAW,GAC3C,UAAU,OAAO,OAAO;AAE9B,KAAI,QAAQ;AACV,QAAM,GAAG,MAAM,KAAK,QAAQ,OAAO,EAAE,EAAE,WAAW,MAAM,CAAC;AACzD,QAAM,GAAG,UAAU,QAAQ,IAAI;OAE/B,SAAQ,IAAI,IAAI;EAGrB;AAEH,SAAS,oBAAoB,MAAM,iCAAiC,QAAsB;AACxF,KAAI,OAAO,aAAc,OAAM,aAAa;AAE5C,QAAO,IAAI,WAAW,UAAU,IAAI,IAAI,WAAW,WAAW,GAC1D,IAAI,mBAAmB,KAAK,OAAO,GACnC,IAAI,oBAAoB,KAAK,OAAO;;AAG1C,QAAQ,OAAO"}
|
|
@@ -232,10 +232,10 @@ var ComponentInstaller = class {
|
|
|
232
232
|
const config = this.rootClient.config;
|
|
233
233
|
const dir = {
|
|
234
234
|
components: config.aliases.componentsDir,
|
|
235
|
-
block: config.aliases.blockDir,
|
|
236
235
|
ui: config.aliases.uiDir,
|
|
237
236
|
css: config.aliases.cssDir,
|
|
238
237
|
lib: config.aliases.libDir,
|
|
238
|
+
layout: config.aliases.layoutDir,
|
|
239
239
|
route: "./"
|
|
240
240
|
}[file.type];
|
|
241
241
|
if (file.target) return path.resolve(this.cwd, config.baseDir, file.target.replace("<dir>", dir));
|
|
@@ -245,4 +245,4 @@ var ComponentInstaller = class {
|
|
|
245
245
|
//#endregion
|
|
246
246
|
export { ComponentInstaller as t };
|
|
247
247
|
|
|
248
|
-
//# sourceMappingURL=installer-
|
|
248
|
+
//# sourceMappingURL=installer-B3-my9zN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installer-BS70ExnQ.js","names":[],"sources":["../src/utils/get-package-manager.ts","../src/registry/installer/dep-manager.ts","../src/registry/installer/index.ts"],"sourcesContent":["import { detect, type AgentName } from 'package-manager-detector';\n\nexport type PackageManager = AgentName;\n\nexport async function getPackageManager(): Promise<PackageManager> {\n const result = await detect();\n\n return result?.name ?? 'npm';\n}\n","import fs from 'node:fs/promises';\nimport { getPackageManager, PackageManager } from '@/utils/get-package-manager';\nimport { x } from 'tinyexec';\nimport path from 'node:path';\n\ninterface PackageJsonType {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n}\n\nexport class DependencyManager {\n private installedDeps = new Map<string, string>();\n dependencies: string[] = [];\n devDependencies: string[] = [];\n packageManager: PackageManager = 'npm';\n\n constructor(private readonly cwd: string) {}\n\n async init(deps: Record<string, string | null>, devDeps: Record<string, string | null>) {\n this.installedDeps.clear();\n const packageJsonPath = path.join(this.cwd, 'package.json');\n const content = await fs\n .readFile(packageJsonPath)\n .then((res) => res.toString())\n .catch(() => null);\n\n if (content !== null) {\n const parsed = JSON.parse(content) as PackageJsonType;\n\n for (const [k, v] of Object.entries(parsed?.dependencies ?? {})) {\n this.installedDeps.set(k, v);\n }\n\n for (const [k, v] of Object.entries(parsed?.devDependencies ?? {})) {\n this.installedDeps.set(k, v);\n }\n }\n\n this.dependencies = this.resolveRequiredDependencies(deps);\n this.devDependencies = this.resolveRequiredDependencies(devDeps);\n this.packageManager = await getPackageManager();\n }\n\n private resolveRequiredDependencies(deps: Record<string, string | null>): string[] {\n return Object.entries(deps)\n .filter(([k]) => !this.installedDeps.has(k))\n .map(([k, v]) => (v === null || v.length === 0 ? k : `${k}@${v}`));\n }\n\n hasRequired() {\n return this.dependencies.length > 0 || this.devDependencies.length > 0;\n }\n\n async writeRequired() {\n const packageJsonPath = path.join(this.cwd, 'package.json');\n const content = await fs.readFile(packageJsonPath).catch(() => null);\n if (content === null) return false;\n\n const parsed = JSON.parse(content.toString()) as PackageJsonType;\n if (!parsed) return false;\n\n for (const dep of this.dependencies) {\n const { name, version } = parseDep(dep);\n parsed.dependencies ??= {};\n parsed.dependencies[name] ??= version;\n }\n\n for (const dep of this.devDependencies) {\n const { name, version } = parseDep(dep);\n parsed.devDependencies ??= {};\n parsed.devDependencies[name] ??= version;\n }\n\n await fs.writeFile(packageJsonPath, JSON.stringify(parsed, null, 2));\n }\n\n async installRequired() {\n if (this.dependencies.length > 0)\n await x(this.packageManager, ['install', ...this.dependencies]);\n if (this.devDependencies.length > 0)\n await x(this.packageManager, ['install', ...this.devDependencies, '-D']);\n }\n}\n\nfunction parseDep(dep: string) {\n const idx = dep.indexOf('@', 1);\n if (idx === -1) {\n return { name: dep, version: 'latest' };\n } else {\n return { name: dep.slice(0, idx), version: dep.slice(idx + 1) };\n }\n}\n","import path from 'node:path';\nimport fs from 'node:fs/promises';\nimport { typescriptExtensions } from '@/constants';\nimport { toImportSpecifier, transformSpecifiers } from '@/utils/ast';\nimport type { Component, File } from '@/registry/schema';\nimport { HttpRegistryClient, type RegistryClient } from '@/registry/client';\nimport { x } from 'tinyexec';\nimport { DependencyManager } from '@/registry/installer/dep-manager';\nimport { createCache } from '@/utils/cache';\nimport { parse, type ParseResult } from 'oxc-parser';\nimport MagicString from 'magic-string';\n\ninterface PluginContext {\n installer: ComponentInstaller;\n}\n\ninterface TransformContext extends PluginContext, InstallContext {\n s: MagicString;\n parsed: ParseResult;\n file: File;\n component: DownloadedComponent;\n}\n\ninterface InstallContext {\n pathToFile: Map<string, File>;\n io: IOInterface;\n /** full variables of the current component. */\n $variables: Record<string, unknown>;\n /** the last item is always the current component. */\n stack: DownloadedComponent[];\n}\n\ninterface DownloadedComponent extends Component {\n $subComponents: DownloadedComponent[];\n $registry: RegistryClient;\n}\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface ComponentInstallerPlugin {\n /**\n * transform file before writing (before default transformation)\n */\n beforeTransform?: (context: TransformContext) => Awaitable<void>;\n\n /**\n * transform file before writing (after default transformation)\n */\n afterTransform?: (context: TransformContext) => Awaitable<void>;\n\n /**\n * transform component before install\n */\n beforeInstall?: (\n comp: DownloadedComponent,\n context: InstallContext & PluginContext,\n ) => Awaitable<DownloadedComponent | undefined>;\n\n beforeDownload?: (\n context: PluginContext & {\n name: string;\n },\n ) => void | Promise<void>;\n\n afterDownload?: (\n context: PluginContext & {\n name: string;\n result: DownloadedComponent;\n },\n ) => void | Promise<void>;\n}\n\nexport interface IOInterface {\n onWarn: (message: string) => void;\n confirmFileOverride: (options: { path: string }) => Promise<boolean>;\n onFileDownloaded: (options: { path: string; file: File; component: Component }) => void;\n}\n\nexport interface ComponentInstallerOptions {\n plugins?: ComponentInstallerPlugin[];\n cwd?: string;\n}\n\nexport class ComponentInstaller {\n private readonly installedFiles = new Set<string>();\n private readonly downloadCache = createCache<DownloadedComponent>();\n private readonly cwd: string;\n private readonly plugins: ComponentInstallerPlugin[];\n readonly dependencies: Record<string, string | null> = {};\n readonly devDependencies: Record<string, string | null> = {};\n\n constructor(\n private readonly rootClient: RegistryClient,\n options: ComponentInstallerOptions = {},\n ) {\n this.cwd = options.cwd ?? process.cwd();\n this.plugins = options.plugins ?? [];\n }\n\n private async installComponent(comp: DownloadedComponent, ctx: InstallContext) {\n // avoid circular refs\n if (ctx.stack.indexOf(comp) !== ctx.stack.length - 1) return;\n\n const pluginCtx = { installer: this, ...ctx };\n for (const plugin of this.plugins) {\n comp = (await plugin.beforeInstall?.(comp, pluginCtx)) ?? comp;\n }\n\n Object.assign(this.dependencies, comp.dependencies);\n Object.assign(this.devDependencies, comp.devDependencies);\n\n for (const file of comp.files) {\n const outPath = this.resolveOutputPath(file);\n if (this.installedFiles.has(outPath)) continue;\n this.installedFiles.add(outPath);\n\n const output = typescriptExtensions.includes(path.extname(outPath))\n ? await this.transform(file, comp, ctx)\n : file.content;\n\n const status = await fs\n .readFile(outPath)\n .then((res) => {\n if (res.toString().trim() === output.trim()) return 'ignore';\n return 'need-update';\n })\n .catch(() => 'write');\n\n if (status === 'ignore') continue;\n\n if (status === 'need-update') {\n const override = await ctx.io.confirmFileOverride({ path: outPath });\n if (!override) continue;\n }\n\n await fs.mkdir(path.dirname(outPath), { recursive: true });\n await fs.writeFile(outPath, output);\n ctx.io.onFileDownloaded({ path: outPath, file, component: comp });\n }\n\n for (const child of comp.$subComponents) {\n const stack = [...ctx.stack, child];\n const variables = { ...ctx.$variables };\n if (child.$registry.registryId !== comp.$registry.registryId) {\n const info = await child.$registry.fetchRegistryInfo();\n Object.assign(variables, info.variables);\n }\n Object.assign(variables, child.variables);\n\n await this.installComponent(child, { ...ctx, stack, $variables: variables });\n }\n }\n\n async install(name: string, io: IOInterface) {\n let downloaded: DownloadedComponent;\n // detect linked registry\n const rootInfo = await this.rootClient.fetchRegistryInfo();\n const registry = rootInfo.registries?.find((registry) => name.startsWith(`${registry}/`));\n\n if (registry) {\n downloaded = await this.download(\n name.slice(registry.length + 1),\n this.rootClient.createLinkedRegistryClient(registry),\n );\n } else {\n downloaded = await this.download(name, this.rootClient);\n }\n\n const allComponents = new Set<DownloadedComponent>();\n function scan(comp: DownloadedComponent) {\n if (allComponents.has(comp)) return;\n\n allComponents.add(comp);\n for (const child of comp.$subComponents) scan(child);\n }\n\n scan(downloaded);\n\n const pathToFile = new Map<string, File>();\n for (const comp of allComponents) {\n for (const file of comp.files) pathToFile.set(file.target ?? file.path, file);\n }\n\n const info = await downloaded.$registry.fetchRegistryInfo();\n await this.installComponent(downloaded, {\n pathToFile,\n io,\n $variables: { ...info.env, ...downloaded.variables },\n stack: [downloaded],\n });\n }\n\n async deps() {\n const manager = new DependencyManager(this.cwd);\n await manager.init(this.dependencies, this.devDependencies);\n return manager;\n }\n\n async onEnd() {\n const config = this.rootClient.config;\n if (config.commands.format) {\n await x(config.commands.format);\n }\n }\n\n /**\n * download component & its sub components\n */\n private async download(name: string, client: RegistryClient): Promise<DownloadedComponent> {\n return this.downloadCache.cached(\n JSON.stringify([client.registryId, name]),\n async (presolve) => {\n for (const plugin of this.plugins) {\n await plugin.beforeDownload?.({\n installer: this,\n name,\n });\n }\n\n const comp = await client.fetchComponent(name);\n const result: DownloadedComponent = {\n ...comp,\n $registry: client,\n $subComponents: [],\n };\n // place it before downloading child components to avoid recursive downloads\n presolve(result);\n\n result.$subComponents = await Promise.all(\n comp.subComponents.map((sub) => {\n if (typeof sub === 'string') return this.download(sub, client);\n\n let subClient: RegistryClient;\n if (this.rootClient instanceof HttpRegistryClient) {\n const baseUrl = new URL(sub.baseUrl, `${this.rootClient.baseUrl}/`).href;\n subClient =\n client instanceof HttpRegistryClient && client.baseUrl === baseUrl\n ? client\n : new HttpRegistryClient(baseUrl, client.config);\n } else {\n subClient = new HttpRegistryClient(sub.baseUrl, client.config);\n }\n\n return this.download(sub.component, subClient);\n }),\n );\n\n for (const plugin of this.plugins) {\n await plugin.afterDownload?.({\n installer: this,\n name,\n result,\n });\n }\n\n return result;\n },\n );\n }\n\n private async transform(\n file: File,\n component: DownloadedComponent,\n ctx: InstallContext,\n ): Promise<string> {\n const filePath = this.resolveOutputPath(file);\n const parsed = await parse(filePath, file.content);\n const s = new MagicString(file.content);\n const transformCtx: TransformContext = { installer: this, s, file, component, parsed, ...ctx };\n\n for (const plugin of this.plugins) {\n await plugin.beforeTransform?.(transformCtx);\n }\n\n // transform alias\n const prefix = '@/';\n\n transformSpecifiers(parsed.program, s, (specifier) => {\n for (const [k, v] of Object.entries(ctx.$variables)) {\n if (typeof v === 'string') specifier = specifier.replaceAll(`<${k}>`, v);\n }\n\n if (specifier.startsWith(prefix)) {\n const lookup = specifier.substring(prefix.length);\n const target = ctx.pathToFile.get(lookup);\n\n if (target) {\n specifier = toImportSpecifier(filePath, this.resolveOutputPath(target));\n } else {\n ctx.io.onWarn(`cannot find the referenced file of ${specifier}`);\n }\n }\n\n return specifier;\n });\n\n for (const plugin of this.plugins) {\n await plugin.afterTransform?.(transformCtx);\n }\n\n return s.toString();\n }\n\n private resolveOutputPath(file: File): string {\n const config = this.rootClient.config;\n const dir = (\n {\n components: config.aliases.componentsDir,\n block: config.aliases.blockDir,\n ui: config.aliases.uiDir,\n css: config.aliases.cssDir,\n lib: config.aliases.libDir,\n route: './',\n } as const\n )[file.type];\n if (file.target) {\n return path.resolve(this.cwd, config.baseDir, file.target.replace('<dir>', dir));\n }\n\n return path.resolve(this.cwd, config.baseDir, dir, path.basename(file.path));\n }\n}\n"],"mappings":";;;;;;;;;AAIA,eAAsB,oBAA6C;AAGjE,SAFe,MAAM,QAAQ,GAEd,QAAQ;;;;ACGzB,IAAa,oBAAb,MAA+B;CAM7B,YAAY,KAA8B;AAAb,OAAA,MAAA;uCALL,IAAI,KAAqB;sBACxB,EAAE;yBACC,EAAE;wBACG;;CAIjC,MAAM,KAAK,MAAqC,SAAwC;AACtF,OAAK,cAAc,OAAO;EAC1B,MAAM,kBAAkB,KAAK,KAAK,KAAK,KAAK,eAAe;EAC3D,MAAM,UAAU,MAAM,GACnB,SAAS,gBAAgB,CACzB,MAAM,QAAQ,IAAI,UAAU,CAAC,CAC7B,YAAY,KAAK;AAEpB,MAAI,YAAY,MAAM;GACpB,MAAM,SAAS,KAAK,MAAM,QAAQ;AAElC,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,QAAQ,gBAAgB,EAAE,CAAC,CAC7D,MAAK,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tB,IAAI,OAAO,QAAQ;GACnB,KAAK,OAAO,QAAQ;GACpB,KAAK,OAAO,QAAQ;GACpB,OAAO;GACR,CACD,KAAK;AACP,MAAI,KAAK,OACP,QAAO,KAAK,QAAQ,KAAK,KAAK,OAAO,SAAS,KAAK,OAAO,QAAQ,SAAS,IAAI,CAAC;AAGlF,SAAO,KAAK,QAAQ,KAAK,KAAK,OAAO,SAAS,KAAK,KAAK,SAAS,KAAK,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"installer-B3-my9zN.js","names":[],"sources":["../src/utils/get-package-manager.ts","../src/registry/installer/dep-manager.ts","../src/registry/installer/index.ts"],"sourcesContent":["import { detect, type AgentName } from 'package-manager-detector';\n\nexport type PackageManager = AgentName;\n\nexport async function getPackageManager(): Promise<PackageManager> {\n const result = await detect();\n\n return result?.name ?? 'npm';\n}\n","import fs from 'node:fs/promises';\nimport { getPackageManager, PackageManager } from '@/utils/get-package-manager';\nimport { x } from 'tinyexec';\nimport path from 'node:path';\n\ninterface PackageJsonType {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n}\n\nexport class DependencyManager {\n private installedDeps = new Map<string, string>();\n dependencies: string[] = [];\n devDependencies: string[] = [];\n packageManager: PackageManager = 'npm';\n\n constructor(private readonly cwd: string) {}\n\n async init(deps: Record<string, string | null>, devDeps: Record<string, string | null>) {\n this.installedDeps.clear();\n const packageJsonPath = path.join(this.cwd, 'package.json');\n const content = await fs\n .readFile(packageJsonPath)\n .then((res) => res.toString())\n .catch(() => null);\n\n if (content !== null) {\n const parsed = JSON.parse(content) as PackageJsonType;\n\n for (const [k, v] of Object.entries(parsed?.dependencies ?? {})) {\n this.installedDeps.set(k, v);\n }\n\n for (const [k, v] of Object.entries(parsed?.devDependencies ?? {})) {\n this.installedDeps.set(k, v);\n }\n }\n\n this.dependencies = this.resolveRequiredDependencies(deps);\n this.devDependencies = this.resolveRequiredDependencies(devDeps);\n this.packageManager = await getPackageManager();\n }\n\n private resolveRequiredDependencies(deps: Record<string, string | null>): string[] {\n return Object.entries(deps)\n .filter(([k]) => !this.installedDeps.has(k))\n .map(([k, v]) => (v === null || v.length === 0 ? k : `${k}@${v}`));\n }\n\n hasRequired() {\n return this.dependencies.length > 0 || this.devDependencies.length > 0;\n }\n\n async writeRequired() {\n const packageJsonPath = path.join(this.cwd, 'package.json');\n const content = await fs.readFile(packageJsonPath).catch(() => null);\n if (content === null) return false;\n\n const parsed = JSON.parse(content.toString()) as PackageJsonType;\n if (!parsed) return false;\n\n for (const dep of this.dependencies) {\n const { name, version } = parseDep(dep);\n parsed.dependencies ??= {};\n parsed.dependencies[name] ??= version;\n }\n\n for (const dep of this.devDependencies) {\n const { name, version } = parseDep(dep);\n parsed.devDependencies ??= {};\n parsed.devDependencies[name] ??= version;\n }\n\n await fs.writeFile(packageJsonPath, JSON.stringify(parsed, null, 2));\n }\n\n async installRequired() {\n if (this.dependencies.length > 0)\n await x(this.packageManager, ['install', ...this.dependencies]);\n if (this.devDependencies.length > 0)\n await x(this.packageManager, ['install', ...this.devDependencies, '-D']);\n }\n}\n\nfunction parseDep(dep: string) {\n const idx = dep.indexOf('@', 1);\n if (idx === -1) {\n return { name: dep, version: 'latest' };\n } else {\n return { name: dep.slice(0, idx), version: dep.slice(idx + 1) };\n }\n}\n","import path from 'node:path';\nimport fs from 'node:fs/promises';\nimport { typescriptExtensions } from '@/constants';\nimport { toImportSpecifier, transformSpecifiers } from '@/utils/ast';\nimport type { Component, File } from '@/registry/schema';\nimport { HttpRegistryClient, type RegistryClient } from '@/registry/client';\nimport { x } from 'tinyexec';\nimport { DependencyManager } from '@/registry/installer/dep-manager';\nimport { createCache } from '@/utils/cache';\nimport { parse, type ParseResult } from 'oxc-parser';\nimport MagicString from 'magic-string';\n\ninterface PluginContext {\n installer: ComponentInstaller;\n}\n\ninterface TransformContext extends PluginContext, InstallContext {\n s: MagicString;\n parsed: ParseResult;\n file: File;\n component: DownloadedComponent;\n}\n\ninterface InstallContext {\n pathToFile: Map<string, File>;\n io: IOInterface;\n /** full variables of the current component. */\n $variables: Record<string, unknown>;\n /** the last item is always the current component. */\n stack: DownloadedComponent[];\n}\n\ninterface DownloadedComponent extends Component {\n $subComponents: DownloadedComponent[];\n $registry: RegistryClient;\n}\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface ComponentInstallerPlugin {\n /**\n * transform file before writing (before default transformation)\n */\n beforeTransform?: (context: TransformContext) => Awaitable<void>;\n\n /**\n * transform file before writing (after default transformation)\n */\n afterTransform?: (context: TransformContext) => Awaitable<void>;\n\n /**\n * transform component before install\n */\n beforeInstall?: (\n comp: DownloadedComponent,\n context: InstallContext & PluginContext,\n ) => Awaitable<DownloadedComponent | undefined>;\n\n beforeDownload?: (\n context: PluginContext & {\n name: string;\n },\n ) => void | Promise<void>;\n\n afterDownload?: (\n context: PluginContext & {\n name: string;\n result: DownloadedComponent;\n },\n ) => void | Promise<void>;\n}\n\nexport interface IOInterface {\n onWarn: (message: string) => void;\n confirmFileOverride: (options: { path: string }) => Promise<boolean>;\n onFileDownloaded: (options: { path: string; file: File; component: Component }) => void;\n}\n\nexport interface ComponentInstallerOptions {\n plugins?: ComponentInstallerPlugin[];\n cwd?: string;\n}\n\nexport class ComponentInstaller {\n private readonly installedFiles = new Set<string>();\n private readonly downloadCache = createCache<DownloadedComponent>();\n private readonly cwd: string;\n private readonly plugins: ComponentInstallerPlugin[];\n readonly dependencies: Record<string, string | null> = {};\n readonly devDependencies: Record<string, string | null> = {};\n\n constructor(\n private readonly rootClient: RegistryClient,\n options: ComponentInstallerOptions = {},\n ) {\n this.cwd = options.cwd ?? process.cwd();\n this.plugins = options.plugins ?? [];\n }\n\n private async installComponent(comp: DownloadedComponent, ctx: InstallContext) {\n // avoid circular refs\n if (ctx.stack.indexOf(comp) !== ctx.stack.length - 1) return;\n\n const pluginCtx = { installer: this, ...ctx };\n for (const plugin of this.plugins) {\n comp = (await plugin.beforeInstall?.(comp, pluginCtx)) ?? comp;\n }\n\n Object.assign(this.dependencies, comp.dependencies);\n Object.assign(this.devDependencies, comp.devDependencies);\n\n for (const file of comp.files) {\n const outPath = this.resolveOutputPath(file);\n if (this.installedFiles.has(outPath)) continue;\n this.installedFiles.add(outPath);\n\n const output = typescriptExtensions.includes(path.extname(outPath))\n ? await this.transform(file, comp, ctx)\n : file.content;\n\n const status = await fs\n .readFile(outPath)\n .then((res) => {\n if (res.toString().trim() === output.trim()) return 'ignore';\n return 'need-update';\n })\n .catch(() => 'write');\n\n if (status === 'ignore') continue;\n\n if (status === 'need-update') {\n const override = await ctx.io.confirmFileOverride({ path: outPath });\n if (!override) continue;\n }\n\n await fs.mkdir(path.dirname(outPath), { recursive: true });\n await fs.writeFile(outPath, output);\n ctx.io.onFileDownloaded({ path: outPath, file, component: comp });\n }\n\n for (const child of comp.$subComponents) {\n const stack = [...ctx.stack, child];\n const variables = { ...ctx.$variables };\n if (child.$registry.registryId !== comp.$registry.registryId) {\n const info = await child.$registry.fetchRegistryInfo();\n Object.assign(variables, info.variables);\n }\n Object.assign(variables, child.variables);\n\n await this.installComponent(child, { ...ctx, stack, $variables: variables });\n }\n }\n\n async install(name: string, io: IOInterface) {\n let downloaded: DownloadedComponent;\n // detect linked registry\n const rootInfo = await this.rootClient.fetchRegistryInfo();\n const registry = rootInfo.registries?.find((registry) => name.startsWith(`${registry}/`));\n\n if (registry) {\n downloaded = await this.download(\n name.slice(registry.length + 1),\n this.rootClient.createLinkedRegistryClient(registry),\n );\n } else {\n downloaded = await this.download(name, this.rootClient);\n }\n\n const allComponents = new Set<DownloadedComponent>();\n function scan(comp: DownloadedComponent) {\n if (allComponents.has(comp)) return;\n\n allComponents.add(comp);\n for (const child of comp.$subComponents) scan(child);\n }\n\n scan(downloaded);\n\n const pathToFile = new Map<string, File>();\n for (const comp of allComponents) {\n for (const file of comp.files) pathToFile.set(file.target ?? file.path, file);\n }\n\n const info = await downloaded.$registry.fetchRegistryInfo();\n await this.installComponent(downloaded, {\n pathToFile,\n io,\n $variables: { ...info.env, ...downloaded.variables },\n stack: [downloaded],\n });\n }\n\n async deps() {\n const manager = new DependencyManager(this.cwd);\n await manager.init(this.dependencies, this.devDependencies);\n return manager;\n }\n\n async onEnd() {\n const config = this.rootClient.config;\n if (config.commands.format) {\n await x(config.commands.format);\n }\n }\n\n /**\n * download component & its sub components\n */\n private async download(name: string, client: RegistryClient): Promise<DownloadedComponent> {\n return this.downloadCache.cached(\n JSON.stringify([client.registryId, name]),\n async (presolve) => {\n for (const plugin of this.plugins) {\n await plugin.beforeDownload?.({\n installer: this,\n name,\n });\n }\n\n const comp = await client.fetchComponent(name);\n const result: DownloadedComponent = {\n ...comp,\n $registry: client,\n $subComponents: [],\n };\n // place it before downloading child components to avoid recursive downloads\n presolve(result);\n\n result.$subComponents = await Promise.all(\n comp.subComponents.map((sub) => {\n if (typeof sub === 'string') return this.download(sub, client);\n\n let subClient: RegistryClient;\n if (this.rootClient instanceof HttpRegistryClient) {\n const baseUrl = new URL(sub.baseUrl, `${this.rootClient.baseUrl}/`).href;\n subClient =\n client instanceof HttpRegistryClient && client.baseUrl === baseUrl\n ? client\n : new HttpRegistryClient(baseUrl, client.config);\n } else {\n subClient = new HttpRegistryClient(sub.baseUrl, client.config);\n }\n\n return this.download(sub.component, subClient);\n }),\n );\n\n for (const plugin of this.plugins) {\n await plugin.afterDownload?.({\n installer: this,\n name,\n result,\n });\n }\n\n return result;\n },\n );\n }\n\n private async transform(\n file: File,\n component: DownloadedComponent,\n ctx: InstallContext,\n ): Promise<string> {\n const filePath = this.resolveOutputPath(file);\n const parsed = await parse(filePath, file.content);\n const s = new MagicString(file.content);\n const transformCtx: TransformContext = { installer: this, s, file, component, parsed, ...ctx };\n\n for (const plugin of this.plugins) {\n await plugin.beforeTransform?.(transformCtx);\n }\n\n // transform alias\n const prefix = '@/';\n\n transformSpecifiers(parsed.program, s, (specifier) => {\n for (const [k, v] of Object.entries(ctx.$variables)) {\n if (typeof v === 'string') specifier = specifier.replaceAll(`<${k}>`, v);\n }\n\n if (specifier.startsWith(prefix)) {\n const lookup = specifier.substring(prefix.length);\n const target = ctx.pathToFile.get(lookup);\n\n if (target) {\n specifier = toImportSpecifier(filePath, this.resolveOutputPath(target));\n } else {\n ctx.io.onWarn(`cannot find the referenced file of ${specifier}`);\n }\n }\n\n return specifier;\n });\n\n for (const plugin of this.plugins) {\n await plugin.afterTransform?.(transformCtx);\n }\n\n return s.toString();\n }\n\n private resolveOutputPath(file: File): string {\n const config = this.rootClient.config;\n const dir = (\n {\n components: config.aliases.componentsDir,\n ui: config.aliases.uiDir,\n css: config.aliases.cssDir,\n lib: config.aliases.libDir,\n layout: config.aliases.layoutDir,\n route: './',\n } as const\n )[file.type];\n if (file.target) {\n return path.resolve(this.cwd, config.baseDir, file.target.replace('<dir>', dir));\n }\n\n return path.resolve(this.cwd, config.baseDir, dir, path.basename(file.path));\n }\n}\n"],"mappings":";;;;;;;;;AAIA,eAAsB,oBAA6C;AAGjE,SAFe,MAAM,QAAQ,GAEd,QAAQ;;;;ACGzB,IAAa,oBAAb,MAA+B;CAM7B,YAAY,KAA8B;AAAb,OAAA,MAAA;uCALL,IAAI,KAAqB;sBACxB,EAAE;yBACC,EAAE;wBACG;;CAIjC,MAAM,KAAK,MAAqC,SAAwC;AACtF,OAAK,cAAc,OAAO;EAC1B,MAAM,kBAAkB,KAAK,KAAK,KAAK,KAAK,eAAe;EAC3D,MAAM,UAAU,MAAM,GACnB,SAAS,gBAAgB,CACzB,MAAM,QAAQ,IAAI,UAAU,CAAC,CAC7B,YAAY,KAAK;AAEpB,MAAI,YAAY,MAAM;GACpB,MAAM,SAAS,KAAK,MAAM,QAAQ;AAElC,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,QAAQ,gBAAgB,EAAE,CAAC,CAC7D,MAAK,cAAc,IAAI,GAAG,EAAE;AAG9B,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,QAAQ,mBAAmB,EAAE,CAAC,CAChE,MAAK,cAAc,IAAI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AAO,KAAK,QAAQ,KAAK,KAAK,OAAO,SAAS,KAAK,OAAO,QAAQ,SAAS,IAAI,CAAC;AAGlF,SAAO,KAAK,QAAQ,KAAK,KAAK,OAAO,SAAS,KAAK,KAAK,SAAS,KAAK,KAAK,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as DownloadedRegistryInfo, i as Component } from "../schema-
|
|
2
|
-
import { n as LoadedConfig } from "../config-
|
|
1
|
+
import { a as DownloadedRegistryInfo, i as Component } from "../schema-DrgqlhpT.js";
|
|
2
|
+
import { n as LoadedConfig } from "../config-Dyass4D9.js";
|
|
3
3
|
|
|
4
4
|
//#region src/registry/client.d.ts
|
|
5
5
|
interface RegistryClient {
|
|
@@ -21,6 +21,11 @@ declare class HttpRegistryClient implements RegistryClient {
|
|
|
21
21
|
title?: string | undefined;
|
|
22
22
|
description?: string | undefined;
|
|
23
23
|
}[];
|
|
24
|
+
unlistedIndexes: {
|
|
25
|
+
name: string;
|
|
26
|
+
title?: string | undefined;
|
|
27
|
+
description?: string | undefined;
|
|
28
|
+
}[];
|
|
24
29
|
variables?: Record<string, {
|
|
25
30
|
description?: string | undefined;
|
|
26
31
|
}> | undefined;
|
|
@@ -30,7 +35,7 @@ declare class HttpRegistryClient implements RegistryClient {
|
|
|
30
35
|
fetchComponent(name: string): Promise<{
|
|
31
36
|
name: string;
|
|
32
37
|
files: {
|
|
33
|
-
type: "components" | "lib" | "css" | "route" | "ui" | "
|
|
38
|
+
type: "components" | "lib" | "css" | "route" | "ui" | "layout";
|
|
34
39
|
path: string;
|
|
35
40
|
content: string;
|
|
36
41
|
target?: string | undefined;
|
|
@@ -61,6 +66,11 @@ declare class LocalRegistryClient implements RegistryClient {
|
|
|
61
66
|
title?: string | undefined;
|
|
62
67
|
description?: string | undefined;
|
|
63
68
|
}[];
|
|
69
|
+
unlistedIndexes: {
|
|
70
|
+
name: string;
|
|
71
|
+
title?: string | undefined;
|
|
72
|
+
description?: string | undefined;
|
|
73
|
+
}[];
|
|
64
74
|
variables?: Record<string, {
|
|
65
75
|
description?: string | undefined;
|
|
66
76
|
}> | undefined;
|
|
@@ -70,7 +80,7 @@ declare class LocalRegistryClient implements RegistryClient {
|
|
|
70
80
|
fetchComponent(name: string): Promise<{
|
|
71
81
|
name: string;
|
|
72
82
|
files: {
|
|
73
|
-
type: "components" | "lib" | "css" | "route" | "ui" | "
|
|
83
|
+
type: "components" | "lib" | "css" | "route" | "ui" | "layout";
|
|
74
84
|
path: string;
|
|
75
85
|
content: string;
|
|
76
86
|
target?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","names":[],"sources":["../../src/registry/client.ts"],"mappings":";;;;UAWiB,cAAA;EAAA,SACN,UAAA;EAAA,SACA,MAAA,EAAQ,YAAA;EACjB,iBAAA,QAAyB,OAAA,CAAQ,sBAAA;EACjC,cAAA,GAAiB,IAAA,aAAiB,OAAA,CAAQ,SAAA;EAC1C,YAAA,GAAe,IAAA,aAAiB,OAAA;EAChC,0BAAA,GAA6B,YAAA,aAAyB,cAAA;AAAA;AAAA,cAK3C,kBAAA,YAA8B,cAAA;EAAA,SAI9B,OAAA;EAAA,SACA,MAAA,EAAQ,YAAA;EAAA,SAJV,UAAA;cAGE,OAAA,UACA,MAAA,EAAQ,YAAA;EAKb,iBAAA,CAAkB,OAAA,YAAsB,OAAA
|
|
1
|
+
{"version":3,"file":"client.d.ts","names":[],"sources":["../../src/registry/client.ts"],"mappings":";;;;UAWiB,cAAA;EAAA,SACN,UAAA;EAAA,SACA,MAAA,EAAQ,YAAA;EACjB,iBAAA,QAAyB,OAAA,CAAQ,sBAAA;EACjC,cAAA,GAAiB,IAAA,aAAiB,OAAA,CAAQ,SAAA;EAC1C,YAAA,GAAe,IAAA,aAAiB,OAAA;EAChC,0BAAA,GAA6B,YAAA,aAAyB,cAAA;AAAA;AAAA,cAK3C,kBAAA,YAA8B,cAAA;EAAA,SAI9B,OAAA;EAAA,SACA,MAAA,EAAQ,YAAA;EAAA,SAJV,UAAA;cAGE,OAAA,UACA,MAAA,EAAQ,YAAA;EAKb,iBAAA,CAAkB,OAAA,YAAsB,OAAA;;;;;;;;;;;;;;;;;EAaxC,cAAA,CAAe,IAAA,WAAY,OAAA;;;;;;;;;;;;;;;;;;;EAgB3B,YAAA,CAAa,IAAA,WAAY,OAAA;EAM/B,0BAAA,CAA2B,IAAA,WAAY,kBAAA;AAAA;AAAA,cAK5B,mBAAA,YAA+B,cAAA;EAAA,iBAKvB,GAAA;EAAA,SACR,MAAA,EAAQ,YAAA;EAAA,SALV,UAAA;EAAA,QACD,YAAA;cAGW,GAAA,UACR,MAAA,EAAQ,YAAA;EAKb,iBAAA,CAAkB,GAAA,YAAc,OAAA;;;;;;;;;;;;;;;;;EAgBhC,cAAA,CAAe,IAAA,WAAY,OAAA;;;;;;;;;;;;;;;;;;;EAY3B,YAAA,CAAa,IAAA,WAAY,OAAA;EAU/B,0BAAA,CAA2B,IAAA,WAAY,mBAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Component, o as File } from "../../schema-
|
|
1
|
+
import { i as Component, o as File } from "../../schema-DrgqlhpT.js";
|
|
2
2
|
import { RegistryClient } from "../client.js";
|
|
3
3
|
import { ParseResult } from "oxc-parser";
|
|
4
4
|
import { AgentName } from "package-manager-detector";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as DownloadedRegistryInfo, c as componentSchema, d as indexSchema, f as namespaces, i as Component, l as fileSchema, n as CompiledFile, o as File, p as registryInfoSchema, r as CompiledRegistryInfo, s as NamespaceType, t as CompiledComponent, u as httpSubComponent } from "../schema-
|
|
1
|
+
import { a as DownloadedRegistryInfo, c as componentSchema, d as indexSchema, f as namespaces, i as Component, l as fileSchema, n as CompiledFile, o as File, p as registryInfoSchema, r as CompiledRegistryInfo, s as NamespaceType, t as CompiledComponent, u as httpSubComponent } from "../schema-DrgqlhpT.js";
|
|
2
2
|
export { CompiledComponent, CompiledFile, CompiledRegistryInfo, Component, DownloadedRegistryInfo, File, NamespaceType, componentSchema, fileSchema, httpSubComponent, indexSchema, namespaces, registryInfoSchema };
|
package/dist/registry/schema.js
CHANGED
|
@@ -6,7 +6,7 @@ const namespaces = [
|
|
|
6
6
|
"css",
|
|
7
7
|
"route",
|
|
8
8
|
"ui",
|
|
9
|
-
"
|
|
9
|
+
"layout"
|
|
10
10
|
];
|
|
11
11
|
const indexSchema = z.object({
|
|
12
12
|
name: z.string(),
|
|
@@ -38,6 +38,7 @@ const registryInfoSchema = z.object({
|
|
|
38
38
|
variables: z.record(z.string(), z.object({ description: z.string().optional() })).optional(),
|
|
39
39
|
env: z.record(z.string(), z.unknown()).optional(),
|
|
40
40
|
indexes: z.array(indexSchema).default([]),
|
|
41
|
+
unlistedIndexes: z.array(indexSchema).default([]),
|
|
41
42
|
registries: z.array(z.string()).optional()
|
|
42
43
|
});
|
|
43
44
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/registry/schema.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport type NamespaceType = (typeof namespaces)[number];\nexport type CompiledFile = z.input<typeof fileSchema>;\nexport type CompiledComponent = z.input<typeof componentSchema>;\nexport type CompiledRegistryInfo = z.input<typeof registryInfoSchema>;\nexport type DownloadedRegistryInfo = z.output<typeof registryInfoSchema>;\nexport type File = z.output<typeof fileSchema>;\nexport type Component = z.output<typeof componentSchema>;\n\nexport const namespaces = ['components', 'lib', 'css', 'route', 'ui', '
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/registry/schema.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport type NamespaceType = (typeof namespaces)[number];\nexport type CompiledFile = z.input<typeof fileSchema>;\nexport type CompiledComponent = z.input<typeof componentSchema>;\nexport type CompiledRegistryInfo = z.input<typeof registryInfoSchema>;\nexport type DownloadedRegistryInfo = z.output<typeof registryInfoSchema>;\nexport type File = z.output<typeof fileSchema>;\nexport type Component = z.output<typeof componentSchema>;\n\nexport const namespaces = ['components', 'lib', 'css', 'route', 'ui', 'layout'] as const;\n\nexport const indexSchema = z.object({\n name: z.string(),\n title: z.string().optional(),\n description: z.string().optional(),\n});\n\nexport const fileSchema = z.object({\n type: z.literal(namespaces),\n path: z.string(),\n target: z.string().optional(),\n content: z.string(),\n});\n\nexport const httpSubComponent = z.object({\n type: z.literal('http'),\n baseUrl: z.string(),\n component: z.string(),\n});\n\nexport const componentSchema = z.object({\n name: z.string(),\n title: z.string().optional(),\n description: z.string().optional(),\n files: z.array(fileSchema),\n dependencies: z.record(z.string(), z.string().or(z.null())),\n devDependencies: z.record(z.string(), z.string().or(z.null())),\n /**\n * list of sub components, either local (component name) or remote (registry info & component name)\n */\n subComponents: z.array(z.string().or(httpSubComponent)).default([]),\n\n /**\n * override variables for the current component & its sub components.\n *\n * this is powerful to customise how sub components are installed vs. installing them directly.\n */\n variables: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const registryInfoSchema = z.object({\n /**\n * define metadata for variables, variables can be referenced in the target path of component files, or in plugins.\n */\n variables: z\n .record(\n z.string(),\n z.object({\n description: z.string().optional(),\n }),\n )\n .optional(),\n /**\n * override variables for all components.\n */\n env: z.record(z.string(), z.unknown()).optional(),\n indexes: z.array(indexSchema).default([]),\n unlistedIndexes: z.array(indexSchema).default([]),\n\n registries: z.array(z.string()).optional(),\n});\n"],"mappings":";;AAUA,MAAa,aAAa;CAAC;CAAc;CAAO;CAAO;CAAS;CAAM;CAAS;AAE/E,MAAa,cAAc,EAAE,OAAO;CAClC,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,QAAQ,CAAC,UAAU;CAC5B,aAAa,EAAE,QAAQ,CAAC,UAAU;CACnC,CAAC;AAEF,MAAa,aAAa,EAAE,OAAO;CACjC,MAAM,EAAE,QAAQ,WAAW;CAC3B,MAAM,EAAE,QAAQ;CAChB,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,SAAS,EAAE,QAAQ;CACpB,CAAC;AAEF,MAAa,mBAAmB,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,OAAO;CACvB,SAAS,EAAE,QAAQ;CACnB,WAAW,EAAE,QAAQ;CACtB,CAAC;AAEF,MAAa,kBAAkB,EAAE,OAAO;CACtC,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,QAAQ,CAAC,UAAU;CAC5B,aAAa,EAAE,QAAQ,CAAC,UAAU;CAClC,OAAO,EAAE,MAAM,WAAW;CAC1B,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;CAC3D,iBAAiB,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;CAI9D,eAAe,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,iBAAiB,CAAC,CAAC,QAAQ,EAAE,CAAC;CAOnE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU;CACxD,CAAC;AAEF,MAAa,qBAAqB,EAAE,OAAO;CAIzC,WAAW,EACR,OACC,EAAE,QAAQ,EACV,EAAE,OAAO,EACP,aAAa,EAAE,QAAQ,CAAC,UAAU,EACnC,CAAC,CACH,CACA,UAAU;CAIb,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU;CACjD,SAAS,EAAE,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC;CACzC,iBAAiB,EAAE,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC;CAEjD,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CAC3C,CAAC"}
|
package/dist/schema/default.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"$schema":{"default":"node_modules/@fumadocs/cli/dist/schema/default.json","type":"string"},"aliases":{"default":{"uiDir":"./components/ui","componentsDir":"./components","
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"$schema":{"default":"node_modules/@fumadocs/cli/dist/schema/default.json","type":"string"},"aliases":{"default":{"uiDir":"./components/ui","componentsDir":"./components","layoutDir":"./layouts","cssDir":"./styles","libDir":"./lib"},"type":"object","properties":{"uiDir":{"default":"./components/ui","type":"string"},"componentsDir":{"default":"./components/ui","type":"string"},"layoutDir":{"default":"./layouts","type":"string"},"cssDir":{"default":"./components","type":"string"},"libDir":{"default":"./lib","type":"string"}}},"baseDir":{"default":"","type":"string"},"uiLibrary":{"default":"radix-ui","type":"string","enum":["radix-ui","base-ui"]},"commands":{"default":{},"type":"object","properties":{"format":{"type":"string"}}}}}
|
package/dist/schema/src.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"$schema":{"default":"node_modules/@fumadocs/cli/dist/schema/src.json","type":"string"},"aliases":{"default":{"uiDir":"./components/ui","componentsDir":"./components","
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"$schema":{"default":"node_modules/@fumadocs/cli/dist/schema/src.json","type":"string"},"aliases":{"default":{"uiDir":"./components/ui","componentsDir":"./components","layoutDir":"./layouts","cssDir":"./styles","libDir":"./lib"},"type":"object","properties":{"uiDir":{"default":"./components/ui","type":"string"},"componentsDir":{"default":"./components/ui","type":"string"},"layoutDir":{"default":"./layouts","type":"string"},"cssDir":{"default":"./components","type":"string"},"libDir":{"default":"./lib","type":"string"}}},"baseDir":{"default":"src","type":"string"},"uiLibrary":{"default":"radix-ui","type":"string","enum":["radix-ui","base-ui"]},"commands":{"default":{},"type":"object","properties":{"format":{"type":"string"}}}}}
|
|
@@ -8,14 +8,14 @@ type CompiledRegistryInfo = z.input<typeof registryInfoSchema>;
|
|
|
8
8
|
type DownloadedRegistryInfo = z.output<typeof registryInfoSchema>;
|
|
9
9
|
type File = z.output<typeof fileSchema>;
|
|
10
10
|
type Component = z.output<typeof componentSchema>;
|
|
11
|
-
declare const namespaces: readonly ["components", "lib", "css", "route", "ui", "
|
|
11
|
+
declare const namespaces: readonly ["components", "lib", "css", "route", "ui", "layout"];
|
|
12
12
|
declare const indexSchema: z.ZodObject<{
|
|
13
13
|
name: z.ZodString;
|
|
14
14
|
title: z.ZodOptional<z.ZodString>;
|
|
15
15
|
description: z.ZodOptional<z.ZodString>;
|
|
16
16
|
}, z.core.$strip>;
|
|
17
17
|
declare const fileSchema: z.ZodObject<{
|
|
18
|
-
type: z.ZodLiteral<"components" | "lib" | "css" | "route" | "ui" | "
|
|
18
|
+
type: z.ZodLiteral<"components" | "lib" | "css" | "route" | "ui" | "layout">;
|
|
19
19
|
path: z.ZodString;
|
|
20
20
|
target: z.ZodOptional<z.ZodString>;
|
|
21
21
|
content: z.ZodString;
|
|
@@ -30,7 +30,7 @@ declare const componentSchema: z.ZodObject<{
|
|
|
30
30
|
title: z.ZodOptional<z.ZodString>;
|
|
31
31
|
description: z.ZodOptional<z.ZodString>;
|
|
32
32
|
files: z.ZodArray<z.ZodObject<{
|
|
33
|
-
type: z.ZodLiteral<"components" | "lib" | "css" | "route" | "ui" | "
|
|
33
|
+
type: z.ZodLiteral<"components" | "lib" | "css" | "route" | "ui" | "layout">;
|
|
34
34
|
path: z.ZodString;
|
|
35
35
|
target: z.ZodOptional<z.ZodString>;
|
|
36
36
|
content: z.ZodString;
|
|
@@ -54,8 +54,13 @@ declare const registryInfoSchema: z.ZodObject<{
|
|
|
54
54
|
title: z.ZodOptional<z.ZodString>;
|
|
55
55
|
description: z.ZodOptional<z.ZodString>;
|
|
56
56
|
}, z.core.$strip>>>;
|
|
57
|
+
unlistedIndexes: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
58
|
+
name: z.ZodString;
|
|
59
|
+
title: z.ZodOptional<z.ZodString>;
|
|
60
|
+
description: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, z.core.$strip>>>;
|
|
57
62
|
registries: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
58
63
|
}, z.core.$strip>;
|
|
59
64
|
//#endregion
|
|
60
65
|
export { DownloadedRegistryInfo as a, componentSchema as c, indexSchema as d, namespaces as f, Component as i, fileSchema as l, CompiledFile as n, File as o, registryInfoSchema as p, CompiledRegistryInfo as r, NamespaceType as s, CompiledComponent as t, httpSubComponent as u };
|
|
61
|
-
//# sourceMappingURL=schema-
|
|
66
|
+
//# sourceMappingURL=schema-DrgqlhpT.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-
|
|
1
|
+
{"version":3,"file":"schema-DrgqlhpT.d.ts","names":[],"sources":["../src/registry/schema.ts"],"mappings":";;;KAEY,aAAA,WAAwB,UAAA;AAAA,KACxB,YAAA,GAAe,CAAA,CAAE,KAAA,QAAa,UAAA;AAAA,KAC9B,iBAAA,GAAoB,CAAA,CAAE,KAAA,QAAa,eAAA;AAAA,KACnC,oBAAA,GAAuB,CAAA,CAAE,KAAA,QAAa,kBAAA;AAAA,KACtC,sBAAA,GAAyB,CAAA,CAAE,MAAA,QAAc,kBAAA;AAAA,KACzC,IAAA,GAAO,CAAA,CAAE,MAAA,QAAc,UAAA;AAAA,KACvB,SAAA,GAAY,CAAA,CAAE,MAAA,QAAc,eAAA;AAAA,cAE3B,UAAA;AAAA,cAEA,WAAA,EAAW,CAAA,CAAA,SAAA;;;;;cAMX,UAAA,EAAU,CAAA,CAAA,SAAA;;;;;;cAOV,gBAAA,EAAgB,CAAA,CAAA,SAAA;;;;;cAMhB,eAAA,EAAe,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;cAoBf,kBAAA,EAAkB,CAAA,CAAA,SAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fumadocs/cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "The CLI tool for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@oxc-project/types": "^0.121.0",
|
|
44
44
|
"@types/node": "25.5.0",
|
|
45
|
-
"shadcn": "4.0
|
|
45
|
+
"shadcn": "4.1.0",
|
|
46
46
|
"tsdown": "0.21.4",
|
|
47
47
|
"eslint-config-custom": "0.0.0",
|
|
48
48
|
"tsconfig": "0.0.0"
|