Support binary Info.plist (#41)

This commit is contained in:
Krzysztof Zbudniewek 2019-12-06 10:20:17 +01:00 committed by Sindre Sorhus
parent 4f80ea2d80
commit 5eb1c69420
8 changed files with 32 additions and 7 deletions

21
cli.js
View File

@ -47,9 +47,11 @@ if (!destPath) {
destPath = process.cwd();
}
const infoPlistPath = path.join(appPath, 'Contents/Info.plist');
let infoPlist;
try {
infoPlist = fs.readFileSync(path.join(appPath, 'Contents/Info.plist'), 'utf8');
infoPlist = fs.readFileSync(infoPlistPath, 'utf8');
} catch (error) {
if (error.code === 'ENOENT') {
console.error(`Could not find \`${path.relative(process.cwd(), appPath)}\``);
@ -59,15 +61,22 @@ try {
throw error;
}
const appInfo = plist.parse(infoPlist);
const appName = appInfo.CFBundleDisplayName || appInfo.CFBundleName;
const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, '');
const dmgPath = path.join(destPath, `${appName} ${appInfo.CFBundleShortVersionString}.dmg`);
const ora = new Ora('Creating DMG');
ora.start();
async function init() {
let appInfo;
try {
appInfo = plist.parse(infoPlist);
} catch (_) {
const {stdout} = await execa('plutil', ['-convert', 'xml1', '-o', '-', infoPlistPath]);
appInfo = plist.parse(stdout);
}
const appName = appInfo.CFBundleDisplayName || appInfo.CFBundleName;
const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, '');
const dmgPath = path.join(destPath, `${appName} ${appInfo.CFBundleShortVersionString}.dmg`);
if (cli.flags.overwrite) {
try {
fs.unlinkSync(dmgPath);

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
APPL????

17
test.js
View File

@ -11,7 +11,22 @@ test('main', async t => {
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixture.app')], {cwd});
} catch (error) {
// Silence code signing failure
if (!/Code signing failed/.test(error.message)) {
if (!error.message.includes('Code signing failed')) {
throw error;
}
}
t.true(fs.existsSync(path.join(cwd, 'Fixture 0.0.1.dmg')));
});
test('binary plist', async t => {
const cwd = tempy.directory();
try {
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixture-with-binary-plist.app')], {cwd});
} catch (error) {
// Silence code signing failure
if (!error.message.includes('Code signing failed')) {
throw error;
}
}