2
0

Gruntfile.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. module.exports = function(grunt) {
  2. var _ = require('underscore');
  3. // Load required NPM tasks.
  4. // You must first run `npm install` in the project's root directory to get these dependencies.
  5. grunt.loadNpmTasks('grunt-contrib-concat');
  6. grunt.loadNpmTasks('grunt-contrib-uglify');
  7. grunt.loadNpmTasks('grunt-contrib-copy');
  8. grunt.loadNpmTasks('grunt-contrib-compress');
  9. grunt.loadNpmTasks('grunt-contrib-clean');
  10. grunt.loadNpmTasks('grunt-contrib-jshint');
  11. grunt.loadNpmTasks('grunt-jscs-checker');
  12. grunt.loadNpmTasks('lumbar');
  13. // Parse config files
  14. var packageConfig = grunt.file.readJSON('package.json');
  15. var pluginConfig = grunt.file.readJSON('fullcalendar.jquery.json');
  16. // This will eventually get passed to grunt.initConfig()
  17. // Initialize multitasks...
  18. var config = {
  19. concat: {},
  20. uglify: {},
  21. copy: {},
  22. compress: {},
  23. clean: {}
  24. };
  25. // Combine certain configs for the "meta" template variable (<%= meta.whatever %>)
  26. config.meta = _.extend({}, packageConfig, pluginConfig);
  27. // The "grunt" command with no arguments
  28. grunt.registerTask('default', 'archive');
  29. // Bare minimum for debugging
  30. grunt.registerTask('dev', [
  31. 'lumbar:build',
  32. 'generateLanguages'
  33. ]);
  34. /* FullCalendar Modules
  35. ----------------------------------------------------------------------------------------------------*/
  36. grunt.registerTask('modules', 'Build the FullCalendar modules', [
  37. 'jscs:srcModules',
  38. 'clean:modules',
  39. 'lumbar:build',
  40. 'concat:moduleVariables',
  41. 'jshint:builtModules',
  42. 'uglify:modules'
  43. ]);
  44. // assemble modules
  45. config.lumbar = {
  46. build: {
  47. build: 'lumbar.json',
  48. output: 'build/out' // a directory. lumbar doesn't like trailing slash
  49. }
  50. };
  51. // replace template variables (<%= %>), IN PLACE
  52. config.concat.moduleVariables = {
  53. options: {
  54. process: true // replace
  55. },
  56. expand: true,
  57. cwd: 'build/out/',
  58. src: [ '*.js', '*.css' ],
  59. dest: 'build/out/'
  60. };
  61. // create minified versions (*.min.js)
  62. config.uglify.modules = {
  63. options: {
  64. preserveComments: 'some' // keep comments starting with /*!
  65. },
  66. expand: true,
  67. src: 'build/out/fullcalendar.js', // only do it for fullcalendar.js
  68. ext: '.min.js'
  69. };
  70. config.clean.modules = 'build/out/**';
  71. /* Languages
  72. ----------------------------------------------------------------------------------------------------*/
  73. grunt.registerTask('languages', [
  74. 'jscs:srcLanguages',
  75. 'jshint:srcLanguages',
  76. 'clean:languages',
  77. 'generateLanguages',
  78. 'uglify:languages'
  79. ]);
  80. config.generateLanguages = {
  81. moment: 'lib/moment/lang/',
  82. datepicker: 'lib/jquery-ui/ui/i18n/',
  83. fullCalendar: 'lang/',
  84. dest: 'build/out/lang/'
  85. };
  86. config.uglify.languages = {
  87. expand: true,
  88. cwd: 'build/out/lang/',
  89. src: '*.js',
  90. dest: 'build/out/lang-min/'
  91. };
  92. config.clean.languages = [
  93. 'build/out/lang/*',
  94. 'build/out/lang-min/*'
  95. ];
  96. /* Archive
  97. ----------------------------------------------------------------------------------------------------*/
  98. grunt.registerTask('archive', 'Create a distributable ZIP archive', [
  99. 'clean:archive',
  100. 'modules',
  101. 'languages',
  102. 'copy:archiveModules',
  103. 'copy:archiveLanguages',
  104. 'copy:archiveMoment',
  105. 'copy:archiveJQuery',
  106. 'concat:archiveJQueryUI',
  107. 'copy:archiveDemos',
  108. 'copy:archiveDemoTheme',
  109. 'copy:archiveMisc',
  110. 'compress:archive'
  111. ]);
  112. // copy FullCalendar modules into ./fullcalendar/ directory
  113. config.copy.archiveModules = {
  114. expand: true,
  115. cwd: 'build/out/',
  116. src: [ '*.js', '*.css' ],
  117. dest: 'build/archive/fullcalendar/'
  118. };
  119. config.copy.archiveLanguages = {
  120. expand: true,
  121. cwd: 'build/out/lang-min/',
  122. src: '*.js',
  123. dest: 'build/archive/fullcalendar/lang/'
  124. };
  125. config.copy.archiveMoment = {
  126. src: 'lib/moment/min/moment.min.js',
  127. dest: 'build/archive/lib/moment.min.js'
  128. };
  129. config.copy.archiveJQuery = {
  130. src: 'lib/jquery/jquery.min.js',
  131. dest: 'build/archive/lib/jquery.min.js'
  132. };
  133. config.concat.archiveJQueryUI = {
  134. src: [
  135. 'lib/jquery-ui/ui/minified/jquery.ui.core.min.js',
  136. 'lib/jquery-ui/ui/minified/jquery.ui.widget.min.js',
  137. 'lib/jquery-ui/ui/minified/jquery.ui.mouse.min.js',
  138. 'lib/jquery-ui/ui/minified/jquery.ui.draggable.min.js',
  139. 'lib/jquery-ui/ui/minified/jquery.ui.resizable.min.js'
  140. ],
  141. dest: 'build/archive/lib/jquery-ui.custom.min.js'
  142. };
  143. // copy demo files into ./demos/ directory
  144. config.copy.archiveDemos = {
  145. options: {
  146. processContent: function(content) {
  147. content = content.replace(/((?:src|href)=['"])([^'"]*)(['"])/g, function(m0, m1, m2, m3) {
  148. return m1 + transformDemoPath(m2) + m3;
  149. });
  150. return content;
  151. }
  152. },
  153. src: 'demos/**',
  154. dest: 'build/archive/'
  155. };
  156. // copy the "cupertino" jquery-ui theme into the demo directory (for demos/theme.html)
  157. config.copy.archiveDemoTheme = {
  158. expand: true,
  159. cwd: 'lib/jquery-ui/themes/cupertino/',
  160. src: [ 'jquery-ui.min.css', 'images/*' ],
  161. dest: 'build/archive/lib/cupertino/'
  162. };
  163. // in demo HTML, rewrites paths to work in the archive
  164. function transformDemoPath(path) {
  165. path = path.replace('../lib/moment/moment.js', '../lib/moment.min.js');
  166. path = path.replace('../lib/jquery/jquery.js', '../lib/jquery.min.js');
  167. path = path.replace('../lib/jquery-ui/ui/jquery-ui.js', '../lib/jquery-ui.custom.min.js');
  168. path = path.replace('../lib/jquery-ui/themes/cupertino/', '../lib/cupertino/');
  169. path = path.replace('../build/out/', '../fullcalendar/');
  170. path = path.replace('/fullcalendar.js', '/fullcalendar.min.js');
  171. return path;
  172. }
  173. // copy license and changelog
  174. config.copy.archiveMisc = {
  175. files: {
  176. 'build/archive/license.txt': 'license.txt',
  177. 'build/archive/changelog.txt': 'changelog.md'
  178. }
  179. };
  180. // create the ZIP
  181. config.compress.archive = {
  182. options: {
  183. archive: 'dist/<%= meta.name %>-<%= meta.version %>.zip'
  184. },
  185. expand: true,
  186. cwd: 'build/archive/',
  187. src: '**',
  188. dest: '<%= meta.name %>-<%= meta.version %>/' // have a top-level directory in the ZIP file
  189. };
  190. config.clean.archive = 'build/archive/*';
  191. config.clean.dist = 'dist/*';
  192. /* Bower Component (http://bower.io/)
  193. ----------------------------------------------------------------------------------------------------*/
  194. grunt.registerTask('bower', 'Build the FullCalendar Bower component', [
  195. 'clean:bower',
  196. 'modules',
  197. 'copy:bowerModules',
  198. 'copy:bowerReadme',
  199. 'bowerConfig'
  200. ]);
  201. // copy FullCalendar modules into bower component's root
  202. config.copy.bowerModules = {
  203. expand: true,
  204. cwd: 'build/out/',
  205. src: [ '*.js', '*.css' ],
  206. dest: 'build/bower/'
  207. };
  208. // copy the bower-specific README
  209. config.copy.bowerReadme = {
  210. src: 'build/bower-readme.md',
  211. dest: 'build/bower/readme.md'
  212. };
  213. // assemble the bower config from existing configs
  214. grunt.registerTask('bowerConfig', function() {
  215. var bowerConfig = grunt.file.readJSON('build/bower.json');
  216. grunt.file.write(
  217. 'build/bower/bower.json',
  218. JSON.stringify(
  219. _.extend({}, pluginConfig, bowerConfig), // combine 2 configs
  220. null, // replacer
  221. 2 // indent
  222. )
  223. );
  224. });
  225. config.clean.bower = 'build/bower/*';
  226. /* CDNJS (http://cdnjs.com/)
  227. ----------------------------------------------------------------------------------------------------*/
  228. grunt.registerTask('cdnjs', 'Build files for CDNJS\'s hosted version of FullCalendar', [
  229. 'clean:cdnjs',
  230. 'modules',
  231. 'copy:cdnjsModules',
  232. 'cdnjsConfig'
  233. ]);
  234. config.copy.cdnjsModules = {
  235. expand: true,
  236. cwd: 'build/out/',
  237. src: [ '*.js', '*.css' ],
  238. dest: 'build/cdnjs/<%= meta.version %>/'
  239. };
  240. grunt.registerTask('cdnjsConfig', function() {
  241. var cdnjsConfig = grunt.file.readJSON('build/cdnjs.json');
  242. grunt.file.write(
  243. 'build/cdnjs/package.json',
  244. JSON.stringify(
  245. _.extend({}, pluginConfig, cdnjsConfig), // combine 2 configs
  246. null, // replace
  247. 2 // indent
  248. )
  249. );
  250. });
  251. config.clean.cdnjs = 'build/cdnjs/<%= meta.version %>/*';
  252. // NOTE: not a complete clean. also need to manually worry about package.json and version folders
  253. /* Linting and Code Style Checking
  254. ----------------------------------------------------------------------------------------------------*/
  255. grunt.registerTask('check', 'Lint and check code style', [
  256. 'jscs',
  257. 'jshint:srcModules', // so we can fix most quality errors in their original files
  258. 'lumbar:build',
  259. 'jshint' // will run srcModules again but oh well
  260. ]);
  261. // configs located elsewhere
  262. config.jshint = require('./jshint.conf');
  263. config.jscs = require('./jscs.conf');
  264. // finally, give grunt the config object...
  265. grunt.initConfig(config);
  266. // load everything in the ./tasks/ directory
  267. grunt.loadTasks('tasks');
  268. };