Gruntfile.js 6.2 KB

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