@renr/parcel-reporter-docgen 0.0.1-alpha.3 → 0.1.0-alpha.5
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.
|
@@ -3,11 +3,48 @@ import { fileURLToPath } from "url";
|
|
|
3
3
|
import fs from "fs/promises";
|
|
4
4
|
import { withCustomConfig } from "react-docgen-typescript";
|
|
5
5
|
import { glob } from "tinyglobby";
|
|
6
|
+
import ts from "typescript";
|
|
6
7
|
//#region src/generate-props.ts
|
|
7
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
9
|
path.dirname(__filename);
|
|
10
|
+
const fileMtimeCache = /* @__PURE__ */ new Map();
|
|
9
11
|
async function generateProps(pagesPattern, rootDir, outputPath, log = console.log) {
|
|
10
|
-
const
|
|
12
|
+
const files = await glob(pagesPattern, { cwd: rootDir });
|
|
13
|
+
if (files.length === 0) {
|
|
14
|
+
log(`No files found for pattern: ${pagesPattern}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const resolvedOutputPath = path.resolve(rootDir, outputPath);
|
|
18
|
+
await fs.mkdir(resolvedOutputPath, { recursive: true });
|
|
19
|
+
const filesToProcess = [];
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
const filePath = path.resolve(rootDir, file);
|
|
22
|
+
const componentName = path.basename(file, path.extname(file));
|
|
23
|
+
const outputFilePath = path.join(resolvedOutputPath, `${componentName}.json`);
|
|
24
|
+
try {
|
|
25
|
+
const sourceStat = await fs.stat(filePath);
|
|
26
|
+
const cachedMtime = fileMtimeCache.get(filePath);
|
|
27
|
+
let isUpToDate = false;
|
|
28
|
+
try {
|
|
29
|
+
const outStat = await fs.stat(outputFilePath);
|
|
30
|
+
if (cachedMtime !== void 0 && cachedMtime === sourceStat.mtimeMs || outStat.mtimeMs >= sourceStat.mtimeMs) {
|
|
31
|
+
isUpToDate = true;
|
|
32
|
+
fileMtimeCache.set(filePath, sourceStat.mtimeMs);
|
|
33
|
+
}
|
|
34
|
+
} catch (_unused) {}
|
|
35
|
+
if (isUpToDate) continue;
|
|
36
|
+
filesToProcess.push({
|
|
37
|
+
relFile: file,
|
|
38
|
+
absPath: filePath,
|
|
39
|
+
componentName
|
|
40
|
+
});
|
|
41
|
+
fileMtimeCache.set(filePath, sourceStat.mtimeMs);
|
|
42
|
+
} catch (_unused2) {}
|
|
43
|
+
}
|
|
44
|
+
if (filesToProcess.length === 0) return;
|
|
45
|
+
log(`Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`);
|
|
46
|
+
const tsconfigPath = path.resolve(rootDir, "./tsconfig.json");
|
|
47
|
+
const docgenParser = withCustomConfig(tsconfigPath, {
|
|
11
48
|
shouldExtractLiteralValuesFromEnum: true,
|
|
12
49
|
savePropValueAsString: true,
|
|
13
50
|
propFilter: (prop) => {
|
|
@@ -19,40 +56,64 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
|
|
|
19
56
|
return true;
|
|
20
57
|
}
|
|
21
58
|
});
|
|
22
|
-
const files = await glob(pagesPattern, { cwd: rootDir });
|
|
23
|
-
if (files.length === 0) {
|
|
24
|
-
log(`No files found for pattern: ${pagesPattern}`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
log(`Found ${files.length} files for pattern: ${pagesPattern}`);
|
|
28
|
-
await fs.mkdir(path.resolve(rootDir, outputPath), { recursive: true });
|
|
29
59
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
const absPaths = filesToProcess.map((f) => f.absPath);
|
|
61
|
+
const allDocs = docgenParser.parse(absPaths);
|
|
62
|
+
const docsByFilePath = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const doc of allDocs) if (doc.filePath) {
|
|
64
|
+
const key = path.resolve(doc.filePath);
|
|
65
|
+
const list = docsByFilePath.get(key) || [];
|
|
66
|
+
list.push(doc);
|
|
67
|
+
docsByFilePath.set(key, list);
|
|
68
|
+
}
|
|
69
|
+
await Promise.all(filesToProcess.map(async ({ relFile, absPath, componentName }) => {
|
|
70
|
+
log(`parsing file: : ${relFile}`);
|
|
71
|
+
const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];
|
|
72
|
+
const assignedInfo = getAssignedInfo(await fs.readFile(absPath, "utf-8"), componentName);
|
|
73
|
+
const primaryDoc = fileDocs.find((d) => d.displayName === componentName) || (assignedInfo.baseIdentifier ? fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier) : void 0) || fileDocs.find((d) => Object.keys(d.props).length > 0) || fileDocs[0];
|
|
74
|
+
let primaryProps = primaryDoc ? primaryDoc.props : {};
|
|
75
|
+
if (assignedInfo.baseIdentifier && primaryDoc && primaryDoc.displayName === componentName) {
|
|
76
|
+
const baseDoc = fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier);
|
|
77
|
+
if (baseDoc && Object.keys(baseDoc.props).length > Object.keys(primaryProps).length) primaryProps = baseDoc.props;
|
|
78
|
+
}
|
|
79
|
+
const formattedPrimaryProps = formatProps(primaryProps);
|
|
80
|
+
const subcomponents = {};
|
|
81
|
+
for (const [subName, targetName] of assignedInfo.subcomponentsMap) {
|
|
82
|
+
const subDoc = fileDocs.find((d) => d.displayName === targetName || d.displayName === `${componentName}.${subName}`);
|
|
83
|
+
if (subDoc) subcomponents[subName] = {
|
|
84
|
+
name: `${componentName}.${subName}`,
|
|
85
|
+
description: subDoc.description || void 0,
|
|
86
|
+
props: formatProps(subDoc.props)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
for (const doc of fileDocs) {
|
|
90
|
+
if (doc === primaryDoc) continue;
|
|
91
|
+
if (assignedInfo.baseIdentifier && doc.displayName === assignedInfo.baseIdentifier) continue;
|
|
92
|
+
let subName;
|
|
93
|
+
if (doc.displayName.startsWith(`${componentName}.`)) subName = doc.displayName.slice(componentName.length + 1);
|
|
94
|
+
else if (doc.displayName.startsWith(componentName)) subName = doc.displayName.slice(componentName.length);
|
|
95
|
+
if (subName) {
|
|
96
|
+
const existing = subcomponents[subName];
|
|
97
|
+
if (existing && Object.keys(existing.props).length >= Object.keys(doc.props).length) continue;
|
|
98
|
+
subcomponents[subName] = {
|
|
99
|
+
name: `${componentName}.${subName}`,
|
|
100
|
+
description: doc.description || void 0,
|
|
101
|
+
props: formatProps(doc.props)
|
|
102
|
+
};
|
|
44
103
|
}
|
|
45
104
|
}
|
|
46
105
|
const componentJSON = JSON.stringify({
|
|
47
106
|
name: componentName,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
107
|
+
description: (primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.description) || void 0,
|
|
108
|
+
path: relFile,
|
|
109
|
+
fileName: relFile.split("/").pop(),
|
|
110
|
+
props: formattedPrimaryProps,
|
|
111
|
+
subcomponents: Object.keys(subcomponents).length > 0 ? subcomponents : void 0
|
|
51
112
|
}, null, 2);
|
|
52
|
-
const outputFilePath = path.join(
|
|
113
|
+
const outputFilePath = path.join(resolvedOutputPath, `${componentName}.json`);
|
|
53
114
|
await fs.writeFile(outputFilePath, componentJSON + "\n", "utf-8");
|
|
54
115
|
log(`Generated props for ${componentName}`);
|
|
55
|
-
}
|
|
116
|
+
}));
|
|
56
117
|
} catch (err) {
|
|
57
118
|
log(`Error generating props: ${err.message}`);
|
|
58
119
|
}
|
|
@@ -83,6 +144,47 @@ function getShortPropType(name, type) {
|
|
|
83
144
|
detailedType: true
|
|
84
145
|
};
|
|
85
146
|
}
|
|
147
|
+
function formatProps(rawProps) {
|
|
148
|
+
const props = {};
|
|
149
|
+
for (const propName in rawProps) {
|
|
150
|
+
const rawProp = rawProps[propName];
|
|
151
|
+
if (!rawProp) continue;
|
|
152
|
+
const prop = { ...rawProp };
|
|
153
|
+
if (prop.type && prop.type.name) {
|
|
154
|
+
const { type: shortPropTypeName, detailedType } = getShortPropType(propName, prop.type.name);
|
|
155
|
+
const hasExpandedType = Boolean(detailedType);
|
|
156
|
+
prop.type.name = hasExpandedType && prop.type.name.split("|").length > 3 ? prop.type.name.split("|").map((line) => `| ${line}\n`).join("") : prop.type.name;
|
|
157
|
+
prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;
|
|
158
|
+
}
|
|
159
|
+
props[propName] = prop;
|
|
160
|
+
}
|
|
161
|
+
return props;
|
|
162
|
+
}
|
|
163
|
+
function getAssignedInfo(sourceText, compName) {
|
|
164
|
+
const sourceFile = ts.createSourceFile("temp.tsx", sourceText, ts.ScriptTarget.Latest, true);
|
|
165
|
+
let baseIdentifier = null;
|
|
166
|
+
const subcomponentsMap = /* @__PURE__ */ new Map();
|
|
167
|
+
ts.forEachChild(sourceFile, (node) => {
|
|
168
|
+
if (ts.isVariableStatement(node)) {
|
|
169
|
+
for (const decl of node.declarationList.declarations) if (decl.name.getText(sourceFile) === compName && decl.initializer && ts.isCallExpression(decl.initializer)) {
|
|
170
|
+
const call = decl.initializer;
|
|
171
|
+
const exprText = call.expression.getText(sourceFile);
|
|
172
|
+
if ((exprText === "Object.assign" || exprText.endsWith(".assign")) && call.arguments.length > 0) {
|
|
173
|
+
const firstArg = call.arguments[0];
|
|
174
|
+
if (firstArg) baseIdentifier = firstArg.getText(sourceFile);
|
|
175
|
+
if (call.arguments.length > 1 && ts.isObjectLiteralExpression(call.arguments[1])) {
|
|
176
|
+
for (const prop of call.arguments[1].properties) if (ts.isPropertyAssignment(prop)) subcomponentsMap.set(prop.name.getText(sourceFile), prop.initializer.getText(sourceFile));
|
|
177
|
+
else if (ts.isShorthandPropertyAssignment(prop)) subcomponentsMap.set(prop.name.getText(sourceFile), prop.name.getText(sourceFile));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
baseIdentifier,
|
|
185
|
+
subcomponentsMap
|
|
186
|
+
};
|
|
187
|
+
}
|
|
86
188
|
//#endregion
|
|
87
189
|
export { generateProps };
|
|
88
190
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-props.mjs","names":[],"sources":["../../src/generate-props.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport path from \"path\";\nimport { PropItem, withCustomConfig } from \"react-docgen-typescript\";\nimport { glob } from \"tinyglobby\";\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nexport async function generateProps(\n pagesPattern: string,\n rootDir: string,\n outputPath: string,\n log = console.log\n) {\n // TODO - should this be the root tsconfig, the parcel project tsconfig, or the ui library tsconfig?\n // TODO - make this configurable\n const tsconfigPath = path.resolve(rootDir, \"./tsconfig.json\");\n\n const docgenParser = withCustomConfig(tsconfigPath, {\n shouldExtractLiteralValuesFromEnum: true,\n savePropValueAsString: true,\n propFilter: (prop) => {\n if (Array.isArray(prop.declarations) && prop.declarations[0]) {\n const declaration = prop.declarations[0];\n\n if (declaration.fileName.includes(\"node_modules/@types/react\")) {\n if (prop.name !== \"ref\" && prop.name !== \"className\") {\n return false;\n }\n }\n }\n return true;\n },\n });\n\n const files = await glob(pagesPattern, {\n cwd: rootDir,\n });\n\n if (files.length === 0) {\n log(`No files found for pattern: ${pagesPattern}`);\n return;\n }\n\n log(`Found ${files.length} files for pattern: ${pagesPattern}`);\n\n await fs.mkdir(path.resolve(rootDir, outputPath), { recursive: true });\n\n try {\n for (const file of files) {\n log(`parsing file: : ${file}`);\n\n const componentName = path.basename(file, path.extname(file));\n const filePath = path.join(rootDir, file);\n\n const docs = docgenParser.parse(filePath);\n const props = docs[0] ? docs[0].props : {};\n\n for (const propName in props) {\n const prop = props[propName] as\n | (PropItem & {\n shortPropTypeName: string | null;\n })\n | undefined;\n\n if (!prop) {\n throw new Error(`No prop found for ${propName} in ${componentName}`);\n }\n\n if (prop.type && prop.type.name) {\n const { type: shortPropTypeName, detailedType } = getShortPropType(\n propName,\n prop.type.name\n );\n\n const hasExpandedType = Boolean(detailedType);\n\n prop.type.name =\n hasExpandedType && prop.type.name.split(\"|\").length > 3\n ? prop.type.name\n .split(\"|\")\n .map((line) => `| ${line}\\n`)\n .join(\"\")\n : prop.type.name;\n\n prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;\n }\n }\n\n const componentJSON = JSON.stringify(\n {\n name: componentName,\n path: file,\n fileName: file.split(\"/\").pop(),\n props,\n },\n null,\n 2\n );\n\n const outputFilePath = path.join(outputPath, `${componentName}.json`);\n await fs.writeFile(outputFilePath, componentJSON + \"\\n\", \"utf-8\");\n\n log(`Generated props for ${componentName}`);\n }\n } catch (err) {\n log(`Error generating props: ${(err as Error).message}`);\n }\n}\n\n// based on https://github.com/mui/base-ui/blob/master/docs/src/components/ReferenceTable/PropsReferenceAccordion.tsx\nfunction getShortPropType(name: string, type: string) {\n if (/^(on|get)[A-Z].*/.test(name)) {\n return { type: \"function\", detailedType: true };\n }\n\n if (type === undefined || type === null) {\n return { type: String(type), detailedType: false };\n }\n\n if (name === \"className\") {\n return { type: \"string | function\", detailedType: true };\n }\n\n if (name === \"render\") {\n return { type: \"ReactElement | function\", detailedType: true };\n }\n\n if (\n name.endsWith(\"Ref\") ||\n name === \"children\" ||\n type === \"boolean\" ||\n type === \"string\" ||\n type === \"number\" ||\n type.indexOf(\" | \") === -1 ||\n (type.split(\"|\").length < 3 && type.length < 30)\n ) {\n return { type, detailedType: false };\n }\n\n return { type: \"Union\", detailedType: true };\n}\n"],"mappings":";;;;;;AAMA,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AAC/B,KAAK,QAAQ,WAAW;AAE1C,eAAsB,cACpB,cACA,SACA,YACA,MAAM,QAAQ,KACd;CAKA,MAAM,eAAe,iBAFA,KAAK,QAAQ,SAAS,kBAEO,EAAE;EAClD,oCAAoC;EACpC,uBAAuB;EACvB,aAAa,SAAS;GACpB,IAAI,MAAM,Q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N,UAAU,KAAK,MAAM,IAAI,CAAC,KAAK;IAC/B;IACD,EACD,MACA,EACD;GAED,MAAM,iBAAiB,KAAK,KAAK,YAAY,GAAG,cAAc,OAAO;GACrE,MAAM,GAAG,UAAU,gBAAgB,gBAAgB,MAAM,QAAQ;GAEjE,IAAI,uBAAuB,gBAAgB;;UAEtC,KAAK;EACZ,IAAI,2BAA4B,IAAc,UAAU;;;AAK5D,SAAS,iBAAiB,MAAc,MAAc;CACpD,IAAI,mBAAmB,KAAK,KAAK,EAC/B,OAAO;EAAE,MAAM;EAAY,cAAc;EAAM;CAGjD,IAAI,SAAS,KAAA,KAAa,SAAS,MACjC,OAAO;EAAE,MAAM,OAAO,KAAK;EAAE,cAAc;EAAO;CAGpD,IAAI,SAAS,aACX,OAAO;EAAE,MAAM;EAAqB,cAAc;EAAM;CAG1D,IAAI,SAAS,UACX,OAAO;EAAE,MAAM;EAA2B,cAAc;EAAM;CAGhE,IACE,KAAK,SAAS,MAAM,IACpB,SAAS,cACT,SAAS,aACT,SAAS,YACT,SAAS,YACT,KAAK,QAAQ,MAAM,KAAK,MACvB,KAAK,MAAM,IAAI,CAAC,SAAS,KAAK,KAAK,SAAS,IAE7C,OAAO;EAAE;EAAM,cAAc;EAAO;CAGtC,OAAO;EAAE,MAAM;EAAS,cAAc;EAAM"}
|
|
1
|
+
{"version":3,"file":"generate-props.mjs","names":[],"sources":["../../src/generate-props.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport path from \"path\";\nimport { PropItem, withCustomConfig } from \"react-docgen-typescript\";\nimport { glob } from \"tinyglobby\";\nimport ts from \"typescript\";\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// cache for watch mode across buildStart events\nconst fileMtimeCache = new Map<string, number>();\n\nexport async function generateProps(\n pagesPattern: string,\n rootDir: string,\n outputPath: string,\n log = console.log\n) {\n const files = await glob(pagesPattern, {\n cwd: rootDir,\n });\n\n if (files.length === 0) {\n log(`No files found for pattern: ${pagesPattern}`);\n return;\n }\n\n const resolvedOutputPath = path.resolve(rootDir, outputPath);\n await fs.mkdir(resolvedOutputPath, { recursive: true });\n\n const filesToProcess: {\n relFile: string;\n absPath: string;\n componentName: string;\n }[] = [];\n\n for (const file of files) {\n const filePath = path.resolve(rootDir, file);\n const componentName = path.basename(file, path.extname(file));\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n\n try {\n const sourceStat = await fs.stat(filePath);\n const cachedMtime = fileMtimeCache.get(filePath);\n\n let isUpToDate = false;\n try {\n const outStat = await fs.stat(outputFilePath);\n if (\n (cachedMtime !== undefined && cachedMtime === sourceStat.mtimeMs) ||\n outStat.mtimeMs >= sourceStat.mtimeMs\n ) {\n isUpToDate = true;\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n }\n } catch {\n // output file does not exist\n }\n\n if (isUpToDate) {\n continue;\n }\n\n filesToProcess.push({\n relFile: file,\n absPath: filePath,\n componentName,\n });\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n } catch {\n // source file not accessible\n }\n }\n\n if (filesToProcess.length === 0) {\n return;\n }\n\n log(\n `Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`\n );\n\n // TODO - should this be the root tsconfig, the parcel project tsconfig, or the ui library tsconfig?\n // TODO - make this configurable\n const tsconfigPath = path.resolve(rootDir, \"./tsconfig.json\");\n\n const docgenParser = withCustomConfig(tsconfigPath, {\n shouldExtractLiteralValuesFromEnum: true,\n savePropValueAsString: true,\n propFilter: (prop) => {\n if (Array.isArray(prop.declarations) && prop.declarations[0]) {\n const declaration = prop.declarations[0];\n\n if (declaration.fileName.includes(\"node_modules/@types/react\")) {\n if (prop.name !== \"ref\" && prop.name !== \"className\") {\n return false;\n }\n }\n }\n return true;\n },\n });\n\n try {\n const absPaths = filesToProcess.map((f) => f.absPath);\n const allDocs = docgenParser.parse(absPaths);\n\n const docsByFilePath = new Map<string, typeof allDocs>();\n for (const doc of allDocs) {\n if (doc.filePath) {\n const key = path.resolve(doc.filePath);\n const list = docsByFilePath.get(key) || [];\n list.push(doc);\n docsByFilePath.set(key, list);\n }\n }\n\n await Promise.all(\n filesToProcess.map(async ({ relFile, absPath, componentName }) => {\n log(`parsing file: : ${relFile}`);\n\n const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];\n\n // Check if the component was composed using Object.assign(Base, { SubName: Target, ... })\n const sourceText = await fs.readFile(absPath, \"utf-8\");\n const assignedInfo = getAssignedInfo(sourceText, componentName);\n\n // 1. Identify primary component doc matching componentName or assigned base\n const primaryDoc =\n fileDocs.find((d) => d.displayName === componentName) ||\n (assignedInfo.baseIdentifier\n ? fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n )\n : undefined) ||\n fileDocs.find((d) => Object.keys(d.props).length > 0) ||\n fileDocs[0];\n\n // If primaryDoc was created by Object.assign and lost props, recover from base\n let primaryProps = primaryDoc ? primaryDoc.props : {};\n if (\n assignedInfo.baseIdentifier &&\n primaryDoc &&\n primaryDoc.displayName === componentName\n ) {\n const baseDoc = fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n );\n if (\n baseDoc &&\n Object.keys(baseDoc.props).length > Object.keys(primaryProps).length\n ) {\n primaryProps = baseDoc.props;\n }\n }\n\n const formattedPrimaryProps = formatProps(primaryProps);\n\n // 2. Identify subcomponents\n const subcomponents: Record<\n string,\n {\n name: string;\n description?: string;\n props: ReturnType<typeof formatProps>;\n }\n > = {};\n\n // a) Handle subcomponents explicitly assigned via Object.assign(Base, { SubName: Target })\n for (const [subName, targetName] of assignedInfo.subcomponentsMap) {\n const subDoc = fileDocs.find(\n (d) =>\n d.displayName === targetName ||\n d.displayName === `${componentName}.${subName}`\n );\n if (subDoc) {\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: subDoc.description || undefined,\n props: formatProps(subDoc.props),\n };\n }\n }\n\n // b) Handle subcomponents matching standard React dot notation or component prefix\n for (const doc of fileDocs) {\n if (doc === primaryDoc) continue;\n if (\n assignedInfo.baseIdentifier &&\n doc.displayName === assignedInfo.baseIdentifier\n ) {\n continue;\n }\n\n let subName: string | undefined;\n if (doc.displayName.startsWith(`${componentName}.`)) {\n subName = doc.displayName.slice(componentName.length + 1);\n } else if (doc.displayName.startsWith(componentName)) {\n subName = doc.displayName.slice(componentName.length);\n }\n\n if (subName) {\n const existing = subcomponents[subName];\n if (\n existing &&\n Object.keys(existing.props).length >=\n Object.keys(doc.props).length\n ) {\n continue;\n }\n\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: doc.description || undefined,\n props: formatProps(doc.props),\n };\n }\n }\n\n const componentJSON = JSON.stringify(\n {\n name: componentName,\n description: primaryDoc?.description || undefined,\n path: relFile,\n fileName: relFile.split(\"/\").pop(),\n props: formattedPrimaryProps,\n subcomponents:\n Object.keys(subcomponents).length > 0 ? subcomponents : undefined,\n },\n null,\n 2\n );\n\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n await fs.writeFile(outputFilePath, componentJSON + \"\\n\", \"utf-8\");\n\n log(`Generated props for ${componentName}`);\n })\n );\n } catch (err) {\n log(`Error generating props: ${(err as Error).message}`);\n }\n}\n\n// based on https://github.com/mui/base-ui/blob/master/docs/src/components/ReferenceTable/PropsReferenceAccordion.tsx\nfunction getShortPropType(name: string, type: string) {\n if (/^(on|get)[A-Z].*/.test(name)) {\n return { type: \"function\", detailedType: true };\n }\n\n if (type === undefined || type === null) {\n return { type: String(type), detailedType: false };\n }\n\n if (name === \"className\") {\n return { type: \"string | function\", detailedType: true };\n }\n\n if (name === \"render\") {\n return { type: \"ReactElement | function\", detailedType: true };\n }\n\n if (\n name.endsWith(\"Ref\") ||\n name === \"children\" ||\n type === \"boolean\" ||\n type === \"string\" ||\n type === \"number\" ||\n type.indexOf(\" | \") === -1 ||\n (type.split(\"|\").length < 3 && type.length < 30)\n ) {\n return { type, detailedType: false };\n }\n\n return { type: \"Union\", detailedType: true };\n}\n\nfunction formatProps(rawProps: Record<string, PropItem>) {\n const props: Record<\n string,\n PropItem & {\n shortPropTypeName: string | null;\n }\n > = {};\n\n for (const propName in rawProps) {\n const rawProp = rawProps[propName];\n if (!rawProp) {\n continue;\n }\n\n const prop = { ...rawProp } as PropItem & {\n shortPropTypeName: string | null;\n };\n\n if (prop.type && prop.type.name) {\n const { type: shortPropTypeName, detailedType } = getShortPropType(\n propName,\n prop.type.name\n );\n\n const hasExpandedType = Boolean(detailedType);\n\n prop.type.name =\n hasExpandedType && prop.type.name.split(\"|\").length > 3\n ? prop.type.name\n .split(\"|\")\n .map((line) => `| ${line}\\n`)\n .join(\"\")\n : prop.type.name;\n\n prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;\n }\n\n props[propName] = prop;\n }\n\n return props;\n}\n\nfunction getAssignedInfo(sourceText: string, compName: string) {\n const sourceFile = ts.createSourceFile(\n \"temp.tsx\",\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n let baseIdentifier: string | null = null;\n const subcomponentsMap = new Map<string, string>();\n\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isVariableStatement(node)) {\n for (const decl of node.declarationList.declarations) {\n if (\n decl.name.getText(sourceFile) === compName &&\n decl.initializer &&\n ts.isCallExpression(decl.initializer)\n ) {\n const call = decl.initializer;\n const exprText = call.expression.getText(sourceFile);\n if (\n (exprText === \"Object.assign\" || exprText.endsWith(\".assign\")) &&\n call.arguments.length > 0\n ) {\n const firstArg = call.arguments[0];\n if (firstArg) {\n baseIdentifier = firstArg.getText(sourceFile);\n }\n if (\n call.arguments.length > 1 &&\n ts.isObjectLiteralExpression(call.arguments[1]!)\n ) {\n for (const prop of call.arguments[1]!.properties) {\n if (ts.isPropertyAssignment(prop)) {\n subcomponentsMap.set(\n prop.name.getText(sourceFile),\n prop.initializer.getText(sourceFile)\n );\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n subcomponentsMap.set(\n prop.name.getText(sourceFile),\n prop.name.getText(s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
package/dist/esm/index.d.mts
CHANGED
package/dist/esm/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/index.ts"],"mappings":""}
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["pacakgeJSON.name"],"sources":["../../src/index.ts"],"sourcesContent":["import ThrowableDiagnostic from \"@parcel/diagnostic\";\nimport { Reporter } from \"@parcel/plugin\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { generateProps } from \"./generate-props.js\";\nimport pacakgeJSON from \"../package.json\" with { type: \"json\" };\nimport dedent from \"dedent\";\n\nconst origin = pacakgeJSON.name;\n\nexport default new Reporter({\n async report({ event, options, logger }) {\n if (event.type === \"buildStart\") {\n try {\n const packageJSON = path.join(options.projectRoot, \"package.json\");\n\n const fileURL = pathToFileURL(packageJSON).toString();\n\n const config = (await import(fileURL, {\n with: {\n type: \"json\",\n },\n }).then((mod) => mod.default)) as {\n [origin]?: {\n source: string;\n output?: string;\n };\n };\n\n const source = config[origin]?.source;\n const output = config[origin]?.output;\n\n if (!source) {\n // @ts-expect-error compiled verison needs to use default\n throw new ThrowableDiagnostic.default({\n diagnostic: {\n origin,\n message: dedent`No \"@renr/parcel-reporter-docgen\" source found in package.json. \n NOTE: if you are using a monorepo, you need to run parcel from the package that contains your pages rather than the project root.\n See https://github.com/parcel-bundler/parcel/issues/7206 for a workaround.`,\n // TODO why isn't the hint/documentation showing up in the terminal/error page?\n hints: [\n 'Add a \"@renr/parcel-reporter-docgen\" source to your package.json with a source e.g `../packages/ui/src/**/*.{ts,tsx}`.',\n ],\n\n codeFrames: [\n {\n codeHighlights: [\n {\n start: { line: 3, column: 2 },\n end: { line: 7, column: 44 },\n message:\n 'Add a \"@renr/parcel-reporter-docgen\" source to generate docs for your UI components.',\n },\n ],\n language: \"json\",\n filePath: packageJSON,\n code: dedent`{\n \"@renr/parcel-reporter-docgen\": {\n \"source\": \"../packages/ui/src/**/*.{ts,tsx}\",\n \"output\": \"docs/components\"\n }\n } `,\n },\n ],\n },\n });\n }\n try {\n await generateProps(\n source,\n options.projectRoot,\n output || \"docgen\",\n (...args) => logger.info({ origin, message: args.join(\" \") })\n );\n } catch (error) {\n throwError(error as Error);\n }\n } catch (error) {\n throwError(error as Error);\n }\n return;\n }\n },\n});\n\nfunction throwError(error: Error) {\n // @ts-expect-error compiled verison needs to use default\n throw new ThrowableDiagnostic.default({\n diagnostic: {\n origin,\n message: error.message,\n stack: error.stack,\n },\n });\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,SAASA;AAEf,IAAA,cAAe,IAAI,SAAS,EAC1B,MAAM,OAAO,EAAE,OAAO,SAAS,UAAU;CACvC,IAAI,MAAM,SAAS,cAAc;EAC/B,IAAI;;GACF,MAAM,cAAc,KAAK,KAAK,QAAQ,aAAa,
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["pacakgeJSON.name"],"sources":["../../src/index.ts"],"sourcesContent":["import ThrowableDiagnostic from \"@parcel/diagnostic\";\nimport { Reporter } from \"@parcel/plugin\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { generateProps } from \"./generate-props.js\";\nimport pacakgeJSON from \"../package.json\" with { type: \"json\" };\nimport dedent from \"dedent\";\n\nconst origin = pacakgeJSON.name;\n\nexport default new Reporter({\n async report({ event, options, logger }) {\n if (event.type === \"buildStart\") {\n try {\n const packageJSON = path.join(options.projectRoot, \"package.json\");\n\n const fileURL = pathToFileURL(packageJSON).toString();\n\n const config = (await import(fileURL, {\n with: {\n type: \"json\",\n },\n }).then((mod) => mod.default)) as {\n [origin]?: {\n source: string;\n output?: string;\n };\n };\n\n const source = config[origin]?.source;\n const output = config[origin]?.output;\n\n if (!source) {\n // @ts-expect-error compiled verison needs to use default\n throw new ThrowableDiagnostic.default({\n diagnostic: {\n origin,\n message: dedent`No \"@renr/parcel-reporter-docgen\" source found in package.json. \n NOTE: if you are using a monorepo, you need to run parcel from the package that contains your pages rather than the project root.\n See https://github.com/parcel-bundler/parcel/issues/7206 for a workaround.`,\n // TODO why isn't the hint/documentation showing up in the terminal/error page?\n hints: [\n 'Add a \"@renr/parcel-reporter-docgen\" source to your package.json with a source e.g `../packages/ui/src/**/*.{ts,tsx}`.',\n ],\n\n codeFrames: [\n {\n codeHighlights: [\n {\n start: { line: 3, column: 2 },\n end: { line: 7, column: 44 },\n message:\n 'Add a \"@renr/parcel-reporter-docgen\" source to generate docs for your UI components.',\n },\n ],\n language: \"json\",\n filePath: packageJSON,\n code: dedent`{\n \"@renr/parcel-reporter-docgen\": {\n \"source\": \"../packages/ui/src/**/*.{ts,tsx}\",\n \"output\": \"docs/components\"\n }\n } `,\n },\n ],\n },\n });\n }\n try {\n await generateProps(\n source,\n options.projectRoot,\n output || \"docgen\",\n (...args) => logger.info({ origin, message: args.join(\" \") })\n );\n } catch (error) {\n throwError(error as Error);\n }\n } catch (error) {\n throwError(error as Error);\n }\n return;\n }\n },\n});\n\nfunction throwError(error: Error) {\n // @ts-expect-error compiled verison needs to use default\n throw new ThrowableDiagnostic.default({\n diagnostic: {\n origin,\n message: error.message,\n stack: error.stack,\n },\n });\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,SAASA;AAEf,IAAA,cAAe,IAAI,SAAS,EAC1B,MAAM,OAAO,EAAE,OAAO,SAAS,UAAU;CACvC,IAAI,MAAM,SAAS,cAAc;EAC/B,IAAI;;GACF,MAAM,cAAc,KAAK,KAAK,QAAQ,aAAa,cAAc;GAIjE,MAAM,SAAU,MAAM,OAFN,cAAc,WAAW,CAAC,CAAC,SAER,GAAG,EACpC,MAAM,EACJ,MAAM,OACR,EACF,EAAE,CAAC,MAAM,QAAQ,IAAI,OAAO;GAO5B,MAAM,UAAA,iBAAS,OAAO,aAAA,QAAA,mBAAA,KAAA,IAAA,KAAA,IAAA,eAAS;GAC/B,MAAM,UAAA,kBAAS,OAAO,aAAA,QAAA,oBAAA,KAAA,IAAA,KAAA,IAAA,gBAAS;GAE/B,IAAI,CAAC,QAEH,MAAM,IAAI,oBAAoB,QAAQ,EACpC,YAAY;IACV;IACA,SAAS,MAAM;;;IAIf,OAAO,CACL,0HACF;IAEA,YAAY,CACV;KACE,gBAAgB,CACd;MACE,OAAO;OAAE,MAAM;OAAG,QAAQ;MAAE;MAC5B,KAAK;OAAE,MAAM;OAAG,QAAQ;MAAG;MAC3B,SACE;KACJ,CACF;KACA,UAAU;KACV,UAAU;KACV,MAAM,MAAM;;;;;;IAMd,CACF;GACF,EACF,CAAC;GAEH,IAAI;IACF,MAAM,cACJ,QACA,QAAQ,aACR,UAAU,WACT,GAAG,SAAS,OAAO,KAAK;KAAE;KAAQ,SAAS,KAAK,KAAK,GAAG;IAAE,CAAC,CAC9D;GACF,SAAS,OAAO;IACd,WAAW,KAAc;GAC3B;EACF,SAAS,OAAO;GACd,WAAW,KAAc;EAC3B;EACA;CACF;AACF,EACF,CAAC;AAED,SAAS,WAAW,OAAc;CAEhC,MAAM,IAAI,oBAAoB,QAAQ,EACpC,YAAY;EACV;EACA,SAAS,MAAM;EACf,OAAO,MAAM;CACf,EACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renr/parcel-reporter-docgen",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"author": "Ren Rizzolo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Parcel reporter that generates ui docs via react-docgen-typescript",
|
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
"@parcel/diagnostic": "^2.16.4",
|
|
30
30
|
"@parcel/plugin": "^2.16.4",
|
|
31
31
|
"dedent": "^1.7.2",
|
|
32
|
-
"tinyglobby": "^0.2.
|
|
33
|
-
"prettier": "^3.
|
|
32
|
+
"tinyglobby": "^0.2.17",
|
|
33
|
+
"prettier": "^3.9.9",
|
|
34
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@types/node": "^25.6.2"
|
|
@@ -40,6 +41,6 @@
|
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "tsdown",
|
|
43
|
-
"type-check": "
|
|
44
|
+
"type-check": "tsc --noEmit"
|
|
44
45
|
}
|
|
45
46
|
}
|