-1

I'm developing Phonegap application (using AngularJs+Bootstrap) which supports iOS and Android. We had to maintain two code bases so far but its the same functionalities, only few differences like below.

  • Application name/icons are different
  • Main url is different for web-service calls

Ex :

PhoneGap App X : call http://abc/xappinfo weservice, use x_icon_app.png (This has to build for both iOS and Android which i have no issue)

PhoneGap App Y : call http://xyz/yappinfo weservice, use y_icon_app.png and other UI elements for mobile skin (This also has to build for both iOS and Android)

Both PhoneGap App X and Y uses same code for business logics.

I would like to maintain one code base for both apps since there only few differences. Is there any way I could achieve this or simplify my development effort?

happycoder
  • 927
  • 3
  • 13
  • 28
  • Write a single code (where you need to change URL) and check the browser OS, like if...else... and assign url variable accordingly. http://stackoverflow.com/questions/12606245/detect-if-browser-is-running-on-an-android-or-ios-device – Mrunal Jun 18 '15 at 07:21
  • AppIcons will be based on project settings, in XCode for iOS and in Eclipse for Android so that can be easily handled. – Mrunal Jun 18 '15 at 07:23
  • Hi Mrunal, thank you for your comment. I think you didnt understand my question. I have edited it and please look at it. – happycoder Jun 18 '15 at 08:19
  • In this case, whichever code base is common, keep it in single folder. Add that folder as a reference in iOS as well in Android project. And for the URL and image part the same logic I have mentioned above. – Mrunal Jun 18 '15 at 08:59

2 Answers2

1

I had a similar situation. I placed all my app folders in a single folder and placed the following code in a file in the root folder called: persist.js. Its purpose is to persist file changes across all of the different apps keeping the same path. It is a little manual, but works...

var fs = require('fs');
var chalk = require('chalk');
var argv = require('minimist')(process.argv.slice(2));
var file = argv.f;

var apps = [
    'app_folder_1',
    'app_folder_2',
    'app_folder_3',
    'app_folder_4',
    'app_folder_5',
];

if(file){

    if (fs.existsSync(file)) {
        console.log(chalk.blue('Found source file'));
        var fileWithoutApp = file.substring(file.indexOf('/'));
        apps.map(app => {
            fs.writeFileSync(app + fileWithoutApp, fs.readFileSync(file));
            console.log(chalk.green(`File copied to: ${app + fileWithoutApp}`))
        });

    } else {
        console.log(chalk.red('File does not exist'));
    }

} else {
    console.log(chalk.red('No file specified'));
}

After changes are made to a file within any of the project folders just call the following from the command line:

node persist -f [relative path to your file that has changes]

This will persist the change across all projects. Like I said, a little manual... but effective :)

rileynet
  • 151
  • 2
  • 5
0

When u use cordova or ionic + angularjs you can compile application for both device this is more simple you like complication !!

Jess
  • 21
  • 5