Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 429bd33e526b5e51821099a41d13f23a948e3769 @jney committed Jul 26, 2012
Showing with 320 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .npmignore
  3. +22 −0 LICENSE-MIT
  4. +40 −0 README.md
  5. +3 −0 bin/grunt-md5
  6. +40 −0 grunt.js
  7. +40 −0 package.json
  8. +88 −0 tasks/grunt-md5.js
  9. +1 −0 test/fixtures/js/test.js
  10. +1 −0 test/fixtures/output/8ba6ae54067b2766661cd6f11331f557.js
  11. +35 −0 test/grunt.js
  12. +15 −0 test/invalid.html
  13. +17 −0 test/md5_test.js
  14. +16 −0 test/valid.html
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1 @@
+/node_modules/
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Jean-Sebastien Ney
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
+# grunt-md5
+
+[Grunt][grunt] plugin for generating `MD5` filenames.
+
+## Getting Started
+
+Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-md5`
+
+Then add this line to your project's `grunt.js` gruntfile:
+
+```javascript
+grunt.loadNpmTasks('grunt-md5');
+```
+
+Then specify what files you want to generate an md5 filename in your config:
+
+```javascript
+grunt.initConfig({
+ md5: {
+ compile: {
+ files: {
+ 'dest/folder': 'src/file'
+ },
+ options: {
+ keepExtension: true
+ }
+ }
+ }
+});
+```
+
+[grunt]: https://github.com/cowboy/grunt
+[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
+
+## Release History
+* 0.0.1 First Release
+
+## License
+Copyright (c) 2012 Jean-Sébastien Ney
+Licensed under the MIT license.
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+require('grunt').npmTasks('grunt-md5').cli();
+
@@ -0,0 +1,40 @@
+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');
+
+};
@@ -0,0 +1,40 @@
+{
+ "name": "grunt-md5",
+ "description": "generate md5 filename",
+ "version": "0.0.1",
+ "homepage": "https://github.com/jney/grunt-md5",
+ "author": {
+ "name": "Jean-Sébastien Ney",
+ "url": "http://github.com/jney/md5"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jney/grunt-md5.git"
+ },
+ "bugs": {
+ "url": "https://github.com/jney/grunt-md5/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/jney/grunt-md5/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "grunt.js",
+ "bin": "bin/grunt-md5",
+ "engines": {
+ "node": "*"
+ },
+ "scripts": {
+ "test": "grunt --base ./test/ --config ./test/grunt.js"
+ },
+ "dependencies": {
+ "grunt": "~0.3.10"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.10"
+ },
+ "keywords": [
+ "gruntplugin"
+ ]
+}
@@ -0,0 +1,88 @@
+/*
+ * grunt-md5
+ * https://github.com/jney/grunt-md5
+ *
+ * Copyright (c) 2012 Jean-Sébastien Ney
+ * Licensed under the MIT license.
+ */
+
+/*global _:true */
+
+module.exports = function(grunt) {
+ 'use strict';
+
+ // TODO: ditch this when grunt v0.4 is released
+ grunt.util = grunt.util || grunt.utils;
+
+ var _ = grunt.util._;
+ var async = grunt.util.async;
+ var crypto = require('crypto');
+
+ grunt.registerMultiTask('md5', 'Generate a md5 filename', function() {
+ var options = grunt.helper('options', this);
+
+ grunt.verbose.writeflags(options, 'Options');
+
+ // TODO: ditch this when grunt v0.4 is released
+ this.files = this.files || grunt.helper('normalizeMultiTaskFiles', this.data, this.target);
+
+ var done = this.async();
+
+ var srcFiles;
+ var destDir;
+
+ async.forEachSeries(this.files, function(file, next) {
+ srcFiles = grunt.file.expandFiles(file.src);
+ destDir = file.dest;
+ // TODO generate error if file does not exists
+
+ if (grunt.file.exists(destDir) === false) {
+ grunt.file.mkdir(destDir);
+ }
+
+ async.concatSeries(srcFiles, function(srcFile, nextConcat) {
+ grunt.helper('md5', srcFile, destDir, options, function(file) {
+ nextConcat(file);
+ });
+ }, function(filename) {
+ grunt.log.writeln('File \'' + filename + '\' created.');
+ next();
+ });
+ }, function() {
+ done();
+ });
+ });
+
+ grunt.registerHelper('md5', function(srcFile, destPath, opts, callback) {
+ try {
+ var srcCode = grunt.file.read(srcFile);
+ var ext = '';
+ if (opts.keepExtension !== false) {
+ ext = '.' + fileExtension(srcFile);
+ }
+ var filename = require('crypto').
+ createHash('md5').
+ update(srcCode).
+ digest('hex') + ext;
+
+ var output = require('path').join(destPath, filename);
+
+ grunt.file.copy(srcFile, output);
+
+ callback(output);
+
+ } catch(err) {
+ grunt.log.error(err);
+ grunt.fail.warn("Fail to generate an MD5 file name");
+ }
+ });
+
+ function fileExtension(filename) {
+ var array = filename.split('.');
+ if (array.length === 1) {
+ return '';
+ } else {
+ return array.pop();
+ }
+ }
+};
@@ -0,0 +1 @@
+/* only for testing */
@@ -0,0 +1 @@
+/* only for testing */
@@ -0,0 +1,35 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.file.mkdir('fixtures/output');
+
+ grunt.initConfig({
+ pkg: {
+ name: 'grunt-md5',
+ version: '0.0.1'
+ },
+
+ test: {
+ tasks: ["*_test.js"],
+ },
+
+ clean: {
+ output: ['fixtures/output']
+ },
+
+ md5: {
+ compile: {
+ files: {
+ 'fixtures/output': 'fixtures/js/test.js'
+ },
+ options: {
+ keepExtension: true
+ }
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-contrib');
+ grunt.loadTasks('../tasks');
+ grunt.registerTask('default', 'clean md5 test:tasks');
+};
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>jQuery UI Autocomplete - Custom data and display</title>
+ <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
+ <script src="../../jquery-1.7.2.js"></script>
+</head>
+<body>
+
+<img id="project-icon" src="images/transparent_1x1.png" class="ui-state-default">
+
+<br clear="both" />
+
+</body>
+</html>
@@ -0,0 +1,17 @@
+var fs = require('fs');
+var grunt = require('grunt');
+
+exports.md5 = {
+ main: function(test) {
+ test.expect(1);
+
+ var filename = require('crypto').
+ createHash('md5').
+ update(fs.readFileSync('fixtures/js/test.js', 'utf8')).
+ digest('hex') + '.js';
+ var result = fs.existsSync('fixtures/output/'+filename);
+ test.ok(result, 'should generate a md5 filename');
+
+ test.done();
+ }
+};
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>jQuery UI Autocomplete - Custom data and display</title>
+ <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
+ <script src="../../jquery-1.7.2.js"></script>
+</head>
+<body>
+
+<img id="project-icon" src="images/transparent_1x1.png" class="ui-state-default" alt="default">
+
+<br style="clear:both" />
+
+</body>
+</html>

0 comments on commit 429bd33

Please sign in to comment.