fuma-content 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +18 -0
- package/dist/build-mdx-Q4RMDWYK.js +8 -0
- package/dist/bun/index.d.ts +16 -0
- package/dist/bun/index.js +36 -0
- package/dist/bun-DMNX4PBC.js +40 -0
- package/dist/chunk-3VQS3KSP.js +39 -0
- package/dist/chunk-4RMSJCK2.js +50 -0
- package/dist/chunk-6XDQG2GV.js +17 -0
- package/dist/chunk-AMBGM4OK.js +412 -0
- package/dist/chunk-BTRE6MOX.js +16 -0
- package/dist/chunk-E4HRKSP4.js +24 -0
- package/dist/chunk-ERBMAQYP.js +33 -0
- package/dist/chunk-IGLM4N4P.js +34 -0
- package/dist/chunk-LDBQ66H3.js +38 -0
- package/dist/chunk-M72VQL5M.js +40 -0
- package/dist/chunk-OUJENWQ4.js +45 -0
- package/dist/chunk-PNA5UGSL.js +104 -0
- package/dist/chunk-RMSV4HP6.js +85 -0
- package/dist/chunk-RXR7OL76.js +37 -0
- package/dist/chunk-VWJKRQZR.js +19 -0
- package/dist/chunk-Z7KHD7MS.js +368 -0
- package/dist/collections/handlers/fs.d.ts +10 -0
- package/dist/collections/handlers/fs.js +6 -0
- package/dist/collections/index.d.ts +10 -0
- package/dist/collections/index.js +6 -0
- package/dist/collections/mdx/loader-webpack.d.ts +17 -0
- package/dist/collections/mdx/loader-webpack.js +38 -0
- package/dist/collections/mdx/runtime-browser.d.ts +44 -0
- package/dist/collections/mdx/runtime-browser.js +74 -0
- package/dist/collections/mdx/runtime-dynamic.d.ts +42 -0
- package/dist/collections/mdx/runtime-dynamic.js +94 -0
- package/dist/collections/mdx/runtime.d.ts +69 -0
- package/dist/collections/mdx/runtime.js +45 -0
- package/dist/collections/mdx.d.ts +10 -0
- package/dist/collections/mdx.js +287 -0
- package/dist/collections/meta/loader-webpack.d.ts +17 -0
- package/dist/collections/meta/loader-webpack.js +41 -0
- package/dist/collections/meta/runtime.d.ts +19 -0
- package/dist/collections/meta/runtime.js +18 -0
- package/dist/collections/meta.d.ts +10 -0
- package/dist/collections/meta.js +166 -0
- package/dist/collections/runtime/file-store.d.ts +19 -0
- package/dist/collections/runtime/file-store.js +7 -0
- package/dist/collections/runtime/store.d.ts +28 -0
- package/dist/collections/runtime/store.js +6 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +7 -0
- package/dist/core-DxnSmTRe.d.ts +411 -0
- package/dist/index.d.ts +13 -31
- package/dist/index.js +0 -53
- package/dist/load-from-file-MLL4WQ5J.js +7 -0
- package/dist/loader-T756NSCS.js +7 -0
- package/dist/loader-VGDLYG4T.js +7 -0
- package/dist/next/index.cjs +571 -0
- package/dist/next/index.d.ts +27 -0
- package/dist/next/index.js +99 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +46 -0
- package/dist/node-DCMYL4DL.js +34 -0
- package/dist/plugins/git.d.ts +10 -0
- package/dist/plugins/git.js +70 -0
- package/dist/plugins/json-schema.d.ts +10 -0
- package/dist/plugins/json-schema.js +59 -0
- package/dist/plugins/with-loader/index.d.ts +61 -0
- package/dist/plugins/with-loader/index.js +6 -0
- package/dist/plugins/with-loader/webpack.d.ts +27 -0
- package/dist/plugins/with-loader/webpack.js +11 -0
- package/dist/vite/index.d.ts +33 -0
- package/dist/vite/index.js +60 -0
- package/dist/vite-QCUPZHHB.js +32 -0
- package/package.json +103 -36
- package/dist/internal.d.ts +0 -108
- package/dist/internal.js +0 -384
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withLoader
|
|
3
|
+
} from "../chunk-ERBMAQYP.js";
|
|
4
|
+
import {
|
|
5
|
+
buildFileHandler
|
|
6
|
+
} from "../chunk-E4HRKSP4.js";
|
|
7
|
+
import {
|
|
8
|
+
createCollection
|
|
9
|
+
} from "../chunk-BTRE6MOX.js";
|
|
10
|
+
|
|
11
|
+
// src/collections/meta.ts
|
|
12
|
+
import path from "path";
|
|
13
|
+
var metaTypeInfo = {
|
|
14
|
+
id: "meta",
|
|
15
|
+
plugins: [plugin()]
|
|
16
|
+
};
|
|
17
|
+
function defineMeta(config) {
|
|
18
|
+
return createCollection(metaTypeInfo, (collection, options) => {
|
|
19
|
+
const handlers = collection.handlers;
|
|
20
|
+
handlers.fs = buildFileHandler(options, config, ["json", "yaml"]);
|
|
21
|
+
handlers.meta = {
|
|
22
|
+
schema: config.schema
|
|
23
|
+
};
|
|
24
|
+
handlers["json-schema"] = {
|
|
25
|
+
async create() {
|
|
26
|
+
const { z, ZodType } = await import("zod");
|
|
27
|
+
if (config.schema instanceof ZodType)
|
|
28
|
+
return z.toJSONSchema(config.schema, {
|
|
29
|
+
io: "input",
|
|
30
|
+
unrepresentable: "any"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function plugin() {
|
|
37
|
+
const metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
38
|
+
async function generateCollectionStore(context, collection) {
|
|
39
|
+
const fsHandler = collection.handlers.fs;
|
|
40
|
+
if (!fsHandler) return;
|
|
41
|
+
const { codegen, core } = context;
|
|
42
|
+
codegen.addNamedImport(
|
|
43
|
+
["metaStore"],
|
|
44
|
+
"fuma-content/collections/meta/runtime"
|
|
45
|
+
);
|
|
46
|
+
codegen.addNamedImport(
|
|
47
|
+
["default as Config"],
|
|
48
|
+
codegen.formatImportPath(core.getOptions().configPath),
|
|
49
|
+
true
|
|
50
|
+
);
|
|
51
|
+
const base2 = path.relative(process.cwd(), fsHandler.dir);
|
|
52
|
+
const glob = await codegen.generateGlobImport(fsHandler.patterns, {
|
|
53
|
+
query: {
|
|
54
|
+
collection: collection.name,
|
|
55
|
+
workspace: context.workspace
|
|
56
|
+
},
|
|
57
|
+
import: "default",
|
|
58
|
+
base: fsHandler.dir,
|
|
59
|
+
eager: true
|
|
60
|
+
});
|
|
61
|
+
const initializer = `metaStore<typeof Config, "${collection.name}">("${collection.name}", "${base2}", ${glob})`;
|
|
62
|
+
codegen.push(`export const ${collection.name} = ${initializer};`);
|
|
63
|
+
}
|
|
64
|
+
const base = {
|
|
65
|
+
name: "meta",
|
|
66
|
+
configureServer(server) {
|
|
67
|
+
if (!server.watcher) return;
|
|
68
|
+
server.watcher.on("all", async (event, file) => {
|
|
69
|
+
if (event === "change") return;
|
|
70
|
+
const updatedCollection = this.core.getCollections().find((collection) => {
|
|
71
|
+
const handlers = collection.handlers;
|
|
72
|
+
if (!handlers.meta || !handlers.fs) return false;
|
|
73
|
+
return handlers.fs.hasFile(file);
|
|
74
|
+
});
|
|
75
|
+
if (!updatedCollection) return;
|
|
76
|
+
await this.core.emit({
|
|
77
|
+
filterPlugin: (plugin2) => plugin2.name === "meta",
|
|
78
|
+
filterWorkspace: () => false,
|
|
79
|
+
write: true
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
emit() {
|
|
84
|
+
return Promise.all([
|
|
85
|
+
this.createCodeGenerator("meta.ts", async (ctx) => {
|
|
86
|
+
for (const collection of this.core.getCollections()) {
|
|
87
|
+
await generateCollectionStore(ctx, collection);
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
]);
|
|
91
|
+
},
|
|
92
|
+
next: {
|
|
93
|
+
config(nextConfig) {
|
|
94
|
+
const { configPath, outDir } = this.core.getOptions();
|
|
95
|
+
const loaderPath = "fuma-content/collections/meta/loader-webpack";
|
|
96
|
+
const loaderOptions = {
|
|
97
|
+
configPath,
|
|
98
|
+
outDir,
|
|
99
|
+
absoluteCompiledConfigPath: path.resolve(
|
|
100
|
+
this.core.getCompiledConfigPath()
|
|
101
|
+
),
|
|
102
|
+
isDev: process.env.NODE_ENV === "development"
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
...nextConfig,
|
|
106
|
+
turbopack: {
|
|
107
|
+
...nextConfig.turbopack,
|
|
108
|
+
rules: {
|
|
109
|
+
...nextConfig.turbopack?.rules,
|
|
110
|
+
"*.json": {
|
|
111
|
+
loaders: [
|
|
112
|
+
{
|
|
113
|
+
loader: loaderPath,
|
|
114
|
+
options: loaderOptions
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
as: "*.json"
|
|
118
|
+
},
|
|
119
|
+
"*.yaml": {
|
|
120
|
+
loaders: [
|
|
121
|
+
{
|
|
122
|
+
loader: loaderPath,
|
|
123
|
+
options: loaderOptions
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
as: "*.js"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
webpack(config, options) {
|
|
131
|
+
config.module ||= {};
|
|
132
|
+
config.module.rules ||= [];
|
|
133
|
+
config.module.rules.push({
|
|
134
|
+
test: metaLoaderGlob,
|
|
135
|
+
enforce: "pre",
|
|
136
|
+
use: [
|
|
137
|
+
{
|
|
138
|
+
loader: loaderPath,
|
|
139
|
+
options: loaderOptions
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
return nextConfig.webpack?.(config, options) ?? config;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return withLoader(base, {
|
|
150
|
+
test: metaLoaderGlob,
|
|
151
|
+
async createLoader(environment) {
|
|
152
|
+
const { createMetaLoader } = await import("../loader-T756NSCS.js");
|
|
153
|
+
return createMetaLoader(
|
|
154
|
+
{
|
|
155
|
+
getCore: () => this.core
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
json: environment === "vite" ? "json" : "js"
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
defineMeta
|
|
166
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SimpleCollectionStore } from './store.js';
|
|
2
|
+
|
|
3
|
+
interface FileInfo {
|
|
4
|
+
/**
|
|
5
|
+
* path relative to content directory
|
|
6
|
+
*/
|
|
7
|
+
path: string;
|
|
8
|
+
/**
|
|
9
|
+
* the full file path in file system
|
|
10
|
+
*/
|
|
11
|
+
fullPath: string;
|
|
12
|
+
}
|
|
13
|
+
declare class FileCollectionStore<V> extends SimpleCollectionStore<FileInfo & V> {
|
|
14
|
+
constructor(base: string, glob: Record<string, V>);
|
|
15
|
+
transform<T>(fn: (input: FileInfo & V) => FileInfo & T): FileCollectionStore<T>;
|
|
16
|
+
$data<T>(_cast: (input: FileInfo & V) => FileInfo & T): FileCollectionStore<T>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { FileCollectionStore, type FileInfo };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type Awaitable<T> = T | PromiseLike<T>;
|
|
2
|
+
interface CollectionStore<Id, Data> {
|
|
3
|
+
/**
|
|
4
|
+
* type-only operation to change data type, doesn't do any runtime transformation.
|
|
5
|
+
*/
|
|
6
|
+
$data: <T>(_cast: (input: Data) => T) => CollectionStore<Id, T>;
|
|
7
|
+
get: (id: Id) => Awaitable<Data | undefined>;
|
|
8
|
+
list: () => Awaitable<Data[]>;
|
|
9
|
+
/**
|
|
10
|
+
* For typescript to infer data types, can be anything
|
|
11
|
+
*/
|
|
12
|
+
$inferData: Data;
|
|
13
|
+
}
|
|
14
|
+
declare class SimpleCollectionStore<Data> implements CollectionStore<string, Data> {
|
|
15
|
+
private readonly dataMap;
|
|
16
|
+
private readonly dataList;
|
|
17
|
+
constructor(input: Map<string, Data>);
|
|
18
|
+
get(id: string): Data | undefined;
|
|
19
|
+
list(): Data[];
|
|
20
|
+
$data<T>(_cast: (input: Data) => T): SimpleCollectionStore<T>;
|
|
21
|
+
/**
|
|
22
|
+
* in-place transformation on all data
|
|
23
|
+
*/
|
|
24
|
+
transform<T>(fn: (input: Data) => T): SimpleCollectionStore<T>;
|
|
25
|
+
get $inferData(): Data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { type CollectionStore, SimpleCollectionStore };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { G as GlobalConfig, W as WorkspaceConfig, D as defineConfig } from '../core-DxnSmTRe.js';
|
|
2
|
+
import 'chokidar';
|
|
3
|
+
import '@mdx-js/mdx';
|
|
4
|
+
import 'vfile';
|
|
5
|
+
import '@standard-schema/spec';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'mdast';
|
|
8
|
+
import 'vite';
|
|
9
|
+
import 'next';
|
|
10
|
+
import 'node:module';
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { FSWatcher } from 'chokidar';
|
|
2
|
+
import { ProcessorOptions } from '@mdx-js/mdx';
|
|
3
|
+
import { VFile } from 'vfile';
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
|
+
import { Processor } from 'unified';
|
|
6
|
+
import { Root } from 'mdast';
|
|
7
|
+
import * as Vite from 'vite';
|
|
8
|
+
import { NextConfig } from 'next';
|
|
9
|
+
import { LoadHook } from 'node:module';
|
|
10
|
+
|
|
11
|
+
interface JSONSchemaOptions {
|
|
12
|
+
/**
|
|
13
|
+
* insert `$schema` field to JSON files on creation.
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue false
|
|
16
|
+
*/
|
|
17
|
+
insert?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface JSONSchemaHandler {
|
|
20
|
+
create: () => object | undefined | Promise<object | undefined>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Generate JSON schemas locally for collection schemas
|
|
24
|
+
*
|
|
25
|
+
* note: **it only works with Zod**
|
|
26
|
+
*/
|
|
27
|
+
declare function jsonSchema({ insert, }?: JSONSchemaOptions): Plugin;
|
|
28
|
+
|
|
29
|
+
interface FileHandlerConfig {
|
|
30
|
+
/**
|
|
31
|
+
* Directory to scan
|
|
32
|
+
*/
|
|
33
|
+
dir: string;
|
|
34
|
+
/**
|
|
35
|
+
* what files to include/exclude (glob patterns)
|
|
36
|
+
*
|
|
37
|
+
* Include all files if not specified
|
|
38
|
+
*/
|
|
39
|
+
files?: string[];
|
|
40
|
+
}
|
|
41
|
+
interface FIleCollectionHandler {
|
|
42
|
+
/**
|
|
43
|
+
* content directory (absolute)
|
|
44
|
+
*/
|
|
45
|
+
dir: string;
|
|
46
|
+
hasFile: (filePath: string) => boolean;
|
|
47
|
+
isFileSupported: (filePath: string) => boolean;
|
|
48
|
+
patterns: string[];
|
|
49
|
+
}
|
|
50
|
+
declare function buildFileHandler({ workspace }: InitOptions, config: FileHandlerConfig, supportedFormats: string[]): FIleCollectionHandler;
|
|
51
|
+
|
|
52
|
+
interface ExtractedReference {
|
|
53
|
+
href: string;
|
|
54
|
+
}
|
|
55
|
+
interface PostprocessOptions {
|
|
56
|
+
_format: "md" | "mdx";
|
|
57
|
+
/**
|
|
58
|
+
* Properties to export from `vfile.data`
|
|
59
|
+
*/
|
|
60
|
+
valueToExport?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* stringify MDAST and export via `_markdown`.
|
|
63
|
+
*/
|
|
64
|
+
includeProcessedMarkdown?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* extract link references, export via `extractedReferences`.
|
|
67
|
+
*/
|
|
68
|
+
extractLinkReferences?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* store MDAST and export via `_mdast`.
|
|
71
|
+
*/
|
|
72
|
+
includeMDAST?: boolean | {
|
|
73
|
+
removePosition?: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface PreprocessOptions {
|
|
78
|
+
preprocessor?: Processor<Root>;
|
|
79
|
+
}
|
|
80
|
+
declare module "vfile" {
|
|
81
|
+
interface DataMap {
|
|
82
|
+
_preprocessed?: boolean;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
type Awaitable$2<T> = T | PromiseLike<T>;
|
|
87
|
+
interface CompilationContext {
|
|
88
|
+
collection: Collection;
|
|
89
|
+
filePath: string;
|
|
90
|
+
source: string;
|
|
91
|
+
}
|
|
92
|
+
interface MDXCollectionHandler {
|
|
93
|
+
readonly cwd: string;
|
|
94
|
+
readonly dynamic: boolean;
|
|
95
|
+
readonly lazy: boolean;
|
|
96
|
+
preprocess?: PreprocessOptions;
|
|
97
|
+
postprocess?: Partial<PostprocessOptions>;
|
|
98
|
+
getMDXOptions?: (environment: "bundler" | "runtime") => Awaitable$2<ProcessorOptions>;
|
|
99
|
+
/**
|
|
100
|
+
* Transform frontmatter
|
|
101
|
+
*/
|
|
102
|
+
frontmatter?: (this: CompilationContext, data: Record<string, unknown>) => Awaitable$2<Record<string, unknown> | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Transform `vfile` on compilation stage
|
|
105
|
+
*/
|
|
106
|
+
vfile?: (this: CompilationContext, file: VFile) => Awaitable$2<VFile>;
|
|
107
|
+
onGenerateStore?: (this: EmitCodeGeneratorContext & {
|
|
108
|
+
environment: "browser" | "server" | "dynamic";
|
|
109
|
+
}, initializer: string) => string;
|
|
110
|
+
}
|
|
111
|
+
interface MDXCollectionConfig<FrontmatterSchema extends StandardSchemaV1 | undefined = undefined> extends FileHandlerConfig {
|
|
112
|
+
postprocess?: Partial<PostprocessOptions>;
|
|
113
|
+
frontmatter?: FrontmatterSchema;
|
|
114
|
+
options?: (environment: "bundler" | "runtime") => Awaitable$2<ProcessorOptions>;
|
|
115
|
+
lazy?: boolean;
|
|
116
|
+
dynamic?: boolean;
|
|
117
|
+
}
|
|
118
|
+
type MDXCollection<Frontmatter> = Collection & {
|
|
119
|
+
_frontmatter?: Frontmatter;
|
|
120
|
+
};
|
|
121
|
+
declare function defineMDX<FrontmatterSchema extends StandardSchemaV1 | undefined = undefined>(config: MDXCollectionConfig<FrontmatterSchema>): MDXCollection<FrontmatterSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<FrontmatterSchema> : Record<string, unknown>>;
|
|
122
|
+
|
|
123
|
+
type Awaitable$1<T> = T | PromiseLike<T>;
|
|
124
|
+
interface MetaContext {
|
|
125
|
+
path: string;
|
|
126
|
+
source: string;
|
|
127
|
+
}
|
|
128
|
+
interface MetaCollectionHandler {
|
|
129
|
+
/**
|
|
130
|
+
* Transform metadata
|
|
131
|
+
*/
|
|
132
|
+
transform?: (this: MetaContext, data: unknown) => Awaitable$1<unknown | undefined>;
|
|
133
|
+
schema?: StandardSchemaV1 | ((context: MetaContext) => StandardSchemaV1);
|
|
134
|
+
}
|
|
135
|
+
interface MetaCollectionConfig<Schema extends StandardSchemaV1> extends FileHandlerConfig {
|
|
136
|
+
schema?: Schema | ((context: MetaContext) => Schema);
|
|
137
|
+
}
|
|
138
|
+
type MetaCollection<_Data> = Collection & {
|
|
139
|
+
_type?: _Data;
|
|
140
|
+
};
|
|
141
|
+
declare function defineMeta<Schema extends StandardSchemaV1>(config: MetaCollectionConfig<Schema>): MetaCollection<Schema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Schema> : Record<string, unknown>>;
|
|
142
|
+
|
|
143
|
+
interface VersionControlFileData {
|
|
144
|
+
/**
|
|
145
|
+
* Last modified date of file, obtained from version control.
|
|
146
|
+
*/
|
|
147
|
+
lastModified: Date | null;
|
|
148
|
+
/**
|
|
149
|
+
* Creation date of file, obtained from version control.
|
|
150
|
+
*/
|
|
151
|
+
creationDate: Date | null;
|
|
152
|
+
}
|
|
153
|
+
interface VersionControlHandler {
|
|
154
|
+
/**
|
|
155
|
+
* receive the version control client.
|
|
156
|
+
*/
|
|
157
|
+
client: (context: {
|
|
158
|
+
client: VersionControlClient;
|
|
159
|
+
}) => void | Promise<void>;
|
|
160
|
+
}
|
|
161
|
+
interface GitPluginOptions {
|
|
162
|
+
/**
|
|
163
|
+
* Filter the collections to include by names
|
|
164
|
+
*/
|
|
165
|
+
filter?: (collection: string) => boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Add version control integration for Git.
|
|
169
|
+
* 1. Injects `creationDate` & `lastModified` properties to page exports.
|
|
170
|
+
*
|
|
171
|
+
* @remarks If you are using Vercel, please set `VERCEL_DEEP_CLONE` environment variable to `true`. This ensures the client can access the full commit history of Git.
|
|
172
|
+
*/
|
|
173
|
+
declare function git(options?: GitPluginOptions): Plugin;
|
|
174
|
+
interface VersionControlClient {
|
|
175
|
+
getFileData: (options: {
|
|
176
|
+
filePath: string;
|
|
177
|
+
}) => Promise<VersionControlFileData>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface InitOptions {
|
|
181
|
+
name: string;
|
|
182
|
+
workspace?: WorkspaceConfig;
|
|
183
|
+
}
|
|
184
|
+
interface Collection {
|
|
185
|
+
name: string;
|
|
186
|
+
init?: (options: InitOptions) => void;
|
|
187
|
+
readonly handlers: CollectionHandlers;
|
|
188
|
+
/**
|
|
189
|
+
* information for the collection type, can be shared for all collections of same type.
|
|
190
|
+
*/
|
|
191
|
+
readonly typeInfo: CollectionTypeInfo;
|
|
192
|
+
}
|
|
193
|
+
interface CollectionTypeInfo {
|
|
194
|
+
/**
|
|
195
|
+
* ID for collection type.
|
|
196
|
+
*
|
|
197
|
+
* @example `my-package:my-collection-type`
|
|
198
|
+
*/
|
|
199
|
+
readonly id: string;
|
|
200
|
+
/**
|
|
201
|
+
* plugins to register, registered once for each collection type.
|
|
202
|
+
*/
|
|
203
|
+
readonly plugins?: PluginOption;
|
|
204
|
+
}
|
|
205
|
+
interface CollectionHandlers {
|
|
206
|
+
fs?: FIleCollectionHandler;
|
|
207
|
+
mdx?: MDXCollectionHandler;
|
|
208
|
+
meta?: MetaCollectionHandler;
|
|
209
|
+
"json-schema"?: JSONSchemaHandler;
|
|
210
|
+
"version-control"?: VersionControlHandler;
|
|
211
|
+
}
|
|
212
|
+
declare function createCollection(info: CollectionTypeInfo, init: (collection: Collection, options: InitOptions) => void): Collection;
|
|
213
|
+
|
|
214
|
+
interface GlobalConfig<Collections extends Record<string, Collection> = Record<string, Collection>> {
|
|
215
|
+
plugins?: PluginOption[];
|
|
216
|
+
collections?: Collections;
|
|
217
|
+
workspaces?: Record<string, Omit<WorkspaceConfig, "name">>;
|
|
218
|
+
/**
|
|
219
|
+
* specify a directory to access & store cache (disabled during development mode).
|
|
220
|
+
*
|
|
221
|
+
* The cache will never be updated, delete the cache folder to clean.
|
|
222
|
+
*/
|
|
223
|
+
experimentalBuildCache?: string;
|
|
224
|
+
}
|
|
225
|
+
interface WorkspaceConfig {
|
|
226
|
+
name: string;
|
|
227
|
+
dir: string;
|
|
228
|
+
config: GlobalConfig | {
|
|
229
|
+
default: GlobalConfig;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
declare function defineConfig<Collections extends Record<string, Collection> = Record<string, Collection>>(config?: GlobalConfig<Collections>): GlobalConfig<Collections>;
|
|
233
|
+
|
|
234
|
+
interface LoadedConfig extends Omit<GlobalConfig, "workspaces" | "collections"> {
|
|
235
|
+
collections: Map<string, Collection>;
|
|
236
|
+
workspaces: Record<string, {
|
|
237
|
+
dir: string;
|
|
238
|
+
config: LoadedConfig;
|
|
239
|
+
}>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface GlobImportOptions {
|
|
243
|
+
base: string;
|
|
244
|
+
query?: Record<string, string | undefined>;
|
|
245
|
+
import?: string;
|
|
246
|
+
eager?: boolean;
|
|
247
|
+
}
|
|
248
|
+
interface CodeGeneratorOptions {
|
|
249
|
+
target: "default" | "vite";
|
|
250
|
+
outDir: string;
|
|
251
|
+
/**
|
|
252
|
+
* add .js extenstion to imports
|
|
253
|
+
*/
|
|
254
|
+
jsExtension: boolean;
|
|
255
|
+
globCache: Map<string, Promise<string[]>>;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Code generator (one instance per file)
|
|
259
|
+
*/
|
|
260
|
+
declare class CodeGenerator {
|
|
261
|
+
private readonly lines;
|
|
262
|
+
private readonly globCache;
|
|
263
|
+
private readonly importInfos;
|
|
264
|
+
private eagerImportId;
|
|
265
|
+
readonly options: CodeGeneratorOptions;
|
|
266
|
+
constructor({ target, jsExtension, globCache, outDir, }: Partial<CodeGeneratorOptions>);
|
|
267
|
+
addNamespaceImport(namespace: string, specifier: string, types?: boolean): void;
|
|
268
|
+
addNamedImport(names: string[], specifier: string, types?: boolean): void;
|
|
269
|
+
push(...insert: string[]): void;
|
|
270
|
+
pushAsync(insert: Promise<string | undefined>[]): Promise<void>;
|
|
271
|
+
generateGlobImport(patterns: string | string[], options: GlobImportOptions): Promise<string>;
|
|
272
|
+
private generateViteGlobImport;
|
|
273
|
+
private generateNodeGlobImport;
|
|
274
|
+
formatImportPath(file: string): string;
|
|
275
|
+
toString(): string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type Awaitable<T> = T | PromiseLike<T>;
|
|
279
|
+
interface EmitEntry {
|
|
280
|
+
/**
|
|
281
|
+
* path relative to output directory
|
|
282
|
+
*/
|
|
283
|
+
path: string;
|
|
284
|
+
content: string;
|
|
285
|
+
}
|
|
286
|
+
interface PluginContext {
|
|
287
|
+
core: Core;
|
|
288
|
+
}
|
|
289
|
+
interface EmitContext extends PluginContext {
|
|
290
|
+
createCodeGenerator: (path: string, content: (ctx: EmitCodeGeneratorContext) => Promise<void>) => Promise<EmitEntry>;
|
|
291
|
+
}
|
|
292
|
+
interface EmitCodeGeneratorContext {
|
|
293
|
+
core: Core;
|
|
294
|
+
workspace?: string;
|
|
295
|
+
codegen: CodeGenerator;
|
|
296
|
+
}
|
|
297
|
+
interface Plugin {
|
|
298
|
+
/**
|
|
299
|
+
* unique name for plugin
|
|
300
|
+
*
|
|
301
|
+
* @example `my-package:my-plugin`
|
|
302
|
+
*/
|
|
303
|
+
name: string;
|
|
304
|
+
/**
|
|
305
|
+
* on config loaded/updated
|
|
306
|
+
*/
|
|
307
|
+
config?: (this: PluginContext, config: LoadedConfig) => Awaitable<void | LoadedConfig>;
|
|
308
|
+
collection?: (this: PluginContext, collection: Collection) => Awaitable<void>;
|
|
309
|
+
/**
|
|
310
|
+
* Generate files (e.g. types, index file, or JSON schemas)
|
|
311
|
+
*/
|
|
312
|
+
emit?: (this: EmitContext) => Awaitable<EmitEntry[]>;
|
|
313
|
+
/**
|
|
314
|
+
* Configure Fumadocs dev server
|
|
315
|
+
*/
|
|
316
|
+
configureServer?: (this: PluginContext, server: ServerContext) => Awaitable<void>;
|
|
317
|
+
vite?: {
|
|
318
|
+
createPlugin?: (this: PluginContext) => Vite.PluginOption;
|
|
319
|
+
};
|
|
320
|
+
bun?: {
|
|
321
|
+
build?: (this: PluginContext, build: Bun.PluginBuilder) => Awaitable<void>;
|
|
322
|
+
};
|
|
323
|
+
next?: {
|
|
324
|
+
config?: (this: PluginContext, config: NextConfig) => NextConfig;
|
|
325
|
+
};
|
|
326
|
+
node?: {
|
|
327
|
+
createLoad?: (this: PluginContext) => Awaitable<LoadHook>;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
type PluginOption = Awaitable<Plugin | PluginOption[] | false | undefined>;
|
|
331
|
+
interface ServerContext {
|
|
332
|
+
/**
|
|
333
|
+
* the file watcher, by default all content files are watched, along with other files.
|
|
334
|
+
*
|
|
335
|
+
* make sure to filter when listening to events
|
|
336
|
+
*/
|
|
337
|
+
watcher?: FSWatcher;
|
|
338
|
+
}
|
|
339
|
+
interface CoreOptions {
|
|
340
|
+
configPath: string;
|
|
341
|
+
outDir: string;
|
|
342
|
+
plugins?: PluginOption[];
|
|
343
|
+
emit?: {
|
|
344
|
+
target?: "default" | "vite";
|
|
345
|
+
/**
|
|
346
|
+
* add .js extenstion to imports
|
|
347
|
+
*/
|
|
348
|
+
jsExtension?: boolean;
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* the workspace info if this instance is created as a workspace
|
|
352
|
+
*/
|
|
353
|
+
workspace?: {
|
|
354
|
+
parent: Core;
|
|
355
|
+
name: string;
|
|
356
|
+
dir: string;
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
interface EmitOptions {
|
|
360
|
+
/**
|
|
361
|
+
* filter the plugins to run emit
|
|
362
|
+
*/
|
|
363
|
+
filterPlugin?: (plugin: Plugin) => boolean;
|
|
364
|
+
/**
|
|
365
|
+
* filter the workspaces to run emit
|
|
366
|
+
*/
|
|
367
|
+
filterWorkspace?: (workspace: string) => boolean;
|
|
368
|
+
/**
|
|
369
|
+
* write files
|
|
370
|
+
*/
|
|
371
|
+
write?: boolean;
|
|
372
|
+
}
|
|
373
|
+
interface EmitOutput {
|
|
374
|
+
entries: EmitEntry[];
|
|
375
|
+
workspaces: Record<string, EmitEntry[]>;
|
|
376
|
+
}
|
|
377
|
+
declare class Core {
|
|
378
|
+
private readonly workspaces;
|
|
379
|
+
private readonly options;
|
|
380
|
+
private plugins;
|
|
381
|
+
private config;
|
|
382
|
+
static defaultOptions: {
|
|
383
|
+
configPath: string;
|
|
384
|
+
outDir: string;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* Convenient cache store, reset when config changes.
|
|
388
|
+
*
|
|
389
|
+
* You can group namespaces in cache key with ":", like `my-plugin:data`
|
|
390
|
+
*/
|
|
391
|
+
readonly cache: Map<string, unknown>;
|
|
392
|
+
constructor(options: CoreOptions);
|
|
393
|
+
init({ config: newConfig }: {
|
|
394
|
+
config: Awaitable<LoadedConfig>;
|
|
395
|
+
}): Promise<void>;
|
|
396
|
+
getWorkspaces(): Map<string, Core>;
|
|
397
|
+
getOptions(): CoreOptions;
|
|
398
|
+
getConfig(): LoadedConfig;
|
|
399
|
+
/**
|
|
400
|
+
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
401
|
+
*/
|
|
402
|
+
getCompiledConfigPath(): string;
|
|
403
|
+
getPlugins(workspace?: boolean): Plugin[];
|
|
404
|
+
getCollections(workspace?: boolean): Collection[];
|
|
405
|
+
getCollection(name: string): Collection | undefined;
|
|
406
|
+
getPluginContext(): PluginContext;
|
|
407
|
+
initServer(server: ServerContext): Promise<void>;
|
|
408
|
+
emit(emitOptions?: EmitOptions): Promise<EmitOutput>;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export { type CollectionHandlers as A, createCollection as B, type CoreOptions as C, defineConfig as D, type ExtractedReference as E, type FileHandlerConfig as F, type GlobalConfig as G, type InitOptions as I, type JSONSchemaOptions as J, type MDXCollection as M, type PluginContext as P, type ServerContext as S, type VersionControlFileData as V, type WorkspaceConfig as W, Core as a, type MDXCollectionConfig as b, type MetaCollection as c, type Plugin as d, type EmitEntry as e, type EmitContext as f, type EmitCodeGeneratorContext as g, type PluginOption as h, type EmitOptions as i, type EmitOutput as j, jsonSchema as k, type JSONSchemaHandler as l, type FIleCollectionHandler as m, buildFileHandler as n, type MDXCollectionHandler as o, defineMDX as p, type MetaContext as q, type MetaCollectionHandler as r, type MetaCollectionConfig as s, defineMeta as t, git as u, type VersionControlHandler as v, type GitPluginOptions as w, type VersionControlClient as x, type Collection as y, type CollectionTypeInfo as z };
|