fumadocs-mdx 11.8.3 → 11.9.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/{chunk-BWRDVK5L.js → chunk-766EAFX6.js} +1 -1
- package/dist/chunk-COQ4VMK2.js +158 -0
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/zod-3.d.cts +1 -1
- package/dist/config/zod-3.d.ts +1 -1
- package/dist/{define-DAZmbu3U.d.cts → define-DnJzAZrj.d.cts} +1 -1
- package/dist/{define-DAZmbu3U.d.ts → define-DnJzAZrj.d.ts} +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/loader-mdx.cjs +1 -1
- package/dist/loader-mdx.js +2 -2
- package/dist/next/index.cjs +126 -11
- package/dist/next/index.js +27 -9
- package/dist/runtime/async.d.cts +2 -2
- package/dist/runtime/async.d.ts +2 -2
- package/dist/runtime/async.js +1 -1
- package/dist/runtime/vite.cjs +47 -33
- package/dist/runtime/vite.d.cts +17 -12
- package/dist/runtime/vite.d.ts +17 -12
- package/dist/runtime/vite.js +37 -33
- package/dist/{types-B2kQsHs7.d.cts → types-BmVgoqsr.d.cts} +1 -1
- package/dist/{types-CkmezNbX.d.ts → types-WSHJKA8L.d.ts} +1 -1
- package/dist/vite/index.cjs +99 -84
- package/dist/vite/index.js +13 -93
- package/package.json +5 -5
- package/dist/chunk-6Y5JDZHD.js +0 -65
package/dist/vite/index.cjs
CHANGED
|
@@ -492,41 +492,12 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
492
492
|
|
|
493
493
|
// src/vite/index.ts
|
|
494
494
|
var import_zod = require("zod");
|
|
495
|
-
|
|
496
|
-
// src/utils/import-formatter.ts
|
|
497
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
498
|
-
function toImportPath(file, config) {
|
|
499
|
-
const ext = import_node_path.default.extname(file);
|
|
500
|
-
let filename;
|
|
501
|
-
if (ext === ".ts" && config.jsExtension) {
|
|
502
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
503
|
-
} else if (ext === ".ts") {
|
|
504
|
-
filename = file.substring(0, file.length - ext.length);
|
|
505
|
-
} else {
|
|
506
|
-
filename = file;
|
|
507
|
-
}
|
|
508
|
-
let importPath;
|
|
509
|
-
if ("relativeTo" in config) {
|
|
510
|
-
importPath = import_node_path.default.relative(config.relativeTo, filename);
|
|
511
|
-
if (!import_node_path.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
512
|
-
importPath = `./${importPath}`;
|
|
513
|
-
}
|
|
514
|
-
} else {
|
|
515
|
-
importPath = import_node_path.default.resolve(filename);
|
|
516
|
-
}
|
|
517
|
-
return importPath.replaceAll(import_node_path.default.sep, "/");
|
|
518
|
-
}
|
|
519
|
-
function ident(code, tab = 1) {
|
|
520
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// src/vite/index.ts
|
|
524
495
|
var fs2 = __toESM(require("fs/promises"), 1);
|
|
525
496
|
var path4 = __toESM(require("path"), 1);
|
|
526
497
|
var import_js_yaml2 = require("js-yaml");
|
|
527
498
|
|
|
528
499
|
// src/utils/git-timestamp.ts
|
|
529
|
-
var
|
|
500
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
530
501
|
var import_tinyexec = require("tinyexec");
|
|
531
502
|
var cache2 = /* @__PURE__ */ new Map();
|
|
532
503
|
async function getGitTimestamp(file) {
|
|
@@ -535,7 +506,7 @@ async function getGitTimestamp(file) {
|
|
|
535
506
|
try {
|
|
536
507
|
const out = await (0, import_tinyexec.x)(
|
|
537
508
|
"git",
|
|
538
|
-
["log", "-1", '--pretty="%ai"',
|
|
509
|
+
["log", "-1", '--pretty="%ai"', import_node_path.default.relative(process.cwd(), file)],
|
|
539
510
|
{
|
|
540
511
|
throwOnError: true
|
|
541
512
|
}
|
|
@@ -548,37 +519,51 @@ async function getGitTimestamp(file) {
|
|
|
548
519
|
}
|
|
549
520
|
}
|
|
550
521
|
|
|
551
|
-
// src/utils/
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
522
|
+
// src/utils/import-formatter.ts
|
|
523
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
524
|
+
function toImportPath(file, config) {
|
|
525
|
+
const ext = import_node_path2.default.extname(file);
|
|
526
|
+
let filename;
|
|
527
|
+
if (ext === ".ts" && config.jsExtension) {
|
|
528
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
529
|
+
} else if (ext === ".ts") {
|
|
530
|
+
filename = file.substring(0, file.length - ext.length);
|
|
531
|
+
} else {
|
|
532
|
+
filename = file;
|
|
533
|
+
}
|
|
534
|
+
let importPath;
|
|
535
|
+
if ("relativeTo" in config) {
|
|
536
|
+
importPath = import_node_path2.default.relative(config.relativeTo, filename);
|
|
537
|
+
if (!import_node_path2.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
538
|
+
importPath = `./${importPath}`;
|
|
539
|
+
}
|
|
540
|
+
} else {
|
|
541
|
+
importPath = import_node_path2.default.resolve(filename);
|
|
542
|
+
}
|
|
543
|
+
return importPath.replaceAll(import_node_path2.default.sep, "/");
|
|
557
544
|
}
|
|
558
|
-
function
|
|
559
|
-
|
|
560
|
-
return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
|
|
545
|
+
function ident(code, tab = 1) {
|
|
546
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
561
547
|
}
|
|
562
548
|
|
|
563
549
|
// src/vite/generate-glob.ts
|
|
564
|
-
function generateGlob(name,
|
|
565
|
-
const patterns = mapGlobPatterns(getGlobPatterns(collection));
|
|
550
|
+
function generateGlob(name, patterns, globOptions) {
|
|
566
551
|
const options = {
|
|
567
552
|
...globOptions,
|
|
568
553
|
query: {
|
|
569
554
|
...globOptions?.query,
|
|
570
555
|
collection: name
|
|
571
|
-
}
|
|
572
|
-
base: getGlobBase(collection)
|
|
556
|
+
}
|
|
573
557
|
};
|
|
574
|
-
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(options, null, 2)})`;
|
|
558
|
+
return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
|
|
575
559
|
}
|
|
576
560
|
function mapGlobPatterns(patterns) {
|
|
577
|
-
return patterns.map(
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
561
|
+
return patterns.map(enforceRelative);
|
|
562
|
+
}
|
|
563
|
+
function enforceRelative(file) {
|
|
564
|
+
if (file.startsWith("./")) return file;
|
|
565
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
566
|
+
return `./${file}`;
|
|
582
567
|
}
|
|
583
568
|
function getGlobBase(collection) {
|
|
584
569
|
let dir = collection.dir;
|
|
@@ -589,10 +574,19 @@ function getGlobBase(collection) {
|
|
|
589
574
|
);
|
|
590
575
|
dir = dir[0];
|
|
591
576
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
577
|
+
return enforceRelative(dir);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// src/utils/collections.ts
|
|
581
|
+
function getSupportedFormats(collection) {
|
|
582
|
+
return {
|
|
583
|
+
doc: ["mdx", "md"],
|
|
584
|
+
meta: ["json", "yaml"]
|
|
585
|
+
}[collection.type];
|
|
586
|
+
}
|
|
587
|
+
function getGlobPatterns(collection) {
|
|
588
|
+
if (collection.files) return collection.files;
|
|
589
|
+
return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
|
|
596
590
|
}
|
|
597
591
|
|
|
598
592
|
// src/vite/generate.ts
|
|
@@ -606,21 +600,56 @@ ${obj}
|
|
|
606
600
|
}`;
|
|
607
601
|
}
|
|
608
602
|
function doc(name, collection) {
|
|
603
|
+
const patterns = getGlobPatterns(collection);
|
|
604
|
+
const base = getGlobBase(collection);
|
|
605
|
+
const docGlob = generateGlob(name, patterns, {
|
|
606
|
+
base
|
|
607
|
+
});
|
|
609
608
|
if (collection.async) {
|
|
610
|
-
|
|
609
|
+
const headBlob = generateGlob(name, patterns, {
|
|
611
610
|
query: {
|
|
612
611
|
only: "frontmatter"
|
|
613
612
|
},
|
|
614
|
-
import: "frontmatter"
|
|
615
|
-
|
|
613
|
+
import: "frontmatter",
|
|
614
|
+
base
|
|
615
|
+
});
|
|
616
|
+
return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
|
|
616
617
|
}
|
|
617
|
-
return `create.doc("${name}", ${
|
|
618
|
+
return `create.doc("${name}", "${base}", ${docGlob})`;
|
|
618
619
|
}
|
|
619
620
|
function meta(name, collection) {
|
|
620
|
-
|
|
621
|
-
|
|
621
|
+
const patterns = getGlobPatterns(collection);
|
|
622
|
+
const base = getGlobBase(collection);
|
|
623
|
+
return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
|
|
624
|
+
import: "default",
|
|
625
|
+
base
|
|
622
626
|
})})`;
|
|
623
627
|
}
|
|
628
|
+
function entry(configPath, config, outDir, jsExtension) {
|
|
629
|
+
const lines = [
|
|
630
|
+
'/// <reference types="vite/client" />',
|
|
631
|
+
`import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
|
|
632
|
+
`import type * as Config from '${toImportPath(configPath, {
|
|
633
|
+
relativeTo: outDir,
|
|
634
|
+
jsExtension
|
|
635
|
+
})}';`,
|
|
636
|
+
"",
|
|
637
|
+
`export const create = fromConfig<typeof Config>();`
|
|
638
|
+
];
|
|
639
|
+
for (const [name, collection] of config.collections.entries()) {
|
|
640
|
+
let body;
|
|
641
|
+
if (collection.type === "docs") {
|
|
642
|
+
body = docs(name, collection);
|
|
643
|
+
} else if (collection.type === "meta") {
|
|
644
|
+
body = meta(name, collection);
|
|
645
|
+
} else {
|
|
646
|
+
body = doc(name, collection);
|
|
647
|
+
}
|
|
648
|
+
lines.push("");
|
|
649
|
+
lines.push(`export const ${name} = ${body};`);
|
|
650
|
+
}
|
|
651
|
+
return lines.join("\n");
|
|
652
|
+
}
|
|
624
653
|
|
|
625
654
|
// src/vite/index.ts
|
|
626
655
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
@@ -742,31 +771,17 @@ function mdx(config, options = {}) {
|
|
|
742
771
|
async buildStart() {
|
|
743
772
|
if (!generateIndexFile) return;
|
|
744
773
|
console.log("[Fumadocs MDX] Generating index files");
|
|
745
|
-
const
|
|
774
|
+
const outDir = process.cwd();
|
|
746
775
|
const outFile = "source.generated.ts";
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
];
|
|
757
|
-
for (const [name, collection] of loaded.collections.entries()) {
|
|
758
|
-
let body;
|
|
759
|
-
if (collection.type === "docs") {
|
|
760
|
-
body = docs(name, collection);
|
|
761
|
-
} else if (collection.type === "meta") {
|
|
762
|
-
body = meta(name, collection);
|
|
763
|
-
} else {
|
|
764
|
-
body = doc(name, collection);
|
|
765
|
-
}
|
|
766
|
-
lines.push("");
|
|
767
|
-
lines.push(`export const ${name} = ${body};`);
|
|
768
|
-
}
|
|
769
|
-
await fs2.writeFile(path4.join(outdir, outFile), lines.join("\n"));
|
|
776
|
+
await fs2.writeFile(
|
|
777
|
+
path4.join(outDir, outFile),
|
|
778
|
+
entry(
|
|
779
|
+
configPath,
|
|
780
|
+
loaded,
|
|
781
|
+
outDir,
|
|
782
|
+
typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
|
|
783
|
+
)
|
|
784
|
+
);
|
|
770
785
|
},
|
|
771
786
|
async transform(value, id) {
|
|
772
787
|
const [file, query = ""] = id.split("?");
|
package/dist/vite/index.js
CHANGED
|
@@ -2,10 +2,8 @@ import {
|
|
|
2
2
|
countLines
|
|
3
3
|
} from "../chunk-UCY7OBZG.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
toImportPath
|
|
8
|
-
} from "../chunk-6Y5JDZHD.js";
|
|
5
|
+
entry
|
|
6
|
+
} from "../chunk-COQ4VMK2.js";
|
|
9
7
|
import {
|
|
10
8
|
ValidationError,
|
|
11
9
|
getGitTimestamp,
|
|
@@ -14,10 +12,10 @@ import {
|
|
|
14
12
|
import {
|
|
15
13
|
buildMDX
|
|
16
14
|
} from "../chunk-QQWCBFFE.js";
|
|
15
|
+
import "../chunk-SVTXMVLQ.js";
|
|
17
16
|
import {
|
|
18
17
|
buildConfig
|
|
19
18
|
} from "../chunk-QVZ7JH4H.js";
|
|
20
|
-
import "../chunk-SVTXMVLQ.js";
|
|
21
19
|
import {
|
|
22
20
|
fumaMatter
|
|
23
21
|
} from "../chunk-VWJKRQZR.js";
|
|
@@ -31,70 +29,6 @@ import { z } from "zod";
|
|
|
31
29
|
import * as fs from "fs/promises";
|
|
32
30
|
import * as path from "path";
|
|
33
31
|
import { load } from "js-yaml";
|
|
34
|
-
|
|
35
|
-
// src/vite/generate-glob.ts
|
|
36
|
-
function generateGlob(name, collection, globOptions) {
|
|
37
|
-
const patterns = mapGlobPatterns(getGlobPatterns(collection));
|
|
38
|
-
const options = {
|
|
39
|
-
...globOptions,
|
|
40
|
-
query: {
|
|
41
|
-
...globOptions?.query,
|
|
42
|
-
collection: name
|
|
43
|
-
},
|
|
44
|
-
base: getGlobBase(collection)
|
|
45
|
-
};
|
|
46
|
-
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(options, null, 2)})`;
|
|
47
|
-
}
|
|
48
|
-
function mapGlobPatterns(patterns) {
|
|
49
|
-
return patterns.map((file) => {
|
|
50
|
-
if (file.startsWith("./")) return file;
|
|
51
|
-
if (file.startsWith("/")) return `.${file}`;
|
|
52
|
-
return `./${file}`;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function getGlobBase(collection) {
|
|
56
|
-
let dir = collection.dir;
|
|
57
|
-
if (Array.isArray(dir)) {
|
|
58
|
-
if (dir.length !== 1)
|
|
59
|
-
throw new Error(
|
|
60
|
-
`[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
|
|
61
|
-
);
|
|
62
|
-
dir = dir[0];
|
|
63
|
-
}
|
|
64
|
-
if (!dir.startsWith("./") && !dir.startsWith("/")) {
|
|
65
|
-
return "/" + dir;
|
|
66
|
-
}
|
|
67
|
-
return dir;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/vite/generate.ts
|
|
71
|
-
function docs(name, collection) {
|
|
72
|
-
const obj = [
|
|
73
|
-
ident(`doc: ${doc(name, collection.docs)}`),
|
|
74
|
-
ident(`meta: ${meta(name, collection.meta)}`)
|
|
75
|
-
].join(",\n");
|
|
76
|
-
return `{
|
|
77
|
-
${obj}
|
|
78
|
-
}`;
|
|
79
|
-
}
|
|
80
|
-
function doc(name, collection) {
|
|
81
|
-
if (collection.async) {
|
|
82
|
-
return `create.docLazy("${name}", ${generateGlob(name, collection, {
|
|
83
|
-
query: {
|
|
84
|
-
only: "frontmatter"
|
|
85
|
-
},
|
|
86
|
-
import: "frontmatter"
|
|
87
|
-
})}, ${generateGlob(name, collection)})`;
|
|
88
|
-
}
|
|
89
|
-
return `create.doc("${name}", ${generateGlob(name, collection)})`;
|
|
90
|
-
}
|
|
91
|
-
function meta(name, collection) {
|
|
92
|
-
return `create.meta("${name}", ${generateGlob(name, collection, {
|
|
93
|
-
import: "default"
|
|
94
|
-
})})`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// src/vite/index.ts
|
|
98
32
|
var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
99
33
|
var querySchema = z.object({
|
|
100
34
|
only: z.literal(["frontmatter", "all"]).default("all"),
|
|
@@ -214,31 +148,17 @@ function mdx(config, options = {}) {
|
|
|
214
148
|
async buildStart() {
|
|
215
149
|
if (!generateIndexFile) return;
|
|
216
150
|
console.log("[Fumadocs MDX] Generating index files");
|
|
217
|
-
const
|
|
151
|
+
const outDir = process.cwd();
|
|
218
152
|
const outFile = "source.generated.ts";
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
];
|
|
229
|
-
for (const [name, collection] of loaded.collections.entries()) {
|
|
230
|
-
let body;
|
|
231
|
-
if (collection.type === "docs") {
|
|
232
|
-
body = docs(name, collection);
|
|
233
|
-
} else if (collection.type === "meta") {
|
|
234
|
-
body = meta(name, collection);
|
|
235
|
-
} else {
|
|
236
|
-
body = doc(name, collection);
|
|
237
|
-
}
|
|
238
|
-
lines.push("");
|
|
239
|
-
lines.push(`export const ${name} = ${body};`);
|
|
240
|
-
}
|
|
241
|
-
await fs.writeFile(path.join(outdir, outFile), lines.join("\n"));
|
|
153
|
+
await fs.writeFile(
|
|
154
|
+
path.join(outDir, outFile),
|
|
155
|
+
entry(
|
|
156
|
+
configPath,
|
|
157
|
+
loaded,
|
|
158
|
+
outDir,
|
|
159
|
+
typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
|
|
160
|
+
)
|
|
161
|
+
);
|
|
242
162
|
},
|
|
243
163
|
async transform(value, id) {
|
|
244
164
|
const [file, query = ""] = id.split("?");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-mdx",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.9.0",
|
|
4
4
|
"description": "The built-in source for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"esbuild": "^0.25.9",
|
|
63
63
|
"estree-util-value-to-estree": "^3.4.0",
|
|
64
64
|
"js-yaml": "^4.1.0",
|
|
65
|
-
"lru-cache": "^11.1
|
|
65
|
+
"lru-cache": "^11.2.1",
|
|
66
66
|
"picocolors": "^1.1.1",
|
|
67
67
|
"remark-mdx": "^3.1.1",
|
|
68
68
|
"remark-parse": "^11.0.0",
|
|
@@ -76,18 +76,18 @@
|
|
|
76
76
|
"@types/js-yaml": "^4.0.9",
|
|
77
77
|
"@types/mdast": "^4.0.3",
|
|
78
78
|
"@types/mdx": "^2.0.13",
|
|
79
|
-
"@types/node": "^24.3.
|
|
79
|
+
"@types/node": "^24.3.1",
|
|
80
80
|
"@types/react": "^19.1.12",
|
|
81
81
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
82
82
|
"next": "^15.5.2",
|
|
83
83
|
"react": "^19.1.1",
|
|
84
84
|
"rollup": "^4.50.0",
|
|
85
85
|
"vfile": "^6.0.3",
|
|
86
|
-
"vite": "^7.1.
|
|
86
|
+
"vite": "^7.1.4",
|
|
87
87
|
"webpack": "^5.101.3",
|
|
88
88
|
"@fumadocs/mdx-remote": "1.4.0",
|
|
89
89
|
"eslint-config-custom": "0.0.0",
|
|
90
|
-
"fumadocs-core": "15.7.
|
|
90
|
+
"fumadocs-core": "15.7.10",
|
|
91
91
|
"tsconfig": "0.0.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
package/dist/chunk-6Y5JDZHD.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// src/utils/import-formatter.ts
|
|
2
|
-
import path from "path";
|
|
3
|
-
function getImportCode(info) {
|
|
4
|
-
const specifier = JSON.stringify(info.specifier);
|
|
5
|
-
if (info.type === "default") return `import ${info.name} from ${specifier}`;
|
|
6
|
-
if (info.type === "namespace")
|
|
7
|
-
return `import * as ${info.name} from ${specifier}`;
|
|
8
|
-
if (info.type === "named") {
|
|
9
|
-
const names = info.names.map(
|
|
10
|
-
(name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
|
|
11
|
-
);
|
|
12
|
-
return `import { ${names.join(", ")} } from ${specifier}`;
|
|
13
|
-
}
|
|
14
|
-
return `import ${specifier}`;
|
|
15
|
-
}
|
|
16
|
-
function toImportPath(file, config) {
|
|
17
|
-
const ext = path.extname(file);
|
|
18
|
-
let filename;
|
|
19
|
-
if (ext === ".ts" && config.jsExtension) {
|
|
20
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
21
|
-
} else if (ext === ".ts") {
|
|
22
|
-
filename = file.substring(0, file.length - ext.length);
|
|
23
|
-
} else {
|
|
24
|
-
filename = file;
|
|
25
|
-
}
|
|
26
|
-
let importPath;
|
|
27
|
-
if ("relativeTo" in config) {
|
|
28
|
-
importPath = path.relative(config.relativeTo, filename);
|
|
29
|
-
if (!path.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
30
|
-
importPath = `./${importPath}`;
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
importPath = path.resolve(filename);
|
|
34
|
-
}
|
|
35
|
-
return importPath.replaceAll(path.sep, "/");
|
|
36
|
-
}
|
|
37
|
-
function ident(code, tab = 1) {
|
|
38
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/utils/collections.ts
|
|
42
|
-
function getSupportedFormats(collection) {
|
|
43
|
-
return {
|
|
44
|
-
doc: ["mdx", "md"],
|
|
45
|
-
meta: ["json", "yaml"]
|
|
46
|
-
}[collection.type];
|
|
47
|
-
}
|
|
48
|
-
function getGlobPatterns(collection) {
|
|
49
|
-
if (collection.files) return collection.files;
|
|
50
|
-
return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
|
|
51
|
-
}
|
|
52
|
-
function isFileSupported(filePath, collection) {
|
|
53
|
-
for (const format of getSupportedFormats(collection)) {
|
|
54
|
-
if (filePath.endsWith(`.${format}`)) return true;
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export {
|
|
60
|
-
getImportCode,
|
|
61
|
-
toImportPath,
|
|
62
|
-
ident,
|
|
63
|
-
getGlobPatterns,
|
|
64
|
-
isFileSupported
|
|
65
|
-
};
|