|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | const fs = require('node:fs');
|
21 |
| -const fsp = require('node:fs/promises'); |
22 | 21 | const path = require('node:path');
|
23 | 22 | const util = require('node:util');
|
| 23 | +const nopt = require('nopt'); |
24 | 24 | const which = require('which');
|
25 | 25 | const execa = require('execa');
|
26 | 26 | const { CordovaError, events } = require('cordova-common');
|
@@ -98,47 +98,73 @@ function getDefaultSimulatorTarget () {
|
98 | 98 | });
|
99 | 99 | }
|
100 | 100 |
|
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.'); |
110 | 118 | }
|
111 | 119 |
|
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.'); |
114 | 122 | }
|
115 | 123 |
|
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 | + }); |
120 | 127 |
|
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}`); |
127 | 131 | }
|
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'); |
130 | 134 | const buildConfig = JSON.parse(contents.replace(/^\ufeff/, '')); // Remove BOM
|
131 | 135 | if (buildConfig.ios) {
|
132 |
| - const buildType = buildOpts.release ? 'release' : 'debug'; |
| 136 | + const buildType = options.release ? 'release' : 'debug'; |
133 | 137 | const config = buildConfig.ios[buildType];
|
134 | 138 | if (config) {
|
135 | 139 | buildConfigProperties.forEach(key => {
|
136 |
| - buildOpts[key] = buildOpts[key] || config[key]; |
| 140 | + options[key] = options[key] || config[key]; |
137 | 141 | });
|
138 | 142 | }
|
139 | 143 | }
|
140 | 144 | }
|
141 | 145 |
|
| 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 | + |
142 | 168 | return Promise.resolve()
|
143 | 169 | .then(() => {
|
144 | 170 | if (!buildOpts.emulator && !buildOpts.catalyst) {
|
@@ -215,7 +241,7 @@ module.exports.run = function (buildOpts) {
|
215 | 241 | writeCodeSignStyle('Automatic');
|
216 | 242 | }
|
217 | 243 |
|
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'); |
219 | 245 | }).then(() => {
|
220 | 246 | const configuration = buildOpts.release ? 'Release' : 'Debug';
|
221 | 247 |
|
@@ -287,7 +313,7 @@ module.exports.run = function (buildOpts) {
|
287 | 313 | return execa('xcodebuild', xcodearchiveArgs, { cwd: projectPath, stdio: 'inherit' });
|
288 | 314 | }
|
289 | 315 |
|
290 |
| - return fsp.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8') |
| 316 | + return fs.promises.writeFile(exportOptionsPath, exportOptionsPlist, 'utf-8') |
291 | 317 | .then(checkSystemRuby)
|
292 | 318 | .then(packageArchive);
|
293 | 319 | })
|
|
0 commit comments