Gruntfile.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. const webpackConfig = require('./webpack.config');
  2. const qunitWebpackConfig = require('./qunit/webpack.config');
  3. module.exports = function (grunt) {
  4. function createBanner(fileName) {
  5. return "/*!\n" +
  6. "* " + fileName + "\n" +
  7. "* <%= pkg.homepage %>\n" +
  8. "* Copyright (c) 2010 - <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" +
  9. "* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)\n" +
  10. "* Version: <%= pkg.version %>\n" +
  11. "*/\n";
  12. }
  13. function createUglifyConfig(path) {
  14. var uglifyConfig = {};
  15. var srcFiles = grunt.file.expand(path + "/**/*.js");
  16. for (var srcNdx in srcFiles) {
  17. var dstFile = srcFiles[srcNdx].replace("js/", ""),
  18. dstFileMin = dstFile.replace(".js", ".min.js");
  19. uglifyConfig[dstFile] = {
  20. dest: 'dist/inputmask/' + dstFile,
  21. src: srcFiles[srcNdx],
  22. options: {
  23. banner: createBanner(dstFile),
  24. beautify: true,
  25. mangle: false,
  26. preserveComments: false,
  27. ASCIIOnly: true
  28. }
  29. };
  30. uglifyConfig[dstFileMin] = {
  31. dest: "dist/min/inputmask/" + dstFileMin,
  32. src: srcFiles[srcNdx],
  33. options: {
  34. banner: createBanner(dstFileMin),
  35. preserveComments: false,
  36. ASCIIOnly: true
  37. }
  38. };
  39. }
  40. uglifyConfig["bundle"] = {
  41. dest: "dist/jquery.inputmask.bundle.js",
  42. src: "build/bundle.js",
  43. options: {
  44. banner: createBanner("jquery.inputmask.bundle.js"),
  45. beautify: true,
  46. mangle: false,
  47. preserveComments: false,
  48. ASCIIOnly: true
  49. }
  50. };
  51. uglifyConfig["bundlemin"] = {
  52. dest: "dist/min/jquery.inputmask.bundle.min.js",
  53. src: "build/bundle.js",
  54. options: {
  55. banner: createBanner("jquery.inputmask.bundle.js"),
  56. preserveComments: false,
  57. ASCIIOnly: true
  58. }
  59. };
  60. return uglifyConfig;
  61. }
  62. // Project configuration.
  63. grunt.initConfig({
  64. pkg: grunt.file.readJSON("package.json"),
  65. uglify: createUglifyConfig("js"),
  66. clean: ["dist"],
  67. karma: {
  68. options: {
  69. configFile: 'karma.conf.js'
  70. },
  71. unit: {
  72. runnerPort: 9999,
  73. singleRun: true,
  74. browsers: ["Chrome"], //will later add extra test targets
  75. logLevel: 'ERROR'
  76. }
  77. },
  78. bump: {
  79. options: {
  80. files: ['package.json', 'bower.json', 'composer.json', 'component.json'],
  81. updateConfigs: ['pkg'],
  82. commit: false,
  83. createTag: false,
  84. push: false
  85. }
  86. },
  87. release: {
  88. options: {
  89. bump: false,
  90. commitMessage: 'Inputmask <%= version %>'
  91. }
  92. },
  93. nugetpack: {
  94. dist: {
  95. src: function () {
  96. return 'nuspecs/Inputmask.nuspec';
  97. }(),
  98. dest: 'build/',
  99. options: {
  100. version: '<%= pkg.version %>'
  101. }
  102. },
  103. dist2: {
  104. src: function () {
  105. return 'nuspecs/jquery.inputmask.nuspec';
  106. }(),
  107. dest: 'build/',
  108. options: {
  109. version: '<%= pkg.version %>'
  110. }
  111. }
  112. },
  113. nugetpush: {
  114. dist: {
  115. src: 'build/InputMask.<%= pkg.version %>.nupkg',
  116. options: {
  117. source: "https://www.nuget.org"
  118. }
  119. },
  120. dist2: {
  121. src: 'build/jquery.inputMask.<%= pkg.version %>.nupkg',
  122. options: {
  123. source: "https://www.nuget.org"
  124. }
  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 "Inputmask <%= pkg.version %>"'
  135. ].join('&&')
  136. }
  137. },
  138. eslint: {
  139. target: "{extra/*,js}/*.js"
  140. },
  141. availabletasks: {
  142. tasks: {
  143. options: {
  144. filter: 'exclude',
  145. tasks: ['availabletasks', 'default', 'updateDistConfig'],
  146. showTasks: ['user']
  147. }
  148. }
  149. },
  150. webpack: {
  151. build: webpackConfig,
  152. qunit: qunitWebpackConfig
  153. }
  154. });
  155. // Load the plugin that provides the tasks.
  156. require('load-grunt-tasks')(grunt);
  157. grunt.registerTask('publish:patch', ['clean', 'bump:patch', 'webpack:build', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  158. grunt.registerTask('publish:minor', ['clean', 'bump:minor', 'webpack:build', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  159. grunt.registerTask('publish:major', ['clean', 'bump:major', 'webpack:build', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  160. grunt.registerTask('validate', ['webpack:qunit', 'eslint', 'karma']);
  161. grunt.registerTask('build', ['bump:prerelease', 'clean', 'webpack:build', 'uglify']);
  162. grunt.registerTask('default', ["availabletasks"]);
  163. };