MCPcopy Create free account
hub / github.com/cosscom/coss / getFileContent

Function getFileContent

apps/ui/lib/registry.ts:56–86  ·  view source on GitHub ↗
(file: RegistryFile)

Source from the content-addressed store, hash-verified

54}
55
56async function getFileContent(file: RegistryFile) {
57 const raw = await fs.readFile(file.path, "utf-8");
58
59 const project = new Project({
60 compilerOptions: {},
61 });
62
63 const tempFile = await createTempSourceFile(file.path);
64 const sourceFile = project.createSourceFile(tempFile, raw, {
65 scriptKind: ScriptKind.TSX,
66 });
67
68 // Remove meta variables.
69 // removeVariable(sourceFile, "iframeHeight")
70 // removeVariable(sourceFile, "containerClassName")
71 // removeVariable(sourceFile, "description")
72
73 let code = sourceFile.getFullText();
74
75 // Some registry items uses default export.
76 // We want to use named export instead.
77 // TODO: do we really need this? - @shadcn.
78 // if (file.type !== "registry:page") {
79 // code = code.replaceAll("export default", "export")
80 // }
81
82 // Fix imports.
83 code = fixImport(code);
84
85 return code;
86}
87
88function getFileTarget(file: RegistryFile) {
89 let target = file.target;

Callers 1

getRegistryItemFunction · 0.85

Calls 2

createTempSourceFileFunction · 0.85
fixImportFunction · 0.85

Tested by

no test coverage detected