mirror of https://github.com/jiahaog/Nativefier
parent
e7483549af
commit
372c1d0b13
|
@ -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>): 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') {
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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('');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue