@clarify-labs/cli 0.10.1 → 0.10.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/output/cli.cjs +1 -1
- package/output/cli.js +1 -1
- package/output/{engine-Ca_2MCj9.js → engine-CSSL_gGd.js} +58 -96
- package/output/engine-CSSL_gGd.js.map +1 -0
- package/output/{engine-5bdNX2Oo.cjs → engine-qafLfnXQ.cjs} +60 -95
- package/output/engine-qafLfnXQ.cjs.map +1 -0
- package/output/index.cjs +1 -1
- package/output/index.js +1 -1
- package/output/parsers/markdown/mdx.d.ts +4 -4
- package/package.json +6 -3
- package/output/engine-5bdNX2Oo.cjs.map +0 -1
- package/output/engine-Ca_2MCj9.js.map +0 -1
|
@@ -27,14 +27,20 @@ let _tailwindcss_vite = require("@tailwindcss/vite");
|
|
|
27
27
|
_tailwindcss_vite = __toESM(_tailwindcss_vite, 1);
|
|
28
28
|
let _vitejs_plugin_react = require("@vitejs/plugin-react");
|
|
29
29
|
_vitejs_plugin_react = __toESM(_vitejs_plugin_react, 1);
|
|
30
|
+
let rehype_raw = require("rehype-raw");
|
|
31
|
+
rehype_raw = __toESM(rehype_raw, 1);
|
|
30
32
|
let _mdx_js_mdx = require("@mdx-js/mdx");
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
let
|
|
33
|
+
let _shikijs_rehype = require("@shikijs/rehype");
|
|
34
|
+
_shikijs_rehype = __toESM(_shikijs_rehype, 1);
|
|
35
|
+
let rehype_slug = require("rehype-slug");
|
|
36
|
+
rehype_slug = __toESM(rehype_slug, 1);
|
|
34
37
|
let shiki = require("shiki");
|
|
35
38
|
let unist_util_visit = require("unist-util-visit");
|
|
36
39
|
let _clarify_labs_renderer = require("@clarify-labs/renderer");
|
|
37
40
|
let node_fs_promises = require("node:fs/promises");
|
|
41
|
+
let github_slugger = require("github-slugger");
|
|
42
|
+
github_slugger = __toESM(github_slugger, 1);
|
|
43
|
+
let mdast_util_to_string = require("mdast-util-to-string");
|
|
38
44
|
let remark = require("remark");
|
|
39
45
|
let gray_matter = require("gray-matter");
|
|
40
46
|
gray_matter = __toESM(gray_matter, 1);
|
|
@@ -47,38 +53,11 @@ let _apidevtools_swagger_parser = require("@apidevtools/swagger-parser");
|
|
|
47
53
|
_apidevtools_swagger_parser = __toESM(_apidevtools_swagger_parser, 1);
|
|
48
54
|
let node_os = require("node:os");
|
|
49
55
|
let node_module = require("node:module");
|
|
50
|
-
//#region source/parsers/markdown/utils.ts
|
|
51
|
-
function escapeHtml(text) {
|
|
52
|
-
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
53
|
-
}
|
|
54
|
-
//#endregion
|
|
55
56
|
//#region source/parsers/markdown/mdx.ts
|
|
56
57
|
function getLanguage(className) {
|
|
57
58
|
return (Array.isArray(className) ? className : typeof className === "string" ? className.split(/\s+/) : []).find((item) => typeof item === "string" && item.startsWith("language-"))?.replace(/^language-/, "") || "txt";
|
|
58
59
|
}
|
|
59
|
-
function getTextContent(node) {
|
|
60
|
-
if (!node) return "";
|
|
61
|
-
if (typeof node.value === "string") return node.value;
|
|
62
|
-
return node.children?.map(getTextContent).join("") ?? "";
|
|
63
|
-
}
|
|
64
|
-
function renderPlainCode(code) {
|
|
65
|
-
return code.split("\n").map((line) => `<span>${escapeHtml(line)}</span>`).join("\n");
|
|
66
|
-
}
|
|
67
|
-
function isBundledLanguage(language) {
|
|
68
|
-
return language in shiki.bundledLanguages;
|
|
69
|
-
}
|
|
70
|
-
var highlighterPromise;
|
|
71
60
|
var cssVariablesTheme = (0, shiki.createCssVariablesTheme)();
|
|
72
|
-
async function getHighlighter() {
|
|
73
|
-
highlighterPromise = highlighterPromise ?? (0, shiki.createHighlighter)({
|
|
74
|
-
themes: [cssVariablesTheme],
|
|
75
|
-
langs: []
|
|
76
|
-
});
|
|
77
|
-
return highlighterPromise;
|
|
78
|
-
}
|
|
79
|
-
function renderHighlightedCode(html) {
|
|
80
|
-
return (/<code[^>]*>([\s\S]*?)<\/code>/.exec(html)?.[1] ?? html).split("\n").map((line) => line.trimStart().startsWith("<span") ? line : `<span>${line}</span>`).join("\n");
|
|
81
|
-
}
|
|
82
61
|
function rehypeParseCodeBlocks() {
|
|
83
62
|
return (tree) => {
|
|
84
63
|
(0, unist_util_visit.visit)(tree, "element", (node, _nodeIndex, parentNode) => {
|
|
@@ -96,61 +75,18 @@ function rehypeParseCodeBlocks() {
|
|
|
96
75
|
});
|
|
97
76
|
};
|
|
98
77
|
}
|
|
99
|
-
function rehypeShiki() {
|
|
100
|
-
return async (tree) => {
|
|
101
|
-
const shikiHighlighter = await getHighlighter();
|
|
102
|
-
const languages = /* @__PURE__ */ new Set();
|
|
103
|
-
(0, unist_util_visit.visit)(tree, "element", (node) => {
|
|
104
|
-
if (node.tagName !== "pre") return;
|
|
105
|
-
const codeNode = node.children?.[0];
|
|
106
|
-
if (codeNode?.tagName !== "code") return;
|
|
107
|
-
const language = typeof node.properties?.language === "string" ? node.properties.language : getLanguage(codeNode.properties?.className);
|
|
108
|
-
if (language && language !== "txt" && isBundledLanguage(language)) languages.add(language);
|
|
109
|
-
});
|
|
110
|
-
if (languages.size > 0) await shikiHighlighter.loadLanguage(...languages);
|
|
111
|
-
(0, unist_util_visit.visit)(tree, "element", (node) => {
|
|
112
|
-
if (node.tagName !== "pre") return;
|
|
113
|
-
const codeNode = node.children?.[0];
|
|
114
|
-
if (codeNode?.tagName !== "code") return;
|
|
115
|
-
node.properties = node.properties ?? {};
|
|
116
|
-
codeNode.properties = codeNode.properties ?? {};
|
|
117
|
-
const code = getTextContent(codeNode);
|
|
118
|
-
const language = typeof node.properties.language === "string" ? node.properties.language : getLanguage(codeNode.properties.className);
|
|
119
|
-
node.properties.code = code;
|
|
120
|
-
codeNode.properties.code = code;
|
|
121
|
-
codeNode.properties.language = language;
|
|
122
|
-
let highlighted = renderPlainCode(code);
|
|
123
|
-
if (language && language !== "txt") try {
|
|
124
|
-
highlighted = renderHighlightedCode(shikiHighlighter.codeToHtml(code, {
|
|
125
|
-
lang: language,
|
|
126
|
-
theme: cssVariablesTheme
|
|
127
|
-
}));
|
|
128
|
-
} catch {
|
|
129
|
-
highlighted = renderPlainCode(code);
|
|
130
|
-
}
|
|
131
|
-
codeNode.children = [{
|
|
132
|
-
type: "text",
|
|
133
|
-
value: highlighted
|
|
134
|
-
}];
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function rehypeSlugSections() {
|
|
139
|
-
return (tree) => {
|
|
140
|
-
const slugger = new github_slugger.default();
|
|
141
|
-
(0, unist_util_visit.visit)(tree, "element", (node) => {
|
|
142
|
-
if (node.tagName !== "h2" && node.tagName !== "h3") return;
|
|
143
|
-
node.properties = node.properties ?? {};
|
|
144
|
-
if (node.properties.id) return;
|
|
145
|
-
node.properties.id = slugger.slug((0, mdast_util_to_string.toString)(node));
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
78
|
var remarkPlugins = _clarify_labs_renderer.markdownRemarkPlugins;
|
|
150
79
|
var rehypePlugins = [
|
|
151
|
-
|
|
80
|
+
rehype_slug.default,
|
|
152
81
|
rehypeParseCodeBlocks,
|
|
153
|
-
|
|
82
|
+
[_shikijs_rehype.default, {
|
|
83
|
+
theme: cssVariablesTheme,
|
|
84
|
+
langs: [],
|
|
85
|
+
lazy: true,
|
|
86
|
+
addLanguageClass: true,
|
|
87
|
+
fallbackLanguage: "text",
|
|
88
|
+
parseMetaString: _clarify_labs_renderer.parseCodeMeta
|
|
89
|
+
}]
|
|
154
90
|
];
|
|
155
91
|
function formatMdxDiagnostic(error) {
|
|
156
92
|
if (error instanceof Error) return error.message;
|
|
@@ -162,7 +98,8 @@ function formatMdxDiagnostic(error) {
|
|
|
162
98
|
*
|
|
163
99
|
* `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
|
|
164
100
|
* is expensive. The real highlighting happens at Vite build time via the
|
|
165
|
-
* `@mdx-js/rollup`
|
|
101
|
+
* `@mdx-js/rollup` plugins (see `createMarkdownPlugin` and `createMdxPlugin`
|
|
102
|
+
* in `core/adapters.ts`), which
|
|
166
103
|
* runs the full remark + rehype pipeline. Re-running it here, during route
|
|
167
104
|
* discovery (Phase 3), would compile every `.mdx` file twice and invoke Shiki
|
|
168
105
|
* once per file per `engine.refresh()` — see ARCHITECTURE.md §2.2 which states
|
|
@@ -311,6 +248,11 @@ function kebabToTitle(str) {
|
|
|
311
248
|
function parseMdxTree(content) {
|
|
312
249
|
return remark.remark.parse(content);
|
|
313
250
|
}
|
|
251
|
+
async function compileRouteDiagnostic(content, filePath, baseDir) {
|
|
252
|
+
if ((0, node_path.extname)(filePath).toLowerCase() !== ".mdx") return void 0;
|
|
253
|
+
const result = await compileMdxContent(content, filePath, baseDir);
|
|
254
|
+
return result.ok ? void 0 : result.diagnostic;
|
|
255
|
+
}
|
|
314
256
|
/** 从内容中提取第一个 H1 标题 */
|
|
315
257
|
function extractH1(content) {
|
|
316
258
|
const tree = parseMdxTree(content);
|
|
@@ -405,7 +347,7 @@ async function findContentRoutes(dir, base = dir, options = {}) {
|
|
|
405
347
|
frontmatter,
|
|
406
348
|
content
|
|
407
349
|
};
|
|
408
|
-
const
|
|
350
|
+
const diagnostic = await compileRouteDiagnostic(page.content, fullPath, base);
|
|
409
351
|
let title = typeof page.frontmatter.title === "string" ? page.frontmatter.title : "";
|
|
410
352
|
if (!title) {
|
|
411
353
|
const lastPart = pathParts[pathParts.length - 1] ?? "";
|
|
@@ -427,7 +369,7 @@ async function findContentRoutes(dir, base = dir, options = {}) {
|
|
|
427
369
|
frontmatter: page.frontmatter,
|
|
428
370
|
content: page.content
|
|
429
371
|
},
|
|
430
|
-
diagnostic
|
|
372
|
+
diagnostic
|
|
431
373
|
});
|
|
432
374
|
}
|
|
433
375
|
}
|
|
@@ -1358,9 +1300,9 @@ async function refreshDevServer(engine, server) {
|
|
|
1358
1300
|
invalidateVirtualModules(engine, server);
|
|
1359
1301
|
return hasDevStructureChanged(before, createDevStructureSnapshot(engine.routes, engine.navigation));
|
|
1360
1302
|
}
|
|
1361
|
-
function
|
|
1303
|
+
function createNormalizedContentPlugin(engine) {
|
|
1362
1304
|
return {
|
|
1363
|
-
name: "clarify:normalized-
|
|
1305
|
+
name: "clarify:normalized-content",
|
|
1364
1306
|
enforce: "pre",
|
|
1365
1307
|
transform(_code, id) {
|
|
1366
1308
|
if (!/\.mdx?(?:\?|$)/.test(id)) return null;
|
|
@@ -1376,14 +1318,26 @@ function createNormalizedMdxContentPlugin(engine) {
|
|
|
1376
1318
|
}
|
|
1377
1319
|
function createMdxPlugin() {
|
|
1378
1320
|
return (0, _mdx_js_rollup.default)({
|
|
1379
|
-
include: ["**/*.
|
|
1321
|
+
include: ["**/*.mdx"],
|
|
1322
|
+
format: "mdx",
|
|
1380
1323
|
jsxImportSource: "react",
|
|
1381
1324
|
providerImportSource: "@clarify-labs/renderer",
|
|
1382
1325
|
remarkPlugins,
|
|
1383
1326
|
rehypePlugins
|
|
1384
1327
|
});
|
|
1385
1328
|
}
|
|
1386
|
-
function
|
|
1329
|
+
function createMarkdownPlugin() {
|
|
1330
|
+
return (0, _mdx_js_rollup.default)({
|
|
1331
|
+
include: ["**/*.md"],
|
|
1332
|
+
format: "md",
|
|
1333
|
+
jsxImportSource: "react",
|
|
1334
|
+
providerImportSource: "@clarify-labs/renderer",
|
|
1335
|
+
remarkPlugins,
|
|
1336
|
+
remarkRehypeOptions: { allowDangerousHtml: true },
|
|
1337
|
+
rehypePlugins: [rehype_raw.default, ...rehypePlugins]
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
function createClarifyViteCorePlugin(engine, normalizedContentPlugin, markdown, mdx) {
|
|
1387
1341
|
let viteConfig;
|
|
1388
1342
|
return {
|
|
1389
1343
|
name: "clarify:core",
|
|
@@ -1485,7 +1439,8 @@ function createClarifyViteCorePlugin(engine, normalizedMdxContentPlugin, mdx) {
|
|
|
1485
1439
|
outputDirectory: viteConfig.build.outDir,
|
|
1486
1440
|
ssrPlugins: [
|
|
1487
1441
|
engine.createSSGVirtualPlugin(),
|
|
1488
|
-
|
|
1442
|
+
normalizedContentPlugin,
|
|
1443
|
+
markdown,
|
|
1489
1444
|
mdx
|
|
1490
1445
|
]
|
|
1491
1446
|
});
|
|
@@ -1502,20 +1457,22 @@ function createClarifyViteCorePlugin(engine, normalizedMdxContentPlugin, mdx) {
|
|
|
1502
1457
|
* site itself - it only bridges Vite lifecycle hooks to the engine.
|
|
1503
1458
|
*/
|
|
1504
1459
|
function createViteAdapter(engine) {
|
|
1505
|
-
const
|
|
1460
|
+
const normalizedContentPlugin = createNormalizedContentPlugin(engine);
|
|
1461
|
+
const markdown = createMarkdownPlugin();
|
|
1506
1462
|
const mdx = createMdxPlugin();
|
|
1507
1463
|
const tailwind = (0, _tailwindcss_vite.default)();
|
|
1508
1464
|
return [
|
|
1509
1465
|
...(0, _vitejs_plugin_react.default)(),
|
|
1510
1466
|
...Array.isArray(tailwind) ? tailwind : [tailwind],
|
|
1511
|
-
|
|
1512
|
-
createClarifyViteCorePlugin(engine,
|
|
1467
|
+
normalizedContentPlugin,
|
|
1468
|
+
createClarifyViteCorePlugin(engine, normalizedContentPlugin, markdown, mdx),
|
|
1469
|
+
markdown,
|
|
1513
1470
|
mdx
|
|
1514
1471
|
];
|
|
1515
1472
|
}
|
|
1516
1473
|
var cliPackageVersion = {
|
|
1517
1474
|
name: "@clarify-labs/cli",
|
|
1518
|
-
version: "0.10.
|
|
1475
|
+
version: "0.10.2",
|
|
1519
1476
|
license: "AGPL-3.0-only",
|
|
1520
1477
|
type: "module",
|
|
1521
1478
|
repository: {
|
|
@@ -1556,6 +1513,7 @@ var cliPackageVersion = {
|
|
|
1556
1513
|
"@clarify-labs/templates": "workspace:*",
|
|
1557
1514
|
"@mdx-js/mdx": "^3.1.1",
|
|
1558
1515
|
"@mdx-js/rollup": "^3.1.1",
|
|
1516
|
+
"@shikijs/rehype": "^4.3.0",
|
|
1559
1517
|
"@tailwindcss/vite": "^4.3.2",
|
|
1560
1518
|
"@vitejs/plugin-react": "^6.0.3",
|
|
1561
1519
|
"cac": "^7.0.0",
|
|
@@ -1570,6 +1528,8 @@ var cliPackageVersion = {
|
|
|
1570
1528
|
"react-router": "^7.0.0",
|
|
1571
1529
|
"react-router-dom": "^7.0.0",
|
|
1572
1530
|
"react-zoom-pan-pinch": "^4.0.3",
|
|
1531
|
+
"rehype-raw": "^7.0.0",
|
|
1532
|
+
"rehype-slug": "^6.0.0",
|
|
1573
1533
|
"remark": "^15.0.1",
|
|
1574
1534
|
"remark-gfm": "^4.0.1",
|
|
1575
1535
|
"shiki": "4.3.0",
|
|
@@ -2714,6 +2674,11 @@ function writeClarifyEnvDts(projectRoot, plugins) {
|
|
|
2714
2674
|
(0, node_fs.writeFileSync)(filePath, next, "utf-8");
|
|
2715
2675
|
}
|
|
2716
2676
|
//#endregion
|
|
2677
|
+
//#region source/parsers/markdown/utils.ts
|
|
2678
|
+
function escapeHtml(text) {
|
|
2679
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2680
|
+
}
|
|
2681
|
+
//#endregion
|
|
2717
2682
|
//#region source/core/runtime/html-template.ts
|
|
2718
2683
|
/**
|
|
2719
2684
|
* HTML template manipulation helpers used during SSG.
|
|
@@ -3417,4 +3382,4 @@ Object.defineProperty(exports, "defineConfig", {
|
|
|
3417
3382
|
}
|
|
3418
3383
|
});
|
|
3419
3384
|
|
|
3420
|
-
//# sourceMappingURL=engine-
|
|
3385
|
+
//# sourceMappingURL=engine-qafLfnXQ.cjs.map
|