Gruntfile Editor
An API to modify a Gruntfile.js
content
Installation
npm install --save gruntfile-editor
Example
var GruntfileEditor = ;var editor = ; editor; fs;
API
new GruntfileEditor( content )
Create a new editor instance. You can pass the content of the Gruntfile to edit to the constructor. If no content is provided, a default file structure is used.
editor.insertConfig( name, config )
Insert a configuration block inside the grunt.initConfig()
call.
editor.registerTask( name, tasks )
Register a task inside a named task group
editor;// output: grunt.registerTask('build', ['compass']); editor;// output: grunt.registerTask('build', ['compass', 'uglify']);
You can specify an optional description.
editor;// output: grunt.registerTask('build', 'A task description', ['compass', 'uglify']);
editor.insertVariable( name, value )
Insert a variable to the top of the Gruntfile.
editor;// output: var root = 'project/foo';
editor.prependJavaScript( code )
Insert a piece of arbritary JavaScript code to the top of the Gruntfile.
editor;// output: require('load-grunt-tasks')(grunt);
editor.loadNpmTasks( pluginName )
Load a Grunt plugin.
editor;// output: grunt.loadNpmTasks("grunt-contrib-uglify"); editor;// output:// grunt.loadNpmTasks("grunt-contrib-concat");// grunt.loadNpmTasks("grunt-contrib-uglify");
editor.toString()
Returns the modified Gruntfile as a string.
Licence
Copyright (c) 2012 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.