Gruntfile.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. * Created by Tivie on 12-11-2014.
  3. */
  4. module.exports = function (grunt) {
  5. if (grunt.option('q') || grunt.option('quiet')) {
  6. require('quiet-grunt');
  7. }
  8. // Project configuration.
  9. var config = {
  10. pkg: grunt.file.readJSON('package.json'),
  11. concat: {
  12. options: {
  13. sourceMap: true,
  14. banner: ';/*! <%= pkg.name %> v <%= pkg.version %> - <%= grunt.template.today("dd-mm-yyyy") %> */\n(function(){\n',
  15. footer: '}).call(this);\n'
  16. },
  17. dist: {
  18. src: [
  19. 'src/options.js',
  20. 'src/showdown.js',
  21. 'src/helpers.js',
  22. 'src/subParsers/makehtml/*.js',
  23. 'src/subParsers/makemarkdown/*.js',
  24. 'src/converter.js',
  25. 'src/loader.js'
  26. ],
  27. dest: 'dist/<%= pkg.name %>.js'
  28. },
  29. test: {
  30. src: '<%= concat.dist.src %>',
  31. dest: '.build/<%= pkg.name %>.js',
  32. options: {
  33. sourceMap: false
  34. }
  35. }
  36. },
  37. clean: ['.build/'],
  38. uglify: {
  39. options: {
  40. sourceMap: true,
  41. banner: '/*! <%= pkg.name %> v <%= pkg.version %> - <%= grunt.template.today("dd-mm-yyyy") %> */'
  42. },
  43. dist: {
  44. files: {
  45. 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
  46. }
  47. }
  48. },
  49. endline: {
  50. dist: {
  51. files: {
  52. 'dist/<%= pkg.name %>.js': 'dist/<%= pkg.name %>.js',
  53. 'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.min.js'
  54. }
  55. }
  56. },
  57. jshint: {
  58. options: {
  59. jshintrc: '.jshintrc',
  60. reporterOutput: ''
  61. },
  62. files: [
  63. 'Gruntfile.js',
  64. 'src/**/*.js',
  65. 'test/**/*.js'
  66. ]
  67. },
  68. eslint: {
  69. options: {
  70. config: '.eslintrc.json'
  71. },
  72. target: [
  73. 'Gruntfile.js',
  74. 'src/**/*.js',
  75. 'test/**/*.js'
  76. ]
  77. },
  78. conventionalChangelog: {
  79. options: {
  80. changelogOpts: {
  81. preset: 'angular'
  82. }
  83. },
  84. release: {
  85. src: 'CHANGELOG.md'
  86. }
  87. },
  88. conventionalGithubReleaser: {
  89. release: {
  90. options: {
  91. auth: {
  92. type: 'oauth',
  93. token: process.env.GH_TOEKN
  94. },
  95. changelogOpts: {
  96. preset: 'angular'
  97. }
  98. }
  99. }
  100. },
  101. simplemocha: {
  102. functional: {
  103. src: 'test/functional/**/*.js',
  104. options: {
  105. globals: ['should'],
  106. timeout: 3000,
  107. ignoreLeaks: true,
  108. reporter: 'spec'
  109. }
  110. },
  111. unit: {
  112. src: 'test/unit/**/*.js',
  113. options: {
  114. globals: ['should'],
  115. timeout: 3000,
  116. ignoreLeaks: true,
  117. reporter: 'spec'
  118. }
  119. },
  120. single: {
  121. src: 'test/node/**/*.js',
  122. options: {
  123. globals: ['should'],
  124. timeout: 3000,
  125. ignoreLeaks: false,
  126. reporter: 'spec'
  127. }
  128. }
  129. }
  130. };
  131. grunt.initConfig(config);
  132. /**
  133. * Load common tasks for legacy and normal tests
  134. */
  135. grunt.loadNpmTasks('grunt-contrib-clean');
  136. grunt.loadNpmTasks('grunt-contrib-concat');
  137. grunt.loadNpmTasks('grunt-contrib-uglify');
  138. grunt.loadNpmTasks('grunt-simple-mocha');
  139. grunt.loadNpmTasks('grunt-endline');
  140. grunt.loadNpmTasks('grunt-contrib-jshint');
  141. /**
  142. * Generate Changelog
  143. */
  144. grunt.registerTask('generate-changelog', function () {
  145. 'use strict';
  146. grunt.loadNpmTasks('grunt-conventional-changelog');
  147. grunt.loadNpmTasks('grunt-conventional-github-releaser');
  148. grunt.task.run('conventionalChangelog');
  149. });
  150. /**
  151. * Lint tasks
  152. */
  153. grunt.registerTask('lint', function () {
  154. 'use strict';
  155. grunt.loadNpmTasks('grunt-eslint');
  156. grunt.task.run('jshint', 'eslint');
  157. });
  158. /**
  159. * Performance task
  160. */
  161. grunt.registerTask('performancejs', function () {
  162. 'use strict';
  163. var perf = require('./test/performance/performance.js');
  164. perf.runTests();
  165. perf.generateLogs();
  166. });
  167. /**
  168. * Run a single test
  169. */
  170. grunt.registerTask('single-test', function (grep) {
  171. 'use strict';
  172. grunt.config.merge({
  173. simplemocha: {
  174. single: {
  175. options: {
  176. grep: grep
  177. }
  178. }
  179. }
  180. });
  181. grunt.task.run(['lint', 'concat:test', 'simplemocha:single', 'clean']);
  182. });
  183. /**
  184. * Tasks
  185. */
  186. grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'simplemocha:unit', 'simplemocha:functional', 'clean']);
  187. grunt.registerTask('test-functional', ['concat:test', 'simplemocha:functional', 'clean']);
  188. grunt.registerTask('test-unit', ['concat:test', 'simplemocha:unit', 'clean']);
  189. grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
  190. grunt.registerTask('build', ['test', 'concat:dist', 'uglify', 'endline']);
  191. grunt.registerTask('build-without-test', ['concat:dist', 'uglify', 'endline']);
  192. grunt.registerTask('prep-release', ['build', 'generate-changelog']);
  193. // Default task(s).
  194. grunt.registerTask('default', ['test']);
  195. };