2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-03 05:10:47 +00:00
nativefier/src/helpers/upgrade/plistInfoXMLHelpers.ts
Adam Weeden 9330c8434f
Add an option to upgrade an existing app (fix #1131) (PR #1138)
This adds a `--upgrade` option to upgrade-in-place an old app, re-using its options it can.
Should help fix #1131

Co-authored-by: Ronan Jouchet <ronan@jouchet.fr>
2021-04-28 22:00:31 -04:00

40 lines
1.1 KiB
TypeScript

export function extractBoolean(
infoPlistXML: string,
plistKey: string,
): boolean | undefined {
const plistValue = extractRaw(infoPlistXML, plistKey);
return plistValue === undefined
? undefined
: plistValue.split('<')[1].split('/>')[0].toLowerCase() === 'true';
}
export function extractString(
infoPlistXML: string,
plistKey: string,
): string | undefined {
const plistValue = extractRaw(infoPlistXML, plistKey);
return plistValue === undefined
? undefined
: plistValue.split('<string>')[1].split('</string>')[0];
}
function extractRaw(
infoPlistXML: string,
plistKey: string,
): string | undefined {
// This would be easier with xml2js, but let's not add a dependency for something this minor.
const fullKey = `\n <key>${plistKey}</key>`;
if (infoPlistXML.indexOf(fullKey) === -1) {
// This value wasn't set, so we'll stay agnostic to it
return undefined;
}
return infoPlistXML
.split(fullKey)[1]
.split('\n </dict>')[0] // Get everything between here and the end of the main plist dict
.split('\n <key>')[0]; // Get everything before the next key (if it exists)
}