@qualcomm-ui/mdx-vite 2.9.0 → 2.10.1
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 -387
- 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/common.d.ts.map +1 -1
- 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
|
}
|
|
@@ -5594,7 +5595,6 @@ var KnowledgeApi = class {
|
|
|
5594
5595
|
import { config } from "dotenv";
|
|
5595
5596
|
function loadEnv() {
|
|
5596
5597
|
const options = program.optsWithGlobals();
|
|
5597
|
-
console.debug(options);
|
|
5598
5598
|
if (options.env) {
|
|
5599
5599
|
config({ path: options.env });
|
|
5600
5600
|
} else {
|
|
@@ -5657,296 +5657,19 @@ import {
|
|
|
5657
5657
|
stat,
|
|
5658
5658
|
writeFile as writeFile3
|
|
5659
5659
|
} from "node:fs/promises";
|
|
5660
|
-
import { basename, dirname, extname, join as
|
|
5661
|
-
import
|
|
5660
|
+
import { basename, dirname, extname, join as join3, relative as relative2, resolve as resolve4 } from "node:path";
|
|
5661
|
+
import remarkFrontmatter2 from "remark-frontmatter";
|
|
5662
5662
|
import remarkMdx3 from "remark-mdx";
|
|
5663
5663
|
import remarkParse4 from "remark-parse";
|
|
5664
5664
|
import remarkParseFrontmatter2 from "remark-parse-frontmatter";
|
|
5665
5665
|
import remarkStringify3 from "remark-stringify";
|
|
5666
5666
|
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
5667
|
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";
|
|
5668
|
+
import { kebabCase } from "@qualcomm-ui/utils/change-case";
|
|
5946
5669
|
|
|
5947
5670
|
// src/open-web-ui-knowledge/load-config-from-env.ts
|
|
5948
5671
|
import { existsSync } from "node:fs";
|
|
5949
|
-
import { join as
|
|
5672
|
+
import { join as join2, resolve as resolve3 } from "node:path";
|
|
5950
5673
|
function parseCliMetadata(cliMetadata) {
|
|
5951
5674
|
if (!cliMetadata?.length) {
|
|
5952
5675
|
return void 0;
|
|
@@ -5962,11 +5685,11 @@ function loadKnowledgeConfigFromEnv(options) {
|
|
|
5962
5685
|
if (!outputPath) {
|
|
5963
5686
|
throw new Error("Missing required outputPath");
|
|
5964
5687
|
}
|
|
5965
|
-
const routeDir =
|
|
5688
|
+
const routeDir = join2(
|
|
5966
5689
|
resolvedConfig.appDirectory,
|
|
5967
5690
|
resolvedConfig.pageDirectory
|
|
5968
5691
|
);
|
|
5969
|
-
if (!existsSync(
|
|
5692
|
+
if (!existsSync(resolve3(routeDir))) {
|
|
5970
5693
|
throw new Error(`Route directory ${routeDir} does not exist`);
|
|
5971
5694
|
}
|
|
5972
5695
|
const cliMetadata = parseCliMetadata(options.metadata);
|
|
@@ -6030,7 +5753,7 @@ function extractRelativeImports(content) {
|
|
|
6030
5753
|
}
|
|
6031
5754
|
async function resolveModulePath(importPath, fromFile) {
|
|
6032
5755
|
const fromDir = dirname(fromFile);
|
|
6033
|
-
const baseResolved =
|
|
5756
|
+
const baseResolved = resolve4(fromDir, importPath);
|
|
6034
5757
|
const extensions = [".ts", ".tsx", ".js", ".jsx", ""];
|
|
6035
5758
|
for (const ext of extensions) {
|
|
6036
5759
|
const fullPath = baseResolved + ext;
|
|
@@ -6039,7 +5762,7 @@ async function resolveModulePath(importPath, fromFile) {
|
|
|
6039
5762
|
}
|
|
6040
5763
|
}
|
|
6041
5764
|
if (await exists(baseResolved)) {
|
|
6042
|
-
const indexPath =
|
|
5765
|
+
const indexPath = join3(baseResolved, "index.ts");
|
|
6043
5766
|
if (await exists(indexPath)) {
|
|
6044
5767
|
return indexPath;
|
|
6045
5768
|
}
|
|
@@ -6051,7 +5774,7 @@ function extractMetadata(metadata) {
|
|
|
6051
5774
|
}
|
|
6052
5775
|
var replaceNpmInstallTabs = () => {
|
|
6053
5776
|
return (tree, _file, done) => {
|
|
6054
|
-
|
|
5777
|
+
visit5(tree, "mdxJsxFlowElement", (node) => {
|
|
6055
5778
|
if (node?.name === "NpmInstallTabs") {
|
|
6056
5779
|
const packages = node.attributes?.find(
|
|
6057
5780
|
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "packages"
|
|
@@ -6074,6 +5797,37 @@ function getPath(obj, path) {
|
|
|
6074
5797
|
obj
|
|
6075
5798
|
);
|
|
6076
5799
|
}
|
|
5800
|
+
function escapeText(value) {
|
|
5801
|
+
return value.replace(/\n/g, " ");
|
|
5802
|
+
}
|
|
5803
|
+
function propsToDefinitionList(props) {
|
|
5804
|
+
if (props.length === 0) {
|
|
5805
|
+
return "";
|
|
5806
|
+
}
|
|
5807
|
+
return props.map((prop) => {
|
|
5808
|
+
const parts = [`- **${prop.name}** (\`${escapeText(prop.type)}\``];
|
|
5809
|
+
if (prop.defaultValue) {
|
|
5810
|
+
parts.push(`, default: \`${escapeText(prop.defaultValue)}\``);
|
|
5811
|
+
}
|
|
5812
|
+
if (prop.required) {
|
|
5813
|
+
parts.push(", required");
|
|
5814
|
+
}
|
|
5815
|
+
parts.push(")");
|
|
5816
|
+
if (prop.description) {
|
|
5817
|
+
parts.push(` - ${escapeText(prop.description)}`);
|
|
5818
|
+
}
|
|
5819
|
+
return parts.join("");
|
|
5820
|
+
}).join("\n");
|
|
5821
|
+
}
|
|
5822
|
+
function themeDataToJson(data, cssPropertyName) {
|
|
5823
|
+
if (!data || typeof data !== "object") {
|
|
5824
|
+
return "";
|
|
5825
|
+
}
|
|
5826
|
+
if (cssPropertyName) {
|
|
5827
|
+
return JSON.stringify({ cssProperty: cssPropertyName, data }, null, 2);
|
|
5828
|
+
}
|
|
5829
|
+
return JSON.stringify(data, null, 2);
|
|
5830
|
+
}
|
|
6077
5831
|
var KnowledgeGenerator = class {
|
|
6078
5832
|
config;
|
|
6079
5833
|
docProps = null;
|
|
@@ -6103,7 +5857,7 @@ var KnowledgeGenerator = class {
|
|
|
6103
5857
|
const processedPages = [];
|
|
6104
5858
|
for (const page of pages) {
|
|
6105
5859
|
try {
|
|
6106
|
-
const processed = await this.
|
|
5860
|
+
const processed = await this.processMdxPage(page);
|
|
6107
5861
|
processedPages.push(processed);
|
|
6108
5862
|
} catch (error) {
|
|
6109
5863
|
console.error(`Failed to process page: ${page.name}`);
|
|
@@ -6128,10 +5882,10 @@ var KnowledgeGenerator = class {
|
|
|
6128
5882
|
);
|
|
6129
5883
|
await this.generateExtraFiles(extractedMetadata);
|
|
6130
5884
|
}
|
|
6131
|
-
return pages
|
|
5885
|
+
return pages;
|
|
6132
5886
|
}
|
|
6133
5887
|
async loadDocProps() {
|
|
6134
|
-
const resolvedDocPropsPath = this.config.docPropsPath ? await exists(this.config.docPropsPath) ? this.config.docPropsPath :
|
|
5888
|
+
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
5889
|
if (!await exists(resolvedDocPropsPath)) {
|
|
6136
5890
|
if (this.config.verbose) {
|
|
6137
5891
|
console.log(`Doc props file not found at: ${resolvedDocPropsPath}`);
|
|
@@ -6178,22 +5932,23 @@ var KnowledgeGenerator = class {
|
|
|
6178
5932
|
}
|
|
6179
5933
|
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
6180
5934
|
const mdxFiles = entries.filter(
|
|
6181
|
-
(f) => f.name.endsWith(".mdx") && !shouldExclude(
|
|
5935
|
+
(f) => f.name.endsWith(".mdx") && !shouldExclude(join3(dirPath, f.name))
|
|
6182
5936
|
) ?? [];
|
|
6183
5937
|
for (const mdxFile of mdxFiles) {
|
|
6184
5938
|
const demosFolder = entries.find((f) => f.name === "demos");
|
|
6185
|
-
const demosFolderPath = demosFolder ?
|
|
5939
|
+
const demosFolderPath = demosFolder ? join3(dirPath, demosFolder.name) : void 0;
|
|
6186
5940
|
const segments = getPathSegmentsFromFileName(
|
|
6187
|
-
|
|
5941
|
+
join3(dirPath, mdxFile.name),
|
|
6188
5942
|
this.config.routeDir
|
|
6189
5943
|
);
|
|
6190
5944
|
const url = getPathnameFromPathSegments(segments);
|
|
6191
5945
|
components.push({
|
|
6192
5946
|
demosFolder: demosFolderPath,
|
|
5947
|
+
filePath: dirPath,
|
|
6193
5948
|
id: segments.join("-").trim(),
|
|
6194
|
-
mdxFile:
|
|
5949
|
+
mdxFile: join3(dirPath, mdxFile.name),
|
|
6195
5950
|
name: segments.at(-1),
|
|
6196
|
-
|
|
5951
|
+
pathname: url,
|
|
6197
5952
|
url: this.config.baseUrl ? new URL(url, this.config.baseUrl).toString() : void 0
|
|
6198
5953
|
});
|
|
6199
5954
|
if (this.config.verbose) {
|
|
@@ -6202,7 +5957,7 @@ var KnowledgeGenerator = class {
|
|
|
6202
5957
|
}
|
|
6203
5958
|
}
|
|
6204
5959
|
for (const entry of entries) {
|
|
6205
|
-
const fullPath =
|
|
5960
|
+
const fullPath = join3(dirPath, entry.name);
|
|
6206
5961
|
const stats = await stat(fullPath);
|
|
6207
5962
|
if (stats.isDirectory()) {
|
|
6208
5963
|
await scanDirectory(fullPath);
|
|
@@ -6213,7 +5968,7 @@ var KnowledgeGenerator = class {
|
|
|
6213
5968
|
return components;
|
|
6214
5969
|
}
|
|
6215
5970
|
async collectRelativeImports(filePath, visited = /* @__PURE__ */ new Set()) {
|
|
6216
|
-
const normalizedPath =
|
|
5971
|
+
const normalizedPath = resolve4(filePath);
|
|
6217
5972
|
if (visited.has(normalizedPath)) {
|
|
6218
5973
|
return [];
|
|
6219
5974
|
}
|
|
@@ -6321,7 +6076,9 @@ ${codeText}
|
|
|
6321
6076
|
}
|
|
6322
6077
|
default:
|
|
6323
6078
|
if (this.config.outputMode === "per-page" && "tag" in part && part.tag === "@link" && typeof part.target === "string") {
|
|
6324
|
-
|
|
6079
|
+
if (part.text === "Learn more") {
|
|
6080
|
+
return "";
|
|
6081
|
+
}
|
|
6325
6082
|
}
|
|
6326
6083
|
return part.text;
|
|
6327
6084
|
}
|
|
@@ -6340,8 +6097,8 @@ ${codeText}
|
|
|
6340
6097
|
};
|
|
6341
6098
|
}
|
|
6342
6099
|
/**
|
|
6343
|
-
* Creates a remark plugin that replaces
|
|
6344
|
-
*
|
|
6100
|
+
* Creates a remark plugin that replaces theme JSX elements with
|
|
6101
|
+
* markdown tables containing theme data.
|
|
6345
6102
|
*/
|
|
6346
6103
|
async replaceThemeNodes() {
|
|
6347
6104
|
let themes = null;
|
|
@@ -6368,7 +6125,7 @@ ${codeText}
|
|
|
6368
6125
|
}
|
|
6369
6126
|
};
|
|
6370
6127
|
return () => (tree, _file, done) => {
|
|
6371
|
-
|
|
6128
|
+
visit5(tree, "mdxJsxFlowElement", (node) => {
|
|
6372
6129
|
const handler = node.name && handlers[node.name];
|
|
6373
6130
|
if (!handler) {
|
|
6374
6131
|
return;
|
|
@@ -6378,11 +6135,21 @@ ${codeText}
|
|
|
6378
6135
|
console.warn(`No theme data for ${node.name}`);
|
|
6379
6136
|
return;
|
|
6380
6137
|
}
|
|
6138
|
+
let markdownTable;
|
|
6139
|
+
if (typeof data === "object" && data !== null && "cssPropertyName" in data && "data" in data) {
|
|
6140
|
+
const { cssPropertyName, data: themeData } = data;
|
|
6141
|
+
markdownTable = themeDataToJson(themeData, cssPropertyName);
|
|
6142
|
+
} else {
|
|
6143
|
+
markdownTable = themeDataToJson(data);
|
|
6144
|
+
}
|
|
6145
|
+
if (!markdownTable) {
|
|
6146
|
+
return;
|
|
6147
|
+
}
|
|
6381
6148
|
Object.assign(node, {
|
|
6382
6149
|
lang: "json",
|
|
6383
6150
|
meta: null,
|
|
6384
6151
|
type: "code",
|
|
6385
|
-
value:
|
|
6152
|
+
value: markdownTable
|
|
6386
6153
|
});
|
|
6387
6154
|
});
|
|
6388
6155
|
done();
|
|
@@ -6403,12 +6170,30 @@ ${codeText}
|
|
|
6403
6170
|
return null;
|
|
6404
6171
|
}
|
|
6405
6172
|
/**
|
|
6406
|
-
* Creates a remark plugin that
|
|
6407
|
-
|
|
6173
|
+
* Creates a remark plugin that transforms relative URLs to absolute URLs.
|
|
6174
|
+
*/
|
|
6175
|
+
transformRelativeUrls(pageUrl) {
|
|
6176
|
+
const baseUrl = this.config.baseUrl;
|
|
6177
|
+
return () => (tree) => {
|
|
6178
|
+
if (!baseUrl || this.config.outputMode !== "per-page") {
|
|
6179
|
+
return;
|
|
6180
|
+
}
|
|
6181
|
+
visit5(tree, "link", (node) => {
|
|
6182
|
+
if (node.url.startsWith("/")) {
|
|
6183
|
+
node.url = `${baseUrl}${node.url}`;
|
|
6184
|
+
} else if (node.url.startsWith("./#") && pageUrl) {
|
|
6185
|
+
node.url = `${pageUrl}${node.url.slice(2)}`;
|
|
6186
|
+
}
|
|
6187
|
+
});
|
|
6188
|
+
};
|
|
6189
|
+
}
|
|
6190
|
+
/**
|
|
6191
|
+
* Creates a remark plugin that replaces TypeDocProps JSX elements with
|
|
6192
|
+
* markdown tables containing component prop documentation.
|
|
6408
6193
|
*/
|
|
6409
6194
|
replaceTypeDocProps() {
|
|
6410
6195
|
return () => (tree, _file, done) => {
|
|
6411
|
-
|
|
6196
|
+
visit5(
|
|
6412
6197
|
tree,
|
|
6413
6198
|
"mdxJsxFlowElement",
|
|
6414
6199
|
(node, index, parent) => {
|
|
@@ -6451,11 +6236,35 @@ ${codeText}
|
|
|
6451
6236
|
` Replaced TypeDocProps ${propsName} with API documentation`
|
|
6452
6237
|
);
|
|
6453
6238
|
}
|
|
6239
|
+
const regularProps = propsDoc.filter((p) => p.propType === void 0);
|
|
6240
|
+
const inputs = propsDoc.filter((p) => p.propType === "input");
|
|
6241
|
+
const outputs = propsDoc.filter((p) => p.propType === "output");
|
|
6242
|
+
const sections = [];
|
|
6243
|
+
if (regularProps.length > 0) {
|
|
6244
|
+
sections.push(propsToDefinitionList(regularProps));
|
|
6245
|
+
}
|
|
6246
|
+
if (inputs.length > 0) {
|
|
6247
|
+
sections.push(`**Inputs**
|
|
6248
|
+
|
|
6249
|
+
${propsToDefinitionList(inputs)}`);
|
|
6250
|
+
}
|
|
6251
|
+
if (outputs.length > 0) {
|
|
6252
|
+
sections.push(`**Outputs**
|
|
6253
|
+
|
|
6254
|
+
${propsToDefinitionList(outputs)}`);
|
|
6255
|
+
}
|
|
6256
|
+
const markdownContent = sections.join("\n\n");
|
|
6257
|
+
if (!markdownContent) {
|
|
6258
|
+
if (parent && index !== void 0) {
|
|
6259
|
+
parent.children.splice(index, 1);
|
|
6260
|
+
}
|
|
6261
|
+
return;
|
|
6262
|
+
}
|
|
6454
6263
|
Object.assign(node, {
|
|
6455
|
-
lang:
|
|
6264
|
+
lang: null,
|
|
6456
6265
|
meta: null,
|
|
6457
6266
|
type: "code",
|
|
6458
|
-
value:
|
|
6267
|
+
value: markdownContent
|
|
6459
6268
|
});
|
|
6460
6269
|
}
|
|
6461
6270
|
);
|
|
@@ -6469,7 +6278,7 @@ ${codeText}
|
|
|
6469
6278
|
replaceDemos(demosFolder, demoFiles) {
|
|
6470
6279
|
return () => async (tree) => {
|
|
6471
6280
|
const promises = [];
|
|
6472
|
-
|
|
6281
|
+
visit5(
|
|
6473
6282
|
tree,
|
|
6474
6283
|
"mdxJsxFlowElement",
|
|
6475
6284
|
(node, index, parent) => {
|
|
@@ -6513,14 +6322,14 @@ ${codeText}
|
|
|
6513
6322
|
}
|
|
6514
6323
|
return;
|
|
6515
6324
|
}
|
|
6516
|
-
let demoFilePath =
|
|
6325
|
+
let demoFilePath = join3(demosFolder, filePath);
|
|
6517
6326
|
let isAngularDemo = false;
|
|
6518
6327
|
if (!await exists(demoFilePath)) {
|
|
6519
|
-
demoFilePath =
|
|
6328
|
+
demoFilePath = join3(demosFolder, `${kebabName}.ts`);
|
|
6520
6329
|
if (await exists(demoFilePath)) {
|
|
6521
6330
|
isAngularDemo = true;
|
|
6522
6331
|
filePath = `${kebabCase(demoName).replace("-component", ".component")}.ts`;
|
|
6523
|
-
demoFilePath =
|
|
6332
|
+
demoFilePath = join3(demosFolder, filePath);
|
|
6524
6333
|
} else {
|
|
6525
6334
|
console.log(` Demo not found ${demoName}`);
|
|
6526
6335
|
if (parent && index !== void 0) {
|
|
@@ -6559,7 +6368,7 @@ ${codeText}
|
|
|
6559
6368
|
}
|
|
6560
6369
|
replaceFrontmatterExpressions(frontmatter) {
|
|
6561
6370
|
return () => (tree) => {
|
|
6562
|
-
|
|
6371
|
+
visit5(
|
|
6563
6372
|
tree,
|
|
6564
6373
|
"mdxFlowExpression",
|
|
6565
6374
|
(node, index, parent) => {
|
|
@@ -6596,54 +6405,41 @@ ${codeText}
|
|
|
6596
6405
|
*/
|
|
6597
6406
|
async processMdxContent(mdxContent, pageUrl, demosFolder, frontmatter) {
|
|
6598
6407
|
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");
|
|
6408
|
+
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);
|
|
6409
|
+
const processed = await processor.process(mdxContent);
|
|
6410
|
+
const processedContent = String(processed).replace(/\n\s*\n\s*\n/g, "\n\n");
|
|
6608
6411
|
return { content: processedContent, demoFiles };
|
|
6609
6412
|
}
|
|
6610
|
-
async
|
|
6413
|
+
async processMdxPage(pageInfo) {
|
|
6611
6414
|
try {
|
|
6612
|
-
const mdxContent = await readFile(
|
|
6415
|
+
const mdxContent = await readFile(pageInfo.mdxFile, "utf-8");
|
|
6613
6416
|
if (this.config.verbose) {
|
|
6614
|
-
console.log(`Processing page: ${
|
|
6417
|
+
console.log(`Processing page: ${pageInfo.name}`);
|
|
6615
6418
|
}
|
|
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);
|
|
6419
|
+
const processor = unified4().use(remarkParse4).use(remarkMdx3).use(replaceNpmInstallTabs).use(remarkFrontmatter2, ["yaml"]).use(remarkParseFrontmatter2).use(remarkStringify3);
|
|
6621
6420
|
const parsed = await processor.process(mdxContent);
|
|
6622
6421
|
const frontmatter = parsed.data?.frontmatter || {};
|
|
6623
6422
|
const { content: processedContent, demoFiles } = await this.processMdxContent(
|
|
6624
6423
|
String(parsed),
|
|
6625
|
-
|
|
6626
|
-
|
|
6424
|
+
pageInfo.url,
|
|
6425
|
+
pageInfo.demosFolder,
|
|
6627
6426
|
frontmatter
|
|
6628
6427
|
);
|
|
6629
|
-
const removeJsxProcessor = unified4().use(remarkParse4).use(remarkMdx3).use(
|
|
6428
|
+
const removeJsxProcessor = unified4().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(remarkRemoveJsx).use(remarkStringify3);
|
|
6630
6429
|
const removedJsx = String(
|
|
6631
6430
|
await removeJsxProcessor.process(processedContent)
|
|
6632
6431
|
);
|
|
6633
|
-
const contentWithoutFrontmatter = removedJsx.replace(
|
|
6634
|
-
|
|
6635
|
-
""
|
|
6636
|
-
);
|
|
6637
|
-
const title = frontmatter.title || component.name;
|
|
6432
|
+
const contentWithoutFrontmatter = removedJsx.replace(/^---[\s\S]*?---\n/, "").replace(/(^#{1,6} .*\\<[^>]+)>/gm, "$1\\>");
|
|
6433
|
+
const title = frontmatter.title || pageInfo.name;
|
|
6638
6434
|
return {
|
|
6639
6435
|
content: contentWithoutFrontmatter.trim(),
|
|
6640
6436
|
demoFiles,
|
|
6641
6437
|
frontmatter,
|
|
6642
6438
|
title,
|
|
6643
|
-
url:
|
|
6439
|
+
url: pageInfo.url
|
|
6644
6440
|
};
|
|
6645
6441
|
} catch (error) {
|
|
6646
|
-
console.error(`Error processing component ${
|
|
6442
|
+
console.error(`Error processing component ${pageInfo.name}:`, error);
|
|
6647
6443
|
throw error;
|
|
6648
6444
|
}
|
|
6649
6445
|
}
|
|
@@ -6691,6 +6487,11 @@ ${codeText}
|
|
|
6691
6487
|
let totalSize = 0;
|
|
6692
6488
|
await Promise.all(
|
|
6693
6489
|
extraFiles.map(async (extraFile) => {
|
|
6490
|
+
let contents = extraFile.contents;
|
|
6491
|
+
if (extraFile.processAsMdx) {
|
|
6492
|
+
const removeJsxProcessor = unified4().use(remarkParse4).use(remarkMdx3).use(remarkFrontmatter2, ["yaml"]).use(remarkRemoveJsx).use(this.transformRelativeUrls()).use(remarkStringify3);
|
|
6493
|
+
contents = String(await removeJsxProcessor.process(contents));
|
|
6494
|
+
}
|
|
6694
6495
|
const lines = [];
|
|
6695
6496
|
if (metadata.length) {
|
|
6696
6497
|
lines.push("---");
|
|
@@ -6700,11 +6501,13 @@ ${codeText}
|
|
|
6700
6501
|
lines.push("---");
|
|
6701
6502
|
lines.push("");
|
|
6702
6503
|
}
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6504
|
+
if (extraFile.title) {
|
|
6505
|
+
lines.push(`# ${extraFile.title}`);
|
|
6506
|
+
lines.push("");
|
|
6507
|
+
}
|
|
6508
|
+
lines.push(contents);
|
|
6706
6509
|
lines.push("");
|
|
6707
|
-
const outfile = `${
|
|
6510
|
+
const outfile = `${resolve4(this.config.outputPath)}/${kebabCase(extraFile.id)}.md`;
|
|
6708
6511
|
await writeFile3(outfile, lines.join("\n"), "utf-8");
|
|
6709
6512
|
const stats = await stat(outfile);
|
|
6710
6513
|
totalSize += stats.size / 1024;
|
|
@@ -6744,6 +6547,10 @@ ${codeText}
|
|
|
6744
6547
|
page.name = processedPage.frontmatter.title;
|
|
6745
6548
|
}
|
|
6746
6549
|
let content = processedPage.content;
|
|
6550
|
+
content = content.replace(
|
|
6551
|
+
new RegExp(`^# ${processedPage.title}\\n+`, ""),
|
|
6552
|
+
""
|
|
6553
|
+
);
|
|
6747
6554
|
if (this.config.pageTitlePrefix) {
|
|
6748
6555
|
content = content.replace(
|
|
6749
6556
|
`# ${page.name}`,
|
|
@@ -6789,7 +6596,7 @@ ${codeText}
|
|
|
6789
6596
|
}
|
|
6790
6597
|
}
|
|
6791
6598
|
}
|
|
6792
|
-
const outfile = `${
|
|
6599
|
+
const outfile = `${resolve4(this.config.outputPath)}/${kebabCase(page.id || page.name)}.md`;
|
|
6793
6600
|
await writeFile3(outfile, lines.join("\n"), "utf-8");
|
|
6794
6601
|
const stats = await stat(outfile);
|
|
6795
6602
|
totalSize += stats.size / 1024;
|
|
@@ -6825,7 +6632,7 @@ function addGenerateKnowledgeCommand() {
|
|
|
6825
6632
|
import { createHash as createHash2 } from "node:crypto";
|
|
6826
6633
|
import { writeFileSync } from "node:fs";
|
|
6827
6634
|
import { access as access2, readdir as readdir2, readFile as readFile2, stat as stat2 } from "node:fs/promises";
|
|
6828
|
-
import { resolve as
|
|
6635
|
+
import { resolve as resolve5 } from "node:path";
|
|
6829
6636
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
6830
6637
|
import ora from "ora";
|
|
6831
6638
|
|
|
@@ -6955,7 +6762,7 @@ var Uploader = class {
|
|
|
6955
6762
|
const files = await Promise.all(
|
|
6956
6763
|
fileNames.map(async (name) => ({
|
|
6957
6764
|
contents: await readFile2(
|
|
6958
|
-
|
|
6765
|
+
resolve5(this.config.knowledgeFilePath, name),
|
|
6959
6766
|
"utf-8"
|
|
6960
6767
|
),
|
|
6961
6768
|
name
|
|
@@ -7004,7 +6811,7 @@ var Uploader = class {
|
|
|
7004
6811
|
try {
|
|
7005
6812
|
const fileId = knowledgeFile.id;
|
|
7006
6813
|
const fileString = await readFile2(
|
|
7007
|
-
|
|
6814
|
+
resolve5(this.config.knowledgeFilePath, name),
|
|
7008
6815
|
"utf-8"
|
|
7009
6816
|
);
|
|
7010
6817
|
const spinner2 = ora(`Updating ${name}`).start();
|
|
@@ -7019,7 +6826,7 @@ var Uploader = class {
|
|
|
7019
6826
|
}
|
|
7020
6827
|
const spinner = ora(`Uploading ${name}`).start();
|
|
7021
6828
|
const fileBuffer = await readFile2(
|
|
7022
|
-
|
|
6829
|
+
resolve5(this.config.knowledgeFilePath, name)
|
|
7023
6830
|
);
|
|
7024
6831
|
let uploadedFileId = void 0;
|
|
7025
6832
|
try {
|
|
@@ -7057,7 +6864,7 @@ var Uploader = class {
|
|
|
7057
6864
|
}
|
|
7058
6865
|
}
|
|
7059
6866
|
async uploadKnowledge() {
|
|
7060
|
-
const resolvedPath =
|
|
6867
|
+
const resolvedPath = resolve5(this.config.knowledgeFilePath);
|
|
7061
6868
|
if (!await access2(resolvedPath).then(() => true).catch(() => false)) {
|
|
7062
6869
|
throw new Error(`File or folder not found at ${resolvedPath}`);
|
|
7063
6870
|
}
|
|
@@ -7097,7 +6904,7 @@ function addUploadKnowledgeCommand() {
|
|
|
7097
6904
|
const files = await uploader.filesApi.search("*");
|
|
7098
6905
|
console.debug(`found ${files.length} files`);
|
|
7099
6906
|
writeFileSync(
|
|
7100
|
-
|
|
6907
|
+
resolve5(uploader.config.knowledgeFilePath, "files.json"),
|
|
7101
6908
|
JSON.stringify(files, null, 2),
|
|
7102
6909
|
"utf-8"
|
|
7103
6910
|
);
|
|
@@ -7140,16 +6947,16 @@ function addUploadKnowledgeCommand() {
|
|
|
7140
6947
|
}
|
|
7141
6948
|
|
|
7142
6949
|
// src/react-demo-plugin/generate-lazy-demo-map.ts
|
|
7143
|
-
import { glob as
|
|
6950
|
+
import { glob as glob2 } from "glob";
|
|
7144
6951
|
import { uniqBy } from "lodash-es";
|
|
7145
6952
|
import { writeFile as writeFile4 } from "node:fs/promises";
|
|
7146
|
-
import { resolve as
|
|
7147
|
-
import { dedent
|
|
6953
|
+
import { resolve as resolve7 } from "node:path";
|
|
6954
|
+
import { dedent } from "@qualcomm-ui/utils/dedent";
|
|
7148
6955
|
|
|
7149
6956
|
// src/react-demo-plugin/demo-plugin-utils.ts
|
|
7150
|
-
import
|
|
7151
|
-
import { existsSync as existsSync2, readFileSync as
|
|
7152
|
-
import { dirname as dirname2, join as
|
|
6957
|
+
import chalk3 from "chalk";
|
|
6958
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
6959
|
+
import { dirname as dirname2, join as join4, relative as relative3, resolve as resolve6, sep } from "node:path";
|
|
7153
6960
|
import * as ts from "typescript";
|
|
7154
6961
|
import { pascalCase } from "@qualcomm-ui/utils/change-case";
|
|
7155
6962
|
function extractPageId(filePath, routesDir) {
|
|
@@ -7163,7 +6970,7 @@ function extractPageId(filePath, routesDir) {
|
|
|
7163
6970
|
}
|
|
7164
6971
|
function isDemoFile(filePath) {
|
|
7165
6972
|
try {
|
|
7166
|
-
return filePath.includes("/demos/") && filePath.endsWith(".tsx") && !
|
|
6973
|
+
return filePath.includes("/demos/") && filePath.endsWith(".tsx") && !readFileSync2(filePath).includes("export default");
|
|
7167
6974
|
} catch (error) {
|
|
7168
6975
|
return false;
|
|
7169
6976
|
}
|
|
@@ -7174,7 +6981,7 @@ async function scanForDemoPages({
|
|
|
7174
6981
|
demoPattern = "src/routes/**/demos/*.tsx",
|
|
7175
6982
|
routesDir = "src/routes"
|
|
7176
6983
|
}) {
|
|
7177
|
-
const demoFiles = (await
|
|
6984
|
+
const demoFiles = (await glob2(demoPattern)).filter((file) => isDemoFile(file));
|
|
7178
6985
|
return uniqBy(
|
|
7179
6986
|
demoFiles.map((file) => ({
|
|
7180
6987
|
pageId: extractPageId(file, routesDir),
|
|
@@ -7188,7 +6995,7 @@ function generateLazyDemoLoader(demoPages) {
|
|
|
7188
6995
|
return ` "${routePath}": () =>
|
|
7189
6996
|
import("virtual:qui-demo-scope/page:${pageId}")`;
|
|
7190
6997
|
}).sort().join(",\n");
|
|
7191
|
-
return
|
|
6998
|
+
return dedent`
|
|
7192
6999
|
/* eslint-disable */
|
|
7193
7000
|
|
|
7194
7001
|
// This file is generated automatically. Don't edit it directly.
|
|
@@ -7206,7 +7013,7 @@ function generateLazyDemoLoader(demoPages) {
|
|
|
7206
7013
|
}
|
|
7207
7014
|
async function generateLazyDemoMap(options) {
|
|
7208
7015
|
const routesDir = options.routesDir;
|
|
7209
|
-
const outputPath =
|
|
7016
|
+
const outputPath = resolve7(options.output);
|
|
7210
7017
|
console.log(`Scanning for demo pages in: ${routesDir}`);
|
|
7211
7018
|
const demoPages = await scanForDemoPages({ routesDir });
|
|
7212
7019
|
console.log(`Found ${demoPages.length} pages with demos`);
|