cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-9825) Support third-party package managers like Cocoapods and Nuget
Date Tue, 05 Jul 2016 04:14:11 GMT

    [ https://issues.apache.org/jira/browse/CB-9825?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15361974#comment-15361974
] 

ASF GitHub Bot commented on CB-9825:
------------------------------------

Github user shazron commented on a diff in the pull request:

    https://github.com/apache/cordova-ios/pull/234#discussion_r69505602
  
    --- Diff: bin/templates/scripts/cordova/lib/podMod.js ---
    @@ -0,0 +1,162 @@
    +var fs = require('fs');
    +var util = require('util');
    +var events = require('cordova-common').events;
    +var superspawn = require('cordova-common').superspawn;
    +var CordovaError = require('cordova-common').CordovaError;
    +var opts = {};
    +/*
    +-- After pods are installed in a .xcworkspace, all existing ios code needs to go into
the WORKSPACE file -- will need to 
    +    create a workspace file and then embed the Xcode project  
    +
    +        - Holly might have done some work on this, see the docs: 
    +          https://github.com/phonegap/phonegap-webview-ios not sure how applicable it
can be to our case
    +*/
    +function removeProjectFromPath (pathToProjectFile) {
    +    var array = [];
    +    //remove the project from the path
    +    array = pathToProjectFile.split('/');
    +    array.pop();
    +    var path = array.join('/');
    +    return path;
    +}
    +
    +function createPodfile (projectName, pathToProjectFile) {
    +    var path = removeProjectFromPath(pathToProjectFile);
    +    var pathToPodfile = path + '/Podfile';
    +    var podfileText = util.format('platform :ios, \'8.0\'\n\ntarget \'%s\' do\n\n  project
\'%s\'\n\n  \n\nend' , projectName, pathToProjectFile);
    +    fs.writeFileSync(pathToPodfile, podfileText);
    +}
    +
    +function editPodfileSync (Podfile, pod, isRemoval) {
    +    var podfileContents = fs.readFileSync(Podfile, 'utf8');
    +    //split by \n, add in the pod after the project line, shift the rest down
    +    var podfileContentsArray = podfileContents.split('\n');
    +    var linesInPodfileToKeep = [];
    +
    +    if (isRemoval) {
    +        podfileContentsArray.forEach (function (lineInPodfile) {
    +            //if the line in Podfile is the pod to rm, don't save it to new array (to
be returned)
    +            if (!lineInPodfile.includes(pod)){
    +                linesInPodfileToKeep.push(lineInPodfile); 
    +            }
    +        });
    +        podfileContents = linesInPodfileToKeep.join('\n');
    +    } else {
    +        podfileContentsArray.splice(5, 0, pod);
    +        podfileContents = podfileContentsArray.join('\n');
    +    }
    +    return podfileContents;
    +}
    +
    +function superspawnPodInstall (path, isPathToProjectFile) {
    +    // change working directory for all calls of pod install to platforms/ios
    +    if (isPathToProjectFile){
    +        //if the path passed leads to the project, and not the dir that contains the
proj
    +         //remove the project from the path
    +        path = removeProjectFromPath(path);
    +    }
    +    opts.cwd = path;
    +    superspawn.spawn('pod', ['install'], opts);
    +}
    +
    +function installPodSync (projectName, pathToProjectFile, nameOfPod, podSpec, podsJSON)
{
    +    // called from cordova project directory-- when invoked, args are as follows
    +    //  projectName         = cordovaProject (name) and 
    +    //  pathToProjectFile   = ./path/to/cordovaProject 
    +    //  nameOfPod           = obj.src                   //from framework tag
    +    //  podSpec             = obj.spec                  //from framework tag   
    +    //  podsJSON            = pods.json file in cordovaProjectDir/platforms/ios/
    +
    +    // readFileSync will currently truncate the Podfile if it exists
    +    // if a Podfile doesn't exist, one will be created
    +
    +    // this code will be run during cordova plugin add x -- which has to be run in the
cordova project dir
    +    
    +    //-----------
    +    //ERROR
    +    //
    +    //if no podName is specified, console err 
    +    if (nameOfPod === '' || nameOfPod === ' '){
    +        throw new CordovaError('\nERROR: name of pod is not specified\n');
    +    }
    +    //-----------
    +
    +    podSpec = podSpec || ''; //spec is optional
    +    
    +    var stringToWrite; //overwrites Podfile
    +    var lineToInjectInPodfile; //adds pod
    +    var path = removeProjectFromPath(pathToProjectFile);
    +    var podfile = path + '/Podfile';
    +    var podfileExistsInCurrentDirectory = fs.existsSync(podfile);       //bool
    +    var podExistsInPodsJSON = podsJSON[nameOfPod];                      //bool
    +    var podRequestedForSpecChange;                                      //bool
    +   
    +    if (podSpec === '') {
    +        lineToInjectInPodfile = util.format('pod \'%s\'', nameOfPod);
    +        podRequestedForSpecChange = false;
    +    } else {
    +        if (podExistsInPodsJSON){
    +            if (podsJSON[nameOfPod].spec == podSpec){
    +            //-----------
    +            //ERROR
    +            //
    +            // if pod spec is the one already in the Podfile,
    +            // do nothing to the Podfile, return error
    +            throw new CordovaError('\nERROR: pod already installed in Podfile, according
to pods.json');
    +            //------------
    +            } else {
    +                podRequestedForSpecChange = true; 
    +            }
    +        } else {
    +            lineToInjectInPodfile = util.format('pod \'%s\', \'%s\'', nameOfPod, podSpec);
    +            podRequestedForSpecChange = false; 
    +        }
    +    }
    +
    +    //does Podfile exist in the current directory?
    +    if (podfileExistsInCurrentDirectory) {
    +        events.emit('verbose', 'Podfile found in platforms/ios');
    +        //is the pod already in the Podfile? 
    +        if (podExistsInPodsJSON) {
    +            events.emit('verbose', 'Selected pod already exists in Podfile according
to pods.json');
    +            //if pod is in Podfile, is there a change in spec? 
    +            if (podRequestedForSpecChange) {
    +                //if spec change requested, replace the line in the Podfile with the
correct spec 
    +                events.emit('verbose', 'Pod requested for spec change');
    +            } // no change in spec handled above
    +        } else if (!podExistsInPodsJSON) {
    +            //if pod not already in Podfile, inject the line in the existing Podfile
    +            events.emit('verbose', 'Pod not found in Podfile. Injecting now...');
    +            stringToWrite = editPodfileSync(podfile, lineToInjectInPodfile);
    +        }
    +    } else if (!podfileExistsInCurrentDirectory) {
    +        //create the Podfile and inject the line
    +        events.emit('verbose', 'Creating new Podfile in platforms/ios');
    +        createPodfile(projectName, pathToProjectFile);
    +        events.emit('verbose', 'Adding pod to Podfile');
    +        stringToWrite = editPodfileSync(podfile, lineToInjectInPodfile);
    +    }
    +    
    +    if (stringToWrite) {
    +        events.emit('verbose', 'Overwriting Podfile');
    +        fs.writeFileSync(podfile, stringToWrite);
    +    } else {
    +        //the code should have returned early by now
    +    }
    +    events.emit('verbose', 'Pods installed in xcode workspace in platforms/ios');
    +}
    +
    +function uninstallPod (projectDirectory, pod) {
    +    //split podfile by \n
    +    //for each, does each.includes(pod)? if so, remove that line
    +    //that will correspond to the line in the podfile, given the amt of pods currently
installed in the podfile... 
    +    var podfile = projectDirectory + '/Podfile';
    +    var stringToWrite = editPodfileSync(podfile, pod, true);
    +    fs.writeFileSync(podfile, stringToWrite);
    +}
    +
    +module.exports = {
    +    installPodSync          : installPodSync,
    --- End diff --
    
    API names are inconsistent. Recommend:
    ```
    installPodSync
    uninstallPodSync
    installPodSuperspawn
    ```


> Support third-party package managers like Cocoapods and Nuget
> -------------------------------------------------------------
>
>                 Key: CB-9825
>                 URL: https://issues.apache.org/jira/browse/CB-9825
>             Project: Apache Cordova
>          Issue Type: New Feature
>          Components: CordovaLib
>            Reporter: Shazron Abdullah
>            Assignee: Julia Geist
>              Labels: cordova-ios-5.0.x
>
> ML discussion:
> http://markmail.org/message/5qvg6rwr4nz4q7mc
> cordova-discuss proposal (to be brought back to the list when finalized):
> https://github.com/cordova/cordova-discuss/blob/master/proposals/ThirdPartyPackageManagers.md
> From Steve Gill in the ML:
> At the Cordova F2F, everyone seemed to agree that we should bring CocoaPods
> support to plugins as dependencies for iOS.
> Cordova-android currently uses Gradle as a way to enable external
> dependency resolution for plugins using the framework tag.
> A suggestion about using the engine tag to fetch cocoapods-cli (mac) &
> NuGet (windows) followed by using the framework tag was discussed.
> The minutes[1] show Carlos, Shaz and Raghav as looking into the design.
> Someone should write up a proposal on cordova-discuss[2] and create the
> issues. Post them in this thread.
> This shouldn't take priority over cordova-ios 4 issues.
> [1]
> https://docs.google.com/document/d/1MArKRmnLS052LBbhPxJF57_4ZivghOj8znWo5sTCkbU/edit?usp=sharing
> [2] https://github.com/cordova/cordova-discuss



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Mime
View raw message