Skip to content

Commit e7b0181

Browse files
feat(site): add support to .sh and .tpl files (#9674)
1 parent e0e6d7c commit e7b0181

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

site/src/components/TemplateFiles/TemplateFiles.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import { SyntaxHighlighter } from "components/SyntaxHighlighter/SyntaxHighlighte
66
import { UseTabResult } from "hooks/useTab";
77
import { FC } from "react";
88
import { combineClasses } from "utils/combineClasses";
9-
import { TemplateVersionFiles } from "utils/templateVersion";
9+
import { AllowedExtension, TemplateVersionFiles } from "utils/templateVersion";
10+
import InsertDriveFileOutlined from "@mui/icons-material/InsertDriveFileOutlined";
1011

11-
const iconByExtension: Record<string, JSX.Element> = {
12+
const iconByExtension: Record<AllowedExtension, JSX.Element> = {
1213
tf: <TerraformIcon />,
1314
md: <MarkdownIcon />,
1415
mkd: <MarkdownIcon />,
1516
Dockerfile: <DockerIcon />,
17+
protobuf: <InsertDriveFileOutlined />,
18+
sh: <InsertDriveFileOutlined />,
19+
tpl: <InsertDriveFileOutlined />,
1620
};
1721

1822
const getExtension = (filename: string) => {
@@ -24,11 +28,14 @@ const getExtension = (filename: string) => {
2428
return filename;
2529
};
2630

27-
const languageByExtension: Record<string, string> = {
31+
const languageByExtension: Record<AllowedExtension, string> = {
2832
tf: "hcl",
2933
md: "markdown",
3034
mkd: "markdown",
3135
Dockerfile: "dockerfile",
36+
sh: "bash",
37+
tpl: "tpl",
38+
protobuf: "protobuf",
3239
};
3340

3441
export const TemplateFiles: FC<{
@@ -47,7 +54,7 @@ export const TemplateFiles: FC<{
4754
<div className={styles.tabs}>
4855
{filenames.map((filename, index) => {
4956
const tabValue = index.toString();
50-
const extension = getExtension(filename);
57+
const extension = getExtension(filename) as AllowedExtension;
5158
const icon = iconByExtension[extension];
5259
const hasDiff =
5360
previousFiles &&
@@ -76,7 +83,11 @@ export const TemplateFiles: FC<{
7683
<SyntaxHighlighter
7784
value={currentFile}
7885
compareWith={previousFile}
79-
language={languageByExtension[getExtension(selectedFilename)]}
86+
language={
87+
languageByExtension[
88+
getExtension(selectedFilename) as AllowedExtension
89+
]
90+
}
8091
/>
8192
</div>
8293
);

site/src/pages/TemplateVersionPage/TemplateVersionPageView.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const defaultArgs: TemplateVersionPageViewProps = {
4040
currentFiles: {
4141
"README.md": readmeContent,
4242
"main.tf": `{}`,
43+
"some.tpl": `{{.Name}}`,
44+
"some.sh": `echo "Hello world"`,
4345
},
4446
},
4547
};

site/src/utils/templateVersion.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ export const getTemplateVersionFiles = async (
2323
return files;
2424
};
2525

26-
export const allowedExtensions = ["tf", "md", "Dockerfile", "protobuf"];
26+
export const allowedExtensions = [
27+
"tf",
28+
"md",
29+
"mkd",
30+
"Dockerfile",
31+
"protobuf",
32+
"sh",
33+
"tpl",
34+
] as const;
35+
36+
export type AllowedExtension = (typeof allowedExtensions)[number];
2737

2838
export const isAllowedFile = (name: string) => {
2939
return allowedExtensions.some((ext) => name.endsWith(ext));

0 commit comments

Comments
 (0)