Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): Allow platform args with double dash #1516

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 54 additions & 28 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

const fs = require('node:fs');
const fsp = require('node:fs/promises');
const path = require('node:path');
const util = require('node:util');
const nopt = require('nopt');
const which = require('which');
const execa = require('execa');
const { CordovaError, events } = require('cordova-common');
Expand Down Expand Up @@ -98,47 +98,73 @@ function getDefaultSimulatorTarget () {
});
}

/** @returns {Promise<void>} */
module.exports.run = function (buildOpts) {
const projectPath = this.root;
let emulatorTarget = 'iOS Device';

buildOpts = buildOpts || {};

if (buildOpts.debug && buildOpts.release) {
return Promise.reject(new CordovaError('Cannot specify "debug" and "release" options together.'));
function parseOptions (options) {
options = options || {};
options.argv = nopt({
codeSignIdentity: String,
developmentTeam: String,
packageType: String,
provisioningProfile: String,
automaticProvisioning: Boolean,
authenticationKeyPath: String,
authenticationKeyID: String,
authenticationKeyIssuerID: String,
buildFlag: [String, Array],
iCloudContainerEnvironment: String
}, {}, options.argv, 0);

if (options.debug && options.release) {
throw new CordovaError('Cannot specify "debug" and "release" options together.');
}

if (buildOpts.device && buildOpts.emulator) {
return Promise.reject(new CordovaError('Cannot specify "device" and "emulator" options together.'));
if (options.device && options.emulator) {
throw new CordovaError('Cannot specify "device" and "emulator" options together.');
}

if (buildOpts.target && buildOpts.target.match(/mac/i)) {
buildOpts.catalyst = true;
buildOpts.device = true;
buildOpts.emulator = false;
buildConfigProperties.forEach(key => {
options[key] = options.argv[key] || options[key];
});

emulatorTarget = 'macOS Catalyst';
}

if (buildOpts.buildConfig) {
if (!fs.existsSync(buildOpts.buildConfig)) {
return Promise.reject(new CordovaError(`Build config file does not exist: ${buildOpts.buildConfig}`));
if (options.buildConfig) {
if (!fs.existsSync(options.buildConfig)) {
throw new CordovaError(`Build config file does not exist: ${options.buildConfig}`);
}
events.emit('log', `Reading build config file: ${path.resolve(buildOpts.buildConfig)}`);
const contents = fs.readFileSync(buildOpts.buildConfig, 'utf-8');
events.emit('log', `Reading build config file: ${path.resolve(options.buildConfig)}`);
const contents = fs.readFileSync(options.buildConfig, 'utf-8');
const buildConfig = JSON.parse(contents.replace(/^\ufeff/, '')); // Remove BOM
if (buildConfig.ios) {
const buildType = buildOpts.release ? 'release' : 'debug';
const buildType = options.release ? 'release' : 'debug';
const config = buildConfig.ios[buildType];
if (config) {
buildConfigProperties.forEach(key => {
buildOpts[key] = buildOpts[key] || config[key];
options[key] = options[key] || config[key];
});
}
}
}

return options;
}

/** @returns {Promise<void>} */
module.exports.run = function (buildOpts) {
try {
buildOpts = parseOptions(buildOpts);
} catch (e) {
return Promise.reject(e);
}

const projectPath = this.root;
let emulatorTarget = 'iOS Device';

if (buildOpts.target && buildOpts.target.match(/mac/i)) {
buildOpts.catalyst = true;
buildOpts.device = true;
buildOpts.emulator = false;

emulatorTarget = 'macOS Catalyst';
}

return Promise.resolve()
.then(() => {
if (!buildOpts.emulator && !buildOpts.catalyst) {
Expand Down Expand Up @@ -215,7 +241,7 @@ module.exports.run = function (buildOpts) {
writeCodeSignStyle('Automatic');
}

return fsp.writeFile(path.join(projectPath, 'cordova', 'build-extras.xcconfig'), extraConfig, 'utf-8');
return fs.promises.writeFile(path.join(projectPath, 'cordova', 'build-extras.xcconfig'), extraConfig, 'utf-8');
}).then(() => {
const configuration = buildOpts.release ? 'Release' : 'Debug';

Expand Down Expand Up @@ -287,7 +313,7 @@ module.exports.run = function (buildOpts) {
return execa('xcodebuild', xcodearchiveArgs, { cwd: projectPath, stdio: 'inherit' });
}

return fsp.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8')
return fs.promises.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8')
.then(checkSystemRuby)
.then(packageArchive);
})
Expand Down
Loading
Loading