Skip to content

Commit dd35daf

Browse files
committed
add custom file install and uninstall to template
1 parent ae0c9e8 commit dd35daf

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

src/controllers/template.contoller.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ interface TemplateRequestBody {
99
id: string;
1010
organization: string;
1111
version?: string;
12+
customCommands?: string;
1213
}
1314

1415
export class TemplateController {
1516
constructor(private templateService: TemplateFilesService) {}
1617

1718
async downloadEditedTemplate(req: Request, res: Response) {
1819
try {
19-
const { id, organization, version } = req.body as TemplateRequestBody;
20+
const { id, organization, version, customCommands } =
21+
req.body as TemplateRequestBody;
2022

2123
if (!id || !organization) {
2224
return res
@@ -32,15 +34,29 @@ export class TemplateController {
3234
return res.status(400).json({ error: "Invalid version" });
3335
}
3436

35-
const tempDir = await this.templateService.copyTemplateToTemp();
37+
if (customCommands && typeof customCommands !== "string") {
38+
return res.status(400).json({ error: "Invalid custom commands" });
39+
}
3640

37-
const replacements = {
38-
"<Replace me:Id>": `${id}`,
39-
"<Replace me:Organization>": `${organization}`,
40-
"<Replace me:Version>": version ? version : "Latest",
41-
};
41+
const tempDir = await this.templateService.copyTemplateToTemp();
4242

43-
await this.templateService.editTemplateFiles(tempDir, replacements);
43+
if (customCommands) {
44+
const replacements = {
45+
"<Replace me:Id>": `${id}`,
46+
"<Replace me:Organization>": `${organization}`,
47+
"<Replace me:Version>": version ? version : "Latest",
48+
"<Replace me:CustomFileInstall>": customCommands,
49+
"<Replace me:CustomFileUninstall>": customCommands,
50+
};
51+
await this.templateService.editTemplateFiles(tempDir, replacements);
52+
} else {
53+
const replacements = {
54+
"<Replace me:Id>": `${id}`,
55+
"<Replace me:Organization>": `${organization}`,
56+
"<Replace me:Version>": version ? version : "Latest",
57+
};
58+
await this.templateService.editTemplateFiles(tempDir, replacements);
59+
}
4460

4561
const zipPath = path.join(
4662
__dirname,

0 commit comments

Comments
 (0)