Gruntfile.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. // TSLint setup
  106. tslint: {
  107. options: {
  108. configuration: 'tslint.json'
  109. },
  110. all: {
  111. src: [].concat(src, test)
  112. }
  113. },
  114. // JsHint setup
  115. jshint: {
  116. all: [
  117. 'Gruntfile.js', 'karma.conf.js', 'demo/**/*.js'
  118. ]
  119. },
  120. // TypeScript Type Definitions
  121. typings: {
  122. install: {}
  123. },
  124. // Typescript compilation for ES6 module (npm package)
  125. ts: {
  126. default : {
  127. tsconfig: true
  128. }
  129. },
  130. // Cleaning task setup
  131. clean: {
  132. options: {
  133. force: true
  134. },
  135. all: {
  136. src: [
  137. '<%= outputDir.build %>',
  138. '<%= outputDir.dist %>',
  139. '.tscache',
  140. 'src/**/*.js', 'test/**/*.js' // if something went wrong, delete JS from TypeScript source directories
  141. ]
  142. }
  143. },
  144. copy: {
  145. demo: {
  146. files: [
  147. { src: ['*'], dest: '<%= outputDir.build %>/demo/sheets/', cwd: './test/data/', expand: true },
  148. { src: ['*.js', '*.css', '*.html', '*.ico'], cwd: './demo/', expand: true, dest: '<%= outputDir.build %>/demo/' },
  149. { src: ['osmd-debug.js'], cwd: './build/', expand: true, dest: '<%= outputDir.build %>/demo/' }
  150. ]
  151. }
  152. },
  153. // http-server
  154. 'http-server': {
  155. 'demo': {
  156. root: 'build/demo',
  157. port: 8000,
  158. host: '0.0.0.0',
  159. showDir : true,
  160. autoIndex: true,
  161. runInBackground: false,
  162. openBrowser : true
  163. }
  164. }
  165. });
  166. // Load npm tasks
  167. grunt.loadNpmTasks('grunt-browserify');
  168. grunt.loadNpmTasks('grunt-contrib-clean');
  169. grunt.loadNpmTasks('grunt-contrib-copy');
  170. grunt.loadNpmTasks('grunt-contrib-jshint');
  171. grunt.loadNpmTasks('grunt-contrib-uglify');
  172. grunt.loadNpmTasks('grunt-contrib-watch');
  173. grunt.loadNpmTasks('grunt-http-server');
  174. grunt.loadNpmTasks('grunt-karma');
  175. grunt.loadNpmTasks('grunt-ts');
  176. grunt.loadNpmTasks('grunt-tslint');
  177. grunt.loadNpmTasks('grunt-typings');
  178. // Code quality
  179. grunt.registerTask('lint', 'Lints all JavaScript and TypeScript files.', ['jshint', 'tslint']);
  180. // Build tasks
  181. grunt.registerTask('build:demo', 'Builds the demo.', ['browserify:debug', 'copy:demo']);
  182. grunt.registerTask('build:test', 'Builds the tests', ['browserify:test']);
  183. grunt.registerTask('build:dist', 'Builds for distribution on npm and Bower.', ['browserify:dist', 'uglify', 'ts']);
  184. // Tests
  185. grunt.registerTask('test', 'Runs unit, regression and e2e tests.', ['build:test', 'karma:ci']);
  186. // Default task (if grunt is run without any argument, used in contiuous integration)
  187. grunt.registerTask('default', 'Default task, running all other tasks. (CI)', ['lint', 'test', 'build:demo', 'build:dist']);
  188. };