Skip to content

Instantly share code, notes, and snippets.

@grahamgilchrist
Last active August 29, 2015 14:06
Show Gist options
  • Save grahamgilchrist/4f6c840113bb35afa175 to your computer and use it in GitHub Desktop.
Save grahamgilchrist/4f6c840113bb35afa175 to your computer and use it in GitHub Desktop.
Grunt submodule
{
"name": "grunt-my-custom-webfont",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "0.4.1",
"grunt-webfont": "0.4.8",
}
}
// Project configuration.
grunt.initConfig({
'my-custom-webfont': {
target1: {
//some options
},
},
});
// pseudo-code
// sub grunt-spawn code done in each task, rather than top-level grunt module
// advantage here compare to sub-grunt is that you can pass options through to internal tasks to override defaults, but
// also the task defines it's own name in standard grunt task way,a nd you don't have to alias it again in the parent gruntfile
// like subgrunt
// this results in some repeated code per 'sub' task, but this can be abstracted out again via a library
// the spawn code could be in a helper npm module pulled in by each grunt sub-task
module.exports = function(grunt) {
'use strict';
grunt.registerTask('my-custom-webfont', function () {
//copied from grunt-subgrunt
// https://github.com/tusbar/grunt-subgrunt
var defaultTaskOptions = {
webfont: {
//default webfont options
}
}
//using spawn does not allow config to be passed to sub-tasks?
//var done = this.async();
//grunt.util.spawn({
// cmd: path.resolve('node_modules/.bin/grunt'),
// args: this.data.args || [],
// opts: {cwd: subdir},
// }, function(error, result, code) {
// if (code === 127) {
// grunt.log.error('Error running sub-grunt. Did you run "npm install" in the sub-project?');
// } else {
// grunt.log.writeln('\n' + result.stdout);
// }
// done(code === 0);
// });
//});
//what about another instance of grunt?
var subGrunt = require('node_modules/grunt/lib/grunt'),
subGrunt.mergeConfig(defaultConfig);
subGrunt.mergeConfig(options);
subGrunt.task.run('custom-internal-task')
}):
};
@henrahmagix
Copy link

require('node_modules/grunt/lib/grunt') should work just as require('grunt')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment