浏览代码

move amd module loading def to grunt build

Robin Herbots 11 年之前
父节点
当前提交
0c3951a654

+ 2 - 1
.gitignore

@@ -1,4 +1,5 @@
-./InputMask
+InputMask/
+build/
 test.html
 jquery-1.10.2.js
 dist/jQuery.InputMask.*.nupkg

+ 20 - 1
Gruntfile.js

@@ -14,12 +14,16 @@ module.exports = function (grunt) {
         var srcFiles = grunt.file.expand(path + "/*.js");
         for (var srcNdx in srcFiles) {
             var dstFile = srcFiles[srcNdx].replace("js/", "");
+            wrapAMDLoader(srcFiles[srcNdx], "build/" + dstFile, dstFile.indexOf("extension") == -1 ? ["jquery"] : ["jquery", "./jquery.inputmask"]);
             uglifyConfig[dstFile] = {
                 dest: 'dist/inputmask/' + dstFile,
-                src: srcFiles[srcNdx],
+                src: "build/" + dstFile,
                 options: { banner: createBanner(dstFile) }
             };
         }
+
+        srcFiles = grunt.file.expand(path + "/*.extensions.js");
+        srcFiles.splice(0, 0, "js/jquery.inputmask.js");
         uglifyConfig["inputmaskbundle"] = {
             files: {
                 'dist/<%= pkg.name %>.bundle.js': srcFiles
@@ -28,6 +32,20 @@ module.exports = function (grunt) {
         }
         return uglifyConfig;
     }
+    function wrapAMDLoader(src, dst, dependencies) {
+        function stripClosureExecution() {
+            return srcFile.replace(new RegExp("\\(jQuery\\).*$"), "");
+        }
+
+        var srcFile = grunt.file.read(src),
+            dstContent = "(function (factory) {" +
+                "if (typeof define === 'function' && define.amd) {" +
+                "define(" + JSON.stringify(dependencies) + ", factory);" +
+                "} else {" +
+                "factory(jQuery);" +
+                "}}" + stripClosureExecution() + ");";
+        grunt.file.write(dst, dstContent);
+    }
 
     // Project configuration.
     grunt.initConfig({
@@ -43,6 +61,7 @@ module.exports = function (grunt) {
     grunt.loadNpmTasks('grunt-contrib-uglify');
     grunt.loadNpmTasks('grunt-contrib-clean');
     grunt.loadNpmTasks('grunt-contrib-qunit');
+    grunt.loadNpmTasks('grunt-contrib-requirejs');
 
     // Default task(s).
     grunt.registerTask('default', ['clean', 'uglify']);

+ 1 - 1
dist/inputmask/jquery.inputmask.date.extensions.js

@@ -1,5 +1,5 @@
 /*
-* jquery.inputmask.date.extensions
+* jquery.inputmask.date.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)

+ 1 - 1
dist/inputmask/jquery.inputmask.extensions.js

@@ -1,5 +1,5 @@
 /*
-* jquery.inputmask.extensions
+* jquery.inputmask.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)

文件差异内容过多而无法显示
+ 3 - 3
dist/inputmask/jquery.inputmask.js


+ 1 - 1
dist/inputmask/jquery.inputmask.numeric.extensions.js

@@ -1,5 +1,5 @@
 /*
-* jquery.inputmask.numeric.extensions
+* jquery.inputmask.numeric.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)

+ 1 - 1
dist/inputmask/jquery.inputmask.phone.extensions.js

@@ -1,5 +1,5 @@
 /*
-* jquery.inputmask.phone.extensions
+* jquery.inputmask.phone.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)

+ 1 - 1
dist/inputmask/jquery.inputmask.regex.extensions.js

@@ -1,5 +1,5 @@
 /*
-* jquery.inputmask.regex.extensions
+* jquery.inputmask.regex.extensions.js
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)

文件差异内容过多而无法显示
+ 2 - 2
dist/jquery.inputmask.bundle.js


+ 2 - 8
js/jquery.inputmask.date.extensions.js

@@ -7,13 +7,7 @@ Version: 0.0.0
 
 Optional extensions on the jquery.inputmask base
 */
-(function (factory) {
-    if (typeof define === 'function' && define.amd) {
-        define(['jquery', './jquery.inputmask'], factory);
-    } else {
-        factory(jQuery);
-    }
-}(function ($) {
+(function ($) {
     //date & time aliases
     $.extend($.inputmask.defaults.definitions, {
         'h': { //hours
@@ -493,4 +487,4 @@ Optional extensions on the jquery.inputmask base
     });
 
     return $.fn.inputmask;
-}));
+})(jQuery);

+ 2 - 8
js/jquery.inputmask.extensions.js

@@ -7,13 +7,7 @@ Version: 0.0.0
 
 Optional extensions on the jquery.inputmask base
 */
-(function (factory) {
-    if (typeof define === 'function' && define.amd) {
-        define(['jquery', './jquery.inputmask'], factory);
-    } else {
-        factory(jQuery);
-    }
-}(function ($) {
+(function ($) {
     //extra definitions
     $.extend($.inputmask.defaults.definitions, {
         'A': {
@@ -125,4 +119,4 @@ Optional extensions on the jquery.inputmask base
         }
     });
     return $.fn.inputmask;
-}));
+})(jQuery);

+ 2 - 8
js/jquery.inputmask.js

@@ -6,13 +6,7 @@
 * Version: 0.0.0
 */
 
-(function (factory) {
-    if (typeof define === 'function' && define.amd) {
-        define(['jquery'], factory);
-    } else {
-        factory(jQuery);
-    }
-}(function ($) {
+(function ($) {
     if ($.fn.inputmask === undefined) {
 
         //helper functions
@@ -1986,4 +1980,4 @@
         };
     }
     return $.fn.inputmask;
-}));
+})(jQuery);

+ 2 - 8
js/jquery.inputmask.numeric.extensions.js

@@ -7,13 +7,7 @@ Version: 0.0.0
 
 Optional extensions on the jquery.inputmask base
 */
-(function (factory) {
-    if (typeof define === 'function' && define.amd) {
-        define(['jquery', './jquery.inputmask'], factory);
-    } else {
-        factory(jQuery);
-    }
-}(function ($) {
+(function ($) {
     //number aliases
     $.extend($.inputmask.defaults.aliases, {
         'numeric': {
@@ -257,4 +251,4 @@ Optional extensions on the jquery.inputmask base
         }
     });
     return $.fn.inputmask;
-}));
+})(jQuery);

+ 2 - 8
js/jquery.inputmask.phone.extensions.js

@@ -17,13 +17,7 @@ When using this extension make sure you specify the correct url to get the masks
 
 
 */
-(function (factory) {
-    if (typeof define === 'function' && define.amd) {
-        define(['jquery', './jquery.inputmask'], factory);
-    } else {
-        factory(jQuery);
-    }
-}(function ($) {
+(function ($) {
     $.extend($.inputmask.defaults.aliases, {
         'phone': {
             url: "phone-codes/phone-codes.js",
@@ -85,4 +79,4 @@ When using this extension make sure you specify the correct url to get the masks
         }
     });
     return $.fn.inputmask;
-}));
+})(jQuery);

+ 2 - 8
js/jquery.inputmask.regex.extensions.js

@@ -8,13 +8,7 @@ Version: 0.0.0
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 */
-(function (factory) {
-    if (typeof define === 'function' && define.amd) {
-        define(['jquery', './jquery.inputmask'], factory);
-    } else {
-        factory(jQuery);
-    }
-}(function ($) {
+(function ($) {
     $.extend($.inputmask.defaults.aliases, { // $(selector).inputmask("Regex", { regex: "[0-9]*"}
         'Regex': {
             mask: "r",
@@ -191,4 +185,4 @@ Allows for using regular expressions as a mask
         }
     });
     return $.fn.inputmask;
-}));
+})(jQuery);

+ 0 - 1
package.json

@@ -38,7 +38,6 @@
   "devDependencies": {
     "grunt": "^0.4.5",
     "grunt-contrib-clean": "^0.6.0",
-    "grunt-contrib-concat": "^0.5.0",
     "grunt-contrib-qunit": "^0.5.2",
     "grunt-contrib-uglify": "^0.5.1",
     "jquery": ">=1.7"