Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(site): add support for.sh and.tpl files to template editor#9674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 1 commit intomainfrombq/support-tpl-and-sh-files
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletionssite/src/components/TemplateFiles/TemplateFiles.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,17 @@ import { SyntaxHighlighter } from "components/SyntaxHighlighter/SyntaxHighlighte
import { UseTabResult } from "hooks/useTab";
import { FC } from "react";
import { combineClasses } from "utils/combineClasses";
import { TemplateVersionFiles } from "utils/templateVersion";
import { AllowedExtension, TemplateVersionFiles } from "utils/templateVersion";
import InsertDriveFileOutlined from "@mui/icons-material/InsertDriveFileOutlined";

const iconByExtension: Record<string, JSX.Element> = {
const iconByExtension: Record<AllowedExtension, JSX.Element> = {
tf: <TerraformIcon />,
md: <MarkdownIcon />,
mkd: <MarkdownIcon />,
Dockerfile: <DockerIcon />,
protobuf: <InsertDriveFileOutlined />,
sh: <InsertDriveFileOutlined />,
tpl: <InsertDriveFileOutlined />,
};

const getExtension = (filename: string) => {
Expand All@@ -24,11 +28,14 @@ const getExtension = (filename: string) => {
return filename;
};

const languageByExtension: Record<string, string> = {
const languageByExtension: Record<AllowedExtension, string> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
constlanguageByExtension:Record<AllowedExtension,string>={
constlanguageByExtension={

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

actually, move this wholeconst to templateVersion.ts

Copy link
CollaboratorAuthor

@BrunoQuaresmaBrunoQuaresmaSep 13, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Since this is only used on TemplateFiles, I would keep it there.

PS: After seeing your other comment I think it would make sense if thelanguageByExtesion would define the types but I left a comment there why I don't think this is the best option.

tf: "hcl",
md: "markdown",
mkd: "markdown",
Dockerfile: "dockerfile",
sh: "bash",
tpl: "tpl",
protobuf: "protobuf",
};

export const TemplateFiles: FC<{
Expand All@@ -47,7 +54,7 @@ export const TemplateFiles: FC<{
<div className={styles.tabs}>
{filenames.map((filename, index) => {
const tabValue = index.toString();
const extension = getExtension(filename);
const extension = getExtension(filename) as AllowedExtension;
const icon = iconByExtension[extension];
const hasDiff =
previousFiles &&
Expand DownExpand Up@@ -76,7 +83,11 @@ export const TemplateFiles: FC<{
<SyntaxHighlighter
value={currentFile}
compareWith={previousFile}
language={languageByExtension[getExtension(selectedFilename)]}
language={
languageByExtension[
getExtension(selectedFilename) as AllowedExtension
]
}
/>
</div>
);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,6 +40,8 @@ const defaultArgs: TemplateVersionPageViewProps = {
currentFiles: {
"README.md": readmeContent,
"main.tf": `{}`,
"some.tpl": `{{.Name}}`,
"some.sh": `echo "Hello world"`,
},
},
};
Expand Down
12 changes: 11 additions & 1 deletionsite/src/utils/templateVersion.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,17 @@ export const getTemplateVersionFiles = async (
return files;
};

export const allowedExtensions = ["tf", "md", "Dockerfile", "protobuf"];
export const allowedExtensions = [
"tf",
"md",
"mkd",
"Dockerfile",
"protobuf",
"sh",
"tpl",
] as const;

export type AllowedExtension = (typeof allowedExtensions)[number];
Comment on lines +26 to +36
Copy link
Member

@aslilacaslilacSep 13, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
exportconstallowedExtensions=[
"tf",
"md",
"mkd",
"Dockerfile",
"protobuf",
"sh",
"tpl",
]asconst;
exporttypeAllowedExtension=(typeofallowedExtensions)[number];
exporttypeAllowedExtension=keyoftypeoflanguageByExtension;

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hm... in this case theAllowedExtension should be defined from the arrayallowedExtensions and not the other way around. By having it in this way, we are not going to forget to update thelanguageByExtension when a new extension is added.

Copy link
Member

@aslilacaslilacSep 13, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

we just aren't using theallowedExtensions variable anywhere. we could even just definetype AllowedExtension = 'tf' | 'md' | ...

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

we are! we use it to do some checks + filtering when unzipping the template files.

Copy link
Member

@aslilacaslilacSep 14, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

oh, well then nevermind lmao. you're doing great. 💕


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

[8]ページ先頭

©2009-2025 Movatter.jp