Skip to content

Commit

Permalink
feat(grunt): Add support for Environment Specific Configuration. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonetto committed Jul 29, 2014
1 parent b9c4f29 commit 4aa7062
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ IonicGenerator.prototype.readIndex = function readIndex() {
};

IonicGenerator.prototype.appJs = function appJs() {
var scripts = fs.readdirSync(path.join(process.cwd(), 'app/scripts'));
var scripts = ['config.js'];
scripts = scripts.concat(fs.readdirSync(path.join(process.cwd(), 'app/scripts')));
scripts = _.map(scripts, function (script) {
return 'scripts/' + script;
});
Expand Down
33 changes: 32 additions & 1 deletion templates/common/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ module.exports = function (grunt) {
images: 'images'
},

// Environment Variables for Angular App
// This creates an Angular Module that can be injected using via ENV
// Add any desired constants to the ENV objects below.
ngconstant: {
options: {
space: ' ',
wrap: '"use strict";\n\n {%= __ngModule %}',
name: 'config',
dest: '<%%= yeoman.app %>/scripts/config.js'
},
development: {
constants: {
ENV: {
name: 'development',
apiEndpoint: 'http://dev.yoursite.com:10000/'
}
}
},
production: {
constants: {
ENV: {
name: 'production',
apiEndpoint: 'http://api.yoursite.com/'
}
}
}
},

// Watches files for changes and runs tasks based on the changed files
watch: {
js: {
Expand All @@ -44,7 +72,8 @@ module.exports = function (grunt) {
tasks: ['newer:copy:styles', 'autoprefixer']
},<% } %>
gruntfile: {
files: ['Gruntfile.js']
files: ['Gruntfile.js'],
tasks: ['ngconstant:development']
},
livereload: {
options: {
Expand Down Expand Up @@ -458,6 +487,7 @@ module.exports = function (grunt) {

grunt.task.run([
'clean:server',
'ngconstant:development',
'bower-install',
'concurrent:server',
'autoprefixer',
Expand All @@ -476,6 +506,7 @@ module.exports = function (grunt) {

grunt.registerTask('build', [
'clean:dist',
'ngconstant:production',
'bower-install',
'useminPrepare',
'concurrent:dist',
Expand Down
5 changes: 4 additions & 1 deletion templates/common/_gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ node_modules
www
.tmp
.sass-cache
.DS_Store
<%= appPath %>/bower_components
coverage
platforms
plugins
*.swp
*.swo
*.log
*.DS_Store
1 change: 1 addition & 0 deletions templates/common/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"grunt-newer": "~0.6.1",
"grunt-usemin": "~2.0.0",
"grunt-ng-annotate": "~0.2.3",
"grunt-ng-constant": "^0.5.0",
"grunt-karma": "~0.8.0",
"karma": "~0.12.0",
"karma-mocha": "~0.1.3",
Expand Down

0 comments on commit 4aa7062

Please sign in to comment.