lathonez / clicker

Ionic 2 + @angular/cli Seed Project : Angular2 + Typescript + Karma + Protractor + Travis
http://lathonez.com/2018/ionic-2-unit-testing/
MIT License
430 stars 136 forks source link

Use specific files for different enviroments #134

Closed cmolina closed 8 years ago

cmolina commented 8 years ago

It would be awesome to have files for each environment (development, production, qa, etc) available on /config, and to copy them just before running the server/compiling. I am thinking on using different config.xml, and also a static class storing API's urls.

lathonez commented 8 years ago

Totally agree. There must be some guidance out there from Ionic (or Angular2) about the best way of doing this?

The guys at angular2-seed are using different build tasks in gulp per environment (which would take care of the copying for you, I guess). I don't have time to dig into it right now.

https://github.com/mgechev/angular2-seed/blob/master/gulpfile.ts#L13-L67

It's really a question for the Ionic guys, they need to recommend a way for this to be done.

lathonez commented 8 years ago

https://forum.ionicframework.com/t/debate-ionic-2-environment-development-variables-setup/44061

cmolina commented 8 years ago

My first attempt was to make an cordova hook -but we need to run the task before gulp scripts.

So I added this new task

gulp.task('enviroment', function(){
  var env = process.env.ENV || 'dev';
  var options = {
    src: 'config/' + env + '/**/*.*',
    dest: './',
    onComplete: function() {
      console.log('All env files were copied.');
    },
    onError: function(err) {
      console.error(err.toString());
      this.emit('end');
    }
  }

  return gulp.src(options.src)
    .pipe(gulp.dest(options.dest))
    .on('end', options.onComplete)
    .on('error', options.onError);
});

and I added as a dependency to script.

gulp.task('scripts', ['enviroment'], copyScripts);

So now, to make a build for android in the QA enviroment, you need to run ENV=qa ionic build android. What do you think?

lathonez commented 8 years ago

Looks good, I think the solution has to be a gulp script at the moment.

I keep being reminded (#131, https://github.com/lathonez/clicker/issues/38#issuecomment-239497285) that Ionic are moving back to webpack. Not sure what the setup is going to be after that with regard to gulp, but having environment specific config files and [insert task runner here] copying them at build time is the way to go.

Incidentally, our closed source project will be going to prod within the next couple of weeks, so we'll need to address this ourselves.

If we deviate from the pattern above I'll be sure to raise here for discussion.

For now I'd like to close this (I'll add a link from the blog post). Is that OK with you or is there something else to cover?

lathonez commented 8 years ago

Ah I hadn't thought of doing a PR! It's 'cause I don't see myself as having ownership of Ionic's gulpfile (I rarely touch it, if ever).

I do think it's a good idea to have this as an example though.

lathonez commented 8 years ago

135 closed