From aca6a793e9965dbbb4f6163333e14683116cb108 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Wed, 13 May 2015 11:29:51 +0300 Subject: [PATCH] adding a grunt-contrib-copy dev dependency to create a local copy of local.js file and then updating config.js to include it and gruntfile.js to run it in all common tasks --- config/config.js | 5 +++-- gruntfile.js | 19 +++++++++++++++---- package.json | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config/config.js b/config/config.js index aa16f12e..efe758dc 100644 --- a/config/config.js +++ b/config/config.js @@ -4,7 +4,8 @@ * Module dependencies. */ var _ = require('lodash'), - glob = require('glob'); + glob = require('glob'), + fs = require('fs'); /** * Load app configurations @@ -12,7 +13,7 @@ var _ = require('lodash'), module.exports = _.extend( require('./env/all'), require('./env/' + process.env.NODE_ENV), - require('./env/local.js') || {} + (fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {} ); /** diff --git a/gruntfile.js b/gruntfile.js index b45a9cd7..7f995da0 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,5 +1,7 @@ 'use strict'; +var fs = require('fs'); + module.exports = function(grunt) { // Unified Watch Object var watchFiles = { @@ -143,6 +145,15 @@ module.exports = function(grunt) { unit: { configFile: 'karma.conf.js' } + }, + copy: { + localConfig: { + src: 'config/env/development.js', + dest: 'config/env/local.js', + filter: function() { + return !fs.existsSync('config/env/local.js'); + } + } } }); @@ -162,13 +173,13 @@ module.exports = function(grunt) { }); // Default task(s). - grunt.registerTask('default', ['lint', 'concurrent:default']); + grunt.registerTask('default', ['lint', 'copy:localConfig', 'concurrent:default']); // Debug task. - grunt.registerTask('debug', ['lint', 'concurrent:debug']); + grunt.registerTask('debug', ['lint', 'copy:localConfig', 'concurrent:debug']); // Secure task(s). - grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']); + grunt.registerTask('secure', ['env:secure', 'lint', 'copy:localConfig', 'concurrent:default']); // Lint task(s). grunt.registerTask('lint', ['jshint', 'csslint']); @@ -177,7 +188,7 @@ module.exports = function(grunt) { grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']); // Test task. - grunt.registerTask('test', ['test:server', 'test:client']); + grunt.registerTask('test', ['copy:localConfig', 'test:server', 'test:client']); grunt.registerTask('test:server', ['env:test', 'mochaTest']); grunt.registerTask('test:client', ['env:test', 'karma:unit']); }; diff --git a/package.json b/package.json index 8d2a05b9..091f2e12 100755 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "grunt-mocha-test": "~0.12.1", "grunt-karma": "~0.9.0", "load-grunt-tasks": "~1.0.0", + "grunt-contrib-copy": "0.8", "karma": "~0.12.0", "karma-jasmine": "~0.2.1", "karma-coverage": "~0.2.0",