Gruntfile.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module.exports = function (grunt) {
  2. function createBanner(fileName) {
  3. return '/*\n' +
  4. '* ' + fileName + '\n' +
  5. '* http://github.com/RobinHerbots/jquery.inputmask\n' +
  6. '* Copyright (c) 2010 - <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>\n' +
  7. '* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)\n' +
  8. '* Version: <%= pkg.version %>\n' +
  9. '*/\n';
  10. }
  11. function createUglifyConfig(path) {
  12. var uglifyConfig = {};
  13. var srcFiles = grunt.file.expand(path + "/*.js");
  14. for (var srcNdx in srcFiles) {
  15. var dstFile = srcFiles[srcNdx].replace("js/", "");
  16. wrapAMDLoader(srcFiles[srcNdx], "build/" + dstFile, dstFile.indexOf("extension") == -1 ? ["jquery"] : ["jquery", "./jquery.inputmask"]);
  17. uglifyConfig[dstFile] = {
  18. dest: 'dist/inputmask/' + dstFile,
  19. src: "build/" + dstFile,
  20. options: { banner: createBanner(dstFile) }
  21. };
  22. }
  23. srcFiles = grunt.file.expand(path + "/*.extensions.js");
  24. srcFiles.splice(0, 0, "js/jquery.inputmask.js");
  25. uglifyConfig["inputmaskbundle"] = {
  26. files: {
  27. 'dist/<%= pkg.name %>.bundle.js': srcFiles
  28. },
  29. options: { banner: createBanner('<%= pkg.name %>.bundle') }
  30. }
  31. return uglifyConfig;
  32. }
  33. function wrapAMDLoader(src, dst, dependencies) {
  34. function stripClosureExecution() {
  35. return srcFile.replace(new RegExp("\\(jQuery\\).*$"), "");
  36. }
  37. var srcFile = grunt.file.read(src),
  38. dstContent = "(function (factory) {" +
  39. "if (typeof define === 'function' && define.amd) {" +
  40. "define(" + JSON.stringify(dependencies) + ", factory);" +
  41. "} else {" +
  42. "factory(jQuery);" +
  43. "}}" + stripClosureExecution() + ");";
  44. grunt.file.write(dst, dstContent);
  45. }
  46. // Project configuration.
  47. grunt.initConfig({
  48. pkg: grunt.file.readJSON('package.json'),
  49. uglify: createUglifyConfig("js"),
  50. clean: ["dist"],
  51. qunit: {
  52. files: ['qunit/qunit.html']
  53. }
  54. });
  55. // Load the plugin that provides the tasks.
  56. grunt.loadNpmTasks('grunt-contrib-uglify');
  57. grunt.loadNpmTasks('grunt-contrib-clean');
  58. grunt.loadNpmTasks('grunt-contrib-qunit');
  59. // Default task(s).
  60. grunt.registerTask('default', ['clean', 'uglify']);
  61. };