Skip to content

Commit

Permalink
fix(build): Allow platform args with double dash (#1516)
Browse files Browse the repository at this point in the history
Closes GH-1488.
  • Loading branch information
dpogue authored Dec 25, 2024
1 parent 3737f51 commit c1004fe
Show file tree
Hide file tree
Showing 4 changed files with 1,001 additions and 675 deletions.
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

0 comments on commit c1004fe

Please sign in to comment.