-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformFileContent.ts
35 lines (32 loc) · 1.04 KB
/
transformFileContent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { ComponentInfo } from './types.ts';
/**
* Transforms a file's content by replacing all variations of the component name with Handlebars placeholders
* @param sourceFilePath Path to the source file to transform
* @param componentInfo Object containing the component name and its case variations
* @returns Promise resolving to the transformed content as a string
*/
export async function transformFileContent(
sourceFilePath: string,
componentInfo: ComponentInfo
): Promise<string> {
const content = await Deno.readTextFile(sourceFilePath);
let transformedContent = content;
const { variations } = componentInfo;
transformedContent = transformedContent.replaceAll(
variations.pascal,
'{{pascalCaseName}}'
);
transformedContent = transformedContent.replaceAll(
variations.camel,
'{{camelCaseName}}'
);
transformedContent = transformedContent.replaceAll(
variations.kebab,
'{{kebabCaseName}}'
);
transformedContent = transformedContent.replaceAll(
variations.snake,
'{{snakeCaseName}}'
);
return transformedContent;
}