Gruntfile.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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: [].concat(typings, src),
  32. dest: '<%= outputDir.build %>/osmd.js',
  33. options: {
  34. banner: "<%= banner %>"
  35. }
  36. },
  37. demo: {
  38. src: [].concat(typings, src, ['demo/inject.ts']),
  39. dest: '<%= outputDir.build %>/demo/osmd-demo.js',
  40. options: {
  41. banner: "<%= banner %>",
  42. browserifyOptions: {
  43. debug: true
  44. }
  45. }
  46. },
  47. debug: {
  48. src: [].concat(typings, src, test),
  49. dest: '<%= outputDir.build %>/osmd-debug.js',
  50. options: {
  51. banner: "<%= banner %>",
  52. browserifyOptions: {
  53. debug: true
  54. }
  55. }
  56. },
  57. options: {
  58. plugin: ['tsify']
  59. }
  60. },
  61. // Uglify
  62. uglify: {
  63. options: {
  64. compress: {
  65. drop_console: true
  66. },
  67. banner: banner,
  68. mangle: true,
  69. mangleProperties: true,
  70. preserveComments: 'all'
  71. },
  72. bundle: {
  73. files: {
  74. 'build/osmd.min.js': ['build/osmd.js']
  75. }
  76. }
  77. },
  78. // Karma setup
  79. karma: {
  80. // For continuous integration
  81. ci: {
  82. configFile: 'karma.conf.js',
  83. options: {
  84. browsers: ['PhantomJS']
  85. }
  86. },
  87. firefox: {
  88. configFile: 'karma.conf.js',
  89. options: {
  90. singleRun: false,
  91. browsers: ['Firefox']
  92. }
  93. },
  94. chrome: {
  95. configFile: 'karma.conf.js',
  96. options: {
  97. singleRun: false,
  98. browsers: ['Chrome']
  99. }
  100. }
  101. },
  102. // TSLint setup
  103. tslint: {
  104. options: {
  105. configuration: 'tslint.json'
  106. },
  107. all: {
  108. src: [].concat(src, test)
  109. }
  110. },
  111. // JsHint setup
  112. jshint: {
  113. all: [
  114. 'Gruntfile.js', 'karma.conf.js', 'demo/**/*.js'
  115. ]
  116. },
  117. // TypeScript Type Definitions
  118. typings: {
  119. install: {}
  120. },
  121. // Class documentation using typedoc
  122. typedoc: {
  123. build: {
  124. options: {
  125. module: 'commonjs',
  126. out: '<%= outputDir.build %>/docs',
  127. name: 'opensheetmusicdisplay',
  128. target: 'es5',
  129. mode: 'file'
  130. },
  131. src: ['./src/**/*.ts', './external/**/*.ts', './typings/**/*.ts']
  132. }
  133. },
  134. // Typescript compilation for ES6 module (npm package)
  135. ts: {
  136. default : {
  137. tsconfig: true
  138. }
  139. },
  140. // Cleaning task setup
  141. clean: {
  142. options: {
  143. force: true
  144. },
  145. all: {
  146. src: [
  147. '<%= outputDir.build %>',
  148. '<%= outputDir.dist %>',
  149. '.tscache',
  150. 'src/**/*.js', 'test/**/*.js' // if something went wrong, delete JS from TypeScript source directories
  151. ]
  152. }
  153. },
  154. copy: {
  155. demo: {
  156. files: [
  157. { src: ['*'], dest: '<%= outputDir.build %>/demo/sheets/', cwd: './test/data/', expand: true },
  158. { src: ['*.js', '*.css', '*.html'], cwd: './demo/', expand: true, dest: '<%= outputDir.build %>/demo/' }
  159. ]
  160. }
  161. },
  162. // http-server
  163. 'http-server': {
  164. 'demo': {
  165. root: 'build/demo',
  166. port: 8000,
  167. host: '0.0.0.0',
  168. showDir : true,
  169. autoIndex: true,
  170. runInBackground: false,
  171. openBrowser : true
  172. }
  173. }
  174. });
  175. // Load npm tasks
  176. grunt.loadNpmTasks('grunt-browserify');
  177. grunt.loadNpmTasks('grunt-contrib-clean');
  178. grunt.loadNpmTasks('grunt-contrib-copy');
  179. grunt.loadNpmTasks('grunt-contrib-jshint');
  180. grunt.loadNpmTasks('grunt-contrib-uglify');
  181. grunt.loadNpmTasks('grunt-contrib-watch');
  182. grunt.loadNpmTasks('grunt-http-server');
  183. grunt.loadNpmTasks('grunt-karma');
  184. grunt.loadNpmTasks('grunt-ts');
  185. grunt.loadNpmTasks('grunt-tslint');
  186. grunt.loadNpmTasks('grunt-typedoc');
  187. grunt.loadNpmTasks('grunt-typings');
  188. // Code quality
  189. grunt.registerTask('lint', 'Lints all JavaScript and TypeScript files.', ['jshint', 'tslint']);
  190. // Documentation
  191. grunt.registerTask('docs', 'Builds class documentation to /build/docs', ['typedoc']);
  192. // Build tasks
  193. grunt.registerTask('build:demo', 'Builds the demo.', ['browserify:demo', 'copy:demo']);
  194. grunt.registerTask('build:test', 'Builds the tests', ['browserify:debug']);
  195. grunt.registerTask('build:dist', 'Builds for distribution on npm and Bower.', ['browserify:dist', 'uglify', 'ts']);
  196. // Tests
  197. grunt.registerTask('test', 'Runs unit, regression and e2e tests.', ['build:test', 'karma:ci']);
  198. // Default task (if grunt is run without any argument, used in contiuous integration)
  199. grunt.registerTask('default', 'Default task, running all other tasks. (CI)', ['lint', 'test', 'docs', 'build:demo', 'build:dist']);
  200. };