@qualcomm-ui/mdx-vite 2.14.2 → 2.15.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/ai-knowledge/env.d.ts +27 -0
- package/dist/ai-knowledge/env.d.ts.map +1 -0
- package/dist/{open-web-ui-knowledge/generate-knowledge.d.ts → ai-knowledge/generator/command.d.ts} +3 -3
- package/dist/ai-knowledge/generator/command.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/config.d.ts +4 -0
- package/dist/ai-knowledge/generator/config.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/demo-plugin.d.ts +8 -0
- package/dist/ai-knowledge/generator/demo-plugin.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/doc-props-plugin.d.ts +16 -0
- package/dist/ai-knowledge/generator/doc-props-plugin.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/generator.types.d.ts +51 -0
- package/dist/ai-knowledge/generator/generator.types.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/index.d.ts +2 -0
- package/dist/ai-knowledge/generator/index.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/knowledge-generator.d.ts +35 -0
- package/dist/ai-knowledge/generator/knowledge-generator.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/npm-install-tabs-plugin.d.ts +3 -0
- package/dist/ai-knowledge/generator/npm-install-tabs-plugin.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/qds-theme-plugin.d.ts +7 -0
- package/dist/ai-knowledge/generator/qds-theme-plugin.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/section-extractor.d.ts +47 -0
- package/dist/ai-knowledge/generator/section-extractor.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/section.types.d.ts +83 -0
- package/dist/ai-knowledge/generator/section.types.d.ts.map +1 -0
- package/dist/ai-knowledge/generator/utils.d.ts +11 -0
- package/dist/ai-knowledge/generator/utils.d.ts.map +1 -0
- package/dist/ai-knowledge/open-web-ui/api.d.ts.map +1 -0
- package/dist/ai-knowledge/open-web-ui/common.d.ts +67 -0
- package/dist/ai-knowledge/open-web-ui/common.d.ts.map +1 -0
- package/dist/ai-knowledge/open-web-ui/download-knowledge.d.ts.map +1 -0
- package/dist/{open-web-ui-knowledge → ai-knowledge/open-web-ui}/knowledge-cleaner.d.ts +1 -1
- package/dist/ai-knowledge/open-web-ui/knowledge-cleaner.d.ts.map +1 -0
- package/dist/ai-knowledge/open-web-ui/upload-knowledge.d.ts.map +1 -0
- package/dist/ai-knowledge/types.d.ts +57 -0
- package/dist/ai-knowledge/types.d.ts.map +1 -0
- package/dist/cli.js +1879 -1459
- package/dist/cli.js.map +4 -4
- package/dist/docs-plugin/docs-plugin.d.ts.map +1 -1
- package/dist/docs-plugin/internal/config-schema.d.ts +30 -2
- package/dist/docs-plugin/internal/config-schema.d.ts.map +1 -1
- package/dist/docs-plugin/internal/services/markdown/remark-remove-jsx.d.ts.map +1 -1
- package/dist/docs-plugin/mdx-plugins.d.ts.map +1 -1
- package/dist/docs-plugin/remark/remark-extract-meta.d.ts +18 -0
- package/dist/docs-plugin/remark/remark-extract-meta.d.ts.map +1 -0
- package/dist/docs-plugin/types.d.ts +51 -6
- package/dist/docs-plugin/types.d.ts.map +1 -1
- package/dist/index.js +1126 -709
- package/dist/index.js.map +4 -4
- package/dist/tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/open-web-ui-knowledge/api.d.ts.map +0 -1
- package/dist/open-web-ui-knowledge/common.d.ts +0 -33
- package/dist/open-web-ui-knowledge/common.d.ts.map +0 -1
- package/dist/open-web-ui-knowledge/download-knowledge.d.ts.map +0 -1
- package/dist/open-web-ui-knowledge/generate-knowledge.d.ts.map +0 -1
- package/dist/open-web-ui-knowledge/knowledge-cleaner.d.ts.map +0 -1
- package/dist/open-web-ui-knowledge/load-config-from-env.d.ts +0 -32
- package/dist/open-web-ui-knowledge/load-config-from-env.d.ts.map +0 -1
- package/dist/open-web-ui-knowledge/types.d.ts +0 -74
- package/dist/open-web-ui-knowledge/types.d.ts.map +0 -1
- package/dist/open-web-ui-knowledge/upload-knowledge.d.ts.map +0 -1
- /package/dist/{open-web-ui-knowledge → ai-knowledge/open-web-ui}/api.d.ts +0 -0
- /package/dist/{open-web-ui-knowledge → ai-knowledge/open-web-ui}/download-knowledge.d.ts +0 -0
- /package/dist/{open-web-ui-knowledge → ai-knowledge/open-web-ui}/upload-knowledge.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -3489,12 +3489,12 @@ import chalk5 from "chalk";
|
|
|
3489
3489
|
import { watch } from "chokidar";
|
|
3490
3490
|
import { glob as glob2 } from "glob";
|
|
3491
3491
|
import { existsSync, statSync } from "node:fs";
|
|
3492
|
-
import { readFile as
|
|
3493
|
-
import { basename as
|
|
3492
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
3493
|
+
import { basename as basename3, dirname as dirname4, join as join7, relative as relative3, resolve as resolve5 } from "node:path";
|
|
3494
3494
|
import {
|
|
3495
3495
|
createHighlighter
|
|
3496
3496
|
} from "shiki";
|
|
3497
|
-
import * as
|
|
3497
|
+
import * as ts2 from "typescript";
|
|
3498
3498
|
import {
|
|
3499
3499
|
quiCustomDarkTheme as quiCustomDarkTheme2
|
|
3500
3500
|
} from "@qualcomm-ui/mdx-common";
|
|
@@ -3505,7 +3505,7 @@ import chalk4 from "chalk";
|
|
|
3505
3505
|
import chokidar from "chokidar";
|
|
3506
3506
|
import { glob } from "glob";
|
|
3507
3507
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
3508
|
-
import { join as
|
|
3508
|
+
import { join as join6, resolve as resolve4 } from "node:path";
|
|
3509
3509
|
import prettyMilliseconds from "pretty-ms";
|
|
3510
3510
|
|
|
3511
3511
|
// ../../../node_modules/.pnpm/@commander-js+extra-typings@14.0.0_commander@14.0.2/node_modules/@commander-js/extra-typings/esm.mjs
|
|
@@ -3525,29 +3525,8 @@ var {
|
|
|
3525
3525
|
Help
|
|
3526
3526
|
} = import_index.default;
|
|
3527
3527
|
|
|
3528
|
-
// src/
|
|
3529
|
-
import
|
|
3530
|
-
import chalk3 from "chalk";
|
|
3531
|
-
import { minimatch } from "minimatch";
|
|
3532
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
3533
|
-
import {
|
|
3534
|
-
access,
|
|
3535
|
-
mkdir,
|
|
3536
|
-
readdir,
|
|
3537
|
-
readFile,
|
|
3538
|
-
rm,
|
|
3539
|
-
stat,
|
|
3540
|
-
writeFile
|
|
3541
|
-
} from "node:fs/promises";
|
|
3542
|
-
import { basename, dirname, extname, join as join2, relative as relative2, resolve } from "node:path";
|
|
3543
|
-
import remarkFrontmatter2 from "remark-frontmatter";
|
|
3544
|
-
import remarkMdx3 from "remark-mdx";
|
|
3545
|
-
import remarkParse4 from "remark-parse";
|
|
3546
|
-
import remarkParseFrontmatter2 from "remark-parse-frontmatter";
|
|
3547
|
-
import remarkStringify3 from "remark-stringify";
|
|
3548
|
-
import { unified as unified4 } from "unified";
|
|
3549
|
-
import { visit as visit5 } from "unist-util-visit";
|
|
3550
|
-
import { kebabCase } from "@qualcomm-ui/utils/change-case";
|
|
3528
|
+
// src/ai-knowledge/env.ts
|
|
3529
|
+
import { config } from "dotenv";
|
|
3551
3530
|
|
|
3552
3531
|
// src/docs-plugin/internal/config-loader.ts
|
|
3553
3532
|
import { cosmiconfigSync } from "cosmiconfig";
|
|
@@ -3597,15 +3576,27 @@ var knowledgeExtraFileSchema = implement().with({
|
|
|
3597
3576
|
processAsMdx: z2.boolean().optional(),
|
|
3598
3577
|
title: z2.string().optional()
|
|
3599
3578
|
});
|
|
3579
|
+
var frontmatterConfigSchema = z2.object({
|
|
3580
|
+
exclude: z2.array(z2.string()).optional(),
|
|
3581
|
+
extraFields: z2.record(z2.string(), z2.union([z2.string(), z2.array(z2.string())])).optional(),
|
|
3582
|
+
include: z2.array(z2.string()).optional()
|
|
3583
|
+
}).optional();
|
|
3584
|
+
var sectionsExportsSchema = implement().with({
|
|
3585
|
+
depths: z2.array(z2.number()).optional(),
|
|
3586
|
+
minContentLength: z2.number().optional(),
|
|
3587
|
+
outputPath: z2.string().optional()
|
|
3588
|
+
});
|
|
3600
3589
|
var knowledgeExportsSchema = implement().with({
|
|
3601
3590
|
enabled: z2.boolean().optional(),
|
|
3602
3591
|
exclude: z2.array(z2.string()).optional(),
|
|
3603
3592
|
extraFiles: z2.array(knowledgeExtraFileSchema).optional(),
|
|
3593
|
+
frontmatter: frontmatterConfigSchema,
|
|
3604
3594
|
generateBulkZip: z2.boolean().optional(),
|
|
3605
3595
|
generateManifest: z2.boolean().optional(),
|
|
3606
3596
|
manifestPath: z2.string().optional(),
|
|
3607
3597
|
metadata: z2.record(z2.string(), z2.string()).optional(),
|
|
3608
3598
|
pageTitlePrefix: z2.string().optional(),
|
|
3599
|
+
sections: sectionsExportsSchema.optional(),
|
|
3609
3600
|
staticPath: z2.string().optional()
|
|
3610
3601
|
});
|
|
3611
3602
|
var knowledgeIntegrationSchema = implement().with(
|
|
@@ -3615,7 +3606,7 @@ var knowledgeIntegrationSchema = implement().with(
|
|
|
3615
3606
|
exclude: z2.array(z2.string()).optional(),
|
|
3616
3607
|
exports: knowledgeExportsSchema.optional(),
|
|
3617
3608
|
extraFiles: z2.array(knowledgeExtraFileSchema).optional(),
|
|
3618
|
-
|
|
3609
|
+
frontmatter: frontmatterConfigSchema,
|
|
3619
3610
|
metadata: z2.record(z2.string(), z2.string()).optional(),
|
|
3620
3611
|
name: z2.string().optional(),
|
|
3621
3612
|
outputMode: z2.union([z2.literal("per-page"), z2.literal("aggregated")]).optional(),
|
|
@@ -3630,7 +3621,7 @@ var knowledgeEnvironmentSchema = implement().with({
|
|
|
3630
3621
|
exclude: z2.array(z2.string()).optional(),
|
|
3631
3622
|
exports: knowledgeExportsSchema.optional(),
|
|
3632
3623
|
extraFiles: z2.array(knowledgeExtraFileSchema).optional(),
|
|
3633
|
-
|
|
3624
|
+
frontmatter: frontmatterConfigSchema,
|
|
3634
3625
|
id: z2.string(),
|
|
3635
3626
|
metadata: z2.record(z2.string(), z2.string()).optional(),
|
|
3636
3627
|
name: z2.string().optional(),
|
|
@@ -4480,6 +4471,7 @@ var remarkRemoveJsx = () => {
|
|
|
4480
4471
|
return (tree, _file, done) => {
|
|
4481
4472
|
remove2(tree, "mdxjsEsm");
|
|
4482
4473
|
remove2(tree, "mdxJsxFlowElement");
|
|
4474
|
+
remove2(tree, "mdxJsxTextElement");
|
|
4483
4475
|
done();
|
|
4484
4476
|
};
|
|
4485
4477
|
};
|
|
@@ -5306,28 +5298,128 @@ var SearchIndexer = class {
|
|
|
5306
5298
|
}
|
|
5307
5299
|
};
|
|
5308
5300
|
|
|
5309
|
-
// src/
|
|
5310
|
-
import
|
|
5301
|
+
// src/ai-knowledge/generator/knowledge-generator.ts
|
|
5302
|
+
import AdmZip from "adm-zip";
|
|
5303
|
+
import chalk3 from "chalk";
|
|
5304
|
+
import { minimatch } from "minimatch";
|
|
5305
|
+
import { mkdir, readdir, readFile as readFile4, rm, stat, writeFile } from "node:fs/promises";
|
|
5306
|
+
import { basename as basename2, dirname as dirname3, join as join5, relative as relative2, resolve as resolve3 } from "node:path";
|
|
5307
|
+
import remarkFrontmatter2 from "remark-frontmatter";
|
|
5308
|
+
import remarkMdx3 from "remark-mdx";
|
|
5309
|
+
import remarkParse4 from "remark-parse";
|
|
5310
|
+
import remarkParseFrontmatter2 from "remark-parse-frontmatter";
|
|
5311
|
+
import remarkStringify4 from "remark-stringify";
|
|
5312
|
+
import { unified as unified5 } from "unified";
|
|
5313
|
+
import { visit as visit11 } from "unist-util-visit";
|
|
5314
|
+
import { kebabCase as kebabCase3 } from "@qualcomm-ui/utils/change-case";
|
|
5311
5315
|
|
|
5312
|
-
// src/
|
|
5313
|
-
|
|
5314
|
-
|
|
5316
|
+
// src/docs-plugin/remark/remark-extract-meta.ts
|
|
5317
|
+
import { SKIP, visit as visit5 } from "unist-util-visit";
|
|
5318
|
+
function parseValue(value) {
|
|
5319
|
+
const trimmed = value.trim();
|
|
5320
|
+
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
5321
|
+
const inner = trimmed.slice(1, -1);
|
|
5322
|
+
return inner.split(",").map((item) => item.trim()).filter(Boolean);
|
|
5323
|
+
}
|
|
5324
|
+
return trimmed;
|
|
5315
5325
|
}
|
|
5316
|
-
function
|
|
5317
|
-
|
|
5326
|
+
function parseMetaContent(content) {
|
|
5327
|
+
const result = {};
|
|
5328
|
+
const lines = content.split("\n");
|
|
5329
|
+
for (const line of lines) {
|
|
5330
|
+
const trimmed = line.trim();
|
|
5331
|
+
if (!trimmed || trimmed === ":::") {
|
|
5332
|
+
continue;
|
|
5333
|
+
}
|
|
5334
|
+
const colonIndex = trimmed.indexOf(":");
|
|
5335
|
+
if (colonIndex === -1) {
|
|
5336
|
+
continue;
|
|
5337
|
+
}
|
|
5338
|
+
const key = trimmed.slice(0, colonIndex).trim();
|
|
5339
|
+
const value = trimmed.slice(colonIndex + 1).trim();
|
|
5340
|
+
if (key && value) {
|
|
5341
|
+
result[key] = parseValue(value);
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
return result;
|
|
5318
5345
|
}
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5346
|
+
var remarkExtractMeta = (metadata = {}) => {
|
|
5347
|
+
return (tree) => {
|
|
5348
|
+
const nodesToRemove = [];
|
|
5349
|
+
visit5(tree, "paragraph", (node, index, parent) => {
|
|
5350
|
+
if (!parent || index === void 0) {
|
|
5351
|
+
return;
|
|
5352
|
+
}
|
|
5353
|
+
const firstChild = node.children[0];
|
|
5354
|
+
if (firstChild?.type !== "text") {
|
|
5355
|
+
return;
|
|
5356
|
+
}
|
|
5357
|
+
const text = firstChild.value;
|
|
5358
|
+
const openMatch = text.match(/^:::\s*meta\s*/);
|
|
5359
|
+
if (!openMatch) {
|
|
5360
|
+
return;
|
|
5361
|
+
}
|
|
5362
|
+
if (text.includes(":::") && text.lastIndexOf(":::") > openMatch[0].length) {
|
|
5363
|
+
const afterOpen = text.slice(openMatch[0].length);
|
|
5364
|
+
const closeIndex = afterOpen.lastIndexOf(":::");
|
|
5365
|
+
const content = afterOpen.slice(0, closeIndex);
|
|
5366
|
+
const parsed = parseMetaContent(content);
|
|
5367
|
+
Object.assign(metadata, parsed);
|
|
5368
|
+
nodesToRemove.push({ index, parent });
|
|
5369
|
+
return SKIP;
|
|
5370
|
+
}
|
|
5371
|
+
let fullText = text;
|
|
5372
|
+
for (let i = 1; i < node.children.length; i++) {
|
|
5373
|
+
const child = node.children[i];
|
|
5374
|
+
if (child.type === "text") {
|
|
5375
|
+
fullText += child.value;
|
|
5376
|
+
}
|
|
5377
|
+
}
|
|
5378
|
+
const afterOpenFull = fullText.slice(openMatch[0].length);
|
|
5379
|
+
const closeIndexFull = afterOpenFull.lastIndexOf(":::");
|
|
5380
|
+
if (closeIndexFull !== -1) {
|
|
5381
|
+
const content = afterOpenFull.slice(0, closeIndexFull);
|
|
5382
|
+
const parsed = parseMetaContent(content);
|
|
5383
|
+
Object.assign(metadata, parsed);
|
|
5384
|
+
nodesToRemove.push({ index, parent });
|
|
5385
|
+
return SKIP;
|
|
5386
|
+
}
|
|
5387
|
+
});
|
|
5388
|
+
for (let i = nodesToRemove.length - 1; i >= 0; i--) {
|
|
5389
|
+
const { index, parent } = nodesToRemove[i];
|
|
5390
|
+
parent.children.splice(index, 1);
|
|
5391
|
+
}
|
|
5392
|
+
};
|
|
5393
|
+
};
|
|
5394
|
+
|
|
5395
|
+
// src/ai-knowledge/generator/config.ts
|
|
5396
|
+
var currentConfig = null;
|
|
5397
|
+
function setConfig(config2) {
|
|
5398
|
+
currentConfig = config2;
|
|
5322
5399
|
}
|
|
5323
|
-
function
|
|
5324
|
-
|
|
5400
|
+
function getConfig() {
|
|
5401
|
+
if (!currentConfig) {
|
|
5402
|
+
throw new Error("Config not initialized");
|
|
5403
|
+
}
|
|
5404
|
+
return currentConfig;
|
|
5325
5405
|
}
|
|
5326
|
-
|
|
5327
|
-
|
|
5406
|
+
|
|
5407
|
+
// src/ai-knowledge/generator/demo-plugin.ts
|
|
5408
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
5409
|
+
import { basename, extname, join as join3 } from "node:path";
|
|
5410
|
+
import { visit as visit6 } from "unist-util-visit";
|
|
5411
|
+
import { kebabCase } from "@qualcomm-ui/utils/change-case";
|
|
5412
|
+
|
|
5413
|
+
// src/ai-knowledge/generator/utils.ts
|
|
5414
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
5415
|
+
import { access, readFile } from "node:fs/promises";
|
|
5416
|
+
import { dirname, join as join2, resolve } from "node:path";
|
|
5417
|
+
import ts from "typescript";
|
|
5418
|
+
async function exists(dirPath) {
|
|
5419
|
+
return access(dirPath).then(() => true).catch(() => false);
|
|
5328
5420
|
}
|
|
5329
|
-
function
|
|
5330
|
-
return
|
|
5421
|
+
function computeMd5(content) {
|
|
5422
|
+
return createHash2("md5").update(content).digest("hex");
|
|
5331
5423
|
}
|
|
5332
5424
|
function isPreviewLine(trimmedLine) {
|
|
5333
5425
|
return trimmedLine === "// preview" || /^\{\s*\/\*\s*preview\s*\*\/\s*\}$/.test(trimmedLine) || /^<!--\s*preview\s*-->$/.test(trimmedLine);
|
|
@@ -5347,11 +5439,21 @@ function getIntroLines(projectName, description) {
|
|
|
5347
5439
|
return lines.join("\n");
|
|
5348
5440
|
}
|
|
5349
5441
|
function extractRelativeImports(content) {
|
|
5442
|
+
const sourceFile = ts.createSourceFile(
|
|
5443
|
+
"temp.ts",
|
|
5444
|
+
content,
|
|
5445
|
+
ts.ScriptTarget.Latest,
|
|
5446
|
+
false,
|
|
5447
|
+
ts.ScriptKind.TSX
|
|
5448
|
+
);
|
|
5350
5449
|
const imports = [];
|
|
5351
|
-
const
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5450
|
+
for (const statement of sourceFile.statements) {
|
|
5451
|
+
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
5452
|
+
const path = statement.moduleSpecifier.text;
|
|
5453
|
+
if (path.startsWith(".")) {
|
|
5454
|
+
imports.push(path);
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5355
5457
|
}
|
|
5356
5458
|
return imports;
|
|
5357
5459
|
}
|
|
@@ -5376,30 +5478,169 @@ async function resolveModulePath(importPath, fromFile) {
|
|
|
5376
5478
|
function extractMetadata(metadata) {
|
|
5377
5479
|
return Object.entries(metadata ?? {});
|
|
5378
5480
|
}
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5481
|
+
|
|
5482
|
+
// src/ai-knowledge/generator/demo-plugin.ts
|
|
5483
|
+
async function collectDemoImports(demoCode, demoFilePath, visited = /* @__PURE__ */ new Set()) {
|
|
5484
|
+
const modules = [];
|
|
5485
|
+
const relativeImports = extractRelativeImports(demoCode);
|
|
5486
|
+
for (const importPath of relativeImports) {
|
|
5487
|
+
const resolvedPath = await resolveModulePath(importPath, demoFilePath);
|
|
5488
|
+
if (!resolvedPath || visited.has(resolvedPath)) {
|
|
5489
|
+
continue;
|
|
5490
|
+
}
|
|
5491
|
+
visited.add(resolvedPath);
|
|
5492
|
+
try {
|
|
5493
|
+
const importContent = await readFile2(resolvedPath, "utf-8");
|
|
5494
|
+
modules.push({
|
|
5495
|
+
content: importContent,
|
|
5496
|
+
path: resolvedPath
|
|
5497
|
+
});
|
|
5498
|
+
const nestedModules = await collectDemoImports(
|
|
5499
|
+
importContent,
|
|
5500
|
+
resolvedPath,
|
|
5501
|
+
visited
|
|
5502
|
+
);
|
|
5503
|
+
modules.push(...nestedModules);
|
|
5504
|
+
} catch {
|
|
5505
|
+
if (getConfig().verbose) {
|
|
5506
|
+
console.log(` Could not read import: ${resolvedPath}`);
|
|
5507
|
+
}
|
|
5508
|
+
}
|
|
5509
|
+
}
|
|
5510
|
+
return modules;
|
|
5511
|
+
}
|
|
5512
|
+
function formatDemos(demosFolder) {
|
|
5513
|
+
return () => async (tree) => {
|
|
5514
|
+
const promises = [];
|
|
5515
|
+
visit6(
|
|
5516
|
+
tree,
|
|
5517
|
+
"mdxJsxFlowElement",
|
|
5518
|
+
(node, index, parent) => {
|
|
5519
|
+
if (!node?.name || !["QdsDemo", "CodeDemo", "Demo"].includes(node.name)) {
|
|
5520
|
+
return;
|
|
5521
|
+
}
|
|
5522
|
+
const nameAttr = node.attributes?.find(
|
|
5523
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "name"
|
|
5524
|
+
);
|
|
5525
|
+
const nodeAttr = node.attributes?.find(
|
|
5526
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "node"
|
|
5527
|
+
);
|
|
5528
|
+
let demoName;
|
|
5529
|
+
if (nameAttr && typeof nameAttr.value === "string") {
|
|
5530
|
+
demoName = nameAttr.value;
|
|
5531
|
+
} else if (nodeAttr?.value && typeof nodeAttr.value !== "string") {
|
|
5532
|
+
const estree = nodeAttr.value.data?.estree;
|
|
5533
|
+
if (estree?.body?.[0]?.type === "ExpressionStatement") {
|
|
5534
|
+
const expression = estree.body[0].expression;
|
|
5535
|
+
if (expression.type === "MemberExpression" && expression.object.type === "Identifier" && expression.object.name === "Demo" && expression.property.type === "Identifier") {
|
|
5536
|
+
demoName = expression.property.name;
|
|
5537
|
+
}
|
|
5538
|
+
}
|
|
5539
|
+
}
|
|
5540
|
+
if (!demoName) {
|
|
5541
|
+
if (parent && index !== void 0) {
|
|
5542
|
+
parent.children.splice(index, 1);
|
|
5543
|
+
}
|
|
5544
|
+
return;
|
|
5545
|
+
}
|
|
5546
|
+
promises.push(
|
|
5547
|
+
(async () => {
|
|
5548
|
+
const kebabName = kebabCase(demoName);
|
|
5549
|
+
let filePath = `${kebabName}.tsx`;
|
|
5550
|
+
if (!demosFolder) {
|
|
5551
|
+
if (getConfig().verbose) {
|
|
5552
|
+
console.log(` No demos folder for ${demoName}`);
|
|
5553
|
+
}
|
|
5554
|
+
if (parent && index !== void 0) {
|
|
5555
|
+
parent.children.splice(index, 1);
|
|
5556
|
+
}
|
|
5557
|
+
return;
|
|
5558
|
+
}
|
|
5559
|
+
let demoFilePath = join3(demosFolder, filePath);
|
|
5560
|
+
let isAngularDemo = false;
|
|
5561
|
+
if (!await exists(demoFilePath)) {
|
|
5562
|
+
demoFilePath = join3(demosFolder, `${kebabName}.ts`);
|
|
5563
|
+
if (await exists(demoFilePath)) {
|
|
5564
|
+
isAngularDemo = true;
|
|
5565
|
+
filePath = `${kebabCase(demoName).replace("-component", ".component")}.ts`;
|
|
5566
|
+
demoFilePath = join3(demosFolder, filePath);
|
|
5567
|
+
} else {
|
|
5568
|
+
console.log(` Demo not found ${demoName}`);
|
|
5569
|
+
if (parent && index !== void 0) {
|
|
5570
|
+
parent.children.splice(index, 1);
|
|
5571
|
+
}
|
|
5572
|
+
return;
|
|
5573
|
+
}
|
|
5574
|
+
}
|
|
5575
|
+
try {
|
|
5576
|
+
const demoCode = await readFile2(demoFilePath, "utf-8");
|
|
5577
|
+
const cleanedCode = removePreviewLines(demoCode);
|
|
5578
|
+
if (getConfig().verbose) {
|
|
5579
|
+
console.log(` Replaced demo ${demoName} with source code`);
|
|
5580
|
+
}
|
|
5581
|
+
const demoCodeBlock = {
|
|
5582
|
+
lang: isAngularDemo ? "angular-ts" : "tsx",
|
|
5583
|
+
meta: null,
|
|
5584
|
+
type: "code",
|
|
5585
|
+
value: cleanedCode
|
|
5586
|
+
};
|
|
5587
|
+
const importedModules = await collectDemoImports(
|
|
5588
|
+
demoCode,
|
|
5589
|
+
demoFilePath
|
|
5590
|
+
);
|
|
5591
|
+
if (importedModules.length === 0 || !parent || index === void 0) {
|
|
5592
|
+
Object.assign(node, demoCodeBlock);
|
|
5593
|
+
} else {
|
|
5594
|
+
const nodesToInsert = [demoCodeBlock];
|
|
5595
|
+
for (const importedModule of importedModules) {
|
|
5596
|
+
const ext = extname(importedModule.path).slice(1);
|
|
5597
|
+
const filename = basename(importedModule.path);
|
|
5598
|
+
nodesToInsert.push({
|
|
5599
|
+
lang: ext,
|
|
5600
|
+
meta: `title="${filename}"`,
|
|
5601
|
+
type: "code",
|
|
5602
|
+
value: importedModule.content
|
|
5603
|
+
});
|
|
5604
|
+
}
|
|
5605
|
+
parent.children.splice(index, 1, ...nodesToInsert);
|
|
5606
|
+
if (getConfig().verbose) {
|
|
5607
|
+
console.log(
|
|
5608
|
+
` Added ${importedModules.length} imported file(s) after demo`
|
|
5609
|
+
);
|
|
5610
|
+
}
|
|
5611
|
+
}
|
|
5612
|
+
} catch (error) {
|
|
5613
|
+
if (getConfig().verbose) {
|
|
5614
|
+
console.log(`Error reading demo ${demoName}`, error);
|
|
5615
|
+
}
|
|
5616
|
+
if (parent && index !== void 0) {
|
|
5617
|
+
parent.children.splice(index, 1);
|
|
5618
|
+
}
|
|
5619
|
+
}
|
|
5620
|
+
})()
|
|
5385
5621
|
);
|
|
5386
|
-
const packageNames = packages ? extractNamesFromAttribute(packages) : [];
|
|
5387
|
-
Object.assign(node, {
|
|
5388
|
-
lang: "shell",
|
|
5389
|
-
meta: null,
|
|
5390
|
-
type: "code",
|
|
5391
|
-
value: `npm install ${packageNames.join(" ")}`
|
|
5392
|
-
});
|
|
5393
5622
|
}
|
|
5394
|
-
|
|
5395
|
-
|
|
5623
|
+
);
|
|
5624
|
+
await Promise.all(promises);
|
|
5396
5625
|
};
|
|
5397
|
-
}
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5626
|
+
}
|
|
5627
|
+
|
|
5628
|
+
// src/ai-knowledge/generator/doc-props-plugin.ts
|
|
5629
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
5630
|
+
import { dirname as dirname2, join as join4, resolve as resolve2 } from "node:path";
|
|
5631
|
+
import { visit as visit7 } from "unist-util-visit";
|
|
5632
|
+
function extractBestType(propInfo) {
|
|
5633
|
+
const type = propInfo.resolvedType?.prettyType || propInfo.type;
|
|
5634
|
+
return cleanType(type.startsWith("| ") ? type.substring(2) : type);
|
|
5635
|
+
}
|
|
5636
|
+
function extractRequired(propInfo, isPartial) {
|
|
5637
|
+
return Boolean(propInfo.resolvedType?.required && !isPartial);
|
|
5638
|
+
}
|
|
5639
|
+
function cleanType(type) {
|
|
5640
|
+
return type.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
|
5641
|
+
}
|
|
5642
|
+
function cleanDefaultValue(defaultValue) {
|
|
5643
|
+
return defaultValue.replace(/^\n+/, "").replace(/\n+$/, "").trim();
|
|
5403
5644
|
}
|
|
5404
5645
|
function escapeText(value) {
|
|
5405
5646
|
return value.replace(/\n/g, " ");
|
|
@@ -5423,214 +5664,61 @@ function propsToDefinitionList(props) {
|
|
|
5423
5664
|
return parts.join("");
|
|
5424
5665
|
}).join("\n");
|
|
5425
5666
|
}
|
|
5426
|
-
|
|
5427
|
-
if (!data || typeof data !== "object") {
|
|
5428
|
-
return "";
|
|
5429
|
-
}
|
|
5430
|
-
if (cssPropertyName) {
|
|
5431
|
-
return JSON.stringify({ cssProperty: cssPropertyName, data }, null, 2);
|
|
5432
|
-
}
|
|
5433
|
-
return JSON.stringify(data, null, 2);
|
|
5434
|
-
}
|
|
5435
|
-
var KnowledgeGenerator = class {
|
|
5436
|
-
config;
|
|
5667
|
+
var PropFormatter = class {
|
|
5437
5668
|
docProps = null;
|
|
5438
|
-
constructor(config2) {
|
|
5439
|
-
this.config = config2;
|
|
5440
|
-
}
|
|
5441
|
-
async run() {
|
|
5442
|
-
const extractedMetadata = extractMetadata(this.config.metadata);
|
|
5443
|
-
if (this.config.verbose) {
|
|
5444
|
-
console.log(`Scanning pages in: ${this.config.routeDir}`);
|
|
5445
|
-
if (this.config.exclude?.length) {
|
|
5446
|
-
console.log(`Excluding patterns: ${this.config.exclude.join(", ")}`);
|
|
5447
|
-
}
|
|
5448
|
-
}
|
|
5449
|
-
const [docProps, pages] = await Promise.all([
|
|
5450
|
-
this.loadDocProps(),
|
|
5451
|
-
this.scanPages()
|
|
5452
|
-
]);
|
|
5453
|
-
this.docProps = docProps;
|
|
5454
|
-
if (pages.length === 0) {
|
|
5455
|
-
console.log("No pages found.");
|
|
5456
|
-
return [];
|
|
5457
|
-
}
|
|
5458
|
-
if (this.config.verbose) {
|
|
5459
|
-
console.log(`Found ${pages.length} page(s)`);
|
|
5460
|
-
}
|
|
5461
|
-
const processedPages = [];
|
|
5462
|
-
for (const page of pages) {
|
|
5463
|
-
try {
|
|
5464
|
-
const processed = await this.processMdxPage(page);
|
|
5465
|
-
processedPages.push(processed);
|
|
5466
|
-
} catch (error) {
|
|
5467
|
-
console.error(`Failed to process page: ${page.name}`);
|
|
5468
|
-
process.exit(1);
|
|
5469
|
-
}
|
|
5470
|
-
}
|
|
5471
|
-
if (this.config.clean) {
|
|
5472
|
-
await rm(this.config.outputPath, { force: true, recursive: true }).catch(
|
|
5473
|
-
() => {
|
|
5474
|
-
}
|
|
5475
|
-
);
|
|
5476
|
-
}
|
|
5477
|
-
if (this.config.outputMode === "aggregated") {
|
|
5478
|
-
await this.generateAggregatedOutput(processedPages, pages);
|
|
5479
|
-
} else {
|
|
5480
|
-
await mkdir(this.config.outputPath, { recursive: true }).catch(() => {
|
|
5481
|
-
});
|
|
5482
|
-
await this.generatePerPageExports(
|
|
5483
|
-
pages,
|
|
5484
|
-
processedPages,
|
|
5485
|
-
extractedMetadata
|
|
5486
|
-
);
|
|
5487
|
-
}
|
|
5488
|
-
return pages;
|
|
5489
|
-
}
|
|
5490
5669
|
async loadDocProps() {
|
|
5491
|
-
|
|
5670
|
+
if (this.docProps) {
|
|
5671
|
+
return this.docProps;
|
|
5672
|
+
}
|
|
5673
|
+
const config2 = getConfig();
|
|
5674
|
+
const resolvedDocPropsPath = config2.docPropsPath ? await exists(config2.docPropsPath) ? config2.docPropsPath : resolve2(process.cwd(), config2.docPropsPath) : join4(dirname2(config2.routeDir), "doc-props.json");
|
|
5492
5675
|
if (!await exists(resolvedDocPropsPath)) {
|
|
5493
|
-
if (
|
|
5676
|
+
if (config2.verbose) {
|
|
5494
5677
|
console.log(`Doc props file not found at: ${resolvedDocPropsPath}`);
|
|
5495
5678
|
}
|
|
5496
5679
|
return null;
|
|
5497
5680
|
}
|
|
5498
5681
|
try {
|
|
5499
|
-
const content = await
|
|
5682
|
+
const content = await readFile3(resolvedDocPropsPath, "utf-8");
|
|
5500
5683
|
const docProps = JSON.parse(content);
|
|
5501
|
-
if (
|
|
5684
|
+
if (config2.verbose) {
|
|
5502
5685
|
console.log(`Loaded doc props from: ${resolvedDocPropsPath}`);
|
|
5503
5686
|
console.log(
|
|
5504
5687
|
`Found ${Object.keys(docProps.props).length} component types`
|
|
5505
5688
|
);
|
|
5506
5689
|
}
|
|
5690
|
+
this.docProps = docProps;
|
|
5507
5691
|
return docProps;
|
|
5508
5692
|
} catch (error) {
|
|
5509
|
-
if (
|
|
5693
|
+
if (config2.verbose) {
|
|
5510
5694
|
console.log("Error loading doc props", error);
|
|
5511
5695
|
}
|
|
5512
5696
|
return null;
|
|
5513
5697
|
}
|
|
5514
5698
|
}
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5699
|
+
formatCommentParts(parts) {
|
|
5700
|
+
return parts.map((part) => {
|
|
5701
|
+
switch (part.kind) {
|
|
5702
|
+
case "text":
|
|
5703
|
+
return part.text;
|
|
5704
|
+
case "code":
|
|
5705
|
+
const codeText = part.text.replace(/```\w*\n?/g, "").replace(/\n?```/g, "").trim();
|
|
5706
|
+
if (codeText.includes("\n")) {
|
|
5707
|
+
return `\`\`\`
|
|
5708
|
+
${codeText}
|
|
5709
|
+
\`\`\``;
|
|
5710
|
+
} else {
|
|
5711
|
+
return codeText;
|
|
5712
|
+
}
|
|
5713
|
+
default:
|
|
5714
|
+
if (getConfig().outputMode === "per-page" && "tag" in part && part.tag === "@link" && typeof part.target === "string") {
|
|
5715
|
+
if (part.text === "Learn more") {
|
|
5716
|
+
return "";
|
|
5717
|
+
}
|
|
5718
|
+
}
|
|
5719
|
+
return part.text;
|
|
5521
5720
|
}
|
|
5522
|
-
|
|
5523
|
-
return excludePatterns.some(
|
|
5524
|
-
(pattern) => minimatch(relativePath, pattern, { matchBase: true })
|
|
5525
|
-
);
|
|
5526
|
-
};
|
|
5527
|
-
const scanDirectory = async (dirPath) => {
|
|
5528
|
-
if (shouldExclude(dirPath)) {
|
|
5529
|
-
if (this.config.verbose) {
|
|
5530
|
-
console.log(
|
|
5531
|
-
`Excluding directory: ${relative2(this.config.routeDir, dirPath)}`
|
|
5532
|
-
);
|
|
5533
|
-
}
|
|
5534
|
-
return;
|
|
5535
|
-
}
|
|
5536
|
-
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
5537
|
-
const mdxFiles = entries.filter(
|
|
5538
|
-
(f) => f.name.endsWith(".mdx") && !shouldExclude(join2(dirPath, f.name))
|
|
5539
|
-
) ?? [];
|
|
5540
|
-
const pageIdPrefix = this.config.pageIdPrefix ?? "";
|
|
5541
|
-
for (const mdxFile of mdxFiles) {
|
|
5542
|
-
const demosFolder = entries.find((f) => f.name === "demos");
|
|
5543
|
-
const demosFolderPath = demosFolder ? join2(dirPath, demosFolder.name) : void 0;
|
|
5544
|
-
const segments = getPathSegmentsFromFileName(
|
|
5545
|
-
join2(dirPath, mdxFile.name),
|
|
5546
|
-
this.config.routeDir
|
|
5547
|
-
);
|
|
5548
|
-
const url = getPathnameFromPathSegments(segments);
|
|
5549
|
-
components.push({
|
|
5550
|
-
demosFolder: demosFolderPath,
|
|
5551
|
-
filePath: dirPath,
|
|
5552
|
-
id: `${pageIdPrefix ? `${pageIdPrefix}-` : ""}${segments.join("-").trim()}`,
|
|
5553
|
-
mdxFile: join2(dirPath, mdxFile.name),
|
|
5554
|
-
name: segments.at(-1),
|
|
5555
|
-
pathname: url,
|
|
5556
|
-
url: this.config.baseUrl ? new URL(url, this.config.baseUrl).toString() : void 0
|
|
5557
|
-
});
|
|
5558
|
-
if (this.config.verbose) {
|
|
5559
|
-
console.log(`Found file: ${basename(dirPath)}`);
|
|
5560
|
-
console.log(` Demos folder: ${demosFolderPath || "NOT FOUND"}`);
|
|
5561
|
-
}
|
|
5562
|
-
}
|
|
5563
|
-
for (const entry of entries) {
|
|
5564
|
-
const fullPath = join2(dirPath, entry.name);
|
|
5565
|
-
const stats = await stat(fullPath);
|
|
5566
|
-
if (stats.isDirectory()) {
|
|
5567
|
-
await scanDirectory(fullPath);
|
|
5568
|
-
}
|
|
5569
|
-
}
|
|
5570
|
-
};
|
|
5571
|
-
await scanDirectory(this.config.routeDir);
|
|
5572
|
-
return components;
|
|
5573
|
-
}
|
|
5574
|
-
async collectRelativeImports(filePath, visited = /* @__PURE__ */ new Set()) {
|
|
5575
|
-
const normalizedPath = resolve(filePath);
|
|
5576
|
-
if (visited.has(normalizedPath)) {
|
|
5577
|
-
return [];
|
|
5578
|
-
}
|
|
5579
|
-
visited.add(normalizedPath);
|
|
5580
|
-
const modules = [];
|
|
5581
|
-
try {
|
|
5582
|
-
const content = await readFile(normalizedPath, "utf-8");
|
|
5583
|
-
const relativeImports = extractRelativeImports(content);
|
|
5584
|
-
for (const importPath of relativeImports) {
|
|
5585
|
-
const resolvedPath = await resolveModulePath(importPath, normalizedPath);
|
|
5586
|
-
if (!resolvedPath) {
|
|
5587
|
-
if (this.config.verbose) {
|
|
5588
|
-
console.log(
|
|
5589
|
-
` Could not resolve import: ${importPath} from ${normalizedPath}`
|
|
5590
|
-
);
|
|
5591
|
-
}
|
|
5592
|
-
continue;
|
|
5593
|
-
}
|
|
5594
|
-
const importContent = await readFile(resolvedPath, "utf-8");
|
|
5595
|
-
modules.push({
|
|
5596
|
-
content: importContent,
|
|
5597
|
-
path: resolvedPath
|
|
5598
|
-
});
|
|
5599
|
-
const nestedModules = await this.collectRelativeImports(
|
|
5600
|
-
resolvedPath,
|
|
5601
|
-
visited
|
|
5602
|
-
);
|
|
5603
|
-
modules.push(...nestedModules);
|
|
5604
|
-
}
|
|
5605
|
-
} catch (error) {
|
|
5606
|
-
if (this.config.verbose) {
|
|
5607
|
-
console.log(`Error processing ${normalizedPath}`, error);
|
|
5608
|
-
}
|
|
5609
|
-
}
|
|
5610
|
-
return modules;
|
|
5611
|
-
}
|
|
5612
|
-
extractProps(props, isPartial) {
|
|
5613
|
-
const propsInfo = [];
|
|
5614
|
-
if (props.props?.length) {
|
|
5615
|
-
propsInfo.push(
|
|
5616
|
-
...props.props.map((prop) => this.convertPropInfo(prop, isPartial))
|
|
5617
|
-
);
|
|
5618
|
-
}
|
|
5619
|
-
if (props.input?.length) {
|
|
5620
|
-
propsInfo.push(
|
|
5621
|
-
...props.input.map(
|
|
5622
|
-
(prop) => this.convertPropInfo(prop, isPartial, "input")
|
|
5623
|
-
)
|
|
5624
|
-
);
|
|
5625
|
-
}
|
|
5626
|
-
if (props.output?.length) {
|
|
5627
|
-
propsInfo.push(
|
|
5628
|
-
...props.output.map(
|
|
5629
|
-
(prop) => this.convertPropInfo(prop, isPartial, "output")
|
|
5630
|
-
)
|
|
5631
|
-
);
|
|
5632
|
-
}
|
|
5633
|
-
return propsInfo;
|
|
5721
|
+
}).join("").replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
|
5634
5722
|
}
|
|
5635
5723
|
formatComment(comment) {
|
|
5636
5724
|
if (!comment) {
|
|
@@ -5664,29 +5752,28 @@ ${tagContent.trim()}
|
|
|
5664
5752
|
}
|
|
5665
5753
|
return parts.join("\n\n");
|
|
5666
5754
|
}
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
}).join("").replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
|
5755
|
+
extractProps(props, isPartial) {
|
|
5756
|
+
const propsInfo = [];
|
|
5757
|
+
if (props.props?.length) {
|
|
5758
|
+
propsInfo.push(
|
|
5759
|
+
...props.props.map((prop) => this.convertPropInfo(prop, isPartial))
|
|
5760
|
+
);
|
|
5761
|
+
}
|
|
5762
|
+
if (props.input?.length) {
|
|
5763
|
+
propsInfo.push(
|
|
5764
|
+
...props.input.map(
|
|
5765
|
+
(prop) => this.convertPropInfo(prop, isPartial, "input")
|
|
5766
|
+
)
|
|
5767
|
+
);
|
|
5768
|
+
}
|
|
5769
|
+
if (props.output?.length) {
|
|
5770
|
+
propsInfo.push(
|
|
5771
|
+
...props.output.map(
|
|
5772
|
+
(prop) => this.convertPropInfo(prop, isPartial, "output")
|
|
5773
|
+
)
|
|
5774
|
+
);
|
|
5775
|
+
}
|
|
5776
|
+
return propsInfo;
|
|
5690
5777
|
}
|
|
5691
5778
|
convertPropInfo(propInfo, isPartial, propType = void 0) {
|
|
5692
5779
|
return {
|
|
@@ -5700,108 +5787,13 @@ ${codeText}
|
|
|
5700
5787
|
required: extractRequired(propInfo, isPartial) || void 0
|
|
5701
5788
|
};
|
|
5702
5789
|
}
|
|
5703
|
-
/**
|
|
5704
|
-
* Creates a remark plugin that replaces theme JSX elements with
|
|
5705
|
-
* markdown tables containing theme data.
|
|
5706
|
-
*/
|
|
5707
|
-
async replaceThemeNodes() {
|
|
5708
|
-
let themes = null;
|
|
5709
|
-
try {
|
|
5710
|
-
themes = await import("@qualcomm-ui/tailwind-plugin/theme");
|
|
5711
|
-
} catch {
|
|
5712
|
-
return () => {
|
|
5713
|
-
};
|
|
5714
|
-
}
|
|
5715
|
-
const handlers = {
|
|
5716
|
-
ColorTable: (node) => {
|
|
5717
|
-
const path = this.getAttrExpression(node, "data");
|
|
5718
|
-
return path && getPath(themes, path);
|
|
5719
|
-
},
|
|
5720
|
-
FontTable: (node) => {
|
|
5721
|
-
const path = this.getAttrExpression(node, "data");
|
|
5722
|
-
return path && getPath(themes, path);
|
|
5723
|
-
},
|
|
5724
|
-
SpacingTable: (node) => {
|
|
5725
|
-
const path = this.getAttrExpression(node, "data");
|
|
5726
|
-
return path && getPath(themes, path);
|
|
5727
|
-
},
|
|
5728
|
-
ThemePropertyTable: (node) => {
|
|
5729
|
-
const path = this.getAttrExpression(node, "data");
|
|
5730
|
-
const property = this.getAttrExpression(node, "cssProperty");
|
|
5731
|
-
const data = path && getPath(themes, path);
|
|
5732
|
-
return path && property ? { cssPropertyName: property, data } : void 0;
|
|
5733
|
-
}
|
|
5734
|
-
};
|
|
5735
|
-
return () => (tree, _file, done) => {
|
|
5736
|
-
visit5(tree, "mdxJsxFlowElement", (node) => {
|
|
5737
|
-
const handler = node.name && handlers[node.name];
|
|
5738
|
-
if (!handler) {
|
|
5739
|
-
return;
|
|
5740
|
-
}
|
|
5741
|
-
const data = handler(node);
|
|
5742
|
-
if (!data) {
|
|
5743
|
-
console.warn(`No theme data for ${node.name}`);
|
|
5744
|
-
return;
|
|
5745
|
-
}
|
|
5746
|
-
let markdownTable;
|
|
5747
|
-
if (typeof data === "object" && data !== null && "cssPropertyName" in data && "data" in data) {
|
|
5748
|
-
const { cssPropertyName, data: themeData } = data;
|
|
5749
|
-
markdownTable = themeDataToJson(themeData, cssPropertyName);
|
|
5750
|
-
} else {
|
|
5751
|
-
markdownTable = themeDataToJson(data);
|
|
5752
|
-
}
|
|
5753
|
-
if (!markdownTable) {
|
|
5754
|
-
return;
|
|
5755
|
-
}
|
|
5756
|
-
Object.assign(node, {
|
|
5757
|
-
lang: "json",
|
|
5758
|
-
meta: null,
|
|
5759
|
-
type: "code",
|
|
5760
|
-
value: markdownTable
|
|
5761
|
-
});
|
|
5762
|
-
});
|
|
5763
|
-
done();
|
|
5764
|
-
};
|
|
5765
|
-
}
|
|
5766
|
-
getAttrExpression(node, name) {
|
|
5767
|
-
const attr = node.attributes?.find(
|
|
5768
|
-
(a) => a.type === "mdxJsxAttribute" && a.name === name
|
|
5769
|
-
);
|
|
5770
|
-
if (!attr?.value) {
|
|
5771
|
-
return null;
|
|
5772
|
-
}
|
|
5773
|
-
if (typeof attr.value === "string") {
|
|
5774
|
-
return attr.value;
|
|
5775
|
-
} else if (typeof attr.value === "object" && "value" in attr.value) {
|
|
5776
|
-
return attr.value.value;
|
|
5777
|
-
}
|
|
5778
|
-
return null;
|
|
5779
|
-
}
|
|
5780
|
-
/**
|
|
5781
|
-
* Creates a remark plugin that transforms relative URLs to absolute URLs.
|
|
5782
|
-
*/
|
|
5783
|
-
transformRelativeUrls(pageUrl) {
|
|
5784
|
-
const baseUrl = this.config.baseUrl;
|
|
5785
|
-
return () => (tree) => {
|
|
5786
|
-
if (!baseUrl || this.config.outputMode !== "per-page") {
|
|
5787
|
-
return;
|
|
5788
|
-
}
|
|
5789
|
-
visit5(tree, "link", (node) => {
|
|
5790
|
-
if (node.url.startsWith("/")) {
|
|
5791
|
-
node.url = `${baseUrl}${node.url}`;
|
|
5792
|
-
} else if (node.url.startsWith("./#") && pageUrl) {
|
|
5793
|
-
node.url = `${pageUrl}${node.url.slice(2)}`;
|
|
5794
|
-
}
|
|
5795
|
-
});
|
|
5796
|
-
};
|
|
5797
|
-
}
|
|
5798
5790
|
/**
|
|
5799
5791
|
* Creates a remark plugin that replaces TypeDocProps JSX elements with
|
|
5800
|
-
*
|
|
5792
|
+
* Markdown tables containing component prop documentation.
|
|
5801
5793
|
*/
|
|
5802
|
-
|
|
5794
|
+
formatTypeDocProps() {
|
|
5803
5795
|
return () => (tree, _file, done) => {
|
|
5804
|
-
|
|
5796
|
+
visit7(
|
|
5805
5797
|
tree,
|
|
5806
5798
|
"mdxJsxFlowElement",
|
|
5807
5799
|
(node, index, parent) => {
|
|
@@ -5830,7 +5822,7 @@ ${codeText}
|
|
|
5830
5822
|
const propsName = propsNames[0];
|
|
5831
5823
|
const componentProps = this.docProps.props[propsName];
|
|
5832
5824
|
if (!componentProps) {
|
|
5833
|
-
if (
|
|
5825
|
+
if (getConfig().verbose) {
|
|
5834
5826
|
console.log(` TypeDocProps not found: ${propsName}`);
|
|
5835
5827
|
}
|
|
5836
5828
|
if (parent && index !== void 0) {
|
|
@@ -5839,7 +5831,7 @@ ${codeText}
|
|
|
5839
5831
|
return;
|
|
5840
5832
|
}
|
|
5841
5833
|
const propsDoc = this.extractProps(componentProps, Boolean(isPartial));
|
|
5842
|
-
if (
|
|
5834
|
+
if (getConfig().verbose) {
|
|
5843
5835
|
console.log(
|
|
5844
5836
|
` Replaced TypeDocProps ${propsName} with API documentation`
|
|
5845
5837
|
);
|
|
@@ -5868,115 +5860,461 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
5868
5860
|
}
|
|
5869
5861
|
return;
|
|
5870
5862
|
}
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5863
|
+
const propNames = propsDoc.map((p) => p.name);
|
|
5864
|
+
Object.assign(node, {
|
|
5865
|
+
data: { typeDocProps: { name: propsName, props: propNames } },
|
|
5866
|
+
lang: null,
|
|
5867
|
+
meta: null,
|
|
5868
|
+
type: "code",
|
|
5869
|
+
value: markdownContent
|
|
5870
|
+
});
|
|
5871
|
+
}
|
|
5872
|
+
);
|
|
5873
|
+
done();
|
|
5874
|
+
};
|
|
5875
|
+
}
|
|
5876
|
+
};
|
|
5877
|
+
|
|
5878
|
+
// src/ai-knowledge/generator/npm-install-tabs-plugin.ts
|
|
5879
|
+
import { visit as visit8 } from "unist-util-visit";
|
|
5880
|
+
var formatNpmInstallTabs = () => {
|
|
5881
|
+
return (tree, _file, done) => {
|
|
5882
|
+
visit8(
|
|
5883
|
+
tree,
|
|
5884
|
+
"mdxJsxFlowElement",
|
|
5885
|
+
(node, index, parent) => {
|
|
5886
|
+
if (node?.name === "NpmInstallTabs") {
|
|
5887
|
+
const packages = node.attributes?.find(
|
|
5888
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "packages"
|
|
5889
|
+
);
|
|
5890
|
+
const packageNames = packages ? extractNamesFromAttribute(packages) : [];
|
|
5891
|
+
if (packageNames.length === 0) {
|
|
5892
|
+
if (parent && index !== void 0) {
|
|
5893
|
+
parent.children.splice(index, 1);
|
|
5894
|
+
}
|
|
5895
|
+
return;
|
|
5896
|
+
}
|
|
5897
|
+
Object.assign(node, {
|
|
5898
|
+
lang: "shell",
|
|
5899
|
+
meta: null,
|
|
5900
|
+
type: "code",
|
|
5901
|
+
value: `npm install ${packageNames.join(" ")}`
|
|
5902
|
+
});
|
|
5903
|
+
}
|
|
5904
|
+
}
|
|
5905
|
+
);
|
|
5906
|
+
done();
|
|
5907
|
+
};
|
|
5908
|
+
};
|
|
5909
|
+
|
|
5910
|
+
// src/ai-knowledge/generator/qds-theme-plugin.ts
|
|
5911
|
+
import { visit as visit9 } from "unist-util-visit";
|
|
5912
|
+
function themeDataToJson(data, cssPropertyName) {
|
|
5913
|
+
if (!data || typeof data !== "object") {
|
|
5914
|
+
return "";
|
|
5915
|
+
}
|
|
5916
|
+
if (cssPropertyName) {
|
|
5917
|
+
return JSON.stringify({ cssProperty: cssPropertyName, data }, null, 2);
|
|
5918
|
+
}
|
|
5919
|
+
return JSON.stringify(data, null, 2);
|
|
5920
|
+
}
|
|
5921
|
+
function getPath(obj, path) {
|
|
5922
|
+
return path.split(".").reduce(
|
|
5923
|
+
(acc, key) => acc && typeof acc === "object" ? acc[key] : void 0,
|
|
5924
|
+
obj
|
|
5925
|
+
);
|
|
5926
|
+
}
|
|
5927
|
+
function getAttrExpression(node, name) {
|
|
5928
|
+
const attr = node.attributes?.find(
|
|
5929
|
+
(a) => a.type === "mdxJsxAttribute" && a.name === name
|
|
5930
|
+
);
|
|
5931
|
+
if (!attr?.value) {
|
|
5932
|
+
return null;
|
|
5933
|
+
}
|
|
5934
|
+
if (typeof attr.value === "string") {
|
|
5935
|
+
return attr.value;
|
|
5936
|
+
} else if (typeof attr.value === "object" && "value" in attr.value) {
|
|
5937
|
+
return attr.value.value;
|
|
5938
|
+
}
|
|
5939
|
+
return null;
|
|
5940
|
+
}
|
|
5941
|
+
async function formatThemeNodes() {
|
|
5942
|
+
let themes = null;
|
|
5943
|
+
try {
|
|
5944
|
+
themes = await import("@qualcomm-ui/tailwind-plugin/theme");
|
|
5945
|
+
} catch {
|
|
5946
|
+
return () => {
|
|
5947
|
+
};
|
|
5948
|
+
}
|
|
5949
|
+
const handlers = {
|
|
5950
|
+
ColorTable: (node) => {
|
|
5951
|
+
const path = getAttrExpression(node, "data");
|
|
5952
|
+
return path && getPath(themes, path);
|
|
5953
|
+
},
|
|
5954
|
+
FontTable: (node) => {
|
|
5955
|
+
const path = getAttrExpression(node, "data");
|
|
5956
|
+
return path && getPath(themes, path);
|
|
5957
|
+
},
|
|
5958
|
+
SpacingTable: (node) => {
|
|
5959
|
+
const path = getAttrExpression(node, "data");
|
|
5960
|
+
return path && getPath(themes, path);
|
|
5961
|
+
},
|
|
5962
|
+
ThemePropertyTable: (node) => {
|
|
5963
|
+
const path = getAttrExpression(node, "data");
|
|
5964
|
+
const property = getAttrExpression(node, "cssProperty");
|
|
5965
|
+
const data = path && getPath(themes, path);
|
|
5966
|
+
return path && property ? { cssPropertyName: property, data } : void 0;
|
|
5967
|
+
}
|
|
5968
|
+
};
|
|
5969
|
+
return () => (tree, _file, done) => {
|
|
5970
|
+
visit9(tree, "mdxJsxFlowElement", (node) => {
|
|
5971
|
+
const handler = node.name && handlers[node.name];
|
|
5972
|
+
if (!handler) {
|
|
5973
|
+
return;
|
|
5974
|
+
}
|
|
5975
|
+
const data = handler(node);
|
|
5976
|
+
if (!data) {
|
|
5977
|
+
console.warn(`No theme data for ${node.name}`);
|
|
5978
|
+
return;
|
|
5979
|
+
}
|
|
5980
|
+
let markdownTable;
|
|
5981
|
+
if (typeof data === "object" && data !== null && "cssPropertyName" in data && "data" in data) {
|
|
5982
|
+
const { cssPropertyName, data: themeData } = data;
|
|
5983
|
+
markdownTable = themeDataToJson(themeData, cssPropertyName);
|
|
5984
|
+
} else {
|
|
5985
|
+
markdownTable = themeDataToJson(data);
|
|
5986
|
+
}
|
|
5987
|
+
if (!markdownTable) {
|
|
5988
|
+
return;
|
|
5989
|
+
}
|
|
5990
|
+
Object.assign(node, {
|
|
5991
|
+
lang: "json",
|
|
5992
|
+
meta: null,
|
|
5993
|
+
type: "code",
|
|
5994
|
+
value: markdownTable
|
|
5995
|
+
});
|
|
5996
|
+
});
|
|
5997
|
+
done();
|
|
5998
|
+
};
|
|
5999
|
+
}
|
|
6000
|
+
|
|
6001
|
+
// src/ai-knowledge/generator/section-extractor.ts
|
|
6002
|
+
import remarkStringify3 from "remark-stringify";
|
|
6003
|
+
import { unified as unified4 } from "unified";
|
|
6004
|
+
import { visit as visit10 } from "unist-util-visit";
|
|
6005
|
+
import { kebabCase as kebabCase2 } from "@qualcomm-ui/utils/change-case";
|
|
6006
|
+
var SectionExtractor = class {
|
|
6007
|
+
depths;
|
|
6008
|
+
minContentLength;
|
|
6009
|
+
constructor(options) {
|
|
6010
|
+
const defaultDepths = [1, 2, 3, 4];
|
|
6011
|
+
this.depths = new Set(options?.depths ?? defaultDepths);
|
|
6012
|
+
this.minContentLength = options?.minContentLength ?? 0;
|
|
6013
|
+
}
|
|
6014
|
+
/**
|
|
6015
|
+
* Extracts sections from a parsed AST.
|
|
6016
|
+
*/
|
|
6017
|
+
extract(tree, pageInfo) {
|
|
6018
|
+
const sections = [];
|
|
6019
|
+
const headerStack = [{ depth: 1, text: pageInfo.title }];
|
|
6020
|
+
let pendingSection = null;
|
|
6021
|
+
const finalizeSection = () => {
|
|
6022
|
+
if (!pendingSection || pendingSection.nodes.length === 0) {
|
|
6023
|
+
return;
|
|
6024
|
+
}
|
|
6025
|
+
const entry = this.buildSectionEntry(pendingSection, pageInfo);
|
|
6026
|
+
if (entry && entry.content.length >= this.minContentLength) {
|
|
6027
|
+
sections.push(entry);
|
|
6028
|
+
}
|
|
6029
|
+
};
|
|
6030
|
+
for (let i = 0; i < tree.children.length; i++) {
|
|
6031
|
+
const node = tree.children[i];
|
|
6032
|
+
if (node.type === "heading") {
|
|
6033
|
+
const heading2 = node;
|
|
6034
|
+
if (!this.depths.has(heading2.depth)) {
|
|
6035
|
+
if (pendingSection) {
|
|
6036
|
+
pendingSection.nodes.push(node);
|
|
6037
|
+
}
|
|
6038
|
+
continue;
|
|
6039
|
+
}
|
|
6040
|
+
finalizeSection();
|
|
6041
|
+
while (headerStack.length > 0 && headerStack[headerStack.length - 1].depth >= heading2.depth) {
|
|
6042
|
+
headerStack.pop();
|
|
6043
|
+
}
|
|
6044
|
+
const headingText = this.getHeadingText(heading2);
|
|
6045
|
+
headerStack.push({ depth: heading2.depth, text: headingText });
|
|
6046
|
+
pendingSection = {
|
|
6047
|
+
headerPath: headerStack.map((h) => h.text),
|
|
6048
|
+
nodes: [],
|
|
6049
|
+
startIndex: i
|
|
6050
|
+
};
|
|
6051
|
+
} else if (pendingSection) {
|
|
6052
|
+
pendingSection.nodes.push(node);
|
|
6053
|
+
}
|
|
6054
|
+
}
|
|
6055
|
+
finalizeSection();
|
|
6056
|
+
return sections;
|
|
6057
|
+
}
|
|
6058
|
+
getHeadingText(heading2) {
|
|
6059
|
+
let text = "";
|
|
6060
|
+
visit10(heading2, "text", (node) => {
|
|
6061
|
+
text += node.value;
|
|
6062
|
+
});
|
|
6063
|
+
return text.trim();
|
|
6064
|
+
}
|
|
6065
|
+
buildSectionEntry(section, pageInfo) {
|
|
6066
|
+
const { metadata, nodes } = this.extractMetadata(section.nodes);
|
|
6067
|
+
if (nodes.length === 0) {
|
|
6068
|
+
return null;
|
|
6069
|
+
}
|
|
6070
|
+
const contentNodes = [];
|
|
6071
|
+
const codeExamples = [];
|
|
6072
|
+
for (const node of nodes) {
|
|
6073
|
+
if (node.type === "code") {
|
|
6074
|
+
const codeNode = node;
|
|
6075
|
+
if (codeNode.data?.typeDocProps) {
|
|
6076
|
+
const { name, props } = codeNode.data.typeDocProps;
|
|
6077
|
+
metadata.props = [...metadata.props ?? [], ...props];
|
|
6078
|
+
metadata.type = name;
|
|
6079
|
+
}
|
|
6080
|
+
codeExamples.push({
|
|
6081
|
+
code: codeNode.value,
|
|
6082
|
+
language: codeNode.lang ?? ""
|
|
6083
|
+
});
|
|
6084
|
+
} else {
|
|
6085
|
+
contentNodes.push(node);
|
|
6086
|
+
}
|
|
6087
|
+
}
|
|
6088
|
+
const rawContent = this.nodesToRawContent(nodes);
|
|
6089
|
+
const content = this.nodesToContent(contentNodes);
|
|
6090
|
+
const sectionId = this.generateSectionId(section.headerPath);
|
|
6091
|
+
const url = pageInfo.url ? `${pageInfo.url}#${this.generateAnchorId(section.headerPath.at(-1) ?? "")}` : void 0;
|
|
6092
|
+
const hashData = {
|
|
6093
|
+
headerPath: section.headerPath,
|
|
6094
|
+
metadata: Object.keys(metadata).length ? metadata : void 0,
|
|
6095
|
+
pageFrontmatter: Object.keys(pageInfo.frontmatter).length ? pageInfo.frontmatter : void 0,
|
|
6096
|
+
pageId: pageInfo.id,
|
|
6097
|
+
rawContent: rawContent.trim()
|
|
6098
|
+
};
|
|
6099
|
+
const sectionHash = JSON.stringify(hashData);
|
|
6100
|
+
return {
|
|
6101
|
+
...hashData,
|
|
6102
|
+
codeExamples: codeExamples.length ? codeExamples : void 0,
|
|
6103
|
+
content: content.trim(),
|
|
6104
|
+
hash: sectionHash,
|
|
6105
|
+
sectionId,
|
|
6106
|
+
url
|
|
6107
|
+
};
|
|
6108
|
+
}
|
|
6109
|
+
extractMetadata(nodes) {
|
|
6110
|
+
const metadata = {};
|
|
6111
|
+
const filteredNodes = [];
|
|
6112
|
+
for (const node of nodes) {
|
|
6113
|
+
if (node.type === "paragraph") {
|
|
6114
|
+
const firstChild = node.children?.[0];
|
|
6115
|
+
if (firstChild?.type === "text") {
|
|
6116
|
+
const text = firstChild.value;
|
|
6117
|
+
const metaMatch = text.match(/^:::\s*meta\s*/);
|
|
6118
|
+
if (metaMatch) {
|
|
6119
|
+
const parsed = this.parseMetaBlock(text);
|
|
6120
|
+
Object.assign(metadata, parsed);
|
|
6121
|
+
continue;
|
|
6122
|
+
}
|
|
5877
6123
|
}
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
}
|
|
6124
|
+
}
|
|
6125
|
+
filteredNodes.push(node);
|
|
6126
|
+
}
|
|
6127
|
+
return { metadata, nodes: filteredNodes };
|
|
6128
|
+
}
|
|
6129
|
+
parseMetaBlock(text) {
|
|
6130
|
+
const metadata = {};
|
|
6131
|
+
const afterOpen = text.replace(/^:::\s*meta\s*/, "");
|
|
6132
|
+
const closeIndex = afterOpen.lastIndexOf(":::");
|
|
6133
|
+
const content = closeIndex !== -1 ? afterOpen.slice(0, closeIndex) : afterOpen;
|
|
6134
|
+
const lines = content.split("\n");
|
|
6135
|
+
for (const line of lines) {
|
|
6136
|
+
const trimmed = line.trim();
|
|
6137
|
+
if (!trimmed) {
|
|
6138
|
+
continue;
|
|
6139
|
+
}
|
|
6140
|
+
const colonIndex = trimmed.indexOf(":");
|
|
6141
|
+
if (colonIndex === -1) {
|
|
6142
|
+
continue;
|
|
6143
|
+
}
|
|
6144
|
+
const key = trimmed.slice(0, colonIndex).trim();
|
|
6145
|
+
const value = trimmed.slice(colonIndex + 1).trim();
|
|
6146
|
+
if (key && value) {
|
|
6147
|
+
metadata[key] = this.parseValue(value);
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
return metadata;
|
|
6151
|
+
}
|
|
6152
|
+
parseValue(value) {
|
|
6153
|
+
const trimmed = value.trim();
|
|
6154
|
+
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
6155
|
+
const inner = trimmed.slice(1, -1);
|
|
6156
|
+
return inner.split(",").map((item) => item.trim()).filter(Boolean);
|
|
6157
|
+
}
|
|
6158
|
+
return trimmed;
|
|
5881
6159
|
}
|
|
5882
6160
|
/**
|
|
5883
|
-
*
|
|
5884
|
-
*
|
|
6161
|
+
* Convert links to inline code. URLs are not relevant for text embeddings
|
|
6162
|
+
* and will muddy the vector storage.
|
|
5885
6163
|
*/
|
|
5886
|
-
|
|
5887
|
-
return () =>
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
} catch (error) {
|
|
5963
|
-
if (this.config.verbose) {
|
|
5964
|
-
console.log(`Error reading demo ${demoName}`, error);
|
|
5965
|
-
}
|
|
5966
|
-
if (parent && index !== void 0) {
|
|
5967
|
-
parent.children.splice(index, 1);
|
|
5968
|
-
}
|
|
5969
|
-
}
|
|
5970
|
-
})()
|
|
5971
|
-
);
|
|
6164
|
+
transformLinks() {
|
|
6165
|
+
return () => (tree) => {
|
|
6166
|
+
visit10(tree, "link", (node) => {
|
|
6167
|
+
let text = "";
|
|
6168
|
+
visit10(node, "text", (textNode) => {
|
|
6169
|
+
text += textNode.value;
|
|
6170
|
+
});
|
|
6171
|
+
Object.assign(node, {
|
|
6172
|
+
children: void 0,
|
|
6173
|
+
type: "inlineCode",
|
|
6174
|
+
url: void 0,
|
|
6175
|
+
value: text
|
|
6176
|
+
});
|
|
6177
|
+
});
|
|
6178
|
+
};
|
|
6179
|
+
}
|
|
6180
|
+
nodesToRawContent(nodes) {
|
|
6181
|
+
const tree = { children: nodes, type: "root" };
|
|
6182
|
+
const processor = unified4().use(remarkStringify3);
|
|
6183
|
+
return processor.stringify(tree);
|
|
6184
|
+
}
|
|
6185
|
+
nodesToContent(nodes) {
|
|
6186
|
+
const tree = { children: structuredClone(nodes), type: "root" };
|
|
6187
|
+
const processor = unified4().use(this.transformLinks()).use(remarkStringify3);
|
|
6188
|
+
const transformed = processor.runSync(tree);
|
|
6189
|
+
return processor.stringify(transformed);
|
|
6190
|
+
}
|
|
6191
|
+
generateSectionId(headerPath) {
|
|
6192
|
+
return headerPath.map((h) => kebabCase2(h)).join("-");
|
|
6193
|
+
}
|
|
6194
|
+
generateAnchorId(headerText) {
|
|
6195
|
+
return kebabCase2(headerText);
|
|
6196
|
+
}
|
|
6197
|
+
};
|
|
6198
|
+
|
|
6199
|
+
// src/ai-knowledge/generator/knowledge-generator.ts
|
|
6200
|
+
var KnowledgeGenerator = class {
|
|
6201
|
+
config;
|
|
6202
|
+
propFormatter;
|
|
6203
|
+
constructor(config2) {
|
|
6204
|
+
setConfig(config2);
|
|
6205
|
+
this.config = getConfig();
|
|
6206
|
+
this.propFormatter = new PropFormatter();
|
|
6207
|
+
}
|
|
6208
|
+
async run() {
|
|
6209
|
+
const extractedMetadata = extractMetadata(this.config.metadata);
|
|
6210
|
+
if (this.config.verbose) {
|
|
6211
|
+
console.log(`Scanning pages in: ${this.config.routeDir}`);
|
|
6212
|
+
if (this.config.exclude?.length) {
|
|
6213
|
+
console.log(`Excluding patterns: ${this.config.exclude.join(", ")}`);
|
|
6214
|
+
}
|
|
6215
|
+
}
|
|
6216
|
+
const [pages] = await Promise.all([
|
|
6217
|
+
this.scanPages(),
|
|
6218
|
+
this.propFormatter.loadDocProps()
|
|
6219
|
+
]);
|
|
6220
|
+
if (pages.length === 0) {
|
|
6221
|
+
console.log("No pages found.");
|
|
6222
|
+
return [];
|
|
6223
|
+
}
|
|
6224
|
+
if (this.config.verbose) {
|
|
6225
|
+
console.log(`Found ${pages.length} page(s)`);
|
|
6226
|
+
}
|
|
6227
|
+
const processedPages = [];
|
|
6228
|
+
for (const page of pages) {
|
|
6229
|
+
try {
|
|
6230
|
+
const processed = await this.processMdxPage(page);
|
|
6231
|
+
processedPages.push(processed);
|
|
6232
|
+
} catch (error) {
|
|
6233
|
+
console.error(`Failed to process page: ${page.name}`);
|
|
6234
|
+
process.exit(1);
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
if (this.config.clean) {
|
|
6238
|
+
await rm(this.config.outputPath, { force: true, recursive: true }).catch(
|
|
6239
|
+
() => {
|
|
5972
6240
|
}
|
|
5973
6241
|
);
|
|
5974
|
-
|
|
6242
|
+
}
|
|
6243
|
+
if (this.config.outputMode === "aggregated") {
|
|
6244
|
+
await this.generateAggregatedOutput(processedPages, pages);
|
|
6245
|
+
} else {
|
|
6246
|
+
await mkdir(this.config.outputPath, { recursive: true }).catch(() => {
|
|
6247
|
+
});
|
|
6248
|
+
await this.generatePerPageExports(
|
|
6249
|
+
pages,
|
|
6250
|
+
processedPages,
|
|
6251
|
+
extractedMetadata
|
|
6252
|
+
);
|
|
6253
|
+
}
|
|
6254
|
+
return pages;
|
|
6255
|
+
}
|
|
6256
|
+
async scanPages() {
|
|
6257
|
+
const components = [];
|
|
6258
|
+
const excludePatterns = this.config.exclude ?? [];
|
|
6259
|
+
const shouldExclude = (absolutePath) => {
|
|
6260
|
+
if (excludePatterns.length === 0) {
|
|
6261
|
+
return false;
|
|
6262
|
+
}
|
|
6263
|
+
const relativePath = relative2(this.config.routeDir, absolutePath);
|
|
6264
|
+
return excludePatterns.some(
|
|
6265
|
+
(pattern) => minimatch(relativePath, pattern, { matchBase: true })
|
|
6266
|
+
);
|
|
6267
|
+
};
|
|
6268
|
+
const scanDirectory = async (dirPath) => {
|
|
6269
|
+
if (shouldExclude(dirPath)) {
|
|
6270
|
+
if (this.config.verbose) {
|
|
6271
|
+
console.log(
|
|
6272
|
+
`Excluding directory: ${relative2(this.config.routeDir, dirPath)}`
|
|
6273
|
+
);
|
|
6274
|
+
}
|
|
6275
|
+
return;
|
|
6276
|
+
}
|
|
6277
|
+
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
6278
|
+
const mdxFiles = entries.filter(
|
|
6279
|
+
(f) => f.name.endsWith(".mdx") && !shouldExclude(join5(dirPath, f.name))
|
|
6280
|
+
) ?? [];
|
|
6281
|
+
const pageIdPrefix = this.config.pageIdPrefix ?? "";
|
|
6282
|
+
for (const mdxFile of mdxFiles) {
|
|
6283
|
+
const demosFolder = entries.find((f) => f.name === "demos");
|
|
6284
|
+
const demosFolderPath = demosFolder ? join5(dirPath, demosFolder.name) : void 0;
|
|
6285
|
+
const segments = getPathSegmentsFromFileName(
|
|
6286
|
+
join5(dirPath, mdxFile.name),
|
|
6287
|
+
this.config.routeDir
|
|
6288
|
+
);
|
|
6289
|
+
const url = getPathnameFromPathSegments(segments);
|
|
6290
|
+
components.push({
|
|
6291
|
+
demosFolder: demosFolderPath,
|
|
6292
|
+
filePath: dirPath,
|
|
6293
|
+
id: `${pageIdPrefix ? `${pageIdPrefix}-` : ""}${segments.join("-").trim()}`,
|
|
6294
|
+
mdxFile: join5(dirPath, mdxFile.name),
|
|
6295
|
+
name: segments.at(-1),
|
|
6296
|
+
pathname: url,
|
|
6297
|
+
url: this.config.baseUrl ? new URL(url, this.config.baseUrl).toString() : void 0
|
|
6298
|
+
});
|
|
6299
|
+
if (this.config.verbose) {
|
|
6300
|
+
console.log(`Found file: ${basename2(dirPath)}`);
|
|
6301
|
+
console.log(` Demos folder: ${demosFolderPath || "NOT FOUND"}`);
|
|
6302
|
+
}
|
|
6303
|
+
}
|
|
6304
|
+
for (const entry of entries) {
|
|
6305
|
+
const fullPath = join5(dirPath, entry.name);
|
|
6306
|
+
const stats = await stat(fullPath);
|
|
6307
|
+
if (stats.isDirectory()) {
|
|
6308
|
+
await scanDirectory(fullPath);
|
|
6309
|
+
}
|
|
6310
|
+
}
|
|
5975
6311
|
};
|
|
6312
|
+
await scanDirectory(this.config.routeDir);
|
|
6313
|
+
return components;
|
|
5976
6314
|
}
|
|
5977
|
-
|
|
6315
|
+
formatFrontmatterExpressions(frontmatter) {
|
|
5978
6316
|
return () => (tree) => {
|
|
5979
|
-
|
|
6317
|
+
visit11(
|
|
5980
6318
|
tree,
|
|
5981
6319
|
"mdxFlowExpression",
|
|
5982
6320
|
(node, index, parent) => {
|
|
@@ -6007,42 +6345,92 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6007
6345
|
}
|
|
6008
6346
|
};
|
|
6009
6347
|
}
|
|
6348
|
+
/**
|
|
6349
|
+
* Creates a remark plugin that transforms relative URLs to absolute URLs.
|
|
6350
|
+
*/
|
|
6351
|
+
transformRelativeUrls(pageUrl) {
|
|
6352
|
+
const baseUrl = this.config.baseUrl;
|
|
6353
|
+
return () => (tree) => {
|
|
6354
|
+
if (!baseUrl || this.config.outputMode !== "per-page") {
|
|
6355
|
+
return;
|
|
6356
|
+
}
|
|
6357
|
+
visit11(tree, "link", (node) => {
|
|
6358
|
+
if (node.url.startsWith("/")) {
|
|
6359
|
+
node.url = `${baseUrl}${node.url}`;
|
|
6360
|
+
} else if (node.url.startsWith("./#") && pageUrl) {
|
|
6361
|
+
node.url = `${pageUrl}${node.url.slice(2)}`;
|
|
6362
|
+
}
|
|
6363
|
+
});
|
|
6364
|
+
};
|
|
6365
|
+
}
|
|
6366
|
+
applyPlugins(opts, processor) {
|
|
6367
|
+
if (this.config.mdxPlugins) {
|
|
6368
|
+
this.config.mdxPlugins.forEach((plugin) => {
|
|
6369
|
+
processor.use(plugin(opts));
|
|
6370
|
+
});
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
filterFrontmatter(frontmatter) {
|
|
6374
|
+
if (!this.config.frontmatter?.include?.length) {
|
|
6375
|
+
return frontmatter;
|
|
6376
|
+
}
|
|
6377
|
+
const includePatterns = this.config.frontmatter.include;
|
|
6378
|
+
const excludePatterns = this.config.frontmatter.exclude ?? [];
|
|
6379
|
+
const filtered = {};
|
|
6380
|
+
for (const [field, value] of Object.entries(frontmatter)) {
|
|
6381
|
+
if (value === void 0) {
|
|
6382
|
+
continue;
|
|
6383
|
+
}
|
|
6384
|
+
const isIncluded = includePatterns.some(
|
|
6385
|
+
(pattern) => minimatch(field, pattern)
|
|
6386
|
+
);
|
|
6387
|
+
const isExcluded = excludePatterns.some(
|
|
6388
|
+
(pattern) => minimatch(field, pattern)
|
|
6389
|
+
);
|
|
6390
|
+
if (isIncluded && !isExcluded) {
|
|
6391
|
+
filtered[field] = value;
|
|
6392
|
+
}
|
|
6393
|
+
}
|
|
6394
|
+
return filtered;
|
|
6395
|
+
}
|
|
6010
6396
|
/**
|
|
6011
6397
|
* Processes MDX content by transforming JSX elements (TypeDocProps, demos)
|
|
6012
|
-
* into
|
|
6398
|
+
* into Markdown, resolving relative links, and cleaning up formatting.
|
|
6013
6399
|
*/
|
|
6014
|
-
async processMdxContent(mdxContent,
|
|
6015
|
-
const
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
return { content: processedContent, demoFiles };
|
|
6400
|
+
async processMdxContent(mdxContent, pageInfo, frontmatter) {
|
|
6401
|
+
const processor = unified5().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(this.propFormatter.formatTypeDocProps()).use(this.formatFrontmatterExpressions(frontmatter)).use(await formatThemeNodes()).use(formatDemos(pageInfo.demosFolder)).use(this.transformRelativeUrls(pageInfo.url));
|
|
6402
|
+
this.applyPlugins(pageInfo, processor);
|
|
6403
|
+
processor.use(remarkStringify4);
|
|
6404
|
+
return await processor.run(processor.parse(mdxContent));
|
|
6020
6405
|
}
|
|
6021
6406
|
async processMdxPage(pageInfo) {
|
|
6022
6407
|
try {
|
|
6023
|
-
const mdxContent = await
|
|
6408
|
+
const mdxContent = await readFile4(pageInfo.mdxFile, "utf-8");
|
|
6024
6409
|
if (this.config.verbose) {
|
|
6025
6410
|
console.log(`Processing page: ${pageInfo.name}`);
|
|
6026
6411
|
}
|
|
6027
|
-
const processor =
|
|
6412
|
+
const processor = unified5().use(remarkParse4).use(remarkMdx3).use(formatNpmInstallTabs).use(remarkFrontmatter2, ["yaml"]).use(remarkParseFrontmatter2).use(remarkStringify4);
|
|
6028
6413
|
const parsed = await processor.process(mdxContent);
|
|
6029
6414
|
const frontmatter = parsed.data?.frontmatter || {};
|
|
6030
|
-
const
|
|
6415
|
+
const ast = await this.processMdxContent(
|
|
6031
6416
|
String(parsed),
|
|
6032
|
-
pageInfo
|
|
6033
|
-
pageInfo.demosFolder,
|
|
6417
|
+
pageInfo,
|
|
6034
6418
|
frontmatter
|
|
6035
6419
|
);
|
|
6036
|
-
const removeJsxProcessor =
|
|
6037
|
-
const
|
|
6038
|
-
|
|
6420
|
+
const removeJsxProcessor = unified5().use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(remarkRemoveJsx).use(remarkStringify4);
|
|
6421
|
+
const sectionAst = removeJsxProcessor.runSync(ast);
|
|
6422
|
+
const removedJsx = String(removeJsxProcessor.stringify(sectionAst));
|
|
6423
|
+
const rawContent = removedJsx.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").replace(/(^#{1,6} .*\\<[^>]+)>/gm, "$1\\>");
|
|
6424
|
+
const stripMetaProcessor = unified5().use(remarkParse4).use(remarkExtractMeta, {}).use(remarkStringify4);
|
|
6425
|
+
const strippedContent = String(
|
|
6426
|
+
await stripMetaProcessor.process(rawContent)
|
|
6039
6427
|
);
|
|
6040
|
-
const contentWithoutFrontmatter = removedJsx.replace(/^---[\s\S]*?---\n/, "").replace(/(^#{1,6} .*\\<[^>]+)>/gm, "$1\\>");
|
|
6041
6428
|
const title = frontmatter.title || pageInfo.name;
|
|
6042
6429
|
return {
|
|
6043
|
-
content:
|
|
6044
|
-
demoFiles,
|
|
6430
|
+
content: strippedContent.trim(),
|
|
6045
6431
|
frontmatter,
|
|
6432
|
+
rawContent: rawContent.trim(),
|
|
6433
|
+
sectionAst,
|
|
6046
6434
|
title,
|
|
6047
6435
|
url: pageInfo.url
|
|
6048
6436
|
};
|
|
@@ -6075,7 +6463,7 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6075
6463
|
}
|
|
6076
6464
|
async generateAggregatedOutput(processedPages, pages) {
|
|
6077
6465
|
const llmsTxtContent = this.generateLlmsTxt(processedPages);
|
|
6078
|
-
await mkdir(
|
|
6466
|
+
await mkdir(dirname3(this.config.outputPath), { recursive: true }).catch(
|
|
6079
6467
|
() => {
|
|
6080
6468
|
}
|
|
6081
6469
|
);
|
|
@@ -6099,7 +6487,7 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6099
6487
|
extraFiles.map(async (extraFile) => {
|
|
6100
6488
|
let contents = extraFile.contents;
|
|
6101
6489
|
if (extraFile.processAsMdx) {
|
|
6102
|
-
const removeJsxProcessor =
|
|
6490
|
+
const removeJsxProcessor = unified5().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(remarkRemoveJsx).use(this.transformRelativeUrls()).use(remarkStringify4);
|
|
6103
6491
|
contents = String(await removeJsxProcessor.process(contents));
|
|
6104
6492
|
}
|
|
6105
6493
|
const lines = [];
|
|
@@ -6118,8 +6506,8 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6118
6506
|
lines.push(contents);
|
|
6119
6507
|
lines.push("");
|
|
6120
6508
|
const fileContent = lines.join("\n");
|
|
6121
|
-
const fileName = `${
|
|
6122
|
-
const outfile = `${
|
|
6509
|
+
const fileName = `${kebabCase3(extraFile.id)}.md`;
|
|
6510
|
+
const outfile = `${resolve3(this.config.outputPath)}/${fileName}`;
|
|
6123
6511
|
await writeFile(outfile, fileContent, "utf-8");
|
|
6124
6512
|
const stats = await stat(outfile);
|
|
6125
6513
|
totalSize += stats.size / 1024;
|
|
@@ -6141,7 +6529,7 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6141
6529
|
}
|
|
6142
6530
|
async generatePerPageExports(pages, processedPages, metadata) {
|
|
6143
6531
|
const start = performance.now();
|
|
6144
|
-
await mkdir(
|
|
6532
|
+
await mkdir(dirname3(this.config.outputPath), { recursive: true }).catch(
|
|
6145
6533
|
() => {
|
|
6146
6534
|
}
|
|
6147
6535
|
);
|
|
@@ -6159,30 +6547,44 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6159
6547
|
for (const [key, value] of metadata) {
|
|
6160
6548
|
frontmatterEntries.push([key, value]);
|
|
6161
6549
|
}
|
|
6162
|
-
if (this.config.
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
frontmatterEntries.push([key, String(value)]);
|
|
6171
|
-
}
|
|
6550
|
+
if (this.config.frontmatter?.include?.length) {
|
|
6551
|
+
const includePatterns = this.config.frontmatter.include;
|
|
6552
|
+
const excludePatterns = this.config.frontmatter.exclude ?? [];
|
|
6553
|
+
for (const [field, value] of Object.entries(
|
|
6554
|
+
processedPage.frontmatter
|
|
6555
|
+
)) {
|
|
6556
|
+
if (value === void 0) {
|
|
6557
|
+
continue;
|
|
6172
6558
|
}
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6559
|
+
const isIncluded = includePatterns.some(
|
|
6560
|
+
(pattern) => minimatch(field, pattern)
|
|
6561
|
+
);
|
|
6562
|
+
const isExcluded = excludePatterns.some(
|
|
6563
|
+
(pattern) => minimatch(field, pattern)
|
|
6564
|
+
);
|
|
6565
|
+
if (isIncluded && !isExcluded) {
|
|
6566
|
+
frontmatterEntries.push([
|
|
6567
|
+
field,
|
|
6568
|
+
Array.isArray(value) ? value : String(value)
|
|
6569
|
+
]);
|
|
6179
6570
|
}
|
|
6180
6571
|
}
|
|
6181
6572
|
}
|
|
6573
|
+
if (this.config.frontmatter?.extraFields) {
|
|
6574
|
+
for (const [key, value] of Object.entries(
|
|
6575
|
+
this.config.frontmatter.extraFields
|
|
6576
|
+
)) {
|
|
6577
|
+
frontmatterEntries.push([key, value]);
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6182
6580
|
if (frontmatterEntries.length > 0) {
|
|
6183
6581
|
lines.push("---");
|
|
6184
6582
|
for (const [key, value] of frontmatterEntries) {
|
|
6185
|
-
|
|
6583
|
+
if (Array.isArray(value)) {
|
|
6584
|
+
lines.push(`${key}: [${value.join(", ")}]`);
|
|
6585
|
+
} else {
|
|
6586
|
+
lines.push(`${key}: ${value}`);
|
|
6587
|
+
}
|
|
6186
6588
|
}
|
|
6187
6589
|
lines.push("---");
|
|
6188
6590
|
lines.push("");
|
|
@@ -6206,50 +6608,14 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6206
6608
|
}
|
|
6207
6609
|
lines.push(content);
|
|
6208
6610
|
lines.push("");
|
|
6209
|
-
if (processedPage.demoFiles.length > 0) {
|
|
6210
|
-
if (this.config.verbose) {
|
|
6211
|
-
console.log(
|
|
6212
|
-
`Collecting imports for ${page.name} from ${processedPage.demoFiles.length} demo files`
|
|
6213
|
-
);
|
|
6214
|
-
}
|
|
6215
|
-
const allImports = [];
|
|
6216
|
-
for (const demoFile of processedPage.demoFiles) {
|
|
6217
|
-
const imports = await this.collectRelativeImports(
|
|
6218
|
-
demoFile,
|
|
6219
|
-
/* @__PURE__ */ new Set()
|
|
6220
|
-
);
|
|
6221
|
-
allImports.push(...imports);
|
|
6222
|
-
}
|
|
6223
|
-
const uniqueImports = Array.from(
|
|
6224
|
-
new Map(allImports.map((m) => [m.path, m])).values()
|
|
6225
|
-
);
|
|
6226
|
-
if (this.config.verbose) {
|
|
6227
|
-
console.log(
|
|
6228
|
-
` Collected ${uniqueImports.length} unique import modules`
|
|
6229
|
-
);
|
|
6230
|
-
}
|
|
6231
|
-
if (uniqueImports.length > 0) {
|
|
6232
|
-
lines.push("## Related Source Files");
|
|
6233
|
-
lines.push("");
|
|
6234
|
-
for (const importedModule of uniqueImports) {
|
|
6235
|
-
const ext = extname(importedModule.path).slice(1);
|
|
6236
|
-
lines.push(`### ${basename(importedModule.path)}`);
|
|
6237
|
-
lines.push("");
|
|
6238
|
-
lines.push(`\`\`\`${ext}`);
|
|
6239
|
-
lines.push(importedModule.content);
|
|
6240
|
-
lines.push("```");
|
|
6241
|
-
lines.push("");
|
|
6242
|
-
}
|
|
6243
|
-
}
|
|
6244
|
-
}
|
|
6245
6611
|
const fileContent = lines.join("\n");
|
|
6246
|
-
const fileName = `${
|
|
6247
|
-
const outfile = `${
|
|
6612
|
+
const fileName = `${kebabCase3(page.id || page.name)}.md`;
|
|
6613
|
+
const outfile = `${resolve3(this.config.outputPath)}/${fileName}`;
|
|
6248
6614
|
await writeFile(outfile, fileContent, "utf-8");
|
|
6249
6615
|
const stats = await stat(outfile);
|
|
6250
6616
|
totalSize += stats.size / 1024;
|
|
6251
6617
|
manifestEntries.push({
|
|
6252
|
-
id: page.id ||
|
|
6618
|
+
id: page.id || kebabCase3(page.name),
|
|
6253
6619
|
md5: computeMd5(fileContent),
|
|
6254
6620
|
path: fileName,
|
|
6255
6621
|
size: stats.size,
|
|
@@ -6273,6 +6639,11 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6273
6639
|
manifestEntries
|
|
6274
6640
|
);
|
|
6275
6641
|
}
|
|
6642
|
+
await this.generateSectionsOutput(
|
|
6643
|
+
processedPages,
|
|
6644
|
+
pages,
|
|
6645
|
+
this.config.manifestOutputPath
|
|
6646
|
+
);
|
|
6276
6647
|
}
|
|
6277
6648
|
console.log(
|
|
6278
6649
|
`Generated ${count + extraFilesResult.count} files(s) in ${chalk3.magenta.bold(`${Math.round(performance.now() - start + extraFilesResult.duration)}ms`)} at ${chalk3.blue.bold(this.config.outputPath)} - ${(totalSize + extraFilesResult.totalSize).toFixed(1)} KB`
|
|
@@ -6297,7 +6668,7 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6297
6668
|
await mkdir(outputPath, { recursive: true }).catch(() => {
|
|
6298
6669
|
});
|
|
6299
6670
|
await writeFile(
|
|
6300
|
-
|
|
6671
|
+
join5(outputPath, "manifest.json"),
|
|
6301
6672
|
JSON.stringify(manifest, null, 2),
|
|
6302
6673
|
"utf-8"
|
|
6303
6674
|
);
|
|
@@ -6306,16 +6677,58 @@ ${propsToDefinitionList(outputs)}`);
|
|
|
6306
6677
|
async generateBulkZip(outputPath, entries) {
|
|
6307
6678
|
await mkdir(outputPath, { recursive: true }).catch(() => {
|
|
6308
6679
|
});
|
|
6309
|
-
const zipPath =
|
|
6680
|
+
const zipPath = join5(outputPath, "bulk.zip");
|
|
6310
6681
|
const zip = new AdmZip();
|
|
6311
6682
|
for (const entry of entries) {
|
|
6312
|
-
const filePath =
|
|
6313
|
-
const content = await
|
|
6683
|
+
const filePath = join5(this.config.outputPath, entry.path);
|
|
6684
|
+
const content = await readFile4(filePath);
|
|
6314
6685
|
zip.addFile(entry.path, content);
|
|
6315
6686
|
}
|
|
6316
6687
|
zip.writeZip(zipPath);
|
|
6317
6688
|
}
|
|
6689
|
+
async generateSectionsOutput(processedPages, pages, outputPath) {
|
|
6690
|
+
const sectionsConfig = this.config.sections ?? {};
|
|
6691
|
+
const extractor = new SectionExtractor({
|
|
6692
|
+
depths: sectionsConfig.depths,
|
|
6693
|
+
minContentLength: sectionsConfig.minContentLength
|
|
6694
|
+
});
|
|
6695
|
+
const allSections = [];
|
|
6696
|
+
for (let i = 0; i < processedPages.length; i++) {
|
|
6697
|
+
const processed = processedPages[i];
|
|
6698
|
+
const page = pages[i];
|
|
6699
|
+
const filteredFrontmatter = this.filterFrontmatter(processed.frontmatter);
|
|
6700
|
+
const pageSections = extractor.extract(processed.sectionAst, {
|
|
6701
|
+
frontmatter: filteredFrontmatter,
|
|
6702
|
+
id: page.id,
|
|
6703
|
+
title: processed.title,
|
|
6704
|
+
url: processed.url
|
|
6705
|
+
});
|
|
6706
|
+
allSections.push(...pageSections);
|
|
6707
|
+
}
|
|
6708
|
+
const hash = computeMd5(JSON.stringify(allSections));
|
|
6709
|
+
const output = {
|
|
6710
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6711
|
+
hash,
|
|
6712
|
+
sections: allSections,
|
|
6713
|
+
totalSections: allSections.length,
|
|
6714
|
+
version: 1
|
|
6715
|
+
};
|
|
6716
|
+
const sectionsPath = join5(
|
|
6717
|
+
outputPath,
|
|
6718
|
+
sectionsConfig.outputPath ?? "sections.json"
|
|
6719
|
+
);
|
|
6720
|
+
await mkdir(dirname3(sectionsPath), { recursive: true }).catch(() => {
|
|
6721
|
+
});
|
|
6722
|
+
await writeFile(sectionsPath, JSON.stringify(output, null, 2), "utf-8");
|
|
6723
|
+
if (this.config.verbose) {
|
|
6724
|
+
console.log(
|
|
6725
|
+
`Generated ${allSections.length} sections at ${chalk3.blue.bold(sectionsPath)}`
|
|
6726
|
+
);
|
|
6727
|
+
}
|
|
6728
|
+
}
|
|
6318
6729
|
};
|
|
6730
|
+
|
|
6731
|
+
// src/ai-knowledge/generator/command.ts
|
|
6319
6732
|
async function generate(config2) {
|
|
6320
6733
|
const generator = new KnowledgeGenerator(config2);
|
|
6321
6734
|
return generator.run();
|
|
@@ -6381,12 +6794,12 @@ var PluginState = class {
|
|
|
6381
6794
|
createIndexer(config2) {
|
|
6382
6795
|
this.config = config2;
|
|
6383
6796
|
this.configFilePath = config2.filePath;
|
|
6384
|
-
this.docPropsFilePath = config2.typeDocProps ? fixPath(
|
|
6385
|
-
this.routesDir = fixPath(
|
|
6797
|
+
this.docPropsFilePath = config2.typeDocProps ? fixPath(resolve4(this.cwd, config2.typeDocProps)) : "";
|
|
6798
|
+
this.routesDir = fixPath(resolve4(config2.appDirectory, config2.pageDirectory));
|
|
6386
6799
|
this.knowledgeConfig = config2.knowledge;
|
|
6387
6800
|
this.indexer = new SearchIndexer({
|
|
6388
6801
|
...config2,
|
|
6389
|
-
srcDir: fixPath(
|
|
6802
|
+
srcDir: fixPath(resolve4(this.cwd, config2.appDirectory)),
|
|
6390
6803
|
typeDocProps: this.resolveDocProps()
|
|
6391
6804
|
});
|
|
6392
6805
|
const exportsConfig = config2.knowledge?.global?.exports;
|
|
@@ -6476,9 +6889,9 @@ var PluginState = class {
|
|
|
6476
6889
|
const globalConfig = this.knowledgeConfig.global;
|
|
6477
6890
|
const exportsConfig = globalConfig.exports ?? {};
|
|
6478
6891
|
const exportsPath = exportsConfig.staticPath ?? "exports/md";
|
|
6479
|
-
const outputPath =
|
|
6892
|
+
const outputPath = join6(publicDir, exportsPath);
|
|
6480
6893
|
const manifestPath = exportsConfig.manifestPath ?? "exports";
|
|
6481
|
-
const manifestOutputPath =
|
|
6894
|
+
const manifestOutputPath = join6(publicDir, manifestPath);
|
|
6482
6895
|
const startTime = Date.now();
|
|
6483
6896
|
const pageIds = await generate({
|
|
6484
6897
|
baseUrl: globalConfig.baseUrl,
|
|
@@ -6486,6 +6899,7 @@ var PluginState = class {
|
|
|
6486
6899
|
docPropsPath: this.docPropsFilePath || void 0,
|
|
6487
6900
|
exclude: exportsConfig.exclude ?? globalConfig.exclude,
|
|
6488
6901
|
extraFiles: exportsConfig.extraFiles ?? globalConfig.extraFiles,
|
|
6902
|
+
frontmatter: exportsConfig.frontmatter ?? globalConfig.frontmatter,
|
|
6489
6903
|
generateBulkZip: exportsConfig.generateBulkZip ?? true,
|
|
6490
6904
|
generateManifest: exportsConfig.generateManifest ?? true,
|
|
6491
6905
|
manifestOutputPath,
|
|
@@ -6493,7 +6907,8 @@ var PluginState = class {
|
|
|
6493
6907
|
outputMode: "per-page",
|
|
6494
6908
|
outputPath,
|
|
6495
6909
|
pageTitlePrefix: exportsConfig.pageTitlePrefix ?? globalConfig.pageTitlePrefix,
|
|
6496
|
-
routeDir: this.routesDir
|
|
6910
|
+
routeDir: this.routesDir,
|
|
6911
|
+
sections: exportsConfig.sections
|
|
6497
6912
|
});
|
|
6498
6913
|
this.exports.pages = pageIds;
|
|
6499
6914
|
console.debug(
|
|
@@ -6525,7 +6940,7 @@ function quiDocsPlugin(opts) {
|
|
|
6525
6940
|
state.buildIndex(state.buildCount > 0);
|
|
6526
6941
|
state.buildCount++;
|
|
6527
6942
|
if (!isDev && state.exports.enabled) {
|
|
6528
|
-
const publicDir = viteConfig.publicDir ||
|
|
6943
|
+
const publicDir = viteConfig.publicDir || join6(state.getCwd(), "public");
|
|
6529
6944
|
await state.generateExports(publicDir);
|
|
6530
6945
|
}
|
|
6531
6946
|
},
|
|
@@ -6538,12 +6953,12 @@ function quiDocsPlugin(opts) {
|
|
|
6538
6953
|
}
|
|
6539
6954
|
state.initWatchers(opts?.configFile);
|
|
6540
6955
|
if (state.exports.enabled) {
|
|
6541
|
-
const publicDir =
|
|
6956
|
+
const publicDir = join6(state.getCwd(), "public");
|
|
6542
6957
|
await state.generateExports(publicDir);
|
|
6543
6958
|
}
|
|
6544
6959
|
server.watcher.on("add", (path) => {
|
|
6545
6960
|
if (path.endsWith(".mdx")) {
|
|
6546
|
-
const publicDir =
|
|
6961
|
+
const publicDir = join6(state.getCwd(), "public");
|
|
6547
6962
|
state.handleChange({
|
|
6548
6963
|
onComplete: () => {
|
|
6549
6964
|
server.ws.send({ type: "full-reload" });
|
|
@@ -6554,7 +6969,7 @@ function quiDocsPlugin(opts) {
|
|
|
6554
6969
|
});
|
|
6555
6970
|
server.watcher.on("unlink", (path) => {
|
|
6556
6971
|
if (path.endsWith(".mdx")) {
|
|
6557
|
-
const publicDir =
|
|
6972
|
+
const publicDir = join6(state.getCwd(), "public");
|
|
6558
6973
|
state.handleChange({
|
|
6559
6974
|
onComplete: () => {
|
|
6560
6975
|
server.ws.send({ type: "full-reload" });
|
|
@@ -6733,7 +7148,7 @@ var rehypeSectionize = (options = defaultOptions) => {
|
|
|
6733
7148
|
};
|
|
6734
7149
|
|
|
6735
7150
|
// src/docs-plugin/remark/remark-code-tabs.ts
|
|
6736
|
-
import { visit as
|
|
7151
|
+
import { visit as visit12 } from "unist-util-visit";
|
|
6737
7152
|
function parseTabAttributes(meta) {
|
|
6738
7153
|
if (!meta) {
|
|
6739
7154
|
return { label: null, remainingMeta: "", tabsGroup: null };
|
|
@@ -6819,7 +7234,7 @@ function renderTabs(tabs, parent) {
|
|
|
6819
7234
|
var remarkCodeTabs = () => {
|
|
6820
7235
|
return (tree) => {
|
|
6821
7236
|
const transformations = [];
|
|
6822
|
-
|
|
7237
|
+
visit12(
|
|
6823
7238
|
tree,
|
|
6824
7239
|
"code",
|
|
6825
7240
|
(node, index, parent) => {
|
|
@@ -6861,10 +7276,10 @@ var remarkCodeTabs = () => {
|
|
|
6861
7276
|
};
|
|
6862
7277
|
|
|
6863
7278
|
// src/docs-plugin/remark/remark-frontmatter-description.ts
|
|
6864
|
-
import { visit as
|
|
7279
|
+
import { visit as visit13 } from "unist-util-visit";
|
|
6865
7280
|
var remarkFrontmatterDescription = () => {
|
|
6866
7281
|
return (tree) => {
|
|
6867
|
-
|
|
7282
|
+
visit13(
|
|
6868
7283
|
tree,
|
|
6869
7284
|
"mdxFlowExpression",
|
|
6870
7285
|
(node, index, parent) => {
|
|
@@ -6890,14 +7305,14 @@ var remarkFrontmatterDescription = () => {
|
|
|
6890
7305
|
};
|
|
6891
7306
|
|
|
6892
7307
|
// src/docs-plugin/remark/remark-frontmatter-title.ts
|
|
6893
|
-
import { visit as
|
|
7308
|
+
import { visit as visit14 } from "unist-util-visit";
|
|
6894
7309
|
function isMdxTextExpression(node) {
|
|
6895
7310
|
const n = node;
|
|
6896
7311
|
return n.type === "mdxTextExpression" && typeof n.value === "string";
|
|
6897
7312
|
}
|
|
6898
7313
|
var remarkFrontmatterTitle = () => {
|
|
6899
7314
|
return (tree) => {
|
|
6900
|
-
|
|
7315
|
+
visit14(
|
|
6901
7316
|
tree,
|
|
6902
7317
|
"heading",
|
|
6903
7318
|
(node, index, parent) => {
|
|
@@ -6930,7 +7345,7 @@ var remarkFrontmatterTitle = () => {
|
|
|
6930
7345
|
|
|
6931
7346
|
// src/docs-plugin/remark/remark-self-link-headings.ts
|
|
6932
7347
|
import { toString as toString2 } from "mdast-util-to-string";
|
|
6933
|
-
import { visit as
|
|
7348
|
+
import { visit as visit15 } from "unist-util-visit";
|
|
6934
7349
|
var emptyOptions2 = {};
|
|
6935
7350
|
function remarkSelfLinkHeadings(baseUrl = "", options) {
|
|
6936
7351
|
if (!baseUrl) {
|
|
@@ -6958,7 +7373,7 @@ function remarkSelfLinkHeadings(baseUrl = "", options) {
|
|
|
6958
7373
|
}
|
|
6959
7374
|
return (tree) => {
|
|
6960
7375
|
seenIds.clear();
|
|
6961
|
-
|
|
7376
|
+
visit15(tree, "heading", (node) => {
|
|
6962
7377
|
if (allowedLevels.has(node.depth)) {
|
|
6963
7378
|
const text = toString2(node);
|
|
6964
7379
|
const slug = prefix + createSlug(text);
|
|
@@ -6975,7 +7390,7 @@ function remarkSelfLinkHeadings(baseUrl = "", options) {
|
|
|
6975
7390
|
}
|
|
6976
7391
|
|
|
6977
7392
|
// src/docs-plugin/remark/remark-spoilers.ts
|
|
6978
|
-
import { visit as
|
|
7393
|
+
import { visit as visit16 } from "unist-util-visit";
|
|
6979
7394
|
var remarkSpoilers = (options = {}) => {
|
|
6980
7395
|
const {
|
|
6981
7396
|
defaultSummary = "Open spoiler",
|
|
@@ -6983,7 +7398,7 @@ var remarkSpoilers = (options = {}) => {
|
|
|
6983
7398
|
summaryClassName = []
|
|
6984
7399
|
} = options;
|
|
6985
7400
|
return (tree) => {
|
|
6986
|
-
|
|
7401
|
+
visit16(tree, "paragraph", (node, index, parent) => {
|
|
6987
7402
|
if (!parent || index === void 0) {
|
|
6988
7403
|
return;
|
|
6989
7404
|
}
|
|
@@ -7290,6 +7705,7 @@ function getRehypePlugins(options = {}) {
|
|
|
7290
7705
|
merge(
|
|
7291
7706
|
{
|
|
7292
7707
|
defaultColor: "light-dark()",
|
|
7708
|
+
fallbackLanguage: "text",
|
|
7293
7709
|
themes: {
|
|
7294
7710
|
dark: quiCustomDarkTheme,
|
|
7295
7711
|
light: "github-light-high-contrast"
|
|
@@ -7311,18 +7727,19 @@ function getRemarkPlugins() {
|
|
|
7311
7727
|
remarkCodeTabs,
|
|
7312
7728
|
remarkFrontmatterTitle,
|
|
7313
7729
|
remarkFrontmatterDescription,
|
|
7314
|
-
remarkSpoilers
|
|
7730
|
+
remarkSpoilers,
|
|
7731
|
+
remarkExtractMeta
|
|
7315
7732
|
];
|
|
7316
7733
|
}
|
|
7317
7734
|
|
|
7318
7735
|
// src/docs-plugin/shiki/internal/shiki-transformer-tailwind.ts
|
|
7319
7736
|
import { fromHtml as fromHtml2 } from "hast-util-from-html";
|
|
7320
7737
|
import { toHtml } from "hast-util-to-html";
|
|
7321
|
-
import { readFile as
|
|
7738
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
7322
7739
|
import postcss from "postcss";
|
|
7323
7740
|
import selectorParser from "postcss-selector-parser";
|
|
7324
7741
|
import { compile } from "tailwindcss";
|
|
7325
|
-
import { visit as
|
|
7742
|
+
import { visit as visit17 } from "unist-util-visit";
|
|
7326
7743
|
import { camelCase } from "@qualcomm-ui/utils/change-case";
|
|
7327
7744
|
async function loadStylesheetContent(id) {
|
|
7328
7745
|
const resolveId = id === "tailwindcss" ? "tailwindcss/index.css" : id;
|
|
@@ -7335,7 +7752,7 @@ async function loadStylesheetContent(id) {
|
|
|
7335
7752
|
);
|
|
7336
7753
|
resolvedPath = createRequire2(import.meta.url).resolve(resolveId);
|
|
7337
7754
|
}
|
|
7338
|
-
return
|
|
7755
|
+
return readFile5(resolvedPath, "utf-8");
|
|
7339
7756
|
}
|
|
7340
7757
|
async function createCompiler(styles) {
|
|
7341
7758
|
return compile(styles, {
|
|
@@ -7843,7 +8260,7 @@ function angularDemoPlugin({
|
|
|
7843
8260
|
logDev(
|
|
7844
8261
|
`${chalk5.blue.bold(LOG_PREFIX)} Processing Angular demo change: ${chalk5.cyan(file)}`
|
|
7845
8262
|
);
|
|
7846
|
-
const code = await
|
|
8263
|
+
const code = await readFile6(file, "utf-8");
|
|
7847
8264
|
const demoInfo = await parseAngularDemo(file, code);
|
|
7848
8265
|
if (!demoInfo || !isAngularDemoEntrypoint(file)) {
|
|
7849
8266
|
const affectedDemos = await scanDemosForFileImport(file);
|
|
@@ -7909,7 +8326,7 @@ function angularDemoPlugin({
|
|
|
7909
8326
|
const demoFiles = await glob2(demoPattern);
|
|
7910
8327
|
demoRegistry.clear();
|
|
7911
8328
|
for (const filePath of demoFiles) {
|
|
7912
|
-
const code = await
|
|
8329
|
+
const code = await readFile6(filePath, "utf-8");
|
|
7913
8330
|
const demoInfo = await parseAngularDemo(filePath, code);
|
|
7914
8331
|
if (demoInfo) {
|
|
7915
8332
|
demoRegistry.set(demoInfo.id, demoInfo);
|
|
@@ -7923,7 +8340,7 @@ function angularDemoPlugin({
|
|
|
7923
8340
|
logDev(
|
|
7924
8341
|
`${chalk5.blue.bold(LOG_PREFIX)} Reloading demo ${chalk5.cyan(demoId)} due to imported file change: ${chalk5.yellow(file)}`
|
|
7925
8342
|
);
|
|
7926
|
-
const code = await
|
|
8343
|
+
const code = await readFile6(demo.filePath, "utf-8");
|
|
7927
8344
|
const updatedDemo = await parseAngularDemo(demo.filePath, code);
|
|
7928
8345
|
if (updatedDemo) {
|
|
7929
8346
|
delete demoDimensionsCache[updatedDemo.id];
|
|
@@ -7997,10 +8414,10 @@ function angularDemoPlugin({
|
|
|
7997
8414
|
}
|
|
7998
8415
|
async function extractRelativeImports2(filePath) {
|
|
7999
8416
|
try {
|
|
8000
|
-
let
|
|
8001
|
-
if (
|
|
8417
|
+
let visit19 = function(node) {
|
|
8418
|
+
if (ts2.isImportDeclaration(node)) {
|
|
8002
8419
|
const moduleSpecifier = node.moduleSpecifier;
|
|
8003
|
-
if (
|
|
8420
|
+
if (ts2.isStringLiteral(moduleSpecifier)) {
|
|
8004
8421
|
const source = moduleSpecifier.text;
|
|
8005
8422
|
if (isRelativeImport2(source)) {
|
|
8006
8423
|
const resolvedPath = resolveRelativeImport2(source, filePath);
|
|
@@ -8016,19 +8433,19 @@ function angularDemoPlugin({
|
|
|
8016
8433
|
}
|
|
8017
8434
|
}
|
|
8018
8435
|
}
|
|
8019
|
-
|
|
8436
|
+
ts2.forEachChild(node, visit19);
|
|
8020
8437
|
};
|
|
8021
|
-
var
|
|
8022
|
-
const content = await
|
|
8023
|
-
const sourceFile =
|
|
8438
|
+
var visit18 = visit19;
|
|
8439
|
+
const content = await readFile6(filePath, "utf-8");
|
|
8440
|
+
const sourceFile = ts2.createSourceFile(
|
|
8024
8441
|
filePath,
|
|
8025
8442
|
content,
|
|
8026
|
-
|
|
8443
|
+
ts2.ScriptTarget.Latest,
|
|
8027
8444
|
true,
|
|
8028
|
-
|
|
8445
|
+
ts2.ScriptKind.TS
|
|
8029
8446
|
);
|
|
8030
8447
|
const relativeImports = [];
|
|
8031
|
-
|
|
8448
|
+
visit19(sourceFile);
|
|
8032
8449
|
return relativeImports;
|
|
8033
8450
|
} catch (error) {
|
|
8034
8451
|
logDev(
|
|
@@ -8051,25 +8468,25 @@ function angularDemoPlugin({
|
|
|
8051
8468
|
}
|
|
8052
8469
|
function stripImports(code, fileName) {
|
|
8053
8470
|
try {
|
|
8054
|
-
let
|
|
8055
|
-
if (
|
|
8471
|
+
let visit19 = function(node) {
|
|
8472
|
+
if (ts2.isImportDeclaration(node)) {
|
|
8056
8473
|
importRanges.push({
|
|
8057
8474
|
end: node.getEnd(),
|
|
8058
8475
|
start: node.getFullStart()
|
|
8059
8476
|
});
|
|
8060
8477
|
}
|
|
8061
|
-
|
|
8478
|
+
ts2.forEachChild(node, visit19);
|
|
8062
8479
|
};
|
|
8063
|
-
var
|
|
8064
|
-
const sourceFile =
|
|
8480
|
+
var visit18 = visit19;
|
|
8481
|
+
const sourceFile = ts2.createSourceFile(
|
|
8065
8482
|
fileName,
|
|
8066
8483
|
code,
|
|
8067
|
-
|
|
8484
|
+
ts2.ScriptTarget.Latest,
|
|
8068
8485
|
true,
|
|
8069
|
-
|
|
8486
|
+
ts2.ScriptKind.TS
|
|
8070
8487
|
);
|
|
8071
8488
|
const importRanges = [];
|
|
8072
|
-
|
|
8489
|
+
visit19(sourceFile);
|
|
8073
8490
|
return importRanges.map((range) => {
|
|
8074
8491
|
let endPos = range.end;
|
|
8075
8492
|
if (code[endPos] === "\n") {
|
|
@@ -8099,7 +8516,7 @@ function angularDemoPlugin({
|
|
|
8099
8516
|
}
|
|
8100
8517
|
const demoId = componentClass;
|
|
8101
8518
|
const importPath = relative3(process.cwd(), filePath).replace(/\\/g, "/");
|
|
8102
|
-
const fileName =
|
|
8519
|
+
const fileName = basename3(filePath);
|
|
8103
8520
|
const importsWithoutStrip = stripImports(code, filePath);
|
|
8104
8521
|
const sourceCode = [];
|
|
8105
8522
|
const aggregatedRules = /* @__PURE__ */ new Map();
|
|
@@ -8168,12 +8585,12 @@ function angularDemoPlugin({
|
|
|
8168
8585
|
}
|
|
8169
8586
|
}
|
|
8170
8587
|
function parseAngularComponentMeta(filePath, source) {
|
|
8171
|
-
const sourceFile =
|
|
8588
|
+
const sourceFile = ts2.createSourceFile(
|
|
8172
8589
|
filePath,
|
|
8173
8590
|
source,
|
|
8174
|
-
|
|
8591
|
+
ts2.ScriptTarget.Latest,
|
|
8175
8592
|
true,
|
|
8176
|
-
|
|
8593
|
+
ts2.ScriptKind.TS
|
|
8177
8594
|
);
|
|
8178
8595
|
let componentClass = "";
|
|
8179
8596
|
let selector = "";
|
|
@@ -8181,57 +8598,57 @@ function angularDemoPlugin({
|
|
|
8181
8598
|
let templateUrl = null;
|
|
8182
8599
|
let hasDefaultExport = false;
|
|
8183
8600
|
const importsFromAst = [];
|
|
8184
|
-
function
|
|
8185
|
-
if (
|
|
8601
|
+
function visit18(node) {
|
|
8602
|
+
if (ts2.isImportDeclaration(node)) {
|
|
8186
8603
|
importsFromAst.push(node.getFullText(sourceFile).trim());
|
|
8187
8604
|
}
|
|
8188
|
-
if (
|
|
8189
|
-
const decorators = node.modifiers?.filter(
|
|
8605
|
+
if (ts2.isClassDeclaration(node)) {
|
|
8606
|
+
const decorators = node.modifiers?.filter(ts2.isDecorator);
|
|
8190
8607
|
const componentDecorator = decorators?.find((decorator) => {
|
|
8191
|
-
if (!
|
|
8608
|
+
if (!ts2.isCallExpression(decorator.expression)) {
|
|
8192
8609
|
return false;
|
|
8193
8610
|
}
|
|
8194
8611
|
const expression = decorator.expression.expression;
|
|
8195
|
-
return
|
|
8612
|
+
return ts2.isIdentifier(expression) && expression.text === "Component";
|
|
8196
8613
|
});
|
|
8197
8614
|
if (componentDecorator && node.name) {
|
|
8198
8615
|
componentClass = node.name.text;
|
|
8199
|
-
if (
|
|
8616
|
+
if (ts2.isCallExpression(componentDecorator.expression) && componentDecorator.expression.arguments[0] && ts2.isObjectLiteralExpression(
|
|
8200
8617
|
componentDecorator.expression.arguments[0]
|
|
8201
8618
|
)) {
|
|
8202
8619
|
const properties = componentDecorator.expression.arguments[0].properties;
|
|
8203
8620
|
const selectorProp = properties.find(
|
|
8204
|
-
(prop) =>
|
|
8621
|
+
(prop) => ts2.isPropertyAssignment(prop) && ts2.isIdentifier(prop.name) && prop.name.text === "selector"
|
|
8205
8622
|
);
|
|
8206
|
-
if (selectorProp &&
|
|
8623
|
+
if (selectorProp && ts2.isStringLiteral(selectorProp.initializer)) {
|
|
8207
8624
|
selector = selectorProp.initializer.text;
|
|
8208
8625
|
}
|
|
8209
8626
|
const templateUrlProp = properties.find(
|
|
8210
|
-
(prop) =>
|
|
8627
|
+
(prop) => ts2.isPropertyAssignment(prop) && ts2.isIdentifier(prop.name) && prop.name.text === "templateUrl"
|
|
8211
8628
|
);
|
|
8212
8629
|
if (templateUrlProp) {
|
|
8213
8630
|
const init = templateUrlProp.initializer;
|
|
8214
|
-
if (
|
|
8631
|
+
if (ts2.isStringLiteral(init)) {
|
|
8215
8632
|
templateUrl = init.text;
|
|
8216
|
-
} else if (
|
|
8633
|
+
} else if (ts2.isNoSubstitutionTemplateLiteral(init)) {
|
|
8217
8634
|
templateUrl = init.text;
|
|
8218
8635
|
}
|
|
8219
8636
|
}
|
|
8220
8637
|
const standaloneProp = properties.find(
|
|
8221
|
-
(prop) =>
|
|
8638
|
+
(prop) => ts2.isPropertyAssignment(prop) && ts2.isIdentifier(prop.name) && prop.name.text === "standalone"
|
|
8222
8639
|
);
|
|
8223
|
-
if (standaloneProp && standaloneProp.initializer.kind ===
|
|
8640
|
+
if (standaloneProp && standaloneProp.initializer.kind === ts2.SyntaxKind.FalseKeyword) {
|
|
8224
8641
|
isStandalone = false;
|
|
8225
8642
|
}
|
|
8226
8643
|
}
|
|
8227
8644
|
}
|
|
8228
8645
|
}
|
|
8229
|
-
if (
|
|
8646
|
+
if (ts2.isExportAssignment(node) && !node.isExportEquals) {
|
|
8230
8647
|
hasDefaultExport = true;
|
|
8231
8648
|
}
|
|
8232
|
-
|
|
8649
|
+
ts2.forEachChild(node, visit18);
|
|
8233
8650
|
}
|
|
8234
|
-
|
|
8651
|
+
visit18(sourceFile);
|
|
8235
8652
|
return {
|
|
8236
8653
|
componentClass,
|
|
8237
8654
|
hasDefaultExport,
|
|
@@ -8280,10 +8697,10 @@ function angularDemoPlugin({
|
|
|
8280
8697
|
return null;
|
|
8281
8698
|
}
|
|
8282
8699
|
try {
|
|
8283
|
-
const templateCode = await
|
|
8700
|
+
const templateCode = await readFile6(templatePath, "utf-8");
|
|
8284
8701
|
return buildAngularSourceEntry({
|
|
8285
8702
|
code: templateCode,
|
|
8286
|
-
fileName:
|
|
8703
|
+
fileName: basename3(templatePath),
|
|
8287
8704
|
filePath: templatePath,
|
|
8288
8705
|
language: "angular-html"
|
|
8289
8706
|
});
|
|
@@ -8300,10 +8717,10 @@ function angularDemoPlugin({
|
|
|
8300
8717
|
const relativeImports = await collectAllImports(fromFilePath);
|
|
8301
8718
|
for (const resolvedPath of relativeImports) {
|
|
8302
8719
|
try {
|
|
8303
|
-
const importedCode = await
|
|
8720
|
+
const importedCode = await readFile6(resolvedPath, "utf-8");
|
|
8304
8721
|
const entry = await buildAngularSourceEntry({
|
|
8305
8722
|
code: importedCode,
|
|
8306
|
-
fileName:
|
|
8723
|
+
fileName: basename3(resolvedPath),
|
|
8307
8724
|
filePath: resolvedPath,
|
|
8308
8725
|
language: "angular-ts"
|
|
8309
8726
|
});
|
|
@@ -8391,8 +8808,8 @@ export function getAngularDemoInfo(demoId) {
|
|
|
8391
8808
|
return source.startsWith("node:") || NODE_BUILTINS2.includes(source);
|
|
8392
8809
|
}
|
|
8393
8810
|
function resolveRelativeImport2(source, fromFile) {
|
|
8394
|
-
const fromDir =
|
|
8395
|
-
const resolved =
|
|
8811
|
+
const fromDir = dirname4(fromFile);
|
|
8812
|
+
const resolved = resolve5(fromDir, source);
|
|
8396
8813
|
const extensions = [".ts", ".js"];
|
|
8397
8814
|
for (const ext of extensions) {
|
|
8398
8815
|
const withExt = resolved + ext;
|
|
@@ -8401,7 +8818,7 @@ export function getAngularDemoInfo(demoId) {
|
|
|
8401
8818
|
}
|
|
8402
8819
|
}
|
|
8403
8820
|
for (const ext of extensions) {
|
|
8404
|
-
const indexFile =
|
|
8821
|
+
const indexFile = join7(resolved, `index${ext}`);
|
|
8405
8822
|
if (existsSync(indexFile)) {
|
|
8406
8823
|
return indexFile;
|
|
8407
8824
|
}
|
|
@@ -8409,28 +8826,28 @@ export function getAngularDemoInfo(demoId) {
|
|
|
8409
8826
|
return resolved;
|
|
8410
8827
|
}
|
|
8411
8828
|
function loadTsConfigPaths2(fromFile) {
|
|
8412
|
-
let currentDir =
|
|
8829
|
+
let currentDir = dirname4(fromFile);
|
|
8413
8830
|
const pathAliases = [];
|
|
8414
|
-
while (currentDir !==
|
|
8415
|
-
const tsconfigPath =
|
|
8831
|
+
while (currentDir !== dirname4(currentDir)) {
|
|
8832
|
+
const tsconfigPath = join7(currentDir, "tsconfig.json");
|
|
8416
8833
|
if (existsSync(tsconfigPath)) {
|
|
8417
8834
|
try {
|
|
8418
|
-
const configContent =
|
|
8835
|
+
const configContent = ts2.sys.readFile(tsconfigPath);
|
|
8419
8836
|
if (!configContent) {
|
|
8420
|
-
currentDir =
|
|
8837
|
+
currentDir = dirname4(currentDir);
|
|
8421
8838
|
continue;
|
|
8422
8839
|
}
|
|
8423
|
-
const parseResult =
|
|
8840
|
+
const parseResult = ts2.parseConfigFileTextToJson(
|
|
8424
8841
|
tsconfigPath,
|
|
8425
8842
|
configContent
|
|
8426
8843
|
);
|
|
8427
8844
|
if (parseResult.error) {
|
|
8428
|
-
currentDir =
|
|
8845
|
+
currentDir = dirname4(currentDir);
|
|
8429
8846
|
continue;
|
|
8430
8847
|
}
|
|
8431
8848
|
const paths = parseResult.config?.compilerOptions?.paths;
|
|
8432
8849
|
const baseUrl = parseResult.config?.compilerOptions?.baseUrl || "./";
|
|
8433
|
-
const resolvedBaseUrl =
|
|
8850
|
+
const resolvedBaseUrl = resolve5(currentDir, baseUrl);
|
|
8434
8851
|
if (paths) {
|
|
8435
8852
|
for (const [alias, targets] of Object.entries(paths)) {
|
|
8436
8853
|
if (Array.isArray(targets) && targets.length > 0) {
|
|
@@ -8438,7 +8855,7 @@ export function getAngularDemoInfo(demoId) {
|
|
|
8438
8855
|
const pattern = new RegExp(
|
|
8439
8856
|
`^${alias.replace("*", "(.*)").replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace("\\(\\*\\)", "(.*)")}$`
|
|
8440
8857
|
);
|
|
8441
|
-
const replacement =
|
|
8858
|
+
const replacement = resolve5(
|
|
8442
8859
|
resolvedBaseUrl,
|
|
8443
8860
|
target.replace("*", "$1")
|
|
8444
8861
|
);
|
|
@@ -8448,17 +8865,17 @@ export function getAngularDemoInfo(demoId) {
|
|
|
8448
8865
|
}
|
|
8449
8866
|
const extendsPath = parseResult.config?.extends;
|
|
8450
8867
|
if (extendsPath) {
|
|
8451
|
-
const resolvedExtends =
|
|
8868
|
+
const resolvedExtends = resolve5(currentDir, extendsPath);
|
|
8452
8869
|
const extendedAliases = loadTsConfigPathsFromFile(resolvedExtends);
|
|
8453
8870
|
pathAliases.push(...extendedAliases);
|
|
8454
8871
|
}
|
|
8455
8872
|
return pathAliases;
|
|
8456
8873
|
} catch (error) {
|
|
8457
|
-
currentDir =
|
|
8874
|
+
currentDir = dirname4(currentDir);
|
|
8458
8875
|
continue;
|
|
8459
8876
|
}
|
|
8460
8877
|
}
|
|
8461
|
-
currentDir =
|
|
8878
|
+
currentDir = dirname4(currentDir);
|
|
8462
8879
|
}
|
|
8463
8880
|
return pathAliases;
|
|
8464
8881
|
}
|
|
@@ -8508,7 +8925,7 @@ export function getAngularDemoInfo(demoId) {
|
|
|
8508
8925
|
});
|
|
8509
8926
|
}
|
|
8510
8927
|
async function handleAngularDemoUpdate(filePath) {
|
|
8511
|
-
const code = await
|
|
8928
|
+
const code = await readFile6(filePath, "utf-8");
|
|
8512
8929
|
const demoInfo = await parseAngularDemo(filePath, code);
|
|
8513
8930
|
if (demoInfo) {
|
|
8514
8931
|
demoRegistry.set(demoInfo.id, demoInfo);
|
|
@@ -8528,13 +8945,13 @@ export function getAngularDemoInfo(demoId) {
|
|
|
8528
8945
|
}
|
|
8529
8946
|
function loadTsConfigPathsFromFile(tsconfigPath) {
|
|
8530
8947
|
const pathAliases = [];
|
|
8531
|
-
const configDir =
|
|
8948
|
+
const configDir = dirname4(tsconfigPath);
|
|
8532
8949
|
try {
|
|
8533
|
-
const configContent =
|
|
8950
|
+
const configContent = ts2.sys.readFile(tsconfigPath);
|
|
8534
8951
|
if (!configContent) {
|
|
8535
8952
|
return pathAliases;
|
|
8536
8953
|
}
|
|
8537
|
-
const parseResult =
|
|
8954
|
+
const parseResult = ts2.parseConfigFileTextToJson(
|
|
8538
8955
|
tsconfigPath,
|
|
8539
8956
|
configContent
|
|
8540
8957
|
);
|
|
@@ -8543,7 +8960,7 @@ function loadTsConfigPathsFromFile(tsconfigPath) {
|
|
|
8543
8960
|
}
|
|
8544
8961
|
const paths = parseResult.config?.compilerOptions?.paths;
|
|
8545
8962
|
const baseUrl = parseResult.config?.compilerOptions?.baseUrl || "./";
|
|
8546
|
-
const resolvedBaseUrl =
|
|
8963
|
+
const resolvedBaseUrl = resolve5(configDir, baseUrl);
|
|
8547
8964
|
if (paths) {
|
|
8548
8965
|
for (const [alias, targets] of Object.entries(paths)) {
|
|
8549
8966
|
if (Array.isArray(targets) && targets.length > 0) {
|
|
@@ -8551,7 +8968,7 @@ function loadTsConfigPathsFromFile(tsconfigPath) {
|
|
|
8551
8968
|
const pattern = new RegExp(
|
|
8552
8969
|
`^${alias.replace("*", "(.*)").replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace("\\(\\*\\)", "(.*)")}$`
|
|
8553
8970
|
);
|
|
8554
|
-
const replacement =
|
|
8971
|
+
const replacement = resolve5(
|
|
8555
8972
|
resolvedBaseUrl,
|
|
8556
8973
|
target.replace("*", "$1")
|
|
8557
8974
|
);
|
|
@@ -8561,7 +8978,7 @@ function loadTsConfigPathsFromFile(tsconfigPath) {
|
|
|
8561
8978
|
}
|
|
8562
8979
|
const extendsPath = parseResult.config?.extends;
|
|
8563
8980
|
if (extendsPath) {
|
|
8564
|
-
let resolvedExtends =
|
|
8981
|
+
let resolvedExtends = resolve5(configDir, extendsPath);
|
|
8565
8982
|
if (!resolvedExtends.endsWith(".json")) {
|
|
8566
8983
|
resolvedExtends += ".json";
|
|
8567
8984
|
}
|
|
@@ -8590,7 +9007,7 @@ function resolvePathAlias(source, pathAliases) {
|
|
|
8590
9007
|
}
|
|
8591
9008
|
}
|
|
8592
9009
|
for (const ext of extensions) {
|
|
8593
|
-
const indexFile =
|
|
9010
|
+
const indexFile = join7(resolvedPath, `index${ext}`);
|
|
8594
9011
|
if (existsSync(indexFile)) {
|
|
8595
9012
|
return indexFile;
|
|
8596
9013
|
}
|
|
@@ -8601,8 +9018,8 @@ function resolvePathAlias(source, pathAliases) {
|
|
|
8601
9018
|
return null;
|
|
8602
9019
|
}
|
|
8603
9020
|
function resolveTemplateFile(templateUrl, fromFile) {
|
|
8604
|
-
const fromDir =
|
|
8605
|
-
const resolved =
|
|
9021
|
+
const fromDir = dirname4(fromFile);
|
|
9022
|
+
const resolved = resolve5(fromDir, templateUrl);
|
|
8606
9023
|
if (existsSync(resolved)) {
|
|
8607
9024
|
return resolved;
|
|
8608
9025
|
}
|
|
@@ -8651,9 +9068,9 @@ var NODE_BUILTINS = [
|
|
|
8651
9068
|
// src/react-demo-plugin/demo-plugin-utils.ts
|
|
8652
9069
|
import chalk6 from "chalk";
|
|
8653
9070
|
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
8654
|
-
import { readFile as
|
|
8655
|
-
import { dirname as
|
|
8656
|
-
import * as
|
|
9071
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
9072
|
+
import { dirname as dirname5, join as join8, relative as relative4, resolve as resolve6, sep } from "node:path";
|
|
9073
|
+
import * as ts3 from "typescript";
|
|
8657
9074
|
import { pascalCase } from "@qualcomm-ui/utils/change-case";
|
|
8658
9075
|
function createDemoName(filePath) {
|
|
8659
9076
|
const separatorChar = filePath.includes("/") ? "/" : "\\";
|
|
@@ -8668,7 +9085,7 @@ function createDemoName(filePath) {
|
|
|
8668
9085
|
}
|
|
8669
9086
|
async function extractFileImports(filePath) {
|
|
8670
9087
|
try {
|
|
8671
|
-
const content = await
|
|
9088
|
+
const content = await readFile7(filePath, "utf-8");
|
|
8672
9089
|
return extractImports(content, filePath);
|
|
8673
9090
|
} catch (error) {
|
|
8674
9091
|
console.log(
|
|
@@ -8679,17 +9096,17 @@ async function extractFileImports(filePath) {
|
|
|
8679
9096
|
}
|
|
8680
9097
|
}
|
|
8681
9098
|
function extractImports(code, fileName) {
|
|
8682
|
-
const sourceFile =
|
|
9099
|
+
const sourceFile = ts3.createSourceFile(
|
|
8683
9100
|
fileName,
|
|
8684
9101
|
code,
|
|
8685
|
-
|
|
9102
|
+
ts3.ScriptTarget.Latest,
|
|
8686
9103
|
true,
|
|
8687
9104
|
getScriptKind(fileName)
|
|
8688
9105
|
);
|
|
8689
9106
|
const thirdPartyImports = [];
|
|
8690
9107
|
const relativeImports = [];
|
|
8691
|
-
function
|
|
8692
|
-
if (
|
|
9108
|
+
function visit18(node) {
|
|
9109
|
+
if (ts3.isImportDeclaration(node)) {
|
|
8693
9110
|
const importSpec = parseImportDeclaration(node, fileName);
|
|
8694
9111
|
if (importSpec) {
|
|
8695
9112
|
if (importSpec.type === "relative") {
|
|
@@ -8699,17 +9116,17 @@ function extractImports(code, fileName) {
|
|
|
8699
9116
|
}
|
|
8700
9117
|
}
|
|
8701
9118
|
}
|
|
8702
|
-
|
|
9119
|
+
ts3.forEachChild(node, visit18);
|
|
8703
9120
|
}
|
|
8704
|
-
|
|
9121
|
+
visit18(sourceFile);
|
|
8705
9122
|
return { relativeImports, thirdPartyImports };
|
|
8706
9123
|
}
|
|
8707
9124
|
function getScriptKind(fileName) {
|
|
8708
|
-
return fileName.endsWith(".tsx") || fileName.endsWith(".jsx") ?
|
|
9125
|
+
return fileName.endsWith(".tsx") || fileName.endsWith(".jsx") ? ts3.ScriptKind.TSX : ts3.ScriptKind.TS;
|
|
8709
9126
|
}
|
|
8710
9127
|
function parseImportDeclaration(node, fileName) {
|
|
8711
9128
|
const moduleSpecifier = node.moduleSpecifier;
|
|
8712
|
-
if (!
|
|
9129
|
+
if (!ts3.isStringLiteral(moduleSpecifier)) {
|
|
8713
9130
|
return null;
|
|
8714
9131
|
}
|
|
8715
9132
|
const source = moduleSpecifier.text;
|
|
@@ -8759,9 +9176,9 @@ function extractSpecifiers(importClause) {
|
|
|
8759
9176
|
specifiers.push({ imported: "default", local: "default" });
|
|
8760
9177
|
}
|
|
8761
9178
|
if (importClause.namedBindings) {
|
|
8762
|
-
if (
|
|
9179
|
+
if (ts3.isNamespaceImport(importClause.namedBindings)) {
|
|
8763
9180
|
specifiers.push({ imported: "*", local: "*" });
|
|
8764
|
-
} else if (
|
|
9181
|
+
} else if (ts3.isNamedImports(importClause.namedBindings)) {
|
|
8765
9182
|
importClause.namedBindings.elements.forEach((element) => {
|
|
8766
9183
|
if (!element.isTypeOnly) {
|
|
8767
9184
|
const imported = element.propertyName ? element.propertyName.text : element.name.text;
|
|
@@ -8774,8 +9191,8 @@ function extractSpecifiers(importClause) {
|
|
|
8774
9191
|
return specifiers;
|
|
8775
9192
|
}
|
|
8776
9193
|
function resolveRelativeImport(source, fromFile) {
|
|
8777
|
-
const fromDir =
|
|
8778
|
-
const resolved =
|
|
9194
|
+
const fromDir = dirname5(fromFile);
|
|
9195
|
+
const resolved = resolve6(fromDir, source);
|
|
8779
9196
|
const extensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
8780
9197
|
for (const ext of extensions) {
|
|
8781
9198
|
const withExt = resolved + ext;
|
|
@@ -8784,7 +9201,7 @@ function resolveRelativeImport(source, fromFile) {
|
|
|
8784
9201
|
}
|
|
8785
9202
|
}
|
|
8786
9203
|
for (const ext of extensions) {
|
|
8787
|
-
const indexFile =
|
|
9204
|
+
const indexFile = join8(resolved, `index${ext}`);
|
|
8788
9205
|
if (existsSync2(indexFile)) {
|
|
8789
9206
|
return indexFile;
|
|
8790
9207
|
}
|
|
@@ -8798,28 +9215,28 @@ function isNodeBuiltin(source) {
|
|
|
8798
9215
|
return source.startsWith("node:") || NODE_BUILTINS.includes(source);
|
|
8799
9216
|
}
|
|
8800
9217
|
function loadTsConfigPaths(fromFile) {
|
|
8801
|
-
let currentDir =
|
|
9218
|
+
let currentDir = dirname5(fromFile);
|
|
8802
9219
|
const pathAliases = [];
|
|
8803
|
-
while (currentDir !==
|
|
8804
|
-
const tsconfigPath =
|
|
9220
|
+
while (currentDir !== dirname5(currentDir)) {
|
|
9221
|
+
const tsconfigPath = join8(currentDir, "tsconfig.json");
|
|
8805
9222
|
if (existsSync2(tsconfigPath)) {
|
|
8806
9223
|
try {
|
|
8807
|
-
const configContent =
|
|
9224
|
+
const configContent = ts3.sys.readFile(tsconfigPath);
|
|
8808
9225
|
if (!configContent) {
|
|
8809
|
-
currentDir =
|
|
9226
|
+
currentDir = dirname5(currentDir);
|
|
8810
9227
|
continue;
|
|
8811
9228
|
}
|
|
8812
|
-
const parseResult =
|
|
9229
|
+
const parseResult = ts3.parseConfigFileTextToJson(
|
|
8813
9230
|
tsconfigPath,
|
|
8814
9231
|
configContent
|
|
8815
9232
|
);
|
|
8816
9233
|
if (parseResult.error) {
|
|
8817
|
-
currentDir =
|
|
9234
|
+
currentDir = dirname5(currentDir);
|
|
8818
9235
|
continue;
|
|
8819
9236
|
}
|
|
8820
9237
|
const paths = parseResult.config?.compilerOptions?.paths;
|
|
8821
9238
|
const baseUrl = parseResult.config?.compilerOptions?.baseUrl || "./";
|
|
8822
|
-
const resolvedBaseUrl =
|
|
9239
|
+
const resolvedBaseUrl = resolve6(currentDir, baseUrl);
|
|
8823
9240
|
if (paths) {
|
|
8824
9241
|
for (const [alias, targets] of Object.entries(paths)) {
|
|
8825
9242
|
if (Array.isArray(targets) && targets.length > 0) {
|
|
@@ -8827,7 +9244,7 @@ function loadTsConfigPaths(fromFile) {
|
|
|
8827
9244
|
const pattern = new RegExp(
|
|
8828
9245
|
`^${alias.replace("*", "(.*)").replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace("\\(\\*\\)", "(.*)")}$`
|
|
8829
9246
|
);
|
|
8830
|
-
const replacement =
|
|
9247
|
+
const replacement = resolve6(
|
|
8831
9248
|
resolvedBaseUrl,
|
|
8832
9249
|
target.replace("*", "$1")
|
|
8833
9250
|
);
|
|
@@ -8837,29 +9254,29 @@ function loadTsConfigPaths(fromFile) {
|
|
|
8837
9254
|
}
|
|
8838
9255
|
const extendsPath = parseResult.config?.extends;
|
|
8839
9256
|
if (extendsPath) {
|
|
8840
|
-
const resolvedExtends =
|
|
9257
|
+
const resolvedExtends = resolve6(currentDir, extendsPath);
|
|
8841
9258
|
const extendedAliases = loadTsConfigPathsFromFile2(resolvedExtends);
|
|
8842
9259
|
pathAliases.push(...extendedAliases);
|
|
8843
9260
|
}
|
|
8844
9261
|
return pathAliases;
|
|
8845
9262
|
} catch (error) {
|
|
8846
|
-
currentDir =
|
|
9263
|
+
currentDir = dirname5(currentDir);
|
|
8847
9264
|
continue;
|
|
8848
9265
|
}
|
|
8849
9266
|
}
|
|
8850
|
-
currentDir =
|
|
9267
|
+
currentDir = dirname5(currentDir);
|
|
8851
9268
|
}
|
|
8852
9269
|
return pathAliases;
|
|
8853
9270
|
}
|
|
8854
9271
|
function loadTsConfigPathsFromFile2(tsconfigPath) {
|
|
8855
9272
|
const pathAliases = [];
|
|
8856
|
-
const configDir =
|
|
9273
|
+
const configDir = dirname5(tsconfigPath);
|
|
8857
9274
|
try {
|
|
8858
|
-
const configContent =
|
|
9275
|
+
const configContent = ts3.sys.readFile(tsconfigPath);
|
|
8859
9276
|
if (!configContent) {
|
|
8860
9277
|
return pathAliases;
|
|
8861
9278
|
}
|
|
8862
|
-
const parseResult =
|
|
9279
|
+
const parseResult = ts3.parseConfigFileTextToJson(
|
|
8863
9280
|
tsconfigPath,
|
|
8864
9281
|
configContent
|
|
8865
9282
|
);
|
|
@@ -8868,7 +9285,7 @@ function loadTsConfigPathsFromFile2(tsconfigPath) {
|
|
|
8868
9285
|
}
|
|
8869
9286
|
const paths = parseResult.config?.compilerOptions?.paths;
|
|
8870
9287
|
const baseUrl = parseResult.config?.compilerOptions?.baseUrl || "./";
|
|
8871
|
-
const resolvedBaseUrl =
|
|
9288
|
+
const resolvedBaseUrl = resolve6(configDir, baseUrl);
|
|
8872
9289
|
if (paths) {
|
|
8873
9290
|
for (const [alias, targets] of Object.entries(paths)) {
|
|
8874
9291
|
if (Array.isArray(targets) && targets.length > 0) {
|
|
@@ -8876,7 +9293,7 @@ function loadTsConfigPathsFromFile2(tsconfigPath) {
|
|
|
8876
9293
|
const pattern = new RegExp(
|
|
8877
9294
|
`^${alias.replace("*", "(.*)").replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace("\\(\\*\\)", "(.*)")}$`
|
|
8878
9295
|
);
|
|
8879
|
-
const replacement =
|
|
9296
|
+
const replacement = resolve6(
|
|
8880
9297
|
resolvedBaseUrl,
|
|
8881
9298
|
target.replace("*", "$1")
|
|
8882
9299
|
);
|
|
@@ -8886,7 +9303,7 @@ function loadTsConfigPathsFromFile2(tsconfigPath) {
|
|
|
8886
9303
|
}
|
|
8887
9304
|
const extendsPath = parseResult.config?.extends;
|
|
8888
9305
|
if (extendsPath) {
|
|
8889
|
-
let resolvedExtends =
|
|
9306
|
+
let resolvedExtends = resolve6(configDir, extendsPath);
|
|
8890
9307
|
if (!resolvedExtends.endsWith(".json")) {
|
|
8891
9308
|
resolvedExtends += ".json";
|
|
8892
9309
|
}
|
|
@@ -8915,7 +9332,7 @@ function resolvePathAlias2(source, pathAliases) {
|
|
|
8915
9332
|
}
|
|
8916
9333
|
}
|
|
8917
9334
|
for (const ext of extensions) {
|
|
8918
|
-
const indexFile =
|
|
9335
|
+
const indexFile = join8(resolvedPath, `index${ext}`);
|
|
8919
9336
|
if (existsSync2(indexFile)) {
|
|
8920
9337
|
return indexFile;
|
|
8921
9338
|
}
|
|
@@ -8932,7 +9349,7 @@ function extractPageId(filePath, routesDir) {
|
|
|
8932
9349
|
const demosIndex = pathParts.indexOf("demos");
|
|
8933
9350
|
return pathParts.slice(0, demosIndex).join(sep);
|
|
8934
9351
|
}
|
|
8935
|
-
return
|
|
9352
|
+
return dirname5(relativePath);
|
|
8936
9353
|
}
|
|
8937
9354
|
function isCssAsset(filePath) {
|
|
8938
9355
|
return filePath.endsWith(".css");
|
|
@@ -8948,10 +9365,10 @@ function isDemoFile(filePath) {
|
|
|
8948
9365
|
// src/react-demo-plugin/react-demo-plugin.ts
|
|
8949
9366
|
import chalk7 from "chalk";
|
|
8950
9367
|
import { glob as glob3 } from "glob";
|
|
8951
|
-
import { readFile as
|
|
8952
|
-
import { basename as
|
|
9368
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
9369
|
+
import { basename as basename4, resolve as resolve7 } from "node:path";
|
|
8953
9370
|
import { createHighlighter as createHighlighter2 } from "shiki";
|
|
8954
|
-
import * as
|
|
9371
|
+
import * as ts4 from "typescript";
|
|
8955
9372
|
import {
|
|
8956
9373
|
quiCustomDarkTheme as quiCustomDarkTheme3
|
|
8957
9374
|
} from "@qualcomm-ui/mdx-common";
|
|
@@ -9016,7 +9433,7 @@ function reactDemoPlugin({
|
|
|
9016
9433
|
if (isDemoFile(file)) {
|
|
9017
9434
|
await handleDemoAdditionOrUpdate({ filePath: file });
|
|
9018
9435
|
} else {
|
|
9019
|
-
const normalizedFile =
|
|
9436
|
+
const normalizedFile = resolve7(file);
|
|
9020
9437
|
const dependentDemos = relativeImportDependents.get(normalizedFile);
|
|
9021
9438
|
if (!dependentDemos?.size) {
|
|
9022
9439
|
return [];
|
|
@@ -9202,7 +9619,7 @@ function reactDemoPlugin({
|
|
|
9202
9619
|
}
|
|
9203
9620
|
async function extractHighlightedCode(filePath, code) {
|
|
9204
9621
|
try {
|
|
9205
|
-
const fileName =
|
|
9622
|
+
const fileName = basename4(filePath);
|
|
9206
9623
|
const baseResult = await highlightCode(code);
|
|
9207
9624
|
let inlineResult;
|
|
9208
9625
|
let classesDetected = false;
|
|
@@ -9239,7 +9656,7 @@ function reactDemoPlugin({
|
|
|
9239
9656
|
}
|
|
9240
9657
|
async function extractFileData(filePath) {
|
|
9241
9658
|
try {
|
|
9242
|
-
const code = await
|
|
9659
|
+
const code = await readFile8(filePath, "utf-8").then(transformLines);
|
|
9243
9660
|
const imports = stripImports(code, filePath);
|
|
9244
9661
|
const sourceCode = [];
|
|
9245
9662
|
const aggregatedRules = /* @__PURE__ */ new Map();
|
|
@@ -9256,7 +9673,7 @@ function reactDemoPlugin({
|
|
|
9256
9673
|
if (fileImports) {
|
|
9257
9674
|
for (const relativeImport of fileImports.relativeImports) {
|
|
9258
9675
|
try {
|
|
9259
|
-
const importedCode = await
|
|
9676
|
+
const importedCode = await readFile8(
|
|
9260
9677
|
relativeImport.resolvedPath,
|
|
9261
9678
|
"utf-8"
|
|
9262
9679
|
).then(transformLines);
|
|
@@ -9287,7 +9704,7 @@ function reactDemoPlugin({
|
|
|
9287
9704
|
}
|
|
9288
9705
|
return {
|
|
9289
9706
|
demoName: createDemoName(filePath),
|
|
9290
|
-
fileName: extractedMain?.sourceCodeData.fileName ||
|
|
9707
|
+
fileName: extractedMain?.sourceCodeData.fileName || basename4(filePath),
|
|
9291
9708
|
filePath,
|
|
9292
9709
|
imports,
|
|
9293
9710
|
sourceCode
|
|
@@ -9298,25 +9715,25 @@ function reactDemoPlugin({
|
|
|
9298
9715
|
}
|
|
9299
9716
|
function stripImports(code, fileName) {
|
|
9300
9717
|
try {
|
|
9301
|
-
let
|
|
9302
|
-
if (
|
|
9718
|
+
let visit19 = function(node) {
|
|
9719
|
+
if (ts4.isImportDeclaration(node)) {
|
|
9303
9720
|
importRanges.push({
|
|
9304
9721
|
end: node.getEnd(),
|
|
9305
9722
|
start: node.getFullStart()
|
|
9306
9723
|
});
|
|
9307
9724
|
}
|
|
9308
|
-
|
|
9725
|
+
ts4.forEachChild(node, visit19);
|
|
9309
9726
|
};
|
|
9310
|
-
var
|
|
9311
|
-
const sourceFile =
|
|
9727
|
+
var visit18 = visit19;
|
|
9728
|
+
const sourceFile = ts4.createSourceFile(
|
|
9312
9729
|
fileName,
|
|
9313
9730
|
code,
|
|
9314
|
-
|
|
9731
|
+
ts4.ScriptTarget.Latest,
|
|
9315
9732
|
true,
|
|
9316
9733
|
getScriptKind(fileName)
|
|
9317
9734
|
);
|
|
9318
9735
|
const importRanges = [];
|
|
9319
|
-
|
|
9736
|
+
visit19(sourceFile);
|
|
9320
9737
|
return importRanges.map((range) => {
|
|
9321
9738
|
let endPos = range.end;
|
|
9322
9739
|
if (code[endPos] === "\n") {
|