Sharing ionic project on git

Hi Ionic team,

Thanks for building this awesome product!

Me and my friend were having some difficulties in sharing the ionic project code over git. Can anyone please suggest Which files/directories to ignore and which to include in git?.

Also, which commands I need to run to install all the required dependencies on the machine on which I am cloning the project through git?

Thanks in advance!

1 Like

Any help in this matter will be appreciated!

Hello, jayant did you find a solution? I got errors too because some files won’t be tracked by git add * in the root folder of the app. These files are missing when we clone the app afterwards.

Hi,

Here is my .gitignore :

app/bower_components/
.sass-cache/
.tmp/
coverage/
hooks/
merges/
node_modules/
platforms/
plugins/
www/
.DS_Store
npm-debug.log

*~

And here is my process to get started with commited code :

  • go to project root folder
  • npm install to install all grunt dependencies
  • bower install to install all bower dependencies
  • grunt serve to test on your computer

Your app is now running to your computer. To run it to your android device :

  • mkdir platforms plugins www create folders for cordova
  • cordova platform add android add android platform to the project
  • cordova plugin add org.apache.cordova.device ... add interesting plugins
  • grunt build && cordova run android to run app on your phone

Hope it helps !

1 Like

Why we need to add hooks/ in .gitignore. Can’t we add scripts here to add platform class or scripts to automatically install plugins from package.json into hooks or is it taken care by ionic cli itself.

1 Like

Yeah I would like to know if anyone has something to do this for a fresh clone?

I had to write a script and include it in the project so new developers can get up and running

#!/usr/bin/env node
const fs = require('fs');
const exec = require('child_process').exec;

fs.readFile('package.json', function (err, data) {
  if (err) throw err;
  console.log(data);

  const packageJson = JSON.parse(data);
  const cordovaPlatforms = packageJson.cordovaPlatforms;
  const cordovaPlugins = packageJson.cordovaPlugins;

  console.log('installing platforms');
  cordovaPlatforms.forEach(function (platform) {
    console.log('adding platform ' + platform);

    const installCmd = 'ionic platform add ' + platform;
    exec(installCmd, function (err, stdout, stderr) {
      console.log(stdout);
      console.log(stderr);
    });
  });

  console.log('installing plugins');
  cordovaPlugins.forEach(function (plugin) {
    var installCmd;
    if (typeof plugin == 'string') {
      installCmd = 'ionic plugin add ' + plugin;
    } else {
      installCmd = 'ionic plugin add ' + plugin.locator;
    }

    console.log(installCmd);

    exec(installCmd, function (err, stdout, stderr) {
      if (err) {
        console.log(stderr);
        throw err;
      }

      console.log(stdout);
      console.log(stderr);
    });
  });
});

It would be better if I wrap the platform installs with a promise first then do the plugin installs, but I didn’t want to add a new dependency to the script. It would also be better if I did something like check if the platform and plugins dirs exist already before running the add command.