grunt-rewrite
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -26,3 +26,3 @@ /* | ||
quotes: { | ||
src: ['misc/**/*.js'], | ||
src: 'README.md', | ||
editor: function(src) { | ||
@@ -29,0 +29,0 @@ return src.toUpperCase(); |
{ | ||
"name": "grunt-rewrite", | ||
"description": "A Grunt plugin to edit & replace file contents.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/JamieMason/grunt-rewrite", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -5,25 +5,16 @@ # grunt-rewrite | ||
## Getting Started | ||
grunt-rewrite takes one or more files and a function which when given the contents and path of a file, should return new content to be written to that file. | ||
This plugin requires Grunt `~0.4.1` | ||
Imagine you have a file at `src/languages.json` and you want to mess with it. | ||
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the | ||
[Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a | ||
[Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once | ||
you're familiar with that process, you may install this plugin with this command: | ||
```shell | ||
npm install grunt-rewrite --save-dev | ||
```json | ||
[{ | ||
"name": "Javanese", | ||
"description": "Javanese is the language of the Javanese people from the central and eastern parts of the island of Java, in Indonesia. There are also pockets of Javanese speakers in the northern coast of western Java. It is the native language of more than 75,500,000 people (more than 30% of total population in Indonesia)." | ||
}] | ||
``` | ||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of | ||
JavaScript: | ||
You set your `Gruntfile.js` up like so; | ||
```js | ||
grunt.loadNpmTasks('grunt-rewrite'); | ||
``` | ||
## Example Gruntfile.js | ||
```js | ||
module.exports = function(grunt) { | ||
@@ -35,5 +26,5 @@ | ||
quotes: { | ||
src: ['src/foo.txt', 'src/bar.txt'], | ||
src: 'src/languages.json', | ||
editor: function(contents, filePath) { | ||
return contents.toUpperCase(); | ||
return contents.replace(/Javanese/g, 'JavaScript'); | ||
} | ||
@@ -49,1 +40,53 @@ } | ||
``` | ||
and `src/languages.json` now reads as follows; | ||
```json | ||
[{ | ||
"name": "JavaScript", | ||
"description": "JavaScript is the language of the JavaScript people from the central and eastern parts of the island of Java, in Indonesia. There are also pockets of JavaScript speakers in the northern coast of western Java. It is the native language of more than 75,500,000 people (more than 30% of total population in Indonesia)." | ||
}] | ||
``` | ||
## Getting Started | ||
This plugin requires Grunt `~0.4.1` | ||
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: | ||
```shell | ||
npm install grunt-rewrite --save-dev | ||
``` | ||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
```js | ||
grunt.loadNpmTasks('grunt-rewrite'); | ||
``` | ||
## Configuration | ||
Any valid value for `src` in the Grunt documentation is valid here, some examples; | ||
```js | ||
rewrite: { | ||
oneFile: { | ||
src: 'src/foo.txt', | ||
editor: function(contents, filePath) { | ||
return '/* ' + filePath + ' */\n\n' + contents; | ||
} | ||
}, | ||
arrayOfFiles: { | ||
src: ['src/foo.txt', 'src/bar.txt'], | ||
editor: function(contents, filePath) { | ||
return contents.toUpperCase(); | ||
} | ||
}, | ||
patternMatch: { | ||
src: '**/*.js', | ||
editor: function(contents, filePath) { | ||
return contents.toUpperCase(); | ||
} | ||
} | ||
} | ||
``` |
@@ -47,2 +47,6 @@ 'use strict'; | ||
if (!grunt.file.isFile(filePath)) { | ||
return grunt.log.write('skipped "' + filePath + '" as is not a file'); | ||
} | ||
var original = grunt.file.read(filePath); | ||
@@ -49,0 +53,0 @@ var rewritten = subTask.editor(original, filePath); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9074
133
90