https://github.com/sboudrias/gruntfile-editor
An API to modify a Gruntfile.js content
https://github.com/sboudrias/gruntfile-editor
Last synced: about 2 months ago
JSON representation
An API to modify a Gruntfile.js content
- Host: GitHub
- URL: https://github.com/sboudrias/gruntfile-editor
- Owner: SBoudrias
- License: mit
- Created: 2014-04-07T01:21:31.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T08:50:33.000Z (over 5 years ago)
- Last Synced: 2025-08-18T16:12:10.024Z (about 2 months ago)
- Language: JavaScript
- Size: 1.92 MB
- Stars: 40
- Watchers: 5
- Forks: 10
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
Gruntfile Editor
================[](http://badge.fury.io/js/gruntfile-editor) [](https://travis-ci.org/SBoudrias/gruntfile-editor) [](https://coveralls.io/github/SBoudrias/gruntfile-editor?branch=master) [](https://david-dm.org/SBoudrias/gruntfile-editor)
An API to modify a `Gruntfile.js` content
Installation
---------------```
npm install --save gruntfile-editor
```Example
---------------```javascript
var GruntfileEditor = require('gruntfile-editor');
var editor = new GruntfileEditor();editor.insertConfig('compass', '{ foo: "bar" }');
fs.writeFileSync('Gruntfile.js', editor.toString());
```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
```javascript
editor.registerTask('build', 'compass');
// output: grunt.registerTask('build', ['compass']);editor.registerTask('build', ['compass', 'uglify']);
// output: grunt.registerTask('build', ['compass', 'uglify']);
```You can specify an optional description.
```javascript
editor.registerTask('build', 'A task description', ['compass', 'uglify']);
// output: grunt.registerTask('build', 'A task description', ['compass', 'uglify']);
```### `editor.insertVariable( name, value )`
Insert a variable to the top of the Gruntfile.
```javascript
editor.insertVariable('root', '"project/foo"');
// output: var root = 'project/foo';
```### `editor.prependJavaScript( code )`
Insert a piece of arbritary JavaScript code to the top of the Gruntfile.
```javascript
editor.prependJavaScript('require(\'load-grunt-tasks\')(grunt);');
// output: require('load-grunt-tasks')(grunt);
```### `editor.loadNpmTasks( pluginName )`
Load a Grunt plugin.
```javascript
editor.loadNpmTasks('grunt-contrib-uglify');
// output: grunt.loadNpmTasks("grunt-contrib-uglify");editor.loadNpmTasks(['grunt-contrib-uglify', 'grunt-contrib-concat']);
// 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.