Gruntfile.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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/converter.js',
  23. 'src/subParsers/*.js',
  24. 'src/loader.js'
  25. ],
  26. dest: 'dist/<%= pkg.name %>.js'
  27. },
  28. test: {
  29. src: '<%= concat.dist.src %>',
  30. dest: '.build/<%= pkg.name %>.js',
  31. options: {
  32. sourceMap: false
  33. }
  34. }
  35. },
  36. clean: ['.build/'],
  37. uglify: {
  38. options: {
  39. sourceMap: true,
  40. banner: '/*! <%= pkg.name %> v <%= pkg.version %> - <%= grunt.template.today("dd-mm-yyyy") %> */'
  41. },
  42. dist: {
  43. files: {
  44. 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
  45. }
  46. }
  47. },
  48. endline: {
  49. dist: {
  50. files: {
  51. 'dist/<%= pkg.name %>.js': 'dist/<%= pkg.name %>.js',
  52. 'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.min.js'
  53. }
  54. }
  55. },
  56. jshint: {
  57. options: {
  58. jshintrc: '.jshintrc',
  59. reporterOutput: ''
  60. },
  61. files: [
  62. 'Gruntfile.js',
  63. 'src/**/*.js',
  64. 'test/**/*.js'
  65. ]
  66. },
  67. eslint: {
  68. options: {
  69. config: '.eslintrc.json'
  70. },
  71. target: [
  72. 'Gruntfile.js',
  73. 'src/**/*.js',
  74. 'test/**/*.js'
  75. ]
  76. },
  77. conventionalChangelog: {
  78. options: {
  79. changelogOpts: {
  80. preset: 'angular'
  81. }
  82. },
  83. release: {
  84. src: 'CHANGELOG.md'
  85. }
  86. },
  87. conventionalGithubReleaser: {
  88. release: {
  89. options: {
  90. auth: {
  91. type: 'oauth',
  92. token: process.env.GH_TOEKN
  93. },
  94. changelogOpts: {
  95. preset: 'angular'
  96. }
  97. }
  98. }
  99. },
  100. simplemocha: {
  101. node: {
  102. src: 'test/node/**/*.js',
  103. options: {
  104. globals: ['should'],
  105. timeout: 3000,
  106. ignoreLeaks: true,
  107. reporter: 'spec'
  108. }
  109. },
  110. karlcow: {
  111. src: 'test/node/testsuite.karlcow.js',
  112. options: {
  113. globals: ['should'],
  114. timeout: 3000,
  115. ignoreLeaks: false,
  116. reporter: 'spec'
  117. }
  118. },
  119. issues: {
  120. src: 'test/node/testsuite.issues.js',
  121. options: {
  122. globals: ['should'],
  123. timeout: 3000,
  124. ignoreLeaks: false,
  125. reporter: 'spec'
  126. }
  127. },
  128. standard: {
  129. src: 'test/node/testsuite.standard.js',
  130. options: {
  131. globals: ['should'],
  132. timeout: 3000,
  133. ignoreLeaks: false,
  134. reporter: 'spec'
  135. }
  136. },
  137. features: {
  138. src: 'test/node/testsuite.features.js',
  139. options: {
  140. globals: ['should'],
  141. timeout: 3000,
  142. ignoreLeaks: false,
  143. reporter: 'spec'
  144. }
  145. },
  146. single: {
  147. src: 'test/node/**/*.js',
  148. options: {
  149. globals: ['should'],
  150. timeout: 3000,
  151. ignoreLeaks: false,
  152. reporter: 'spec'
  153. }
  154. }
  155. }
  156. };
  157. grunt.initConfig(config);
  158. /**
  159. * Load common tasks for legacy and normal tests
  160. */
  161. grunt.loadNpmTasks('grunt-contrib-clean');
  162. grunt.loadNpmTasks('grunt-contrib-concat');
  163. grunt.loadNpmTasks('grunt-contrib-uglify');
  164. grunt.loadNpmTasks('grunt-simple-mocha');
  165. grunt.loadNpmTasks('grunt-endline');
  166. grunt.loadNpmTasks('grunt-contrib-jshint');
  167. /**
  168. * Generate Changelog
  169. */
  170. grunt.registerTask('generate-changelog', function () {
  171. 'use strict';
  172. grunt.loadNpmTasks('grunt-conventional-changelog');
  173. grunt.loadNpmTasks('grunt-conventional-github-releaser');
  174. grunt.task.run('conventionalChangelog');
  175. });
  176. /**
  177. * Lint tasks
  178. */
  179. grunt.registerTask('lint', function () {
  180. 'use strict';
  181. grunt.loadNpmTasks('grunt-eslint');
  182. grunt.task.run('jshint', 'eslint');
  183. });
  184. /**
  185. * Performance task
  186. */
  187. grunt.registerTask('performancejs', function () {
  188. 'use strict';
  189. var perf = require('./test/node/performance.js');
  190. perf.runTests();
  191. perf.generateLogs();
  192. });
  193. /**
  194. * Run a single test
  195. */
  196. grunt.registerTask('single-test', function (grep) {
  197. 'use strict';
  198. grunt.config.merge({
  199. simplemocha: {
  200. single: {
  201. options: {
  202. grep: grep
  203. }
  204. }
  205. }
  206. });
  207. grunt.task.run(['lint', 'concat:test', 'simplemocha:single', 'clean']);
  208. });
  209. /**
  210. * Test in Legacy Node
  211. */
  212. grunt.registerTask('test-old', ['concat:test', 'simplemocha:node', 'clean']);
  213. /**
  214. * Tasks for new node versions
  215. */
  216. grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'simplemocha:node', 'clean']);
  217. grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
  218. grunt.registerTask('build', ['test', 'concat:dist', 'uglify', 'endline']);
  219. grunt.registerTask('prep-release', ['build', 'generate-changelog']);
  220. // Default task(s).
  221. grunt.registerTask('default', ['test']);
  222. };