Permalink
Browse files

Upgrading to grunt 0.4.

  • Loading branch information...
1 parent 3f93a79 commit 419dfb7ccfac730a22709a3d8e00b3782ee616bf @Luismahou committed Feb 19, 2013
View
@@ -0,0 +1,14 @@
+{
+ "curly": true,
+ "eqeqeq": true,
+ "immed": true,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "sub": true,
+ "undef": true,
+ "boss": true,
+ "eqnull": true,
+ "node": true,
+ "es5": true
+}
View
@@ -0,0 +1,42 @@
+/*
+ * grunt-hashres
+ * https://github.com/luismahou/grunt-hashres
+ *
+ * Copyright (c) 2013 luismahou
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ jshint: {
+ all: [
+ 'Gruntfile.js',
+ 'tasks/*.js',
+ '<%= vows.all.files %>',
+ ],
+ options: {
+ jshintrc: '.jshintrc',
+ },
+ },
+
+ vows: {
+ all: {
+ files: 'test/*.spec.js'
+ }
+ }
+
+ });
+
+ // These plugins provide necessary tasks.
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-clean');
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
+ grunt.loadNpmTasks('grunt-vows');
+
+ grunt.registerTask('default', ['jshint', 'vows']);
+
+};
View
@@ -1,4 +1,4 @@
-Copyright (c) 2012 Luismahou
+Copyright (c) 2013 luismahou
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
View
127 README.md
@@ -1,72 +1,95 @@
# grunt-hashres
-Hashes your js and css files and rename the ```<script>``` and ```<link>``` declarations that refer to them in your html/php/etc files.
+> )
## Getting Started
-Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-hashres`
+_If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
-Then add this line to your project's `grunt.js` gruntfile:
+From the same directory as your project's [Gruntfile][Getting Started] and [package.json][], install this plugin with the following command:
+
+```bash
+npm install grunt-hashres --save-dev
+```
+
+Once that's done, add this line to your project's Gruntfile:
```js
grunt.loadNpmTasks('grunt-hashres');
```
+If the plugin has been installed correctly, running `grunt --help` at the command line should list the newly-installed plugin's task or tasks. In addition, the plugin should be listed in package.json as a `devDependency`, which ensures that it will be installed whenever the `npm install` command is run.
+
[grunt]: http://gruntjs.com/
-[getting_started]: https://github.com/gruntjs/grunt/blob/master/docs/getting_started.md
+[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
+[package.json]: https://npmjs.org/doc/json.html
+
+## The "hashres" task
-## Documentation
-Add the following to your ```grunt.js``` file, inside the ```initConfig``` function:
+### Overview
+In your project's Gruntfile, add a section named `hashres` to the data object passed into `grunt.initConfig()`.
```js
-hashres: {
- // hashres is a multitask. Here 'prod' is the name of the subtask. You can have as many as you want.
- prod: {
- // Files to hash
- files: [
- // WARNING: These files will be renamed!
- 'dist/prod/scripts/my-compressed-and-minified-scripts.js',
- 'dist/prod/styles/my-compressed-and-minified-styles.css'],
- // File that refers to above files and needs to be updated with the hashed name
- out: 'dist/prod/home.php',
- // Optional. Encoding used to read/write files. Default value 'utf8'
- encoding: 'utf8',
- // Optional. Format used to name the files specified in 'files' property.
- // Default value: '${hash}.${name}.cache.${ext}'
- fileNameFormat: '${hash}.${name}.cache.${ext}',
- // Optional. Should files be renamed or only alter the references to the files
- // Default value: true
- renameFiles: true
- }
-}
+grunt.initConfig({
+ hashres: {
+ options: {
+ // Task-specific options go here.
+ },
+ your_target: {
+ // Target-specific file lists and/or options go here.
+ },
+ },
+})
```
-The way this task works follows my workflow: I only hash the .js and .css files of my production release files,
-which are first both uglified and minified.
-If you want to hash a different set of files for a different environment,
-simply add another subtask under ```hashres```.
-
-### Properties
-* ```files```: A single file expression or an array of file expressions.
-Something like ```myscripts/*.js``` would be valid.
-* ```out```: The file expression(s) that refer to the hashed files and that will be updated with the new names.
-You can update more than one file specifying an array of output files: ```[out/fileOne.html, out/fileTwo.html]```
-* ```encoding```: Encoding used to read and write files. Using ```utf8``` by default.
-* ```fileNameFormat```: The files specified in property ```files``` will be renamed
-according to the pattern specified in this property. The following variables are allowed:
- * ```${hash}```: the first 8 digits of the md5 of the file.
- * ```${name}```: the original name of the file.
- * ```${ext}```: the original extension of the file.
-* ```renameFiles```: Rename the files or leave them in place and only alter the references to them in ```out```. Defaults to ```true```
+### Options
+
+#### options.separator
+Type: `String`
+Default value: `', '`
+
+A string value that is used to do something with whatever.
+
+#### options.punctuation
+Type: `String`
+Default value: `'.'`
+
+A string value that is used to do something else with whatever else.
+
+### Usage Examples
+
+#### Default Options
+In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`
+
+```js
+grunt.initConfig({
+ hashres: {
+ options: {},
+ files: {
+ 'dest/default_options': ['src/testing', 'src/123'],
+ },
+ },
+})
+```
+
+#### Custom Options
+In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`
+
+```js
+grunt.initConfig({
+ hashres: {
+ options: {
+ separator: ': ',
+ punctuation: ' !!!',
+ },
+ files: {
+ 'dest/default_options': ['src/testing', 'src/123'],
+ },
+ },
+})
+```
## Contributing
-In lieu of a formal styleguide, take care to maintain the existing coding style.
-Add unit tests for any new or changed functionality. Lint and test your code using [grunt][grunt].
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt][].
## Release History
-* 19/11/12 - 0.2.1: Optional File Renaming, thanks to [raphaeleidus](https://github.com/raphaeleidus).
-* 14/11/12 - 0.1.5: Feature request [#1](https://github.com/Luismahou/grunt-hashres/issues/1): ```fileNameFormat``` property added.
-* 02/11/12 - 0.1.3: First working release.
-
-## License
-Copyright (c) 2012 Luismahou
-Licensed under the MIT license.
+_(Nothing yet)_
View
@@ -1,2 +0,0 @@
-#!/usr/bin/env node
-require('grunt').npmTasks('grunt-hashres').cli();
View
@@ -1,40 +0,0 @@
-module.exports = function(grunt) {
-
- // Project configuration.
- grunt.initConfig({
- test: {
- files: ['test/**/*.js']
- },
- lint: {
- files: ['grunt.js', 'tasks/**/*.js', 'test/**/*.js']
- },
- watch: {
- files: '<config:lint.files>',
- tasks: 'default'
- },
- jshint: {
- options: {
- curly: true,
- eqeqeq: true,
- immed: true,
- latedef: true,
- newcap: true,
- noarg: true,
- sub: true,
- undef: true,
- boss: true,
- eqnull: true,
- node: true,
- es5: true
- },
- globals: {}
- }
- });
-
- // Load local tasks.
- grunt.loadTasks('tasks');
-
- // Default task.
- grunt.registerTask('default', 'lint test');
-
-};
View
@@ -1,34 +1,37 @@
{
"name": "grunt-hashres",
"description": "Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.",
- "version": "0.2.1",
- "homepage": "https://github.com/Luismahou/grunt-hashres",
+ "version": "0.3.0",
+ "homepage": "https://github.com/luismahou/grunt-hashres",
"author": {
- "name": "Luismahou"
+ "name": "luismahou"
},
"repository": {
"type": "git",
- "url": "git://github.com/Luismahou/grunt-hashres.git"
+ "url": "git://github.com/luismahou/grunt-hashres.git"
},
"bugs": {
- "url": "https://github.com/Luismahou/grunt-hashres/issues"
+ "url": "https://github.com/luismahou/grunt-hashres/issues"
},
"licenses": [
{
"type": "MIT",
- "url": "https://github.com/Luismahou/grunt-hashres/blob/master/LICENSE-MIT"
+ "url": "https://github.com/luismahou/grunt-hashres/blob/master/LICENSE-MIT"
}
],
- "main": "grunt.js",
- "bin": "bin/grunt-hashres",
+ "main": "Gruntfile.js",
"engines": {
- "node": "*"
+ "node": ">= 0.8.0"
},
"scripts": {
"test": "node ./node_modules/vows/bin/vows --spec"
},
"devDependencies": {
- "grunt": "~0.3.16",
+ "grunt-contrib-jshint": "0.1.1rc6",
+ "grunt-contrib-clean": "0.4.0rc6",
+ "grunt-contrib-nodeunit": "0.1.2rc6",
+ "grunt": "0.4.0rc6",
+ "grunt-vows": "0.3.1",
"vows": "~0.6.4"
},
"keywords": [
@@ -37,4 +40,4 @@
"dependencies": {
"wrench": "~1.4.2"
}
-}
+}
View
@@ -2,31 +2,36 @@
* grunt-hashres
* https://github.com/luismahou/grunt-hashres
*
- * Copyright (c) 2012 Luismahou
+ * Copyright (c) 2013 luismahou
* Licensed under the MIT license.
*/
+'use strict';
+
module.exports = function(grunt) {
- // Loading necessary modules
- var fs = require('fs'),
- path = require('path'),
- crypto = require('crypto'),
- helper = require('./hashresHelper');
+ var helper = require('./hashresHelper');
+
+ grunt.registerMultiTask('hashres', 'Your task description goes here.', function() {
- grunt.registerMultiTask(
- 'hashres',
- 'Hashes your resources and updates the files that refer to them',
- function() {
- // Required properties: 'files' and 'out'
- this.requiresConfig(this.name + '.' + this.target + '.files');
- this.requiresConfig(this.name + '.' + this.target + '.out');
+ // Merging options with defaults
+ var options = this.options({
+ fileNameFormat: '${hash}.${name}.cache.${ext}',
+ encoding : 'utf8',
+ renameFiles : true
+ });
+
+ // Required properties: 'src' and 'dest'
+ this.requiresConfig(this.name + '.' + this.target + '.src');
+ this.requiresConfig(this.name + '.' + this.target + '.dest');
helper.hashAndSub(grunt, {
- files : this.data.files,
- out : this.data.out,
- encoding : this.data.encoding,
- fileNameFormat: this.data.fileNameFormat,
- renameFiles : this.data.renameFiles
+ files: this.files,
+ src : options.src,
+ dest : options.dest,
+ encoding : options.encoding,
+ fileNameFormat: options.fileNameFormat,
+ renameFiles : options.renameFiles
});
});
+
};
Oops, something went wrong.

0 comments on commit 419dfb7

Please sign in to comment.