Gruntfile.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. // Class documentation using typedoc
  125. typedoc: {
  126. build: {
  127. options: {
  128. module: 'commonjs',
  129. out: '<%= outputDir.build %>/docs',
  130. name: 'opensheetmusicdisplay',
  131. target: 'es5',
  132. mode: 'file'
  133. },
  134. src: ['./src/**/*.ts', './external/**/*.ts', './typings/**/*.ts']
  135. }
  136. },
  137. // Typescript compilation for ES6 module (npm package)
  138. ts: {
  139. default : {
  140. tsconfig: true
  141. }
  142. },
  143. // Cleaning task setup
  144. clean: {
  145. options: {
  146. force: true
  147. },
  148. all: {
  149. src: [
  150. '<%= outputDir.build %>',
  151. '<%= outputDir.dist %>',
  152. '.tscache',
  153. 'src/**/*.js', 'test/**/*.js' // if something went wrong, delete JS from TypeScript source directories
  154. ]
  155. }
  156. },
  157. copy: {
  158. demo: {
  159. files: [
  160. { src: ['*'], dest: '<%= outputDir.build %>/demo/sheets/', cwd: './test/data/', expand: true },
  161. { src: ['*.js', '*.css', '*.html', '*.ico'], cwd: './demo/', expand: true, dest: '<%= outputDir.build %>/demo/' },
  162. { src: ['osmd-debug.js'], cwd: './build/', expand: true, dest: '<%= outputDir.build %>/demo/' }
  163. ]
  164. }
  165. },
  166. // http-server
  167. 'http-server': {
  168. 'demo': {
  169. root: 'build/demo',
  170. port: 8000,
  171. host: '0.0.0.0',
  172. showDir : true,
  173. autoIndex: true,
  174. runInBackground: false,
  175. openBrowser : true
  176. }
  177. }
  178. });
  179. // Load npm tasks
  180. grunt.loadNpmTasks('grunt-browserify');
  181. grunt.loadNpmTasks('grunt-contrib-clean');
  182. grunt.loadNpmTasks('grunt-contrib-copy');
  183. grunt.loadNpmTasks('grunt-contrib-jshint');
  184. grunt.loadNpmTasks('grunt-contrib-uglify');
  185. grunt.loadNpmTasks('grunt-contrib-watch');
  186. grunt.loadNpmTasks('grunt-http-server');
  187. grunt.loadNpmTasks('grunt-karma');
  188. grunt.loadNpmTasks('grunt-ts');
  189. grunt.loadNpmTasks('grunt-tslint');
  190. grunt.loadNpmTasks('grunt-typedoc');
  191. grunt.loadNpmTasks('grunt-typings');
  192. // Code quality
  193. grunt.registerTask('lint', 'Lints all JavaScript and TypeScript files.', ['jshint', 'tslint']);
  194. // Documentation
  195. grunt.registerTask('docs', 'Builds class documentation to /build/docs', ['typedoc']);
  196. // Build tasks
  197. grunt.registerTask('build:demo', 'Builds the demo.', ['browserify:debug', 'copy:demo']);
  198. grunt.registerTask('build:test', 'Builds the tests', ['browserify:test']);
  199. grunt.registerTask('build:dist', 'Builds for distribution on npm and Bower.', ['browserify:dist', 'uglify', 'ts']);
  200. // Tests
  201. grunt.registerTask('test', 'Runs unit, regression and e2e tests.', ['build:test', 'karma:ci']);
  202. // Default task (if grunt is run without any argument, used in contiuous integration)
  203. grunt.registerTask('default', 'Default task, running all other tasks. (CI)', ['lint', 'test', 'docs', 'build:demo', 'build:dist']);
  204. };