Skip to content

Commit

Permalink
Dynamic config.ts class
Browse files Browse the repository at this point in the history
  • Loading branch information
lathonez committed Sep 1, 2016
1 parent 697b5ce commit b1a9489
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*.tmp
*.tmp.*
*.map
./config.xml
log.txt
*.sublime-project
*.sublime-workspace
Expand All @@ -25,6 +24,10 @@ www/build/
$RECYCLE.BIN/
.io-config.json

# dynamic config files generated at build time
config.xml
config/config.ts

.DS_Store
Thumbs.db
UserInterfaceState.xcuserstate
Expand Down
3 changes: 3 additions & 0 deletions app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ionicBootstrap, MenuController, Nav, Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { ClickersService, DataService, StorageService } from './services';
import { ClickerList, Page2 } from './pages';
import { Config } from '../config/config';
import actions from './actions';
import effects from './effects';
import reducers from './reducers';
Expand Down Expand Up @@ -47,6 +48,8 @@ export class ClickerApp {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
console.log('api URL ' + Config.apiURL);
console.log('api key ' + Config.apiKey);
});
}

Expand Down
Empty file removed config/dev/app/.keep
Empty file.
6 changes: 6 additions & 0 deletions config/dev/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

export class Config {
public static apiURL: string = 'dev.mycorp.io';
public static apiKey: string = 'mydevapikey';
}
Empty file removed config/prod/app/.keep
Empty file.
6 changes: 6 additions & 0 deletions config/prod/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

export class Config {
public static apiURL: string = 'prod.mycorp.io';
public static apiKey: string = 'myprodapikey';
}
Empty file removed config/qa/app/.keep
Empty file.
6 changes: 6 additions & 0 deletions config/qa/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

export class Config {
public static apiURL: string = 'qa.mycorp.io';
public static apiKey: string = 'myqaapikey';
}
47 changes: 37 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,54 @@ gulp.task('build', ['clean'], function(done){
gulp.task('sass', buildSass);
gulp.task('html', copyHTML);
gulp.task('fonts', copyFonts);
gulp.task('scripts', ['enviroment'], copyScripts);
gulp.task('scripts', ['configure-environment'], copyScripts);
gulp.task('clean', function(){
return del('www/build');
});
gulp.task('lint', tslint);
gulp.task('enviroment', function(){

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

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

return gulp.src(options.src)
.pipe(gulp.dest(options.dest))
.on('end', options.onComplete)
.on('error', options.onError);
gulp.task('copy-config-ts', function(){
var env = process.env.ENV || 'dev';
var opts = {
src: 'config/' + env + '/config.ts',
dest: './config',
onComplete: function() {
console.log('copy-config-ts(' + env.toUpperCase() + '): copied to ./config');
},
onError: function(err) {
console.error(err.toString());
this.emit('end');
}
};
return gulp.src(opts.src)
.pipe(gulp.dest(opts.dest))
.on('end', opts.onComplete)
.on('error', opts.onError);
});

gulp.task('configure-environment', function(done){
return runSequence(
['copy-config-ts', 'copy-config-xml'],
done
);
});
1 change: 1 addition & 0 deletions test/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ gulp.task('lint', () => {
gulp.task('unit-test', (done: Function) => {
runSequence(
['clean'], // Ionic's clean task, nukes the whole of www/build
['configure-environment'],
['lint', 'html'],
'karma',
(<any>done)
Expand Down

0 comments on commit b1a9489

Please sign in to comment.