@qualcomm-ui/mdx-vite 2.9.0 → 2.10.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/cli.js +194 -386
- 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 +4 -2
- package/dist/docs-plugin/internal/config-schema.d.ts.map +1 -1
- package/dist/docs-plugin/types.d.ts +10 -4
- package/dist/docs-plugin/types.d.ts.map +1 -1
- package/dist/index.js +126 -41
- package/dist/index.js.map +2 -2
- package/dist/open-web-ui-knowledge/generate-knowledge.d.ts +3 -2
- package/dist/open-web-ui-knowledge/generate-knowledge.d.ts.map +1 -1
- package/dist/tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -520,9 +520,9 @@ var require_help = __commonJS({
|
|
|
520
520
|
* @param {Help} helper
|
|
521
521
|
* @returns string[]
|
|
522
522
|
*/
|
|
523
|
-
formatItemList(
|
|
523
|
+
formatItemList(heading, items, helper) {
|
|
524
524
|
if (items.length === 0) return [];
|
|
525
|
-
return [helper.styleTitle(
|
|
525
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
528
528
|
* Group items by their help group heading.
|
|
@@ -1002,8 +1002,8 @@ var require_option = __commonJS({
|
|
|
1002
1002
|
* @param {string} heading
|
|
1003
1003
|
* @return {Option}
|
|
1004
1004
|
*/
|
|
1005
|
-
helpGroup(
|
|
1006
|
-
this.helpGroupHeading =
|
|
1005
|
+
helpGroup(heading) {
|
|
1006
|
+
this.helpGroupHeading = heading;
|
|
1007
1007
|
return this;
|
|
1008
1008
|
}
|
|
1009
1009
|
/**
|
|
@@ -3099,9 +3099,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3099
3099
|
* @param {string} [heading]
|
|
3100
3100
|
* @return {Command | string}
|
|
3101
3101
|
*/
|
|
3102
|
-
helpGroup(
|
|
3103
|
-
if (
|
|
3104
|
-
this._helpGroupHeading =
|
|
3102
|
+
helpGroup(heading) {
|
|
3103
|
+
if (heading === void 0) return this._helpGroupHeading ?? "";
|
|
3104
|
+
this._helpGroupHeading = heading;
|
|
3105
3105
|
return this;
|
|
3106
3106
|
}
|
|
3107
3107
|
/**
|
|
@@ -3117,9 +3117,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3117
3117
|
* @param {string} [heading]
|
|
3118
3118
|
* @returns {Command | string}
|
|
3119
3119
|
*/
|
|
3120
|
-
commandsGroup(
|
|
3121
|
-
if (
|
|
3122
|
-
this._defaultCommandGroup =
|
|
3120
|
+
commandsGroup(heading) {
|
|
3121
|
+
if (heading === void 0) return this._defaultCommandGroup ?? "";
|
|
3122
|
+
this._defaultCommandGroup = heading;
|
|
3123
3123
|
return this;
|
|
3124
3124
|
}
|
|
3125
3125
|
/**
|
|
@@ -3135,9 +3135,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3135
3135
|
* @param {string} [heading]
|
|
3136
3136
|
* @returns {Command | string}
|
|
3137
3137
|
*/
|
|
3138
|
-
optionsGroup(
|
|
3139
|
-
if (
|
|
3140
|
-
this._defaultOptionGroup =
|
|
3138
|
+
optionsGroup(heading) {
|
|
3139
|
+
if (heading === void 0) return this._defaultOptionGroup ?? "";
|
|
3140
|
+
this._defaultOptionGroup = heading;
|
|
3141
3141
|
return this;
|
|
3142
3142
|
}
|
|
3143
3143
|
/**
|
|
@@ -3552,7 +3552,8 @@ var typeDocPropsSchema = implement().with({
|
|
|
3552
3552
|
var knowledgeExtraFileSchema = implement().with({
|
|
3553
3553
|
contents: z2.string(),
|
|
3554
3554
|
id: z2.string(),
|
|
3555
|
-
|
|
3555
|
+
processAsMdx: z2.boolean().optional(),
|
|
3556
|
+
title: z2.string().optional()
|
|
3556
3557
|
});
|
|
3557
3558
|
var knowledgeExportsSchema = implement().with({
|
|
3558
3559
|
enabled: z2.boolean().optional(),
|
|
@@ -3880,7 +3881,7 @@ var DocPropsIndexer = class {
|
|
|
3880
3881
|
}
|
|
3881
3882
|
assembleProp(prop, id) {
|
|
3882
3883
|
const name = prop.name;
|
|
3883
|
-
const
|
|
3884
|
+
const heading = {
|
|
3884
3885
|
headingLevel: 4,
|
|
3885
3886
|
id,
|
|
3886
3887
|
tagName: "a",
|
|
@@ -3888,7 +3889,7 @@ var DocPropsIndexer = class {
|
|
|
3888
3889
|
};
|
|
3889
3890
|
const comment = prop.comment;
|
|
3890
3891
|
if (!comment) {
|
|
3891
|
-
return { content: [], heading
|
|
3892
|
+
return { content: [], heading, richContent: [] };
|
|
3892
3893
|
}
|
|
3893
3894
|
const content = {
|
|
3894
3895
|
tagName: "p",
|
|
@@ -3896,7 +3897,7 @@ var DocPropsIndexer = class {
|
|
|
3896
3897
|
comment.summary.map((entry) => entry.text.replaceAll("\n", " ")).join("")
|
|
3897
3898
|
]
|
|
3898
3899
|
};
|
|
3899
|
-
return { content: [content], heading
|
|
3900
|
+
return { content: [content], heading, richContent: [] };
|
|
3900
3901
|
}
|
|
3901
3902
|
};
|
|
3902
3903
|
|
|
@@ -4437,8 +4438,8 @@ var MarkdownIndexer = class {
|
|
|
4437
4438
|
this.resetSection();
|
|
4438
4439
|
this.headingLevels = headingLevels;
|
|
4439
4440
|
}
|
|
4440
|
-
appendTocItem(
|
|
4441
|
-
this._toc.push(
|
|
4441
|
+
appendTocItem(heading) {
|
|
4442
|
+
this._toc.push(heading);
|
|
4442
4443
|
}
|
|
4443
4444
|
warn(...data) {
|
|
4444
4445
|
if (process.env.DEBUG) {
|
|
@@ -4473,11 +4474,11 @@ var MarkdownIndexer = class {
|
|
|
4473
4474
|
this.sections.push(clone(this.currentSection));
|
|
4474
4475
|
this.resetSection();
|
|
4475
4476
|
}
|
|
4476
|
-
const
|
|
4477
|
+
const heading = this.parseHeading(element);
|
|
4477
4478
|
if (!isRootHeading) {
|
|
4478
|
-
this.appendTocItem(
|
|
4479
|
+
this.appendTocItem(heading);
|
|
4479
4480
|
}
|
|
4480
|
-
this.currentSection.heading =
|
|
4481
|
+
this.currentSection.heading = heading;
|
|
4481
4482
|
return;
|
|
4482
4483
|
}
|
|
4483
4484
|
this.currentSection.richContent.push(element);
|
|
@@ -4859,7 +4860,7 @@ function getRemixFlatRoutesSegments(name, index, paramPrefixChar = "$") {
|
|
|
4859
4860
|
let routeSegments = [];
|
|
4860
4861
|
let i = 0;
|
|
4861
4862
|
let routeSegment = "";
|
|
4862
|
-
let
|
|
4863
|
+
let state = "START";
|
|
4863
4864
|
let subState = "NORMAL";
|
|
4864
4865
|
let hasPlus = false;
|
|
4865
4866
|
if (name.endsWith("_layout")) {
|
|
@@ -4886,7 +4887,7 @@ function getRemixFlatRoutesSegments(name, index, paramPrefixChar = "$") {
|
|
|
4886
4887
|
};
|
|
4887
4888
|
while (i < name.length) {
|
|
4888
4889
|
const char = name[i];
|
|
4889
|
-
switch (
|
|
4890
|
+
switch (state) {
|
|
4890
4891
|
case "START":
|
|
4891
4892
|
if (routeSegment.includes(paramPrefixChar) && !(routeSegment.startsWith(paramPrefixChar) || routeSegment.startsWith(`(${paramPrefixChar}`))) {
|
|
4892
4893
|
throw new Error(
|
|
@@ -4900,12 +4901,12 @@ function getRemixFlatRoutesSegments(name, index, paramPrefixChar = "$") {
|
|
|
4900
4901
|
}
|
|
4901
4902
|
pushRouteSegment(routeSegment);
|
|
4902
4903
|
routeSegment = "";
|
|
4903
|
-
|
|
4904
|
+
state = "PATH";
|
|
4904
4905
|
continue;
|
|
4905
4906
|
// restart without advancing index
|
|
4906
4907
|
case "PATH":
|
|
4907
4908
|
if (isPathSeparator(char) && subState === "NORMAL") {
|
|
4908
|
-
|
|
4909
|
+
state = "START";
|
|
4909
4910
|
break;
|
|
4910
4911
|
} else if (char === "[") {
|
|
4911
4912
|
subState = "ESCAPE";
|
|
@@ -5397,7 +5398,7 @@ var FilesApi = class {
|
|
|
5397
5398
|
if (status.status === "completed" || status.status === "failed") {
|
|
5398
5399
|
return status;
|
|
5399
5400
|
}
|
|
5400
|
-
await new Promise((
|
|
5401
|
+
await new Promise((resolve8) => setTimeout(resolve8, intervalMs));
|
|
5401
5402
|
}
|
|
5402
5403
|
throw new Error(`File processing timed out after ${maxAttempts} attempts`);
|
|
5403
5404
|
}
|
|
@@ -5657,296 +5658,19 @@ import {
|
|
|
5657
5658
|
stat,
|
|
5658
5659
|
writeFile as writeFile3
|
|
5659
5660
|
} from "node:fs/promises";
|
|
5660
|
-
import { basename, dirname, extname, join as
|
|
5661
|
-
import
|
|
5661
|
+
import { basename, dirname, extname, join as join3, relative as relative2, resolve as resolve4 } from "node:path";
|
|
5662
|
+
import remarkFrontmatter2 from "remark-frontmatter";
|
|
5662
5663
|
import remarkMdx3 from "remark-mdx";
|
|
5663
5664
|
import remarkParse4 from "remark-parse";
|
|
5664
5665
|
import remarkParseFrontmatter2 from "remark-parse-frontmatter";
|
|
5665
5666
|
import remarkStringify3 from "remark-stringify";
|
|
5666
5667
|
import { unified as unified4 } from "unified";
|
|
5667
|
-
import { visit as visit10 } from "unist-util-visit";
|
|
5668
|
-
import { kebabCase } from "@qualcomm-ui/utils/change-case";
|
|
5669
|
-
|
|
5670
|
-
// src/docs-plugin/docs-plugin.ts
|
|
5671
|
-
import chalk3 from "chalk";
|
|
5672
|
-
import chokidar from "chokidar";
|
|
5673
|
-
import { glob as glob2 } from "glob";
|
|
5674
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
5675
|
-
import { join as join2, resolve as resolve3 } from "node:path";
|
|
5676
|
-
import prettyMilliseconds from "pretty-ms";
|
|
5677
|
-
var isDev = process.env.NODE_ENV === "development";
|
|
5678
|
-
var VIRTUAL_MODULE_ID = "\0@qualcomm-ui/mdx-vite-plugin";
|
|
5679
|
-
var PluginState = class {
|
|
5680
|
-
buildCount = 0;
|
|
5681
|
-
config = null;
|
|
5682
|
-
configFilePath = "";
|
|
5683
|
-
docPropsFilePath = "";
|
|
5684
|
-
exports = { basePath: "", enabled: false, pages: [] };
|
|
5685
|
-
indexer;
|
|
5686
|
-
configLoader = null;
|
|
5687
|
-
knowledgeConfig = void 0;
|
|
5688
|
-
routesDir;
|
|
5689
|
-
servers = [];
|
|
5690
|
-
timeout = void 0;
|
|
5691
|
-
exportsTimeout = void 0;
|
|
5692
|
-
watching = false;
|
|
5693
|
-
cwd;
|
|
5694
|
-
init(cwd2) {
|
|
5695
|
-
this.cwd = cwd2;
|
|
5696
|
-
}
|
|
5697
|
-
getCwd() {
|
|
5698
|
-
return this.cwd;
|
|
5699
|
-
}
|
|
5700
|
-
get docPropsDirectory() {
|
|
5701
|
-
if (!this.docPropsFilePath) {
|
|
5702
|
-
return "";
|
|
5703
|
-
}
|
|
5704
|
-
return this.docPropsFilePath.substring(
|
|
5705
|
-
0,
|
|
5706
|
-
this.docPropsFilePath.lastIndexOf("/")
|
|
5707
|
-
);
|
|
5708
|
-
}
|
|
5709
|
-
get siteData() {
|
|
5710
|
-
const { filePath: _filePath, ...config2 } = this.config ?? {};
|
|
5711
|
-
return {
|
|
5712
|
-
config: config2,
|
|
5713
|
-
exports: this.exports,
|
|
5714
|
-
navItems: state.indexer.navItems,
|
|
5715
|
-
pageDocProps: state.indexer.pageDocProps,
|
|
5716
|
-
pageMap: state.indexer.pageMap,
|
|
5717
|
-
searchIndex: state.indexer.searchIndex
|
|
5718
|
-
};
|
|
5719
|
-
}
|
|
5720
|
-
resolveDocProps() {
|
|
5721
|
-
if (!this.docPropsFilePath) {
|
|
5722
|
-
return {};
|
|
5723
|
-
}
|
|
5724
|
-
try {
|
|
5725
|
-
return JSON.parse(readFileSync2(this.docPropsFilePath, "utf-8"))?.props;
|
|
5726
|
-
} catch (e) {
|
|
5727
|
-
console.debug(
|
|
5728
|
-
"Invalid doc props file. Unable to parse JSON. Please check the file"
|
|
5729
|
-
);
|
|
5730
|
-
return {};
|
|
5731
|
-
}
|
|
5732
|
-
}
|
|
5733
|
-
createIndexer(config2) {
|
|
5734
|
-
this.config = config2;
|
|
5735
|
-
this.configFilePath = config2.filePath;
|
|
5736
|
-
this.docPropsFilePath = config2.typeDocProps ? fixPath(resolve3(this.cwd, config2.typeDocProps)) : "";
|
|
5737
|
-
this.routesDir = fixPath(resolve3(config2.appDirectory, config2.pageDirectory));
|
|
5738
|
-
this.knowledgeConfig = config2.knowledge;
|
|
5739
|
-
this.indexer = new SearchIndexer({
|
|
5740
|
-
...config2,
|
|
5741
|
-
srcDir: fixPath(resolve3(this.cwd, config2.appDirectory)),
|
|
5742
|
-
typeDocProps: this.resolveDocProps()
|
|
5743
|
-
});
|
|
5744
|
-
const exportsConfig = config2.knowledge?.global?.exports;
|
|
5745
|
-
const exportsEnabled = exportsConfig?.enabled ?? false;
|
|
5746
|
-
const exportsPath = exportsConfig?.staticPath ?? "exports/md";
|
|
5747
|
-
this.exports = {
|
|
5748
|
-
basePath: exportsEnabled ? `/${exportsPath}` : "",
|
|
5749
|
-
enabled: exportsEnabled,
|
|
5750
|
-
pages: []
|
|
5751
|
-
};
|
|
5752
|
-
}
|
|
5753
|
-
buildIndex(shouldLog) {
|
|
5754
|
-
const files = glob2.sync(
|
|
5755
|
-
[`${this.routesDir}/**/*.mdx`, `${this.routesDir}/**/*.tsx`],
|
|
5756
|
-
{
|
|
5757
|
-
absolute: true,
|
|
5758
|
-
cwd: this.cwd
|
|
5759
|
-
}
|
|
5760
|
-
);
|
|
5761
|
-
if (!files.length) {
|
|
5762
|
-
return [];
|
|
5763
|
-
}
|
|
5764
|
-
const startTime = Date.now();
|
|
5765
|
-
const compiledMdxFiles = this.indexer.buildIndex(files, shouldLog);
|
|
5766
|
-
if (isDev && shouldLog) {
|
|
5767
|
-
console.debug(
|
|
5768
|
-
`${chalk3.magenta.bold(`@qualcomm-ui/mdx-vite/docs-plugin:`)} Compiled search index in: ${chalk3.blueBright.bold(prettyMilliseconds(Date.now() - startTime))}${state.indexer.cachedFileCount ? chalk3.greenBright.bold(` (${state.indexer.cachedFileCount}/${state.indexer.mdxFileCount} files cached)`) : ""}`
|
|
5769
|
-
);
|
|
5770
|
-
}
|
|
5771
|
-
return compiledMdxFiles;
|
|
5772
|
-
}
|
|
5773
|
-
/**
|
|
5774
|
-
* When the user adds or removes mdx files, we re-index the site. This function
|
|
5775
|
-
* handles module invalidation so that virtual file imports are refreshed as
|
|
5776
|
-
* expected by the consumer's dev server.
|
|
5777
|
-
*/
|
|
5778
|
-
sendUpdate() {
|
|
5779
|
-
for (const server of this.servers) {
|
|
5780
|
-
const virtualModule = server.moduleGraph.getModuleById(VIRTUAL_MODULE_ID);
|
|
5781
|
-
if (virtualModule) {
|
|
5782
|
-
server.moduleGraph.invalidateModule(virtualModule);
|
|
5783
|
-
server.reloadModule(virtualModule);
|
|
5784
|
-
}
|
|
5785
|
-
}
|
|
5786
|
-
}
|
|
5787
|
-
handleChange(opts = {}) {
|
|
5788
|
-
clearTimeout(this.timeout);
|
|
5789
|
-
this.timeout = setTimeout(() => {
|
|
5790
|
-
this.buildIndex(true);
|
|
5791
|
-
this.sendUpdate();
|
|
5792
|
-
opts?.onComplete?.();
|
|
5793
|
-
}, 300);
|
|
5794
|
-
}
|
|
5795
|
-
initWatchers(configFile) {
|
|
5796
|
-
if (this.watching) {
|
|
5797
|
-
return;
|
|
5798
|
-
}
|
|
5799
|
-
this.initConfigWatcher(configFile);
|
|
5800
|
-
this.watching = true;
|
|
5801
|
-
}
|
|
5802
|
-
initConfigWatcher(configFile) {
|
|
5803
|
-
const paths = [this.configFilePath];
|
|
5804
|
-
if (this.docPropsFilePath) {
|
|
5805
|
-
paths.push(this.docPropsFilePath);
|
|
5806
|
-
}
|
|
5807
|
-
chokidar.watch(paths, {
|
|
5808
|
-
cwd: this.cwd
|
|
5809
|
-
}).on("change", () => {
|
|
5810
|
-
console.debug(`qui-docs config changed, reloading plugin`);
|
|
5811
|
-
this.configLoader = new ConfigLoader({ configFile });
|
|
5812
|
-
const resolvedConfig = this.configLoader.loadConfig();
|
|
5813
|
-
this.configFilePath = resolvedConfig.filePath;
|
|
5814
|
-
this.createIndexer(resolvedConfig);
|
|
5815
|
-
this.handleChange({
|
|
5816
|
-
onComplete: () => {
|
|
5817
|
-
this.servers.forEach(
|
|
5818
|
-
(server) => server.ws.send({ type: "full-reload" })
|
|
5819
|
-
);
|
|
5820
|
-
}
|
|
5821
|
-
});
|
|
5822
|
-
});
|
|
5823
|
-
}
|
|
5824
|
-
async generateExports(publicDir) {
|
|
5825
|
-
if (!this.exports.enabled || !this.knowledgeConfig?.global) {
|
|
5826
|
-
return;
|
|
5827
|
-
}
|
|
5828
|
-
const globalConfig = this.knowledgeConfig.global;
|
|
5829
|
-
const exportsConfig = globalConfig.exports ?? {};
|
|
5830
|
-
const exportsPath = exportsConfig.staticPath ?? "exports/md";
|
|
5831
|
-
const outputPath = join2(publicDir, exportsPath);
|
|
5832
|
-
const startTime = Date.now();
|
|
5833
|
-
const pageIds = await generate({
|
|
5834
|
-
baseUrl: globalConfig.baseUrl,
|
|
5835
|
-
clean: true,
|
|
5836
|
-
docPropsPath: this.docPropsFilePath || void 0,
|
|
5837
|
-
exclude: exportsConfig.exclude ?? globalConfig.exclude,
|
|
5838
|
-
extraFiles: exportsConfig.extraFiles ?? globalConfig.extraFiles,
|
|
5839
|
-
metadata: exportsConfig.metadata ?? globalConfig.metadata,
|
|
5840
|
-
outputMode: "per-page",
|
|
5841
|
-
outputPath,
|
|
5842
|
-
pageTitlePrefix: exportsConfig.pageTitlePrefix ?? globalConfig.pageTitlePrefix,
|
|
5843
|
-
routeDir: this.routesDir
|
|
5844
|
-
});
|
|
5845
|
-
this.exports.pages = pageIds;
|
|
5846
|
-
console.debug(
|
|
5847
|
-
`${chalk3.magenta.bold(`@qualcomm-ui/mdx-vite/docs-plugin:`)} Generated Markdown exports in: ${chalk3.blueBright.bold(prettyMilliseconds(Date.now() - startTime))}`
|
|
5848
|
-
);
|
|
5849
|
-
}
|
|
5850
|
-
debouncedGenerateExports(publicDir) {
|
|
5851
|
-
if (!this.exports.enabled) {
|
|
5852
|
-
return;
|
|
5853
|
-
}
|
|
5854
|
-
clearTimeout(this.exportsTimeout);
|
|
5855
|
-
this.exportsTimeout = setTimeout(() => {
|
|
5856
|
-
void this.generateExports(publicDir);
|
|
5857
|
-
}, 500);
|
|
5858
|
-
}
|
|
5859
|
-
};
|
|
5860
|
-
var state = new PluginState();
|
|
5861
|
-
|
|
5862
|
-
// src/docs-plugin/mdx-plugins.ts
|
|
5863
|
-
import rehypeShiki from "@shikijs/rehype";
|
|
5864
|
-
import {
|
|
5865
|
-
transformerNotationDiff,
|
|
5866
|
-
transformerNotationErrorLevel,
|
|
5867
|
-
transformerNotationFocus,
|
|
5868
|
-
transformerNotationHighlight,
|
|
5869
|
-
transformerNotationWordHighlight,
|
|
5870
|
-
transformerRemoveNotationEscape,
|
|
5871
|
-
transformerRenderIndentGuides
|
|
5872
|
-
} from "@shikijs/transformers";
|
|
5873
|
-
import { merge } from "lodash-es";
|
|
5874
|
-
import { quiCustomDarkTheme } from "@qualcomm-ui/mdx-common";
|
|
5875
|
-
|
|
5876
|
-
// src/exports.ts
|
|
5877
|
-
import rehypeMdxCodeProps from "rehype-mdx-code-props";
|
|
5878
|
-
import remarkFrontmatter2 from "remark-frontmatter";
|
|
5879
|
-
import remarkGfm2 from "remark-gfm";
|
|
5880
|
-
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
|
|
5881
|
-
|
|
5882
|
-
// src/docs-plugin/rehype/rehype-sectionize.ts
|
|
5883
|
-
import { heading } from "hast-util-heading";
|
|
5884
|
-
import { headingRank as headingRank2 } from "hast-util-heading-rank";
|
|
5885
|
-
|
|
5886
|
-
// src/docs-plugin/remark/remark-code-tabs.ts
|
|
5887
5668
|
import { visit as visit5 } from "unist-util-visit";
|
|
5888
|
-
|
|
5889
|
-
// src/docs-plugin/remark/remark-frontmatter-description.ts
|
|
5890
|
-
import { visit as visit6 } from "unist-util-visit";
|
|
5891
|
-
|
|
5892
|
-
// src/docs-plugin/remark/remark-frontmatter-title.ts
|
|
5893
|
-
import { visit as visit7 } from "unist-util-visit";
|
|
5894
|
-
|
|
5895
|
-
// src/docs-plugin/remark/remark-self-link-headings.ts
|
|
5896
|
-
import { toString as toString2 } from "mdast-util-to-string";
|
|
5897
|
-
import { visit as visit8 } from "unist-util-visit";
|
|
5898
|
-
var emptyOptions2 = {};
|
|
5899
|
-
function remarkSelfLinkHeadings(baseUrl = "", options) {
|
|
5900
|
-
if (!baseUrl) {
|
|
5901
|
-
return () => {
|
|
5902
|
-
};
|
|
5903
|
-
}
|
|
5904
|
-
return () => {
|
|
5905
|
-
const settings = options || emptyOptions2;
|
|
5906
|
-
const prefix = settings.prefix || "";
|
|
5907
|
-
const allowedLevels = new Set(settings.allowedLevels || [2, 3, 4]);
|
|
5908
|
-
const seenIds = /* @__PURE__ */ new Map();
|
|
5909
|
-
function createSlug(text) {
|
|
5910
|
-
const cleaned = text.replace(/[<>]/g, "").replace(/[^\w\s-]/g, "").trim();
|
|
5911
|
-
let slug;
|
|
5912
|
-
if (cleaned.includes(" ")) {
|
|
5913
|
-
slug = cleaned.toLowerCase().replace(/\s+/g, "-").replace(/^-+|-+$/g, "");
|
|
5914
|
-
} else if ((cleaned.match(/[A-Z]/g) || []).length >= 2) {
|
|
5915
|
-
slug = cleaned.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
5916
|
-
} else {
|
|
5917
|
-
slug = cleaned.toLowerCase();
|
|
5918
|
-
}
|
|
5919
|
-
const count = seenIds.get(slug) || 0;
|
|
5920
|
-
seenIds.set(slug, count + 1);
|
|
5921
|
-
return count > 0 ? `${slug}-${count}` : slug;
|
|
5922
|
-
}
|
|
5923
|
-
return (tree) => {
|
|
5924
|
-
seenIds.clear();
|
|
5925
|
-
visit8(tree, "heading", (node) => {
|
|
5926
|
-
if (allowedLevels.has(node.depth)) {
|
|
5927
|
-
const text = toString2(node);
|
|
5928
|
-
const slug = prefix + createSlug(text);
|
|
5929
|
-
const linkNode = {
|
|
5930
|
-
children: node.children,
|
|
5931
|
-
type: "link",
|
|
5932
|
-
url: `${baseUrl}#${slug}`
|
|
5933
|
-
};
|
|
5934
|
-
node.children = [linkNode];
|
|
5935
|
-
}
|
|
5936
|
-
});
|
|
5937
|
-
};
|
|
5938
|
-
};
|
|
5939
|
-
}
|
|
5940
|
-
|
|
5941
|
-
// src/docs-plugin/remark/remark-spoilers.ts
|
|
5942
|
-
import { visit as visit9 } from "unist-util-visit";
|
|
5943
|
-
|
|
5944
|
-
// src/docs-plugin/shiki/shiki-transformer-preview-block.ts
|
|
5945
|
-
import { dedent } from "@qualcomm-ui/utils/dedent";
|
|
5669
|
+
import { kebabCase } from "@qualcomm-ui/utils/change-case";
|
|
5946
5670
|
|
|
5947
5671
|
// src/open-web-ui-knowledge/load-config-from-env.ts
|
|
5948
5672
|
import { existsSync } from "node:fs";
|
|
5949
|
-
import { join as
|
|
5673
|
+
import { join as join2, resolve as resolve3 } from "node:path";
|
|
5950
5674
|
function parseCliMetadata(cliMetadata) {
|
|
5951
5675
|
if (!cliMetadata?.length) {
|
|
5952
5676
|
return void 0;
|
|
@@ -5962,11 +5686,11 @@ function loadKnowledgeConfigFromEnv(options) {
|
|
|
5962
5686
|
if (!outputPath) {
|
|
5963
5687
|
throw new Error("Missing required outputPath");
|
|
5964
5688
|
}
|
|
5965
|
-
const routeDir =
|
|
5689
|
+
const routeDir = join2(
|
|
5966
5690
|
resolvedConfig.appDirectory,
|
|
5967
5691
|
resolvedConfig.pageDirectory
|
|
5968
5692
|
);
|
|
5969
|
-
if (!existsSync(
|
|
5693
|
+
if (!existsSync(resolve3(routeDir))) {
|
|
5970
5694
|
throw new Error(`Route directory ${routeDir} does not exist`);
|
|
5971
5695
|
}
|
|
5972
5696
|
const cliMetadata = parseCliMetadata(options.metadata);
|
|
@@ -6030,7 +5754,7 @@ function extractRelativeImports(content) {
|
|
|
6030
5754
|
}
|
|
6031
5755
|
async function resolveModulePath(importPath, fromFile) {
|
|
6032
5756
|
const fromDir = dirname(fromFile);
|
|
6033
|
-
const baseResolved =
|
|
5757
|
+
const baseResolved = resolve4(fromDir, importPath);
|
|
6034
5758
|
const extensions = [".ts", ".tsx", ".js", ".jsx", ""];
|
|
6035
5759
|
for (const ext of extensions) {
|
|
6036
5760
|
const fullPath = baseResolved + ext;
|
|
@@ -6039,7 +5763,7 @@ async function resolveModulePath(importPath, fromFile) {
|
|
|
6039
5763
|
}
|
|
6040
5764
|
}
|
|
6041
5765
|
if (await exists(baseResolved)) {
|
|
6042
|
-
const indexPath =
|
|
5766
|
+
const indexPath = join3(baseResolved, "index.ts");
|
|
6043
5767
|
if (await exists(indexPath)) {
|
|
6044
5768
|
return indexPath;
|
|
6045
5769
|
}
|
|
@@ -6051,7 +5775,7 @@ function extractMetadata(metadata) {
|
|
|
6051
5775
|
}
|
|
6052
5776
|
var replaceNpmInstallTabs = () => {
|
|
6053
5777
|
return (tree, _file, done) => {
|
|
6054
|
-
|
|
5778
|
+
visit5(tree, "mdxJsxFlowElement", (node) => {
|
|
6055
5779
|
if (node?.name === "NpmInstallTabs") {
|
|
6056
5780
|
const packages = node.attributes?.find(
|
|
6057
5781
|
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "packages"
|
|
@@ -6074,6 +5798,37 @@ function getPath(obj, path) {
|
|
|
6074
5798
|
obj
|
|
6075
5799
|
);
|
|
6076
5800
|
}
|
|
5801
|
+
function escapeText(value) {
|
|
5802
|
+
return value.replace(/\n/g, " ");
|
|
5803
|
+
}
|
|
5804
|
+
function propsToDefinitionList(props) {
|
|
5805
|
+
if (props.length === 0) {
|
|
5806
|
+
return "";
|
|
5807
|
+
}
|
|
5808
|
+
return props.map((prop) => {
|
|
5809
|
+
const parts = [`- **${prop.name}** (\`${escapeText(prop.type)}\``];
|
|
5810
|
+
if (prop.defaultValue) {
|
|
5811
|
+
parts.push(`, default: \`${escapeText(prop.defaultValue)}\``);
|
|
5812
|
+
}
|
|
5813
|
+
if (prop.required) {
|
|
5814
|
+
parts.push(", required");
|
|
5815
|
+
}
|
|
5816
|
+
parts.push(")");
|
|
5817
|
+
if (prop.description) {
|
|
5818
|
+
parts.push(` - ${escapeText(prop.description)}`);
|
|
5819
|
+
}
|
|
5820
|
+
return parts.join("");
|
|
5821
|
+
}).join("\n");
|
|
5822
|
+
}
|
|
5823
|
+
function themeDataToJson(data, cssPropertyName) {
|
|
5824
|
+
if (!data || typeof data !== "object") {
|
|
5825
|
+
return "";
|
|
5826
|
+
}
|
|
5827
|
+
if (cssPropertyName) {
|
|
5828
|
+
return JSON.stringify({ cssProperty: cssPropertyName, data }, null, 2);
|
|
5829
|
+
}
|
|
5830
|
+
return JSON.stringify(data, null, 2);
|
|
5831
|
+
}
|
|
6077
5832
|
var KnowledgeGenerator = class {
|
|
6078
5833
|
config;
|
|
6079
5834
|
docProps = null;
|
|
@@ -6103,7 +5858,7 @@ var KnowledgeGenerator = class {
|
|
|
6103
5858
|
const processedPages = [];
|
|
6104
5859
|
for (const page of pages) {
|
|
6105
5860
|
try {
|
|
6106
|
-
const processed = await this.
|
|
5861
|
+
const processed = await this.processMdxPage(page);
|
|
6107
5862
|
processedPages.push(processed);
|
|
6108
5863
|
} catch (error) {
|
|
6109
5864
|
console.error(`Failed to process page: ${page.name}`);
|
|
@@ -6128,10 +5883,10 @@ var KnowledgeGenerator = class {
|
|
|
6128
5883
|
);
|
|
6129
5884
|
await this.generateExtraFiles(extractedMetadata);
|
|
6130
5885
|
}
|
|
6131
|
-
return pages
|
|
5886
|
+
return pages;
|
|
6132
5887
|
}
|
|
6133
5888
|
async loadDocProps() {
|
|
6134
|
-
const resolvedDocPropsPath = this.config.docPropsPath ? await exists(this.config.docPropsPath) ? this.config.docPropsPath :
|
|
5889
|
+
const resolvedDocPropsPath = this.config.docPropsPath ? await exists(this.config.docPropsPath) ? this.config.docPropsPath : resolve4(process.cwd(), this.config.docPropsPath) : join3(dirname(this.config.routeDir), "doc-props.json");
|
|
6135
5890
|
if (!await exists(resolvedDocPropsPath)) {
|
|
6136
5891
|
if (this.config.verbose) {
|
|
6137
5892
|
console.log(`Doc props file not found at: ${resolvedDocPropsPath}`);
|
|
@@ -6178,22 +5933,23 @@ var KnowledgeGenerator = class {
|
|
|
6178
5933
|
}
|
|
6179
5934
|
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
6180
5935
|
const mdxFiles = entries.filter(
|
|
6181
|
-
(f) => f.name.endsWith(".mdx") && !shouldExclude(
|
|
5936
|
+
(f) => f.name.endsWith(".mdx") && !shouldExclude(join3(dirPath, f.name))
|
|
6182
5937
|
) ?? [];
|
|
6183
5938
|
for (const mdxFile of mdxFiles) {
|
|
6184
5939
|
const demosFolder = entries.find((f) => f.name === "demos");
|
|
6185
|
-
const demosFolderPath = demosFolder ?
|
|
5940
|
+
const demosFolderPath = demosFolder ? join3(dirPath, demosFolder.name) : void 0;
|
|
6186
5941
|
const segments = getPathSegmentsFromFileName(
|
|
6187
|
-
|
|
5942
|
+
join3(dirPath, mdxFile.name),
|
|
6188
5943
|
this.config.routeDir
|
|
6189
5944
|
);
|
|
6190
5945
|
const url = getPathnameFromPathSegments(segments);
|
|
6191
5946
|
components.push({
|
|
6192
5947
|
demosFolder: demosFolderPath,
|
|
5948
|
+
filePath: dirPath,
|
|
6193
5949
|
id: segments.join("-").trim(),
|
|
6194
|
-
mdxFile:
|
|
5950
|
+
mdxFile: join3(dirPath, mdxFile.name),
|
|
6195
5951
|
name: segments.at(-1),
|
|
6196
|
-
|
|
5952
|
+
pathname: url,
|
|
6197
5953
|
url: this.config.baseUrl ? new URL(url, this.config.baseUrl).toString() : void 0
|
|
6198
5954
|
});
|
|
6199
5955
|
if (this.config.verbose) {
|
|
@@ -6202,7 +5958,7 @@ var KnowledgeGenerator = class {
|
|
|
6202
5958
|
}
|
|
6203
5959
|
}
|
|
6204
5960
|
for (const entry of entries) {
|
|
6205
|
-
const fullPath =
|
|
5961
|
+
const fullPath = join3(dirPath, entry.name);
|
|
6206
5962
|
const stats = await stat(fullPath);
|
|
6207
5963
|
if (stats.isDirectory()) {
|
|
6208
5964
|
await scanDirectory(fullPath);
|
|
@@ -6213,7 +5969,7 @@ var KnowledgeGenerator = class {
|
|
|
6213
5969
|
return components;
|
|
6214
5970
|
}
|
|
6215
5971
|
async collectRelativeImports(filePath, visited = /* @__PURE__ */ new Set()) {
|
|
6216
|
-
const normalizedPath =
|
|
5972
|
+
const normalizedPath = resolve4(filePath);
|
|
6217
5973
|
if (visited.has(normalizedPath)) {
|
|
6218
5974
|
return [];
|
|
6219
5975
|
}
|
|
@@ -6321,7 +6077,9 @@ ${codeText}
|
|
|
6321
6077
|
}
|
|
6322
6078
|
default:
|
|
6323
6079
|
if (this.config.outputMode === "per-page" && "tag" in part && part.tag === "@link" && typeof part.target === "string") {
|
|
6324
|
-
|
|
6080
|
+
if (part.text === "Learn more") {
|
|
6081
|
+
return "";
|
|
6082
|
+
}
|
|
6325
6083
|
}
|
|
6326
6084
|
return part.text;
|
|
6327
6085
|
}
|
|
@@ -6340,8 +6098,8 @@ ${codeText}
|
|
|
6340
6098
|
};
|
|
6341
6099
|
}
|
|
6342
6100
|
/**
|
|
6343
|
-
* Creates a remark plugin that replaces
|
|
6344
|
-
*
|
|
6101
|
+
* Creates a remark plugin that replaces theme JSX elements with
|
|
6102
|
+
* markdown tables containing theme data.
|
|
6345
6103
|
*/
|
|
6346
6104
|
async replaceThemeNodes() {
|
|
6347
6105
|
let themes = null;
|
|
@@ -6368,7 +6126,7 @@ ${codeText}
|
|
|
6368
6126
|
}
|
|
6369
6127
|
};
|
|
6370
6128
|
return () => (tree, _file, done) => {
|
|
6371
|
-
|
|
6129
|
+
visit5(tree, "mdxJsxFlowElement", (node) => {
|
|
6372
6130
|
const handler = node.name && handlers[node.name];
|
|
6373
6131
|
if (!handler) {
|
|
6374
6132
|
return;
|
|
@@ -6378,11 +6136,21 @@ ${codeText}
|
|
|
6378
6136
|
console.warn(`No theme data for ${node.name}`);
|
|
6379
6137
|
return;
|
|
6380
6138
|
}
|
|
6139
|
+
let markdownTable;
|
|
6140
|
+
if (typeof data === "object" && data !== null && "cssPropertyName" in data && "data" in data) {
|
|
6141
|
+
const { cssPropertyName, data: themeData } = data;
|
|
6142
|
+
markdownTable = themeDataToJson(themeData, cssPropertyName);
|
|
6143
|
+
} else {
|
|
6144
|
+
markdownTable = themeDataToJson(data);
|
|
6145
|
+
}
|
|
6146
|
+
if (!markdownTable) {
|
|
6147
|
+
return;
|
|
6148
|
+
}
|
|
6381
6149
|
Object.assign(node, {
|
|
6382
6150
|
lang: "json",
|
|
6383
6151
|
meta: null,
|
|
6384
6152
|
type: "code",
|
|
6385
|
-
value:
|
|
6153
|
+
value: markdownTable
|
|
6386
6154
|
});
|
|
6387
6155
|
});
|
|
6388
6156
|
done();
|
|
@@ -6403,12 +6171,30 @@ ${codeText}
|
|
|
6403
6171
|
return null;
|
|
6404
6172
|
}
|
|
6405
6173
|
/**
|
|
6406
|
-
* Creates a remark plugin that
|
|
6407
|
-
|
|
6174
|
+
* Creates a remark plugin that transforms relative URLs to absolute URLs.
|
|
6175
|
+
*/
|
|
6176
|
+
transformRelativeUrls(pageUrl) {
|
|
6177
|
+
const baseUrl = this.config.baseUrl;
|
|
6178
|
+
return () => (tree) => {
|
|
6179
|
+
if (!baseUrl || this.config.outputMode !== "per-page") {
|
|
6180
|
+
return;
|
|
6181
|
+
}
|
|
6182
|
+
visit5(tree, "link", (node) => {
|
|
6183
|
+
if (node.url.startsWith("/")) {
|
|
6184
|
+
node.url = `${baseUrl}${node.url}`;
|
|
6185
|
+
} else if (node.url.startsWith("./#") && pageUrl) {
|
|
6186
|
+
node.url = `${pageUrl}${node.url.slice(2)}`;
|
|
6187
|
+
}
|
|
6188
|
+
});
|
|
6189
|
+
};
|
|
6190
|
+
}
|
|
6191
|
+
/**
|
|
6192
|
+
* Creates a remark plugin that replaces TypeDocProps JSX elements with
|
|
6193
|
+
* markdown tables containing component prop documentation.
|
|
6408
6194
|
*/
|
|
6409
6195
|
replaceTypeDocProps() {
|
|
6410
6196
|
return () => (tree, _file, done) => {
|
|
6411
|
-
|
|
6197
|
+
visit5(
|
|
6412
6198
|
tree,
|
|
6413
6199
|
"mdxJsxFlowElement",
|
|
6414
6200
|
(node, index, parent) => {
|
|
@@ -6451,11 +6237,35 @@ ${codeText}
|
|
|
6451
6237
|
` Replaced TypeDocProps ${propsName} with API documentation`
|
|
6452
6238
|
);
|
|
6453
6239
|
}
|
|
6240
|
+
const regularProps = propsDoc.filter((p) => p.propType === void 0);
|
|
6241
|
+
const inputs = propsDoc.filter((p) => p.propType === "input");
|
|
6242
|
+
const outputs = propsDoc.filter((p) => p.propType === "output");
|
|
6243
|
+
const sections = [];
|
|
6244
|
+
if (regularProps.length > 0) {
|
|
6245
|
+
sections.push(propsToDefinitionList(regularProps));
|
|
6246
|
+
}
|
|
6247
|
+
if (inputs.length > 0) {
|
|
6248
|
+
sections.push(`**Inputs**
|
|
6249
|
+
|
|
6250
|
+
${propsToDefinitionList(inputs)}`);
|
|
6251
|
+
}
|
|
6252
|
+
if (outputs.length > 0) {
|
|
6253
|
+
sections.push(`**Outputs**
|
|
6254
|
+
|
|
6255
|
+
${propsToDefinitionList(outputs)}`);
|
|
6256
|
+
}
|
|
6257
|
+
const markdownContent = sections.join("\n\n");
|
|
6258
|
+
if (!markdownContent) {
|
|
6259
|
+
if (parent && index !== void 0) {
|
|
6260
|
+
parent.children.splice(index, 1);
|
|
6261
|
+
}
|
|
6262
|
+
return;
|
|
6263
|
+
}
|
|
6454
6264
|
Object.assign(node, {
|
|
6455
|
-
lang:
|
|
6265
|
+
lang: null,
|
|
6456
6266
|
meta: null,
|
|
6457
6267
|
type: "code",
|
|
6458
|
-
value:
|
|
6268
|
+
value: markdownContent
|
|
6459
6269
|
});
|
|
6460
6270
|
}
|
|
6461
6271
|
);
|
|
@@ -6469,7 +6279,7 @@ ${codeText}
|
|
|
6469
6279
|
replaceDemos(demosFolder, demoFiles) {
|
|
6470
6280
|
return () => async (tree) => {
|
|
6471
6281
|
const promises = [];
|
|
6472
|
-
|
|
6282
|
+
visit5(
|
|
6473
6283
|
tree,
|
|
6474
6284
|
"mdxJsxFlowElement",
|
|
6475
6285
|
(node, index, parent) => {
|
|
@@ -6513,14 +6323,14 @@ ${codeText}
|
|
|
6513
6323
|
}
|
|
6514
6324
|
return;
|
|
6515
6325
|
}
|
|
6516
|
-
let demoFilePath =
|
|
6326
|
+
let demoFilePath = join3(demosFolder, filePath);
|
|
6517
6327
|
let isAngularDemo = false;
|
|
6518
6328
|
if (!await exists(demoFilePath)) {
|
|
6519
|
-
demoFilePath =
|
|
6329
|
+
demoFilePath = join3(demosFolder, `${kebabName}.ts`);
|
|
6520
6330
|
if (await exists(demoFilePath)) {
|
|
6521
6331
|
isAngularDemo = true;
|
|
6522
6332
|
filePath = `${kebabCase(demoName).replace("-component", ".component")}.ts`;
|
|
6523
|
-
demoFilePath =
|
|
6333
|
+
demoFilePath = join3(demosFolder, filePath);
|
|
6524
6334
|
} else {
|
|
6525
6335
|
console.log(` Demo not found ${demoName}`);
|
|
6526
6336
|
if (parent && index !== void 0) {
|
|
@@ -6559,7 +6369,7 @@ ${codeText}
|
|
|
6559
6369
|
}
|
|
6560
6370
|
replaceFrontmatterExpressions(frontmatter) {
|
|
6561
6371
|
return () => (tree) => {
|
|
6562
|
-
|
|
6372
|
+
visit5(
|
|
6563
6373
|
tree,
|
|
6564
6374
|
"mdxFlowExpression",
|
|
6565
6375
|
(node, index, parent) => {
|
|
@@ -6596,54 +6406,41 @@ ${codeText}
|
|
|
6596
6406
|
*/
|
|
6597
6407
|
async processMdxContent(mdxContent, pageUrl, demosFolder, frontmatter) {
|
|
6598
6408
|
const demoFiles = [];
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
(_, text, anchor) => pageUrl && this.config.outputMode === "per-page" ? `[${text}](${pageUrl}#${anchor})` : text
|
|
6603
|
-
);
|
|
6604
|
-
const processor = unified4().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter3, ["yaml"]).use(this.replaceTypeDocProps()).use(this.replaceFrontmatterExpressions(frontmatter)).use(await this.replaceThemeNodes()).use(this.replaceDemos(demosFolder, demoFiles)).use(remarkStringify3);
|
|
6605
|
-
const processed = await processor.process(processedContent);
|
|
6606
|
-
processedContent = String(processed);
|
|
6607
|
-
processedContent = processedContent.replace(/\n\s*\n\s*\n/g, "\n\n");
|
|
6409
|
+
const processor = unified4().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(this.replaceTypeDocProps()).use(this.replaceFrontmatterExpressions(frontmatter)).use(await this.replaceThemeNodes()).use(this.replaceDemos(demosFolder, demoFiles)).use(this.transformRelativeUrls(pageUrl)).use(remarkStringify3);
|
|
6410
|
+
const processed = await processor.process(mdxContent);
|
|
6411
|
+
const processedContent = String(processed).replace(/\n\s*\n\s*\n/g, "\n\n");
|
|
6608
6412
|
return { content: processedContent, demoFiles };
|
|
6609
6413
|
}
|
|
6610
|
-
async
|
|
6414
|
+
async processMdxPage(pageInfo) {
|
|
6611
6415
|
try {
|
|
6612
|
-
const mdxContent = await readFile(
|
|
6416
|
+
const mdxContent = await readFile(pageInfo.mdxFile, "utf-8");
|
|
6613
6417
|
if (this.config.verbose) {
|
|
6614
|
-
console.log(`Processing page: ${
|
|
6418
|
+
console.log(`Processing page: ${pageInfo.name}`);
|
|
6615
6419
|
}
|
|
6616
|
-
const processor = unified4().use(remarkParse4).use(remarkMdx3).use(replaceNpmInstallTabs).use(
|
|
6617
|
-
if (this.config.outputMode === "per-page") {
|
|
6618
|
-
processor.use(remarkSelfLinkHeadings(component.url));
|
|
6619
|
-
}
|
|
6620
|
-
processor.use(remarkStringify3);
|
|
6420
|
+
const processor = unified4().use(remarkParse4).use(remarkMdx3).use(replaceNpmInstallTabs).use(remarkFrontmatter2, ["yaml"]).use(remarkParseFrontmatter2).use(remarkStringify3);
|
|
6621
6421
|
const parsed = await processor.process(mdxContent);
|
|
6622
6422
|
const frontmatter = parsed.data?.frontmatter || {};
|
|
6623
6423
|
const { content: processedContent, demoFiles } = await this.processMdxContent(
|
|
6624
6424
|
String(parsed),
|
|
6625
|
-
|
|
6626
|
-
|
|
6425
|
+
pageInfo.url,
|
|
6426
|
+
pageInfo.demosFolder,
|
|
6627
6427
|
frontmatter
|
|
6628
6428
|
);
|
|
6629
|
-
const removeJsxProcessor = unified4().use(remarkParse4).use(remarkMdx3).use(
|
|
6429
|
+
const removeJsxProcessor = unified4().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(remarkRemoveJsx).use(remarkStringify3);
|
|
6630
6430
|
const removedJsx = String(
|
|
6631
6431
|
await removeJsxProcessor.process(processedContent)
|
|
6632
6432
|
);
|
|
6633
|
-
const contentWithoutFrontmatter = removedJsx.replace(
|
|
6634
|
-
|
|
6635
|
-
""
|
|
6636
|
-
);
|
|
6637
|
-
const title = frontmatter.title || component.name;
|
|
6433
|
+
const contentWithoutFrontmatter = removedJsx.replace(/^---[\s\S]*?---\n/, "").replace(/(^#{1,6} .*\\<[^>]+)>/gm, "$1\\>");
|
|
6434
|
+
const title = frontmatter.title || pageInfo.name;
|
|
6638
6435
|
return {
|
|
6639
6436
|
content: contentWithoutFrontmatter.trim(),
|
|
6640
6437
|
demoFiles,
|
|
6641
6438
|
frontmatter,
|
|
6642
6439
|
title,
|
|
6643
|
-
url:
|
|
6440
|
+
url: pageInfo.url
|
|
6644
6441
|
};
|
|
6645
6442
|
} catch (error) {
|
|
6646
|
-
console.error(`Error processing component ${
|
|
6443
|
+
console.error(`Error processing component ${pageInfo.name}:`, error);
|
|
6647
6444
|
throw error;
|
|
6648
6445
|
}
|
|
6649
6446
|
}
|
|
@@ -6691,6 +6488,11 @@ ${codeText}
|
|
|
6691
6488
|
let totalSize = 0;
|
|
6692
6489
|
await Promise.all(
|
|
6693
6490
|
extraFiles.map(async (extraFile) => {
|
|
6491
|
+
let contents = extraFile.contents;
|
|
6492
|
+
if (extraFile.processAsMdx) {
|
|
6493
|
+
const removeJsxProcessor = unified4().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(remarkRemoveJsx).use(this.transformRelativeUrls()).use(remarkStringify3);
|
|
6494
|
+
contents = String(await removeJsxProcessor.process(contents));
|
|
6495
|
+
}
|
|
6694
6496
|
const lines = [];
|
|
6695
6497
|
if (metadata.length) {
|
|
6696
6498
|
lines.push("---");
|
|
@@ -6700,11 +6502,13 @@ ${codeText}
|
|
|
6700
6502
|
lines.push("---");
|
|
6701
6503
|
lines.push("");
|
|
6702
6504
|
}
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6505
|
+
if (extraFile.title) {
|
|
6506
|
+
lines.push(`# ${extraFile.title}`);
|
|
6507
|
+
lines.push("");
|
|
6508
|
+
}
|
|
6509
|
+
lines.push(contents);
|
|
6706
6510
|
lines.push("");
|
|
6707
|
-
const outfile = `${
|
|
6511
|
+
const outfile = `${resolve4(this.config.outputPath)}/${kebabCase(extraFile.id)}.md`;
|
|
6708
6512
|
await writeFile3(outfile, lines.join("\n"), "utf-8");
|
|
6709
6513
|
const stats = await stat(outfile);
|
|
6710
6514
|
totalSize += stats.size / 1024;
|
|
@@ -6744,6 +6548,10 @@ ${codeText}
|
|
|
6744
6548
|
page.name = processedPage.frontmatter.title;
|
|
6745
6549
|
}
|
|
6746
6550
|
let content = processedPage.content;
|
|
6551
|
+
content = content.replace(
|
|
6552
|
+
new RegExp(`^# ${processedPage.title}\\n+`, ""),
|
|
6553
|
+
""
|
|
6554
|
+
);
|
|
6747
6555
|
if (this.config.pageTitlePrefix) {
|
|
6748
6556
|
content = content.replace(
|
|
6749
6557
|
`# ${page.name}`,
|
|
@@ -6789,7 +6597,7 @@ ${codeText}
|
|
|
6789
6597
|
}
|
|
6790
6598
|
}
|
|
6791
6599
|
}
|
|
6792
|
-
const outfile = `${
|
|
6600
|
+
const outfile = `${resolve4(this.config.outputPath)}/${kebabCase(page.id || page.name)}.md`;
|
|
6793
6601
|
await writeFile3(outfile, lines.join("\n"), "utf-8");
|
|
6794
6602
|
const stats = await stat(outfile);
|
|
6795
6603
|
totalSize += stats.size / 1024;
|
|
@@ -6825,7 +6633,7 @@ function addGenerateKnowledgeCommand() {
|
|
|
6825
6633
|
import { createHash as createHash2 } from "node:crypto";
|
|
6826
6634
|
import { writeFileSync } from "node:fs";
|
|
6827
6635
|
import { access as access2, readdir as readdir2, readFile as readFile2, stat as stat2 } from "node:fs/promises";
|
|
6828
|
-
import { resolve as
|
|
6636
|
+
import { resolve as resolve5 } from "node:path";
|
|
6829
6637
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
6830
6638
|
import ora from "ora";
|
|
6831
6639
|
|
|
@@ -6955,7 +6763,7 @@ var Uploader = class {
|
|
|
6955
6763
|
const files = await Promise.all(
|
|
6956
6764
|
fileNames.map(async (name) => ({
|
|
6957
6765
|
contents: await readFile2(
|
|
6958
|
-
|
|
6766
|
+
resolve5(this.config.knowledgeFilePath, name),
|
|
6959
6767
|
"utf-8"
|
|
6960
6768
|
),
|
|
6961
6769
|
name
|
|
@@ -7004,7 +6812,7 @@ var Uploader = class {
|
|
|
7004
6812
|
try {
|
|
7005
6813
|
const fileId = knowledgeFile.id;
|
|
7006
6814
|
const fileString = await readFile2(
|
|
7007
|
-
|
|
6815
|
+
resolve5(this.config.knowledgeFilePath, name),
|
|
7008
6816
|
"utf-8"
|
|
7009
6817
|
);
|
|
7010
6818
|
const spinner2 = ora(`Updating ${name}`).start();
|
|
@@ -7019,7 +6827,7 @@ var Uploader = class {
|
|
|
7019
6827
|
}
|
|
7020
6828
|
const spinner = ora(`Uploading ${name}`).start();
|
|
7021
6829
|
const fileBuffer = await readFile2(
|
|
7022
|
-
|
|
6830
|
+
resolve5(this.config.knowledgeFilePath, name)
|
|
7023
6831
|
);
|
|
7024
6832
|
let uploadedFileId = void 0;
|
|
7025
6833
|
try {
|
|
@@ -7057,7 +6865,7 @@ var Uploader = class {
|
|
|
7057
6865
|
}
|
|
7058
6866
|
}
|
|
7059
6867
|
async uploadKnowledge() {
|
|
7060
|
-
const resolvedPath =
|
|
6868
|
+
const resolvedPath = resolve5(this.config.knowledgeFilePath);
|
|
7061
6869
|
if (!await access2(resolvedPath).then(() => true).catch(() => false)) {
|
|
7062
6870
|
throw new Error(`File or folder not found at ${resolvedPath}`);
|
|
7063
6871
|
}
|
|
@@ -7097,7 +6905,7 @@ function addUploadKnowledgeCommand() {
|
|
|
7097
6905
|
const files = await uploader.filesApi.search("*");
|
|
7098
6906
|
console.debug(`found ${files.length} files`);
|
|
7099
6907
|
writeFileSync(
|
|
7100
|
-
|
|
6908
|
+
resolve5(uploader.config.knowledgeFilePath, "files.json"),
|
|
7101
6909
|
JSON.stringify(files, null, 2),
|
|
7102
6910
|
"utf-8"
|
|
7103
6911
|
);
|
|
@@ -7140,16 +6948,16 @@ function addUploadKnowledgeCommand() {
|
|
|
7140
6948
|
}
|
|
7141
6949
|
|
|
7142
6950
|
// src/react-demo-plugin/generate-lazy-demo-map.ts
|
|
7143
|
-
import { glob as
|
|
6951
|
+
import { glob as glob2 } from "glob";
|
|
7144
6952
|
import { uniqBy } from "lodash-es";
|
|
7145
6953
|
import { writeFile as writeFile4 } from "node:fs/promises";
|
|
7146
|
-
import { resolve as
|
|
7147
|
-
import { dedent
|
|
6954
|
+
import { resolve as resolve7 } from "node:path";
|
|
6955
|
+
import { dedent } from "@qualcomm-ui/utils/dedent";
|
|
7148
6956
|
|
|
7149
6957
|
// src/react-demo-plugin/demo-plugin-utils.ts
|
|
7150
|
-
import
|
|
7151
|
-
import { existsSync as existsSync2, readFileSync as
|
|
7152
|
-
import { dirname as dirname2, join as
|
|
6958
|
+
import chalk3 from "chalk";
|
|
6959
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
6960
|
+
import { dirname as dirname2, join as join4, relative as relative3, resolve as resolve6, sep } from "node:path";
|
|
7153
6961
|
import * as ts from "typescript";
|
|
7154
6962
|
import { pascalCase } from "@qualcomm-ui/utils/change-case";
|
|
7155
6963
|
function extractPageId(filePath, routesDir) {
|
|
@@ -7163,7 +6971,7 @@ function extractPageId(filePath, routesDir) {
|
|
|
7163
6971
|
}
|
|
7164
6972
|
function isDemoFile(filePath) {
|
|
7165
6973
|
try {
|
|
7166
|
-
return filePath.includes("/demos/") && filePath.endsWith(".tsx") && !
|
|
6974
|
+
return filePath.includes("/demos/") && filePath.endsWith(".tsx") && !readFileSync2(filePath).includes("export default");
|
|
7167
6975
|
} catch (error) {
|
|
7168
6976
|
return false;
|
|
7169
6977
|
}
|
|
@@ -7174,7 +6982,7 @@ async function scanForDemoPages({
|
|
|
7174
6982
|
demoPattern = "src/routes/**/demos/*.tsx",
|
|
7175
6983
|
routesDir = "src/routes"
|
|
7176
6984
|
}) {
|
|
7177
|
-
const demoFiles = (await
|
|
6985
|
+
const demoFiles = (await glob2(demoPattern)).filter((file) => isDemoFile(file));
|
|
7178
6986
|
return uniqBy(
|
|
7179
6987
|
demoFiles.map((file) => ({
|
|
7180
6988
|
pageId: extractPageId(file, routesDir),
|
|
@@ -7188,7 +6996,7 @@ function generateLazyDemoLoader(demoPages) {
|
|
|
7188
6996
|
return ` "${routePath}": () =>
|
|
7189
6997
|
import("virtual:qui-demo-scope/page:${pageId}")`;
|
|
7190
6998
|
}).sort().join(",\n");
|
|
7191
|
-
return
|
|
6999
|
+
return dedent`
|
|
7192
7000
|
/* eslint-disable */
|
|
7193
7001
|
|
|
7194
7002
|
// This file is generated automatically. Don't edit it directly.
|
|
@@ -7206,7 +7014,7 @@ function generateLazyDemoLoader(demoPages) {
|
|
|
7206
7014
|
}
|
|
7207
7015
|
async function generateLazyDemoMap(options) {
|
|
7208
7016
|
const routesDir = options.routesDir;
|
|
7209
|
-
const outputPath =
|
|
7017
|
+
const outputPath = resolve7(options.output);
|
|
7210
7018
|
console.log(`Scanning for demo pages in: ${routesDir}`);
|
|
7211
7019
|
const demoPages = await scanForDemoPages({ routesDir });
|
|
7212
7020
|
console.log(`Found ${demoPages.length} pages with demos`);
|