Last active
August 29, 2015 14:06
-
-
Save grahamgilchrist/4f6c840113bb35afa175 to your computer and use it in GitHub Desktop.
Grunt submodule
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
{ | |
"name": "grunt-my-custom-webfont", | |
"version": "0.0.0", | |
"dependencies": {}, | |
"devDependencies": { | |
"grunt": "0.4.1", | |
"grunt-webfont": "0.4.8", | |
} | |
} |
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
// Project configuration. | |
grunt.initConfig({ | |
'my-custom-webfont': { | |
target1: { | |
//some options | |
}, | |
}, | |
}); |
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
// 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') | |
}): | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require('node_modules/grunt/lib/grunt')
should work just asrequire('grunt')