Gruntfile.js 5.1 KB

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