Gruntfile.js 5.1 KB

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