|
1 |
| -var fs = require('fs'), |
2 |
| - path = require('path'), |
3 |
| - rjs = require('requirejs'); |
| 1 | +var path = require('path'), |
| 2 | + rjs = require('requirejs'); |
4 | 3 |
|
5 | 4 | module.exports = function(grunt) {
|
6 |
| - grunt.task.registerMultiTask('rjs', 'Optimizes javascript that actually is built with requirejs.', function () { |
7 |
| - this.requiresConfig('rjs'); |
| 5 | + grunt.task.registerTask('rjs', 'Optimizes javascript that actually is built with requirejs.', function () { |
| 6 | + this.requiresConfig(this.name); |
| 7 | + grunt.helper('rjs:optimize:js', grunt.config(this.name), this.async()); |
| 8 | + }); |
8 | 9 |
|
9 |
| - grunt.helper('rjs:optimize:js', this.data, this.async()); |
10 |
| - }); |
| 10 | + grunt.registerHelper('rjs:optimize:js', function(options, cb) { |
| 11 | + if(!cb) { cb = options; options = {}; } |
| 12 | + grunt.log.subhead('Options:'); |
| 13 | + grunt.helper('inspect', options); |
11 | 14 |
|
12 |
| - grunt.registerHelper('rjs:optimize:js', function(file, options, cb) { |
13 |
| - if(!cb) { cb = options; options = {}; } |
14 |
| - options.baseUrl = './'; |
15 |
| - options.appDir = 'js'; |
16 |
| - options.dir = grunt.config('output')+options.appDir; |
17 |
| - options.modules = [{ |
18 |
| - name: file |
19 |
| - }]; |
20 |
| - rjs.optimize(options, function() { |
21 |
| - cb(); |
22 |
| - }); |
23 |
| - }); |
| 15 | + var originals = options.modules.map(function(m) { |
| 16 | + return { |
| 17 | + name: m.name, |
| 18 | + body: grunt.file.read(path.join(options.baseUrl, options.appDir, m.name + '.js')) |
| 19 | + }; |
| 20 | + }); |
| 21 | + |
| 22 | + rjs.optimize(options, function() { |
| 23 | + originals.forEach(function(m) { |
| 24 | + var filepath = path.join(options.dir, m.name + '.js'); |
| 25 | + grunt.log |
| 26 | + .writeln('rjs optimized module ' + m.name) |
| 27 | + .writeln('>> ' + filepath); |
| 28 | + grunt.helper('min_max_info', grunt.file.read(filepath), m.body); |
| 29 | + }); |
| 30 | + |
| 31 | + cb(); |
| 32 | + }); |
| 33 | + }); |
24 | 34 |
|
25 | 35 | };
|
0 commit comments