Gruntfile.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*global module*/
  2. module.exports = function (grunt) {
  3. 'use strict';
  4. // The banner on top of the build
  5. var banner = '/**\n' +
  6. ' * Open Sheet Music Display <%= pkg.version %> built on <%= grunt.template.today("yyyy-mm-dd") %>.\n' +
  7. ' * Copyright (c) 2016 PhonicScore\n' +
  8. ' *\n' +
  9. ' * https://github.com/opensheetmusicdisplay/opensheetmusicdisplay\n' +
  10. ' */\n',
  11. // Additional manual typings:
  12. typings = [
  13. 'typings/browser.d.ts',
  14. 'typings/vexflow.d.ts',
  15. 'typings/fft.d.ts'
  16. ],
  17. // Paths
  18. src = ['src/**/*.ts'],
  19. test = ['test/**/*.ts'];
  20. // Grunt configuration following:
  21. grunt.initConfig({
  22. pkg: grunt.file.readJSON('package.json'),
  23. banner: banner,
  24. // Build output directories
  25. outputDir: {
  26. build: 'build',
  27. dist: 'dist'
  28. },
  29. // Browserify
  30. browserify: {
  31. dist: {
  32. src: [].concat(typings, src),
  33. dest: '<%= outputDir.build %>/osmd.js',
  34. options: {
  35. banner: "<%= banner %>"
  36. }
  37. },
  38. debug: {
  39. src: [].concat(typings, src, test),
  40. dest: '<%= outputDir.build %>/osmd-debug.js',
  41. options: {
  42. banner: "<%= banner %>",
  43. browserifyOptions: {
  44. debug: true
  45. }
  46. }
  47. },
  48. options: {
  49. plugin: ['tsify'],
  50. browserifyOptions: {
  51. standalone: 'MeasureSizeCalculator'
  52. }
  53. }
  54. },
  55. // Uglify
  56. /*uglify: {
  57. options: {
  58. compress: {
  59. drop_console: true
  60. }
  61. },
  62. my_target: {
  63. files: {
  64. 'build/osmd.js': ['src/input.js']
  65. }
  66. }
  67. },*/
  68. // Karma setup
  69. karma: {
  70. // For continuous integration
  71. ci: {
  72. configFile: 'karma.conf.js',
  73. options: {
  74. browsers: ['PhantomJS'],
  75. files: [
  76. '<%= browserify.debug.dest %>'
  77. ]
  78. }
  79. },
  80. debugWithFirefox: {
  81. configFile: 'karma.conf.js',
  82. options: {
  83. singleRun: false,
  84. browsers: ['Firefox'],
  85. files: [
  86. '<%= browserify.debug.dest %>', {
  87. pattern: 'src/**/*.ts',
  88. included: false
  89. }, {
  90. pattern: 'test/**/*.ts',
  91. included: false
  92. }
  93. ]
  94. }
  95. },
  96. debugWithChrome: {
  97. configFile: 'karma.conf.js',
  98. options: {
  99. singleRun: false,
  100. browsers: ['Chrome'],
  101. files: [
  102. '<%= browserify.debug.dest %>', {
  103. pattern: 'src/**/*.ts',
  104. included: false
  105. }, {
  106. pattern: 'test/**/*.ts',
  107. included: false
  108. }
  109. ]
  110. }
  111. }
  112. },
  113. // TSLint setup
  114. tslint: {
  115. options: {
  116. configuration: 'tslint.json'
  117. },
  118. all: {
  119. src: [].concat(src, test)
  120. }
  121. },
  122. // JsHint setup
  123. jshint: {
  124. all: ['Gruntfile.js']
  125. },
  126. // TypeScript Type Definitions
  127. typings: {
  128. install: {}
  129. },
  130. // Documentation
  131. docco: {
  132. src: src,
  133. options: {
  134. layout: 'linear',
  135. output: 'build/docs'
  136. }
  137. },
  138. // Cleaning task setup
  139. clean: {
  140. options: {
  141. force: true
  142. },
  143. all: {
  144. src: [
  145. '<%= outputDir.build %>',
  146. '<%= outputDir.dist %>',
  147. '.tscache',
  148. 'src/**/*.js', 'test/**/*.js'
  149. ]
  150. }
  151. }
  152. });
  153. // Load Npm tasks
  154. grunt.loadNpmTasks('grunt-karma');
  155. grunt.loadNpmTasks('grunt-docco');
  156. grunt.loadNpmTasks('grunt-tslint');
  157. grunt.loadNpmTasks('grunt-typings');
  158. grunt.loadNpmTasks('grunt-browserify');
  159. grunt.loadNpmTasks('grunt-contrib-clean');
  160. grunt.loadNpmTasks('grunt-contrib-watch');
  161. grunt.loadNpmTasks('grunt-contrib-jshint');
  162. // Register tasks
  163. grunt.registerTask('all', ['typings', 'default']);
  164. grunt.registerTask('default', ['lint', 'browserify', 'karma:ci']);
  165. grunt.registerTask('test', ['lint', 'browserify:debug', 'karma:ci']);
  166. grunt.registerTask('rebuild', ['clean', 'default']);
  167. grunt.registerTask('publish', ['clean', 'browserify:dist', 'docco']);
  168. grunt.registerTask('lint', ['tslint', 'jshint']);
  169. // Fix these in the future:
  170. // grunt.registerTask('test debug Firefox', ['browserify:debug', 'karma:debugWithFirefox']);
  171. // grunt.registerTask('test debug Chrome', ['browserify:debug', 'karma:debugWithChrome']);
  172. };