Gruntfile.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*global module*/
  2. var webpack = require('webpack');
  3. var path = require('path');
  4. module.exports = function (grunt) {
  5. 'use strict';
  6. // The banner on top of the build
  7. var banner = '/**\n' +
  8. ' * Open Sheet Music Display <%= pkg.version %> built on <%= grunt.template.today("yyyy-mm-dd") %>.\n' +
  9. ' * Copyright (c) 2016 PhonicScore\n' +
  10. ' *\n' +
  11. ' * https://github.com/opensheetmusicdisplay/opensheetmusicdisplay\n' +
  12. ' */\n',
  13. typings = [
  14. 'typings/index.d.ts',
  15. // Additional manual typings:
  16. 'external/vexflow/vexflow.d.ts'
  17. ];
  18. // Paths
  19. var src = ['src/**/*.ts'];
  20. var test = ['test/**/*.ts'];
  21. // Grunt configuration following:
  22. grunt.initConfig({
  23. pkg: grunt.file.readJSON('package.json'),
  24. banner: '',
  25. // Build output directories
  26. outputDir: {
  27. build: 'build',
  28. dist: 'dist'
  29. },
  30. // Browserify
  31. browserify: {
  32. dist: {
  33. src: ['src/OSMD/OSMD.ts'],
  34. dest: '<%= outputDir.build %>/osmd.js',
  35. options: {
  36. banner: '<%= banner %>',
  37. browserifyOptions: {
  38. standalone: 'opensheetmusicdisplay'
  39. }
  40. }
  41. },
  42. debug: {
  43. src: ['src/OSMD/OSMD.ts'],
  44. dest: '<%= outputDir.build %>/osmd-debug.js',
  45. options: {
  46. banner: '<%= banner %>',
  47. browserifyOptions: {
  48. debug: true,
  49. standalone: 'opensheetmusicdisplay'
  50. }
  51. }
  52. },
  53. test: {
  54. src: [].concat(typings, src, test),
  55. dest: '<%= outputDir.build %>/osmd-test.js',
  56. options: {
  57. banner: '<%= banner %>',
  58. browserifyOptions: {
  59. debug: true
  60. }
  61. }
  62. },
  63. options: {
  64. plugin: ['tsify']
  65. }
  66. },
  67. // Uglify
  68. uglify: {
  69. options: {
  70. compress: {
  71. 'drop_console': true
  72. },
  73. banner: banner,
  74. mangle: true,
  75. mangleProperties: true
  76. },
  77. bundle: {
  78. files: {
  79. 'build/osmd.min.js': ['build/osmd.js']
  80. }
  81. }
  82. },
  83. // Webpack
  84. webpack: {
  85. build: {
  86. entry: ['./src/OSMD/OSMD.ts'],
  87. output: {
  88. path: path.resolve(__dirname, 'build'),
  89. filename: 'osmd.js'
  90. },
  91. resolve: {
  92. // Add '.ts' and '.tsx' as a resolvable extension.
  93. extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js']
  94. },
  95. module: {
  96. loaders: [
  97. // all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'
  98. { test: /\.tsx?$/, loader: 'ts-loader' }
  99. ]
  100. },
  101. plugins: [
  102. // build optimization plugins
  103. new webpack.LoaderOptionsPlugin({
  104. minimize: true,
  105. debug: false
  106. }),
  107. new webpack.optimize.UglifyJsPlugin({
  108. warnings: false,
  109. beautify: false,
  110. compress: true,
  111. comments: false,
  112. sourceMap: true
  113. })
  114. ]
  115. }
  116. },
  117. // Karma setup
  118. karma: {
  119. // For continuous integration
  120. ci: {
  121. configFile: 'karma.conf.js',
  122. options: {
  123. browsers: ['PhantomJS']
  124. }
  125. },
  126. firefox: {
  127. configFile: 'karma.conf.js',
  128. options: {
  129. singleRun: false,
  130. browsers: ['Firefox']
  131. }
  132. },
  133. chrome: {
  134. configFile: 'karma.conf.js',
  135. options: {
  136. singleRun: false,
  137. browsers: ['Chrome']
  138. }
  139. }
  140. },
  141. // Typescript compilation for ES6 module (npm package)
  142. ts: {
  143. default : {
  144. tsconfig: true
  145. }
  146. },
  147. // Cleaning task setup
  148. clean: {
  149. options: {
  150. force: true
  151. },
  152. all: {
  153. src: [
  154. '<%= outputDir.build %>',
  155. '<%= outputDir.dist %>',
  156. '.tscache',
  157. 'src/**/*.js', 'test/**/*.js' // if something went wrong, delete JS from TypeScript source directories
  158. ]
  159. }
  160. },
  161. copy: {
  162. demo: {
  163. files: [
  164. { src: ['*'], dest: '<%= outputDir.build %>/demo/sheets/', cwd: './test/data/', expand: true },
  165. { src: ['*.js', '*.css', '*.html', '*.ico'], cwd: './demo/', expand: true, dest: '<%= outputDir.build %>/demo/' },
  166. { src: ['osmd-debug.js'], cwd: './build/', expand: true, dest: '<%= outputDir.build %>/demo/' }
  167. ]
  168. }
  169. },
  170. // http-server
  171. 'http-server': {
  172. 'demo': {
  173. root: 'build/demo',
  174. port: 8000,
  175. host: '0.0.0.0',
  176. showDir : true,
  177. autoIndex: true,
  178. runInBackground: false,
  179. openBrowser : true
  180. }
  181. }
  182. });
  183. // Load npm tasks
  184. grunt.loadNpmTasks('grunt-browserify');
  185. grunt.loadNpmTasks('grunt-contrib-clean');
  186. grunt.loadNpmTasks('grunt-contrib-copy');
  187. grunt.loadNpmTasks('grunt-contrib-uglify');
  188. grunt.loadNpmTasks('grunt-contrib-watch');
  189. grunt.loadNpmTasks('grunt-http-server');
  190. grunt.loadNpmTasks('grunt-karma');
  191. grunt.loadNpmTasks('grunt-ts');
  192. grunt.loadNpmTasks('grunt-webpack');
  193. // Build tasks
  194. grunt.registerTask('build:demo', 'Builds the demo.', ['browserify:debug', 'copy:demo']);
  195. grunt.registerTask('build:test', 'Builds the tests', ['browserify:test']);
  196. grunt.registerTask('build:dist', 'Builds for distribution on npm and Bower.', ['browserify:dist', 'uglify', 'ts']);
  197. grunt.registerTask('build:pack', 'Builds using webpack', ['webpack:build', 'uglify']);
  198. // Tests
  199. grunt.registerTask('test', 'Runs unit, regression and e2e tests.', ['build:test', 'karma:ci']);
  200. // Default task (if grunt is run without any argument, used in contiuous integration)
  201. grunt.registerTask('default', 'Default task, running all other tasks. (CI)', ['test', 'build:demo', 'build:dist']);
  202. };