diff --git a/Gruntfile.js b/Gruntfile.js index 26e1656..5d67184 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -35,9 +35,7 @@ module.exports = function (grunt) { } }, jquery: { - files: { - 'jquery.fn.sortable.min.js': 'jquery.fn.sortable.js' - } + files: {} } }, @@ -54,22 +52,37 @@ module.exports = function (grunt) { }); - grunt.registerTask('jquery', function (arg) { + grunt.registerTask('jquery', function (exportName, uglify) { + if (exportName == 'min') { + exportName = null; + uglify = 'min'; + } + + if (!exportName) { + exportName = 'sortable'; + } + var fs = require('fs'), - filename = 'jquery.fn.sortable.js'; + filename = 'jquery.fn.' + exportName + '.js'; grunt.log.oklns(filename); fs.writeFileSync( filename, (fs.readFileSync('jquery.binding.js') + '') + .replace('$.fn.sortable', '$.fn.' + exportName) .replace('/* CODE */', (fs.readFileSync('Sortable.js') + '') .replace(/^[\s\S]*?function[\s\S]*?(var[\s\S]+)\/\/\s+Export[\s\S]+/, '$1') ) ); - if (arg === 'min') { + if (uglify) { + var opts = {}; + + opts['jquery.fn.' + exportName + '.min.js'] = filename; + grunt.config.set('uglify.jquery.files', opts); + grunt.task.run('uglify:jquery'); } }); diff --git a/README.md b/README.md index c685025..60caa87 100644 --- a/README.md +++ b/README.md @@ -603,6 +603,7 @@ Now you can use `jquery.fn.sortable.js`:
$("#list").sortable("{method-name}", "foo", "bar"); // call an instance method with parameters ``` +And `grunt jquery:mySortableFunc` → `jquery.fn.mySortableFunc.js` ---