Gruntfile.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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), beautify: true, mangle: false }
  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'), beautify: true, mangle: false }
  30. }
  31. uglifyConfig["inputmaskbundlemin"] = {
  32. files: {
  33. 'dist/<%= pkg.name %>.bundle.min.js': srcFiles
  34. },
  35. options: { banner: createBanner('<%= pkg.name %>.bundle') }
  36. }
  37. return uglifyConfig;
  38. }
  39. function wrapAMDLoader(src, dst, dependencies) {
  40. function stripClosureExecution() {
  41. return srcFile.replace(new RegExp("\\(jQuery\\).*$"), "");
  42. }
  43. var srcFile = grunt.file.read(src),
  44. dstContent = "(function (factory) {" +
  45. "if (typeof define === 'function' && define.amd) {" +
  46. "define(" + JSON.stringify(dependencies) + ", factory);" +
  47. "} else {" +
  48. "factory(jQuery);" +
  49. "}}\n" + stripClosureExecution() + ");";
  50. grunt.file.write(dst, dstContent);
  51. }
  52. // Project configuration.
  53. grunt.initConfig({
  54. pkg: grunt.file.readJSON('package.json'),
  55. uglify: createUglifyConfig("js"),
  56. clean: ["dist"],
  57. qunit: {
  58. files: ['qunit/qunit.html']
  59. },
  60. bump: {
  61. options: {
  62. files: ['package.json', 'bower.json', 'jquery.inputmask.jquery.json'],
  63. updateConfigs: ['pkg'],
  64. commit: false,
  65. createTag: false,
  66. push: false
  67. }
  68. },
  69. release: {
  70. options: {
  71. bump: false,
  72. commitMessage: 'jquery.inputmask <%= version %>'
  73. }
  74. },
  75. nugetpack: {
  76. dist: {
  77. src: function () { return process.platform === "linux" ? 'nuget/jquery.inputmask.linux.nuspec' : 'nuget/jquery.inputmask.nuspec'; }(),
  78. dest: 'dist/',
  79. options: {
  80. version: '<%= pkg.version %>'
  81. }
  82. }
  83. },
  84. nugetpush: {
  85. dist: {
  86. src: 'dist/jQuery.InputMask.<%= pkg.version %>.nupkg'
  87. }
  88. },
  89. shell: {
  90. options: {
  91. stderr: false
  92. },
  93. gitcommitchanges: {
  94. command: ['git add .',
  95. 'git reset -- package.json',
  96. 'git commit -m "jquery.inputmask <%= pkg.version %>"'
  97. ].join('&&')
  98. }
  99. }
  100. });
  101. // Load the plugin that provides the tasks.
  102. grunt.loadNpmTasks('grunt-contrib-uglify');
  103. grunt.loadNpmTasks('grunt-contrib-clean');
  104. grunt.loadNpmTasks('grunt-contrib-qunit');
  105. grunt.loadNpmTasks('grunt-bump');
  106. grunt.loadNpmTasks('grunt-release');
  107. grunt.loadNpmTasks('grunt-nuget');
  108. grunt.loadNpmTasks('grunt-shell');
  109. grunt.registerTask('publish:patch', ['clean', 'bump:patch', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  110. grunt.registerTask('publish:minor', ['clean', 'bump:minor', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  111. grunt.registerTask('publish:major', ['clean', 'bump:major', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
  112. // Default task(s).
  113. grunt.registerTask('default', ['clean', 'uglify']);
  114. };