Gruntfile.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. dstFileMin = dstFile.replace(".js", ".min.js");
  17. wrapModuleLoaders(srcFiles[srcNdx], "build/" + dstFile, dstFile.indexOf("jquery") == -1 ? ["jquery"] : (dstFile.indexOf("extension") == -1 ? ["jquery", "./inputmask"] : ["jquery", "./inputmask", "./jquery.inputmask"]));
  18. uglifyConfig[dstFile] = {
  19. dest: 'dist/inputmask/' + dstFile,
  20. src: "build/" + dstFile,
  21. options: {
  22. banner: createBanner(dstFile),
  23. beautify: true,
  24. mangle: false,
  25. preserveComments: "some",
  26. ASCIIOnly: true
  27. }
  28. };
  29. uglifyConfig[dstFileMin] = {
  30. dest: 'dist/inputmask/' + dstFileMin,
  31. src: "build/" + dstFile,
  32. options: {
  33. banner: createBanner(dstFileMin),
  34. preserveComments: "some",
  35. ASCIIOnly: true
  36. }
  37. };
  38. }
  39. srcFiles = grunt.file.expand(path + "/*.extensions.js");
  40. srcFiles.splice(0, 0, "js/jquery.inputmask.js");
  41. srcFiles.splice(0, 0, "js/inputmask.js");
  42. uglifyConfig["inputmaskbundle"] = {
  43. files: {
  44. 'dist/<%= pkg.name %>.bundle.js': srcFiles
  45. },
  46. options: {
  47. banner: createBanner('<%= pkg.name %>.bundle'),
  48. beautify: true,
  49. mangle: false,
  50. preserveComments: "some",
  51. ASCIIOnly: true
  52. }
  53. }
  54. uglifyConfig["inputmaskbundlemin"] = {
  55. files: {
  56. 'dist/<%= pkg.name %>.bundle.min.js': srcFiles
  57. },
  58. options: {
  59. banner: createBanner('<%= pkg.name %>.bundle'),
  60. preserveComments: "some",
  61. ASCIIOnly: true
  62. }
  63. }
  64. return uglifyConfig;
  65. }
  66. function wrapModuleLoaders(src, dst, dependencies) {
  67. function stripClosureExecution() {
  68. return srcFile.replace(new RegExp("\\(jQuery\\)[\\s\\S]*$"), "");
  69. }
  70. function createCommonJsRequires(dependencies) {
  71. var res = [];
  72. dependencies.forEach(function(dep) {
  73. res.push("require('" + dep + "')");
  74. });
  75. return res.join(", ");
  76. }
  77. var srcFile = grunt.file.read(src),
  78. dstContent = "(function (factory) {" +
  79. "if (typeof define === 'function' && define.amd) {" +
  80. "define(" + JSON.stringify(dependencies) + ", factory);" +
  81. "} else if (typeof exports === 'object') {" +
  82. "module.exports = factory(" + createCommonJsRequires(dependencies) + ");" +
  83. "} else {" +
  84. "factory(jQuery);" +
  85. "}}\n" + stripClosureExecution() + ");";
  86. grunt.file.write(dst, dstContent);
  87. }
  88. // Project configuration.
  89. grunt.initConfig({
  90. pkg: grunt.file.readJSON('package.json'),
  91. uglify: createUglifyConfig("js"),
  92. clean: ["dist"],
  93. qunit: {
  94. files: ['qunit/qunit.html']
  95. },
  96. bump: {
  97. options: {
  98. files: ['package.json', 'bower.json', 'composer.json', 'component.json'],
  99. updateConfigs: ['pkg'],
  100. commit: false,
  101. createTag: false,
  102. push: false
  103. }
  104. },
  105. release: {
  106. options: {
  107. bump: false,
  108. commitMessage: 'jquery.inputmask <%= version %>'
  109. }
  110. },
  111. nugetpack: {
  112. dist: {
  113. src: function() {
  114. return process.platform === "linux" ? 'nuspecs/jquery.inputmask.linux.nuspec' : 'nuspecs/jquery.inputmask.nuspec';
  115. }(),
  116. dest: 'dist/',
  117. options: {
  118. version: '<%= pkg.version %>'
  119. }
  120. }
  121. },
  122. nugetpush: {
  123. dist: {
  124. src: 'dist/jQuery.InputMask.<%= pkg.version %>.nupkg'
  125. }
  126. },
  127. shell: {
  128. options: {
  129. stderr: false
  130. },
  131. gitcommitchanges: {
  132. command: ['git add .',
  133. 'git reset -- package.json',
  134. 'git commit -m "jquery.inputmask <%= pkg.version %>"'
  135. ].join('&&')
  136. }
  137. }
  138. });
  139. // Load the plugin that provides the tasks.
  140. grunt.loadNpmTasks('grunt-contrib-uglify');
  141. grunt.loadNpmTasks('grunt-contrib-clean');
  142. grunt.loadNpmTasks('grunt-contrib-qunit');
  143. grunt.loadNpmTasks('grunt-bump');
  144. grunt.loadNpmTasks('grunt-release');
  145. grunt.loadNpmTasks('grunt-nuget');
  146. grunt.loadNpmTasks('grunt-shell');
  147. grunt.registerTask('publish:patch', ['clean', 'bump:patch', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  148. grunt.registerTask('publish:minor', ['clean', 'bump:minor', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  149. grunt.registerTask('publish:major', ['clean', 'bump:major', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  150. // Default task(s).
  151. grunt.registerTask('default', ['bump:prerelease', 'clean', 'uglify']);
  152. };