Skip to content

Commit

Permalink
fix(flat): don't use pkgbuild for MAS distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao committed Dec 11, 2024
1 parent 35fa05f commit cd45cb5
Showing 1 changed file with 45 additions and 19 deletions.
64 changes: 45 additions & 19 deletions src/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,47 @@ async function validateFlatOpts (opts: FlatOptions): Promise<ValidatedFlatOption

/**
* This function returns a promise flattening the application.
* @function
* @param {Object} opts - Options.
* @returns {Promise} Promise.
* @param opts - Options for building the .pkg archive
*/
async function buildApplicationPkg (opts: ValidatedFlatOptions, identity: Identity) {
const componentPkgPath = path.join(path.dirname(opts.app), path.basename(opts.app, '.app') + '-component.pkg');
const pkgbuildArgs = ['--install-location', opts.install, '--component', opts.app, componentPkgPath];
if (opts.scripts) {
pkgbuildArgs.unshift('--scripts', opts.scripts);
}
debugLog('Building component package... ' + opts.app);
await execFileAsync('pkgbuild', pkgbuildArgs);
if (opts.platform === 'mas') {
const args = ['--component', opts.app, opts.install, '--sign', identity.name, opts.pkg];
if (opts.keychain) {
args.unshift('--keychain', opts.keychain);
}

const args = ['--package', componentPkgPath, opts.install, '--sign', identity.name, opts.pkg];
if (opts.keychain) {
args.unshift('--keychain', opts.keychain);
}
debugLog('Flattening Mac App Store package... ' + opts.app);
await execFileAsync('productbuild', args);
} else {
const componentPkgPath = path.join(
path.dirname(opts.app),
path.basename(opts.app, '.app') + '-component.pkg'
);
const pkgbuildArgs = [
'--install-location',
opts.install,
'--component',
opts.app,
componentPkgPath
];
if (opts.scripts) {
pkgbuildArgs.unshift('--scripts', opts.scripts);
}
debugLog('Building component package... ' + opts.app);
await execFileAsync('pkgbuild', pkgbuildArgs);

debugLog('Flattening... ' + opts.app);
await execFileAsync('productbuild', args);
await execFileAsync('rm', [componentPkgPath]);
const args = ['--package', componentPkgPath, opts.install, '--sign', identity.name, opts.pkg];
if (opts.keychain) {
args.unshift('--keychain', opts.keychain);
}
if (opts.scripts) {
args.unshift('--scripts', opts.scripts);
}

debugLog('Flattening OS X Installer package... ' + opts.app);
await execFileAsync('productbuild', args);
await execFileAsync('rm', [componentPkgPath]);
}
}

/**
Expand All @@ -89,7 +109,10 @@ export async function buildPkg (_opts: FlatOptions) {
if (validatedOptions.identityValidation === false) {
// Do nothing
} else {
identities = await findIdentities(validatedOptions.keychain || null, validatedOptions.identity);
identities = await findIdentities(
validatedOptions.keychain || null,
validatedOptions.identity
);
}
} else {
debugWarn('No `identity` passed in arguments...');
Expand All @@ -105,7 +128,10 @@ export async function buildPkg (_opts: FlatOptions) {
debugLog(
'Finding `Developer ID Application` certificate for distribution outside the Mac App Store...'
);
identities = await findIdentities(validatedOptions.keychain || null, 'Developer ID Installer:');
identities = await findIdentities(
validatedOptions.keychain || null,
'Developer ID Installer:'
);
}
}

Expand Down

0 comments on commit cd45cb5

Please sign in to comment.