Gruntfile.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. ];
  16. // Paths
  17. var src = ['src/**/*.ts'];
  18. var test = ['test/**/*.ts'];
  19. // Grunt configuration following:
  20. grunt.initConfig({
  21. pkg: grunt.file.readJSON('package.json'),
  22. banner: '',
  23. // Build output directories
  24. outputDir: {
  25. build: 'build',
  26. dist: 'dist'
  27. },
  28. // Browserify
  29. browserify: {
  30. dist: {
  31. src: ['src/OSMD/OSMD.ts'],
  32. dest: '<%= outputDir.build %>/osmd.js',
  33. options: {
  34. banner: '<%= banner %>',
  35. browserifyOptions: {
  36. standalone: 'opensheetmusicdisplay'
  37. }
  38. }
  39. },
  40. debug: {
  41. src: ['src/OSMD/OSMD.ts'],
  42. dest: '<%= outputDir.build %>/osmd-debug.js',
  43. options: {
  44. banner: '<%= banner %>',
  45. browserifyOptions: {
  46. debug: true,
  47. standalone: 'opensheetmusicdisplay'
  48. }
  49. }
  50. },
  51. test: {
  52. src: [].concat(typings, src, test),
  53. dest: '<%= outputDir.build %>/osmd-test.js',
  54. options: {
  55. banner: '<%= banner %>',
  56. browserifyOptions: {
  57. debug: true
  58. }
  59. }
  60. },
  61. options: {
  62. plugin: ['tsify']
  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. },
  75. bundle: {
  76. files: {
  77. 'build/osmd.min.js': ['build/osmd.js']
  78. }
  79. }
  80. },
  81. // Karma setup
  82. karma: {
  83. // For continuous integration
  84. ci: {
  85. configFile: 'karma.conf.js',
  86. options: {
  87. browsers: ['PhantomJS']
  88. }
  89. },
  90. firefox: {
  91. configFile: 'karma.conf.js',
  92. options: {
  93. singleRun: false,
  94. browsers: ['Firefox']
  95. }
  96. },
  97. chrome: {
  98. configFile: 'karma.conf.js',
  99. options: {
  100. singleRun: false,
  101. browsers: ['Chrome']
  102. }
  103. }
  104. },
  105. // Typescript compilation for ES6 module (npm package)
  106. ts: {
  107. default : {
  108. tsconfig: true
  109. }
  110. },
  111. // Cleaning task setup
  112. clean: {
  113. options: {
  114. force: true
  115. },
  116. all: {
  117. src: [
  118. '<%= outputDir.build %>',
  119. '<%= outputDir.dist %>',
  120. '.tscache',
  121. 'src/**/*.js', 'test/**/*.js' // if something went wrong, delete JS from TypeScript source directories
  122. ]
  123. }
  124. },
  125. copy: {
  126. demo: {
  127. files: [
  128. { src: ['*'], dest: '<%= outputDir.build %>/demo/sheets/', cwd: './test/data/', expand: true },
  129. { src: ['*.js', '*.css', '*.html', '*.ico'], cwd: './demo/', expand: true, dest: '<%= outputDir.build %>/demo/' },
  130. { src: ['osmd-debug.js'], cwd: './build/', expand: true, dest: '<%= outputDir.build %>/demo/' }
  131. ]
  132. }
  133. },
  134. // http-server
  135. 'http-server': {
  136. 'demo': {
  137. root: 'build/demo',
  138. port: 8000,
  139. host: '0.0.0.0',
  140. showDir : true,
  141. autoIndex: true,
  142. runInBackground: false,
  143. openBrowser : true
  144. }
  145. }
  146. });
  147. // Load npm tasks
  148. grunt.loadNpmTasks('grunt-browserify');
  149. grunt.loadNpmTasks('grunt-contrib-clean');
  150. grunt.loadNpmTasks('grunt-contrib-copy');
  151. grunt.loadNpmTasks('grunt-contrib-uglify');
  152. grunt.loadNpmTasks('grunt-contrib-watch');
  153. grunt.loadNpmTasks('grunt-http-server');
  154. grunt.loadNpmTasks('grunt-karma');
  155. grunt.loadNpmTasks('grunt-ts');
  156. // Build tasks
  157. grunt.registerTask('build:demo', 'Builds the demo.', ['browserify:debug', 'copy:demo']);
  158. grunt.registerTask('build:test', 'Builds the tests', ['browserify:test']);
  159. grunt.registerTask('build:dist', 'Builds for distribution on npm and Bower.', ['browserify:dist', 'uglify', 'ts']);
  160. // Tests
  161. grunt.registerTask('test', 'Runs unit, regression and e2e tests.', ['build:test', 'karma:ci']);
  162. // Default task (if grunt is run without any argument, used in contiuous integration)
  163. grunt.registerTask('default', 'Default task, running all other tasks. (CI)', ['test', 'build:demo', 'build:dist']);
  164. };