Last active
December 18, 2015 02:19
-
-
Save b3nj4m/5710012 to your computer and use it in GitHub Desktop.
Local Gruntfile.js which imports a common Gruntfile.js from a component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is a normal Gruntfile with the exception of the deepExtend function added at the end | |
module.exports = function(grunt) { | |
var port = grunt.option('port') || 8000; | |
grunt.initConfig({ | |
//standard grunt config here | |
}); | |
grunt.loadNpmTasks('grunt-cachepath'); | |
grunt.registerTask('default', ['build']); | |
grunt.registerTask('build', function() { | |
//... | |
}); | |
}; | |
var _ = require('underscore'); | |
module.exports.deepExtend = function(config1, config2) { | |
_.each(config2, function(item, idx) { | |
if (config1[idx] === undefined || _.isNumber(item) || _.isString(item) || _.isFunction(item) || !_.isObject(item)) { | |
config1[idx] = item; | |
} | |
else { | |
module.exports.deepExtend(config1[idx], item); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var GLOBAL_FILENAME = './dev/components/gruntfile/GlobalGruntfile.js'; | |
var global; | |
if (fs.existsSync(GLOBAL_FILENAME)) { | |
global = require(GLOBAL_FILENAME); | |
} | |
else { | |
console.error('Global Gruntfile.js not found. Did you install the gruntfile component?'); | |
process.exit(1); | |
} | |
module.exports = function(grunt) { | |
global(grunt); | |
var globalConfig = grunt.config.getRaw() || {}; | |
//optionally define globalConfig overrides here | |
//this example overrides the port and hostname settings on connect:serve (it is equivalent to the method used below) | |
var localConfig = { | |
connect: { | |
serve: { | |
options: { | |
port: 8002, | |
hostname: '0.0.0.0' | |
} | |
} | |
} | |
}; | |
global.deepExtend(globalConfig, localConfig); | |
//optionally make edits to the config here instead of putting them in localConfig | |
//this example overrides the port and hostname settings on connect:serve | |
globalConfig.connect.serve.options.port = 8002; | |
globalConfig.connect.serve.options.hostname = '0.0.0.0'; | |
//give grunt the new config | |
grunt.initConfig(globalConfig); | |
//optionally register any custom tasks | |
grunt.registerTask('server', 'connect:serve'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment