Skip to content

Commit c1004fe

Browse files
authored
fix(build): Allow platform args with double dash (#1516)
Closes GH-1488.
1 parent 3737f51 commit c1004fe

File tree

4 files changed

+1001
-675
lines changed

4 files changed

+1001
-675
lines changed

lib/build.js

+54-28
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*/
1919

2020
const fs = require('node:fs');
21-
const fsp = require('node:fs/promises');
2221
const path = require('node:path');
2322
const util = require('node:util');
23+
const nopt = require('nopt');
2424
const which = require('which');
2525
const execa = require('execa');
2626
const { CordovaError, events } = require('cordova-common');
@@ -98,47 +98,73 @@ function getDefaultSimulatorTarget () {
9898
});
9999
}
100100

101-
/** @returns {Promise<void>} */
102-
module.exports.run = function (buildOpts) {
103-
const projectPath = this.root;
104-
let emulatorTarget = 'iOS Device';
105-
106-
buildOpts = buildOpts || {};
107-
108-
if (buildOpts.debug && buildOpts.release) {
109-
return Promise.reject(new CordovaError('Cannot specify "debug" and "release" options together.'));
101+
function parseOptions (options) {
102+
options = options || {};
103+
options.argv = nopt({
104+
codeSignIdentity: String,
105+
developmentTeam: String,
106+
packageType: String,
107+
provisioningProfile: String,
108+
automaticProvisioning: Boolean,
109+
authenticationKeyPath: String,
110+
authenticationKeyID: String,
111+
authenticationKeyIssuerID: String,
112+
buildFlag: [String, Array],
113+
iCloudContainerEnvironment: String
114+
}, {}, options.argv, 0);
115+
116+
if (options.debug && options.release) {
117+
throw new CordovaError('Cannot specify "debug" and "release" options together.');
110118
}
111119

112-
if (buildOpts.device && buildOpts.emulator) {
113-
return Promise.reject(new CordovaError('Cannot specify "device" and "emulator" options together.'));
120+
if (options.device && options.emulator) {
121+
throw new CordovaError('Cannot specify "device" and "emulator" options together.');
114122
}
115123

116-
if (buildOpts.target && buildOpts.target.match(/mac/i)) {
117-
buildOpts.catalyst = true;
118-
buildOpts.device = true;
119-
buildOpts.emulator = false;
124+
buildConfigProperties.forEach(key => {
125+
options[key] = options.argv[key] || options[key];
126+
});
120127

121-
emulatorTarget = 'macOS Catalyst';
122-
}
123-
124-
if (buildOpts.buildConfig) {
125-
if (!fs.existsSync(buildOpts.buildConfig)) {
126-
return Promise.reject(new CordovaError(`Build config file does not exist: ${buildOpts.buildConfig}`));
128+
if (options.buildConfig) {
129+
if (!fs.existsSync(options.buildConfig)) {
130+
throw new CordovaError(`Build config file does not exist: ${options.buildConfig}`);
127131
}
128-
events.emit('log', `Reading build config file: ${path.resolve(buildOpts.buildConfig)}`);
129-
const contents = fs.readFileSync(buildOpts.buildConfig, 'utf-8');
132+
events.emit('log', `Reading build config file: ${path.resolve(options.buildConfig)}`);
133+
const contents = fs.readFileSync(options.buildConfig, 'utf-8');
130134
const buildConfig = JSON.parse(contents.replace(/^\ufeff/, '')); // Remove BOM
131135
if (buildConfig.ios) {
132-
const buildType = buildOpts.release ? 'release' : 'debug';
136+
const buildType = options.release ? 'release' : 'debug';
133137
const config = buildConfig.ios[buildType];
134138
if (config) {
135139
buildConfigProperties.forEach(key => {
136-
buildOpts[key] = buildOpts[key] || config[key];
140+
options[key] = options[key] || config[key];
137141
});
138142
}
139143
}
140144
}
141145

146+
return options;
147+
}
148+
149+
/** @returns {Promise<void>} */
150+
module.exports.run = function (buildOpts) {
151+
try {
152+
buildOpts = parseOptions(buildOpts);
153+
} catch (e) {
154+
return Promise.reject(e);
155+
}
156+
157+
const projectPath = this.root;
158+
let emulatorTarget = 'iOS Device';
159+
160+
if (buildOpts.target && buildOpts.target.match(/mac/i)) {
161+
buildOpts.catalyst = true;
162+
buildOpts.device = true;
163+
buildOpts.emulator = false;
164+
165+
emulatorTarget = 'macOS Catalyst';
166+
}
167+
142168
return Promise.resolve()
143169
.then(() => {
144170
if (!buildOpts.emulator && !buildOpts.catalyst) {
@@ -215,7 +241,7 @@ module.exports.run = function (buildOpts) {
215241
writeCodeSignStyle('Automatic');
216242
}
217243

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

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

290-
return fsp.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8')
316+
return fs.promises.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8')
291317
.then(checkSystemRuby)
292318
.then(packageArchive);
293319
})

0 commit comments

Comments
 (0)