@@ -7,6 +7,11 @@ import { input as inputCharsets, output as outputCharsets } from './charsets.ts'
77
88const REGEX_HEX_NUMBER = / ^ [ 0 - 9 a - f A - F ] + $ / ;
99
10+ /**
11+ * Detects the output file from the NSIS output.
12+ * @param str - The string to search for the output file.
13+ * @returns The detected output file path or null if not found.
14+ */
1015function detectOutfile ( str : string ) : null | string {
1116 if ( str . includes ( 'Output: "' ) ) {
1217 const regex = / O u t p u t : " ( .* .e x e ) " / g;
@@ -24,6 +29,13 @@ function detectOutfile(str: string): null | string {
2429 return null ;
2530}
2631
32+ /**
33+ * Normalizes the output of the `makensis` command.
34+ * @param stream - The stream options containing stdout and stderr.
35+ * @param args - The arguments passed to the `makensis` command.
36+ * @param opts - The compiler options used for the makensis functions.
37+ * @returns normalized output with stdout and stderr or JSON.
38+ */
2739function formatOutput (
2840 stream : Makensis . StreamOptions ,
2941 args : Array < string > ,
@@ -63,6 +75,10 @@ function formatOutput(
6375 return output ;
6476}
6577
78+ /**
79+ * Filters environment variables that start with `NSIS_APP_` prefix.
80+ * @returns An object containing the filtered environment variables.
81+ */
6682function getMagicEnvVars ( ) : Makensis . EnvironmentVariables {
6783 const definitions : Makensis . EnvironmentVariables = { } ;
6884 const prefix = 'NSIS_APP_' ;
@@ -77,6 +93,11 @@ function getMagicEnvVars(): Makensis.EnvironmentVariables {
7793 return definitions ;
7894}
7995
96+ /**
97+ * Checks the output for common NodeJS errors.
98+ * @param input - The input string to check for error codes.
99+ * @returns true if the input contains an error code, false otherwise.
100+ */
80101function hasErrorCode ( input : string ) {
81102 if ( input ?. includes ( 'ENOENT' ) && input . match ( / \b E N O E N T \b / ) ) {
82103 return true ;
@@ -94,6 +115,11 @@ function hasErrorCode(input: string) {
94115 return false ;
95116}
96117
118+ /**
119+ * Checks if the given line contains warnings and returns the count.
120+ * @param line - The line to check for warnings.
121+ * @returns The number of warnings found in the line.
122+ */
97123function hasWarnings ( line : string ) : number {
98124 const match = line . match ( / ( \d + ) w a r n i n g s ? : / ) ;
99125
@@ -104,19 +130,39 @@ function hasWarnings(line: string): number {
104130 return 0 ;
105131}
106132
133+ /**
134+ * Checks if the given value is a hexadecimal number string.
135+ * @param x - The value to check if it is a hexadecimal number.
136+ * @returns true if the value is a hexadecimal number, false otherwise.
137+ */
107138function isHex ( x : number | string ) : boolean {
108139 return REGEX_HEX_NUMBER . test ( String ( x ) ) ;
109140}
110141
142+ /**
143+ * Helper function to check if a number is numeric.
144+ * @param x - The number to check.
145+ * @returns true if the number is numeric, false otherwise.
146+ */
111147function isNumeric ( x : number ) : boolean {
112148 return ! Number . isNaN ( x ) ;
113149}
114150
151+ /**
152+ * Checks if a value is within a specified range.
153+ * @param value - The value to check.
154+ * @param min - The minimum value of the range.
155+ * @param max - The maximum value of the range.
156+ * @returns true if the value is within the range, false otherwise.
157+ */
115158function inRange ( value : number , min : number , max : number ) : boolean {
116159 return value >= min && value <= max ;
117160}
118161
119162/**
163+ * Maps argument options to flags to be passed to `makensis` command.
164+ * @param args - The arguments to be passed to `makensis`.
165+ * @param options - The compiler options to be used.
120166 * @private
121167 */
122168export function mapArguments ( args : string [ ] , options : Makensis . CompilerOptions ) : Makensis . MapArguments {
@@ -467,6 +513,12 @@ export function splitCommands(data: string | string[]): string[] {
467513 return args ;
468514}
469515
516+ /**
517+ * Splits the input string into lines based on the platform-specific line break.
518+ * @param input - The input string to split into lines.
519+ * @param opts - Compiler options that may affect line splitting (e.g., wine).
520+ * @returns An array of strings, each representing a line from the input.
521+ */
470522function splitLines ( input : string , opts : Makensis . CompilerOptions = { } ) : string [ ] {
471523 const lineBreak = platform ( ) === 'win32' || opts . wine === true ? '\r\n' : '\n' ;
472524 const output = input . split ( lineBreak ) ;
0 commit comments