From e43d530c5a36333dd59671fa64fa31d7cf1eb337 Mon Sep 17 00:00:00 2001 From: Manassarn Manoonchai Date: Wed, 7 Jul 2021 22:58:24 +0700 Subject: [PATCH] feat: Validate installer name length --- main.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 1fb78b3..28803fb 100644 --- a/main.ts +++ b/main.ts @@ -6,6 +6,7 @@ import { IsIn, IsNotEmptyObject, IsString, + MaxLength, validate, } from "class-validator" import { js2xml } from "xml-js" @@ -34,6 +35,14 @@ export async function generateKlc( throw new Error(errors.map((e) => e.toString()).join(", ")) } + const windowsErrors = await validate( + plainToClass(WindowsAttributes, layout.os.windows) + ) + + if (windowsErrors.length) { + throw new Error(windowsErrors.map((e) => e.toString()).join(", ")) + } + const klcLocales = { Thai: "th-TH", } @@ -435,5 +444,19 @@ export class Layout { } interface OSAttributes { - windows: { company: string; localeId: string; installerName: string } + windows: WindowsAttributes +} + +class WindowsAttributes { + @IsString() + company: string + + @IsString() + localeId: string + + @IsString() + @MaxLength(8, { + message: "Installer name cannot be longer than 8 characters", + }) + installerName: string }