Gruntfile.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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/makemd/*.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. node: {
  103. src: 'test/node/**/*.js',
  104. options: {
  105. globals: ['should'],
  106. timeout: 3000,
  107. ignoreLeaks: true,
  108. reporter: 'spec'
  109. }
  110. },
  111. karlcow: {
  112. src: 'test/node/testsuite.karlcow.js',
  113. options: {
  114. globals: ['should'],
  115. timeout: 3000,
  116. ignoreLeaks: false,
  117. reporter: 'spec'
  118. }
  119. },
  120. issues: {
  121. src: 'test/node/testsuite.issues.js',
  122. options: {
  123. globals: ['should'],
  124. timeout: 3000,
  125. ignoreLeaks: false,
  126. reporter: 'spec'
  127. }
  128. },
  129. standard: {
  130. src: 'test/node/testsuite.standard.js',
  131. options: {
  132. globals: ['should'],
  133. timeout: 3000,
  134. ignoreLeaks: false,
  135. reporter: 'spec'
  136. }
  137. },
  138. features: {
  139. src: 'test/node/testsuite.features.js',
  140. options: {
  141. globals: ['should'],
  142. timeout: 3000,
  143. ignoreLeaks: false,
  144. reporter: 'spec'
  145. }
  146. },
  147. single: {
  148. src: 'test/node/**/*.js',
  149. options: {
  150. globals: ['should'],
  151. timeout: 3000,
  152. ignoreLeaks: false,
  153. reporter: 'spec'
  154. }
  155. }
  156. }
  157. };
  158. grunt.initConfig(config);
  159. /**
  160. * Load common tasks for legacy and normal tests
  161. */
  162. grunt.loadNpmTasks('grunt-contrib-clean');
  163. grunt.loadNpmTasks('grunt-contrib-concat');
  164. grunt.loadNpmTasks('grunt-contrib-uglify');
  165. grunt.loadNpmTasks('grunt-simple-mocha');
  166. grunt.loadNpmTasks('grunt-endline');
  167. grunt.loadNpmTasks('grunt-contrib-jshint');
  168. /**
  169. * Generate Changelog
  170. */
  171. grunt.registerTask('generate-changelog', function () {
  172. 'use strict';
  173. grunt.loadNpmTasks('grunt-conventional-changelog');
  174. grunt.loadNpmTasks('grunt-conventional-github-releaser');
  175. grunt.task.run('conventionalChangelog');
  176. });
  177. /**
  178. * Lint tasks
  179. */
  180. grunt.registerTask('lint', function () {
  181. 'use strict';
  182. grunt.loadNpmTasks('grunt-eslint');
  183. grunt.task.run('jshint', 'eslint');
  184. });
  185. /**
  186. * Performance task
  187. */
  188. grunt.registerTask('performancejs', function () {
  189. 'use strict';
  190. var perf = require('./test/node/performance.js');
  191. perf.runTests();
  192. perf.generateLogs();
  193. });
  194. /**
  195. * Run a single test
  196. */
  197. grunt.registerTask('single-test', function (grep) {
  198. 'use strict';
  199. grunt.config.merge({
  200. simplemocha: {
  201. single: {
  202. options: {
  203. grep: grep
  204. }
  205. }
  206. }
  207. });
  208. grunt.task.run(['lint', 'concat:test', 'simplemocha:single', 'clean']);
  209. });
  210. /**
  211. * Test in Legacy Node
  212. */
  213. grunt.registerTask('test-old', ['concat:test', 'simplemocha:node', 'clean']);
  214. /**
  215. * Tasks for new node versions
  216. */
  217. grunt.registerTask('test', ['clean', 'lint', 'concat:test', 'simplemocha:node', 'clean']);
  218. grunt.registerTask('performance', ['concat:test', 'performancejs', 'clean']);
  219. grunt.registerTask('build', ['test', 'concat:dist', 'uglify', 'endline']);
  220. grunt.registerTask('prep-release', ['build', 'generate-changelog']);
  221. // Default task(s).
  222. grunt.registerTask('default', ['test']);
  223. };