From 23fe173a577210485cae9cb6624ad17035cc834d Mon Sep 17 00:00:00 2001 From: Prabin Varma Date: Thu, 13 Mar 2014 14:53:48 -0500 Subject: [PATCH] Added Env Config --- Gruntfile.js | 49 ++++++++++++++++++++++++++++++++++++++++---- app/scripts/app.js | 8 +++++--- config/config.js | 9 ++++++++ config/env/dev.json | 5 +++++ config/env/prod.json | 5 +++++ package.json | 1 + 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 config/config.js create mode 100644 config/env/dev.json create mode 100644 config/env/prod.json diff --git a/Gruntfile.js b/Gruntfile.js index 6405367..531cab3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -31,14 +31,14 @@ module.exports = function (grunt) { watch: { views: { files: ['<%= yeoman.app %>/{,*/}*.html'], - tasks: ['htmlmin', 'browserify:test'], + tasks: ['htmlmin', 'browserify:test', 'karma'], options: { livereload: true } }, js: { files: ['<%= yeoman.app %>/scripts/{,*/}*.js'], - tasks: ['newer:jshint:all', 'copy:scripts', 'browserify:test'], + tasks: ['newer:jshint:all', 'replace:dev', 'copy:scripts', 'browserify:test', 'karma'], options: { livereload: true } @@ -387,6 +387,35 @@ module.exports = function (grunt) { } }, + replace: { + dev: { + options: { + patterns: [{ + json: grunt.file.readJSON('./config/env/dev.json') + }] + }, + files: [{ + expand: true, + flatten: true, + src: ['./config/config.js'], + dest: '.tmp/scripts/services/' + }] + }, + prod: { + options: { + patterns: [{ + json: grunt.file.readJSON('./config/env/prod.json') + }] + }, + files: [{ + expand: true, + flatten: true, + src: ['./config/config.js'], + dest: '.tmp/scripts/services/' + }] + } + }, + // Test settings karma: { unit: { @@ -419,6 +448,7 @@ module.exports = function (grunt) { grunt.task.run([ 'clean:server', + 'replace:dev', 'bower-install', 'concurrent:server', 'autoprefixer', @@ -438,6 +468,7 @@ module.exports = function (grunt) { grunt.registerTask('test', [ 'clean:server', + 'replace:dev', 'concurrent:test', 'autoprefixer', 'copy:scripts', @@ -447,8 +478,18 @@ module.exports = function (grunt) { 'karma' ]); - grunt.registerTask('build', [ + grunt.registerTask('build:dev', [ 'clean:dist', + 'replace:dev', + 'build' + ]); + + grunt.registerTask('build:prod', [ + 'replace:prod', + 'build' + ]); + + grunt.registerTask('build', [ 'bower-install', 'useminPrepare', 'concurrent:dist', @@ -468,6 +509,6 @@ module.exports = function (grunt) { grunt.registerTask('default', [ 'newer:jshint', 'test', - 'build' + 'build:dev' ]); }; diff --git a/app/scripts/app.js b/app/scripts/app.js index 25918f0..f25af14 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -20,7 +20,8 @@ angular.module('volusionApp', [ 'ngSanitize', 'ui.router', 'seo', - 'pascalprecht.translate' + 'pascalprecht.translate', + require('./services/config').name ]) .provider('api', require('./services/api-provider')) .config(function( @@ -29,10 +30,11 @@ angular.module('volusionApp', [ $locationProvider, $translateProvider, $translatePartialLoaderProvider, - apiProvider) { + apiProvider, + config) { $locationProvider.html5Mode(true); - apiProvider.setBaseRoute('http://www.v65.com/api/v1/'); + apiProvider.setBaseRoute(config.API_URL); $urlRouterProvider.otherwise(getI18NPath); var i18NPrefix = '/:region/:language-:country'; diff --git a/config/config.js b/config/config.js new file mode 100644 index 0000000..23731b6 --- /dev/null +++ b/config/config.js @@ -0,0 +1,9 @@ +/*global angular: true*/ +/*jshint -W109 */ +'use strict'; +var angular = require('angular'); + +module.exports = angular.module('services.config', []) + .constant('config', { + ENV: @@config + }); diff --git a/config/env/dev.json b/config/env/dev.json new file mode 100644 index 0000000..268d74e --- /dev/null +++ b/config/env/dev.json @@ -0,0 +1,5 @@ +{ + "config": { + "API_URL": "http://volusion.apiary.io" + } +} diff --git a/config/env/prod.json b/config/env/prod.json new file mode 100644 index 0000000..2cfec95 --- /dev/null +++ b/config/env/prod.json @@ -0,0 +1,5 @@ +{ + "config": { + "API_URL": "/api/v1" + } +} diff --git a/package.json b/package.json index 714c4d2..e27a118 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "grunt-karma": "~0.6.2", "grunt-newer": "~0.6.1", "grunt-ngmin": "0.0.3", + "grunt-replace": "~0.7.2", "grunt-rev": "~0.1.0", "grunt-svgmin": "~0.3.1", "grunt-usemin": "~2.0.2",