diff --git a/src/cli.ts b/src/cli.ts index 62364f5..5fd5629 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -7,6 +7,7 @@ import yargs from 'yargs'; import { DEFAULT_ELECTRON_VERSION } from './constants'; import { + camelCased, checkInternet, getProcessEnvs, isArgFormatInvalid, @@ -582,6 +583,10 @@ export function parseArgs(args: yargs.Argv): RawOptions { ]) { if (parsed[arg] && typeof parsed[arg] === 'string') { parsed[arg] = parseJson(parsed[arg] as string); + // sets fileDownloadOptions and browserWindowOptions + // as parsed object as they were still strings in `nativefier.json` + // because only their snake-cased variants were being parsed above + parsed[camelCased(arg)] = parsed[arg]; } } if (parsed['process-envs'] && typeof parsed['process-envs'] === 'string') { diff --git a/src/helpers/helpers.test.ts b/src/helpers/helpers.test.ts index f1d22ff..0b9a9c1 100644 --- a/src/helpers/helpers.test.ts +++ b/src/helpers/helpers.test.ts @@ -1,4 +1,8 @@ -import { isArgFormatInvalid, generateRandomSuffix } from './helpers'; +import { + isArgFormatInvalid, + generateRandomSuffix, + camelCased, +} from './helpers'; describe('isArgFormatInvalid', () => { test('is false for correct short args', () => { @@ -56,3 +60,25 @@ describe('generateRandomSuffix', () => { expect(generateRandomSuffix(10).length).toBe(10); }); }); + +describe('camelCased', () => { + test('has no hyphens in camel case', () => { + expect(camelCased('file-download')).toEqual(expect.not.stringMatching(/-/)); + }); + + test('returns camel cased string', () => { + expect(camelCased('file-download')).toBe('fileDownload'); + }); + + test('has no spaces in camel case', () => { + expect(camelCased('--file--download--')).toBe('fileDownload'); + }); + + test('handles multiple hyphens properly', () => { + expect(camelCased('file--download--options')).toBe('fileDownloadOptions'); + }); + + test('does not affect non-snake cased strings', () => { + expect(camelCased('win32options')).toBe('win32options'); + }); +}); diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index 5a57af2..935f416 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -184,3 +184,17 @@ export function checkInternet(): void { } }); } + +/** + * Takes in a snake-cased string and converts to camelCase + */ +export function camelCased(str: string): string { + return str + .split('-') + .filter((s) => s.length > 0) + .map((word, i) => { + if (i === 0) return word; + return `${word[0].toUpperCase()}${word.substring(1)}`; + }) + .join(''); +}