MCPcopy Index your code
hub / github.com/alibaba/lowcode-engine / generateDTS

Function generateDTS

modules/material-parser/src/parse/ts/generateDTS.ts:15–56  ·  view source on GitHub ↗
({
  workDir,
  dslType = 'react',
}: {
  workDir: string;
  dslType?: string;
})

Source from the content-addressed store, hash-verified

13 * @returns {string} - the path of generated xxx.d.ts
14 */
15export default function generateDTS({
16 workDir,
17 dslType = 'react',
18}: {
19 workDir: string;
20 dslType?: string;
21}): {
22 originalTypePath: string;
23 newTypePath: string;
24} {
25 const typeDir = path.join(workDir, 'node_modules', `@types/${dslType}`);
26 const typePath = path.join(typeDir, 'index.d.ts');
27 const fileContent = loadFile(typePath);
28 // const materialParserTypeDir = path.join(workDir, `node_modules/material-parser-types/${type}`);
29 // ensureDirSync(materialParserTypeDir);
30 const materialParserTypeDir = typeDir;
31 const newTypePath = path.join(materialParserTypeDir, 'index.d.ts');
32 // if (!pathExistsSync(newTypePath)) {
33 // copySync(
34 // path.join(typeDir, 'global.d.ts'),
35 // path.join(materialParserTypeDir, 'global.d.ts'),
36 // );
37 let newContent = fileContent.replace(
38 /(?<=interface HTMLAttributes[^e]+)(extends[^}]+)/,
39 `{
40 style?: CSSProperties;
41 className?: string;
42 `,
43 );
44 newContent = newContent.replace(/(?<=interface IntrinsicElements {)([^}]+)/, '');
45 newContent = newContent.replace(/type LibraryManagedAttributes[^;]+;/, '');
46 writeFileSync(newTypePath, newContent);
47 log('generate dts', newTypePath);
48 // } else {
49 // log('found dts', newTypePath);
50 // }
51
52 return {
53 originalTypePath: typePath,
54 newTypePath,
55 };
56}

Callers 1

parseTSFunction · 0.85

Calls 2

loadFileFunction · 0.90
replaceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…