Skip to content

Commit

Permalink
fix(project): Validate that App.xcodeproj exists
Browse files Browse the repository at this point in the history
This is a guard against running a newer version of Cordova iOS tools
against an older project with a different name (which will fail due to
now-hardcoded assumptions about the project name).
  • Loading branch information
dpogue committed Oct 7, 2024
1 parent b8756b2 commit 8e4993b
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions lib/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,39 +81,20 @@ class Api {

setupEvents(events);

let xcodeProjDir;
let xcodeCordovaProj;

try {
const xcodeProjDir_array = fs.readdirSync(this.root).filter(e => e.match(/\.xcodeproj$/i));
if (xcodeProjDir_array.length > 1) {
for (let x = 0; x < xcodeProjDir_array.length; x++) {
if (xcodeProjDir_array[x].substring(0, 2) === '._') {
xcodeProjDir_array.splice(x, 1);
}
}
}
xcodeProjDir = xcodeProjDir_array[0];

if (!xcodeProjDir) {
throw new CordovaError(`The provided path "${this.root}" is not a Cordova iOS project.`);
}

const cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep) + 1, xcodeProjDir.indexOf('.xcodeproj'));
xcodeCordovaProj = path.join(this.root, cordovaProjName);
} catch (e) {
throw new CordovaError(`The provided path "${this.root}" is not a Cordova iOS project.`);
const xcodeProjDir = path.join(this.root, 'App.xcodeproj');
if (!fs.existsSync(xcodeProjDir)) {
throw new CordovaError(`The provided path "${this.root}" is not an up-to-date Cordova iOS project.`);
}

this.locations = {
root: this.root,
www: path.join(this.root, 'www'),
platformWww: path.join(this.root, 'platform_www'),
configXml: path.join(xcodeCordovaProj, 'config.xml'),
configXml: path.join(this.root, 'App', 'config.xml'),
defaultConfigXml: path.join(this.root, 'cordova', 'defaults.xml'),
pbxproj: path.join(this.root, xcodeProjDir, 'project.pbxproj'),
xcodeProjDir: path.join(this.root, xcodeProjDir),
xcodeCordovaProj
pbxproj: path.join(xcodeProjDir, 'project.pbxproj'),
xcodeProjDir,
xcodeCordovaProj: path.join(this.root, 'App')
};
}

Expand Down

0 comments on commit 8e4993b

Please sign in to comment.