Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Nov 17, 2024
1 parent 91dd2c1 commit bdd5c44
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
12 changes: 11 additions & 1 deletion src/charsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ const codePages: string[] = codepages().map((cp: number) => `CP${cp}`);

export const input: string[] = ['ACP', ...codePages, 'OEM', 'UTF8', 'UTF16BE', 'UTF16LE'];

export const output: string[] = ['ACP', ...codePages, 'OEM', 'UTF16BE', 'UTF16BEBOM', 'UTF16LE', 'UTF16LEBOM', 'UTF8', 'UTF8SIG'];
export const output: string[] = [
'ACP',
...codePages,
'OEM',
'UTF16BE',
'UTF16BEBOM',
'UTF16LE',
'UTF16LEBOM',
'UTF8',
'UTF8SIG',
];
32 changes: 25 additions & 7 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import type Makensis from '../types';
* @param compilerOptions - compiler options
* @returns - usage description
*/
export async function commandHelp(command = '', compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
export async function commandHelp(
command = '',
compilerOptions: Makensis.CompilerOptions = {},
spawnOptions: SpawnOptions = {},
): Promise<Makensis.CompilerOutput> {
const options: Makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };

const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-CMDHELP'], options);
Expand All @@ -26,7 +30,11 @@ export async function commandHelp(command = '', compilerOptions: Makensis.Compil
* @param script - path to NSIS script
* @param compilerOptions - compiler options
*/
export async function compile(script: string | null, compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
export async function compile(
script: string | null,
compilerOptions: Makensis.CompilerOptions = {},
spawnOptions: SpawnOptions = {},
): Promise<Makensis.CompilerOutput> {
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments([], compilerOptions);

if (script) {
Expand All @@ -52,7 +60,10 @@ export async function compile(script: string | null, compilerOptions: Makensis.C
* @param compilerOptions - compiler options
* @returns - compiler options
*/
export async function headerInfo(compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
export async function headerInfo(
compilerOptions: Makensis.CompilerOptions = {},
spawnOptions: SpawnOptions = {},
): Promise<Makensis.CompilerOutput> {
const options: Makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-HDRINFO'], options);

Expand All @@ -64,7 +75,10 @@ export async function headerInfo(compilerOptions: Makensis.CompilerOptions = {},
* @param compilerOptions - compiler options
* @returns - compiler license
*/
export async function license(compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
export async function license(
compilerOptions: Makensis.CompilerOptions = {},
spawnOptions: SpawnOptions = {},
): Promise<Makensis.CompilerOutput> {
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-LICENSE'], compilerOptions);

return spawnMakensis(cmd, args, opts, spawnOptions);
Expand All @@ -75,10 +89,11 @@ export async function license(compilerOptions: Makensis.CompilerOptions = {}, sp
* @param compilerOptions - compiler options
* @returns - NSIS directory
*/
export async function nsisDir(compilerOptions: Makensis.CompilerOptions = {}): Promise<string | Makensis.CompilerOutput> {
export async function nsisDir(
compilerOptions: Makensis.CompilerOptions = {},
): Promise<string | Makensis.CompilerOutput> {
const hdrOptions: Makensis.CompilerOptions = { ...compilerOptions, json: true };


function handler(hdrinfo: any) {
if (compilerOptions.json === true) {
return objectify(hdrinfo.stdout['defined_symbols']['NSISDIR'], 'nsisdir');
Expand All @@ -97,7 +112,10 @@ export async function nsisDir(compilerOptions: Makensis.CompilerOptions = {}): P
* @param compilerOptions - compiler options
* @returns - compiler version
*/
export async function version(compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
export async function version(
compilerOptions: Makensis.CompilerOptions = {},
spawnOptions: SpawnOptions = {},
): Promise<Makensis.CompilerOutput> {
const options: Makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-VERSION'], options);

Expand Down
35 changes: 23 additions & 12 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ function detectOutfile(str: string): null | string {
return null;
}

function formatOutput(stream: Makensis.StreamOptions, args: Array<string>, opts: Makensis.CompilerOptions): Makensis.StreamOptionsFormatted {
function formatOutput(
stream: Makensis.StreamOptions,
args: Array<string>,
opts: Makensis.CompilerOptions,
): Makensis.StreamOptionsFormatted {
const stdOut = stream.stdout.toString().trim();
const stdErr = stream.stderr.toString().trim();

Expand Down Expand Up @@ -62,7 +66,7 @@ function getMagicEnvVars(): Makensis.EnvironmentVariables {
const definitions: Makensis.EnvironmentVariables = {};
const prefix = 'NSIS_APP_';

Object.keys(env).map(item => {
Object.keys(env).map((item) => {
if (item?.length && new RegExp(`${prefix}[a-z0-9]+`, 'gi').test(item)) {
definitions[item] = env[item];
}
Expand Down Expand Up @@ -122,7 +126,9 @@ export async function mapArguments(args: string[], options: Makensis.CompilerOpt
let cmd: string;

if (platform() !== 'win32' && options.wine === true) {
console.warn('Wine support has been degraded to an experimental feature, but it will be continued to be supported for the time being.');
console.warn(
'Wine support has been degraded to an experimental feature, but it will be continued to be supported for the time being.',
);

cmd = pathToWine;
args.unshift(pathToMakensis);
Expand All @@ -135,7 +141,7 @@ export async function mapArguments(args: string[], options: Makensis.CompilerOpt
}

if (options?.define) {
Object.keys(options.define).map(key => {
Object.keys(options.define).map((key) => {
if (options.define && options.define[key]) {
args.push(`-D${key}=${options.define[key]}`);
}
Expand All @@ -146,7 +152,7 @@ export async function mapArguments(args: string[], options: Makensis.CompilerOpt
const defines = await getMagicEnvVars();

if (defines && Object.keys(defines).length) {
Object.keys(defines).map(key => {
Object.keys(defines).map((key) => {
if (defines && defines[key]) {
args.push(`-D${key}=${defines[key]}`);
}
Expand Down Expand Up @@ -245,7 +251,7 @@ export function objectifyFlags(input: string, opts: Makensis.CompilerOptions): M
return output;
}

const filteredLines = lines.filter(line => {
const filteredLines = lines.filter((line) => {
if (line !== '') {
return line;
}
Expand All @@ -260,7 +266,7 @@ export function objectifyFlags(input: string, opts: Makensis.CompilerOptions): M
}

// Split sizes
filteredLines.map(line => {
filteredLines.map((line) => {
if (line.startsWith('Size of ')) {
const pair = line.split(' is ');

Expand All @@ -281,7 +287,7 @@ export function objectifyFlags(input: string, opts: Makensis.CompilerOptions): M
}

// Split symbols
symbols.map(symbol => {
symbols.map((symbol) => {
const pair: Array<number | string> = symbol.split('=');

if (pair.length > 1 && pair[0] !== 'undefined') {
Expand All @@ -307,7 +313,7 @@ function objectifyHelp(input: string, opts: Makensis.CompilerOptions): Makensis.
const output: Makensis.CommandHelpOptions = {};

if (lines?.length) {
lines.map(line => {
lines.map((line) => {
let command = line.substring(0, line.indexOf(' '));
const usage = line.substring(line.indexOf(' ') + 1);

Expand All @@ -323,7 +329,12 @@ function objectifyHelp(input: string, opts: Makensis.CompilerOptions): Makensis.
return output;
}

export function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: Makensis.CompilerOptions, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
export function spawnMakensis(
cmd: string,
args: Array<string>,
compilerOptions: Makensis.CompilerOptions,
spawnOptions: SpawnOptions = {},
): Promise<Makensis.CompilerOutput> {
return new Promise<Makensis.CompilerOutput>((resolve, reject) => {
if (compilerOptions.wine) {
spawnOptions['env'] = Object.freeze({
Expand Down Expand Up @@ -418,7 +429,7 @@ export function splitCommands(data: string | string[]): string[] {
if (data.trim().includes('\n')) {
const lines = data.trim().split('\n');

lines.map(line => {
lines.map((line) => {
if (line.trim().length) {
args.push(`-X${line}`);
}
Expand All @@ -427,7 +438,7 @@ export function splitCommands(data: string | string[]): string[] {
args.push(`-X${data}`);
}
} else {
data.map(key => {
data.map((key) => {
if (key.trim().length) {
args.push(`-X${key}`);
}
Expand Down

0 comments on commit bdd5c44

Please sign in to comment.