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

addBuildPhase keeps adding phases when they already exist #110

Open
sitefinitysteve opened this issue Apr 27, 2020 · 1 comment
Open

addBuildPhase keeps adding phases when they already exist #110

sitefinitysteve opened this issue Apr 27, 2020 · 1 comment

Comments

@sitefinitysteve
Copy link

sitefinitysteve commented Apr 27, 2020

This is the build script line

xcodeProject.addBuildPhase(
              [], 'PBXShellScriptBuildPhase', 'Configure Crashlytics', undefined, options
            ).buildPhase;
            fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync());
            $logger.trace('Xcode project written');
          } else {
            $logger.error(xcodeProjectPath + ' is missing.');
            reject();
            return;
          }

So I guess everytime the CLI build runs it adds a NEW "Configure Crashlytics" to the build phase. Eventually my machine just outright died because the script was running hundreds of times.

Is there maybe a way before this I can check to see if it exists first before just adding it again?

@AndrWeisR
Copy link

I did it with this js script, called from a Cordova "after_build" hook:

var xcode = require('xcode'),
    fs = require('fs'),
    projectPath = 'platforms/ios/MyProj.xcodeproj/project.pbxproj',
    proj = xcode.project(projectPath);

proj.parse(function (err) {
        var scriptName = 'My Script';
        var buildPhases = proj.getPBXObject('PBXShellScriptBuildPhase');
        if (JSON.stringify(buildPhases).match(scriptName)) {
            console.log('Xcode project not updated - ' + scriptName + ' already exists')
        } else {
            var options = {shellPath: '/bin/sh', shellScript: 'bash somescript.sh'};
            proj.addBuildPhase([], 'PBXShellScriptBuildPhase', scriptName, proj.getFirstTarget().uuid, options);
           
            fs.writeFileSync(projectPath, proj.writeSync());
            console.log('Xcode project updated - added ' + scriptName);
        }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants