You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
5.0KB

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