Skip to content

Commit

Permalink
feat: Validate installer name length
Browse files Browse the repository at this point in the history
  • Loading branch information
narze committed Jul 7, 2021
1 parent c00f10e commit e43d530
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IsIn,
IsNotEmptyObject,
IsString,
MaxLength,
validate,
} from "class-validator"
import { js2xml } from "xml-js"
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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
}

0 comments on commit e43d530

Please sign in to comment.