Gruntfile.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. typings = [
  12. 'typings/index.d.ts',
  13. // Additional manual typings:
  14. 'external/vexflow/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: '',
  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. debugDemo: {
  39. src: [].concat(typings, src),
  40. dest: '<%= outputDir.build %>/osmd-demo.js',
  41. options: {
  42. banner: "<%= banner %>",
  43. browserifyOptions: {
  44. debug: true
  45. }
  46. }
  47. },
  48. debug: {
  49. src: [].concat(typings, src, test),
  50. dest: '<%= outputDir.build %>/osmd-debug.js',
  51. options: {
  52. banner: "<%= banner %>",
  53. browserifyOptions: {
  54. debug: true
  55. }
  56. }
  57. },
  58. options: {
  59. plugin: ['tsify']//,
  60. // browserifyOptions: {
  61. // standalone: 'MeasureSizeCalculator'
  62. // }
  63. }
  64. },
  65. // Uglify
  66. uglify: {
  67. options: {
  68. compress: {
  69. drop_console: true
  70. },
  71. banner: banner,
  72. mangle: true,
  73. mangleProperties: true,
  74. preserveComments: 'all'
  75. },
  76. bundle: {
  77. files: {
  78. 'build/osmd.min.js': ['build/osmd.js']
  79. }
  80. }
  81. },
  82. // Karma setup
  83. karma: {
  84. // For continuous integration
  85. ci: {
  86. configFile: 'karma.conf.js',
  87. options: {
  88. browsers: ['PhantomJS']
  89. }
  90. },
  91. debugWithFirefox: {
  92. configFile: 'karma.conf.js',
  93. options: {
  94. singleRun: false,
  95. browsers: ['Firefox']
  96. }
  97. },
  98. debugWithChrome: {
  99. configFile: 'karma.conf.js',
  100. options: {
  101. singleRun: false,
  102. browsers: ['Chrome']
  103. }
  104. }
  105. },
  106. // TSLint setup
  107. tslint: {
  108. options: {
  109. configuration: 'tslint.json'
  110. },
  111. all: {
  112. src: [].concat(src, test)
  113. }
  114. },
  115. // JsHint setup
  116. jshint: {
  117. all: [
  118. 'Gruntfile.js', 'karma.conf.js',
  119. 'submodules/**/*.json', 'submodules/**/*.js'
  120. ]
  121. },
  122. // TypeScript Type Definitions
  123. typings: {
  124. install: {}
  125. },
  126. // Cleaning task setup
  127. clean: {
  128. options: {
  129. force: true
  130. },
  131. all: {
  132. src: [
  133. '<%= outputDir.build %>',
  134. '<%= outputDir.dist %>',
  135. 'node-modules',
  136. 'typings',
  137. '.tscache',
  138. 'src/**/*.js', 'test/**/*.js'
  139. ]
  140. }
  141. }
  142. });
  143. // Load Npm tasks
  144. grunt.loadNpmTasks('grunt-karma');
  145. grunt.loadNpmTasks('grunt-tslint');
  146. grunt.loadNpmTasks('grunt-typings');
  147. grunt.loadNpmTasks('grunt-browserify');
  148. grunt.loadNpmTasks('grunt-contrib-clean');
  149. grunt.loadNpmTasks('grunt-contrib-watch');
  150. grunt.loadNpmTasks('grunt-contrib-jshint');
  151. grunt.loadNpmTasks('grunt-contrib-uglify');
  152. // Register tasks
  153. grunt.registerTask('all', ['typings', 'default']);
  154. grunt.registerTask('start', ['typings']);
  155. grunt.registerTask('default', ['browserify', 'lint', 'karma:ci', 'uglify']);
  156. grunt.registerTask('npmtest', ['typings', 'test']);
  157. grunt.registerTask('test', ['browserify:debug', 'lint', 'karma:ci']);
  158. grunt.registerTask('fasttest', ['browserify:debug', 'karma:ci']);
  159. grunt.registerTask('rebuild', ['clean', 'default']);
  160. grunt.registerTask('publish', ['clean', 'typings', 'browserify:dist', 'uglify:bundle']);
  161. grunt.registerTask('lint', ['jshint', 'tslint']);
  162. // Fix these in the future:
  163. // grunt.registerTask('test debug Firefox', ['browserify:debug', 'karma:debugWithFirefox']);
  164. // grunt.registerTask('test debug Chrome', ['browserify:debug', 'karma:debugWithChrome']);
  165. };