Gruntfile.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. bump: {
  55. options: {
  56. files: ['package.json', 'bower.json', 'jquery.inputmask.jquery.json'],
  57. updateConfigs: ['pkg'],
  58. commit: false,
  59. createTag: false,
  60. push: false
  61. }
  62. },
  63. release: {
  64. options: {
  65. bump: false,
  66. commitMessage: 'jquery.inputmask <%= version %>'
  67. }
  68. },
  69. nugetpack: {
  70. dist: {
  71. src: function () { return process.platform === "linux" ? 'nuget/jquery.inputmask.linux.nuspec' : 'nuget/jquery.inputmask.nuspec'; }(),
  72. dest: 'dist/',
  73. options: {
  74. version: '<%= pkg.version %>'
  75. }
  76. }
  77. },
  78. nugetpush: {
  79. dist: {
  80. src: 'dist/jQuery.InputMask.<%= pkg.version %>.nupkg'
  81. }
  82. },
  83. shell: {
  84. options: {
  85. stderr: false
  86. },
  87. gitcommitchanges: {
  88. command: ['git add .',
  89. 'git reset -- package.json',
  90. 'git commit -m "jquery.inputmask <%= pkg.version %>"'
  91. ].join('&&')
  92. }
  93. }
  94. });
  95. // Load the plugin that provides the tasks.
  96. grunt.loadNpmTasks('grunt-contrib-uglify');
  97. grunt.loadNpmTasks('grunt-contrib-clean');
  98. grunt.loadNpmTasks('grunt-contrib-qunit');
  99. grunt.loadNpmTasks('grunt-bump');
  100. grunt.loadNpmTasks('grunt-release');
  101. grunt.loadNpmTasks('grunt-nuget');
  102. grunt.loadNpmTasks('grunt-shell');
  103. grunt.registerTask('publish:patch', ['clean', 'bump:patch', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  104. grunt.registerTask('publish:minor', ['clean', 'bump:minor', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  105. grunt.registerTask('publish:major', ['clean', 'bump:major', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  106. // Default task(s).
  107. grunt.registerTask('default', ['clean', 'uglify']);
  108. };