Gruntfile.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. module.exports = function(grunt) {
  2. var path = require("path");
  3. /**
  4. * Used to process the handlebar template names when compiling them to the "tmpl" namespace.
  5. * @example
  6. * processTemplateName( "src/tmpl/template.hbs" ) => "template" => tmpl["template"]
  7. * processTemplateName( "src/tmpl/_partial.hbs" ) => "partial" => tmpl["partial"]
  8. * processTemplateName( "src/tmpl/group/template.hbs" ) => "group/template" => tmpl["group/template"]
  9. * processTemplateName( "src/tmpl/group/_partial.hbs" ) => "group/partial" => tmpl["group/partial"]
  10. */
  11. var processTemplateName = function(filePath){
  12. return filePath.replace(/^.*?\/tmpl\/(.*)?\.hbs/, '$1').replace(/(\/|^)_/, '$1');
  13. };
  14. grunt.initConfig({
  15. pkg: grunt.file.readJSON('package.json'),
  16. clean: {
  17. test: ['.test/'],
  18. examples: ['examples/'],
  19. template: ['template/']
  20. },
  21. handlebars: {
  22. compile: {
  23. options: {
  24. namespace: 'tmpl',
  25. node: true,
  26. partialsUseNamespace: true,
  27. processName: processTemplateName,
  28. processPartialName: processTemplateName
  29. },
  30. files: {
  31. "template/tmpl.js": ["src/tmpl/**/*.hbs"]
  32. }
  33. }
  34. },
  35. copy : {
  36. template: {
  37. files: [
  38. {expand: true, flatten: true, src: ['src/conf.json'], dest: 'template/', filter: 'isFile'},
  39. {expand: true, flatten: true, src: ['src/publish.js'], dest: 'template/', filter: 'isFile'},
  40. {expand: true, flatten: true, src: ['src/utils/template.js'], dest: 'template/utils/', filter: 'isFile'},
  41. {expand: true, flatten: true, src: ['src/utils/postProcessor.js'], dest: 'template/utils/', filter: 'isFile'},
  42. {expand: true, flatten: true, src: ['src/utils/docletHelper.js'], dest: 'template/utils/', filter: 'isFile'},
  43. {expand: true, flatten: true, src: ['src/utils/handlebarsHelper.js'], dest: 'template/utils/', filter: 'isFile'},
  44. {expand: true, flatten: true, src: ['src/utils/lunrHelper.js'], dest: 'template/utils/', filter: 'isFile'}
  45. ]
  46. },
  47. bootstrap: {
  48. files : [
  49. {expand: true, flatten: true, src: ['node_modules/bootstrap/dist/js/bootstrap.min.js'], dest: 'template/static/js/', filter: 'isFile'},
  50. {expand: true, flatten: true, src: ['node_modules/bootstrap/dist/css/bootstrap.min.css'], dest: 'template/static/css/', filter: 'isFile'},
  51. {expand: true, flatten: true, src: ['node_modules/bootstrap/dist/fonts/*'], dest: 'template/static/fonts/', filter: 'isFile'}
  52. ]
  53. },
  54. jquery: {
  55. files : [
  56. {expand: true, flatten: true, src: ['node_modules/jquery/dist/jquery.min.js'], dest: 'template/static/js/', filter: 'isFile'}
  57. ]
  58. },
  59. clipboard: {
  60. files : [
  61. {expand: true, flatten: true, src: ['node_modules/clipboard/dist/clipboard.min.js'], dest: 'template/static/js/', filter: 'isFile'}
  62. ]
  63. },
  64. prism: {
  65. files : [
  66. {expand: true, flatten: true, src: ['node_modules/prismjs/prism.js'], dest: 'template/static/js/', filter: 'isFile'},
  67. {expand: true, flatten: true, src: ['node_modules/prismjs/themes/prism.css'], dest: 'template/static/css/', filter: 'isFile'}
  68. ]
  69. },
  70. lunr: {
  71. files : [
  72. {expand: true, flatten: true, src: ['node_modules/lunr/lunr.min.js'], dest: 'template/static/js/', filter: 'isFile'}
  73. ]
  74. }
  75. },
  76. uglify: {
  77. prism: { // prism requires it's own build as I've modified some plugins and use some default ones to.
  78. files: {
  79. 'template/static/js/prism.min.js': [
  80. 'node_modules/prismjs/prism.js',
  81. 'node_modules/prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js',
  82. 'src/static/js/prism-line-numbers.js',
  83. 'src/static/js/prism-toolbar.js',
  84. 'src/static/js/prism-copy-to-clipboard.js',
  85. ]
  86. }
  87. },
  88. template: {
  89. files: {
  90. 'template/static/js/template.min.js': [
  91. 'src/static/js/markdown-helpers.js',
  92. 'src/static/js/symbols.js',
  93. 'src/static/js/table-of-contents.js',
  94. 'src/static/js/access-filter.js',
  95. 'src/static/js/lunr-search.js',
  96. 'src/static/js/example-run.js',
  97. 'src/static/js/google-analytics.js'
  98. ]
  99. }
  100. }
  101. },
  102. cssmin: {
  103. prism: {
  104. files: {
  105. 'template/static/css/prism.min.css': [
  106. 'node_modules/prismjs/themes/prism.css',
  107. 'src/static/css/prism-theme-overrides.css',
  108. 'src/static/css/prism-line-numbers.css',
  109. 'src/static/css/prism-toolbar.css'
  110. ]
  111. }
  112. },
  113. template: {
  114. files: {
  115. 'template/static/css/template.min.css': [
  116. 'src/static/css/site.css',
  117. 'src/static/css/callout.css',
  118. 'src/static/css/page-header.css',
  119. 'src/static/css/symbols.css',
  120. 'src/static/css/tags.css',
  121. 'src/static/css/anchor-link.css',
  122. 'src/static/css/breadcrumbs.css',
  123. 'src/static/css/dummy-console.css',
  124. 'src/static/css/lunr-search.css',
  125. 'src/static/css/related-tutorials.css',
  126. 'src/static/css/toc.css',
  127. 'src/static/css/access-filter.css'
  128. ]
  129. }
  130. }
  131. },
  132. jsdoc: {
  133. namespaced: {
  134. src: ["README.md","test-src/namespaced/**/*.js"],
  135. options: {
  136. destination: './.test',
  137. template : './template',
  138. configure : './test-src/default.conf.json',
  139. tutorials: './test-src/fixtures/tutorials/',
  140. private: true
  141. }
  142. },
  143. default: {
  144. src: ["README.md","test-src/fixtures/**/*.js"],
  145. options: {
  146. destination: './examples/default',
  147. template : './template',
  148. configure : './test-src/default.conf.json',
  149. tutorials: './test-src/fixtures/tutorials/',
  150. private: true
  151. }
  152. },
  153. inline: {
  154. src: ["README.md","test-src/fixtures/**/*.js"],
  155. options: {
  156. destination: './examples/inline',
  157. template : './template',
  158. configure : './test-src/inline.conf.json',
  159. tutorials: './test-src/fixtures/tutorials/',
  160. private: true
  161. }
  162. },
  163. "logo-color": {
  164. src: ["README.md","test-src/fixtures/**/*.js"],
  165. options: {
  166. destination: './examples/logo-color',
  167. template : './template',
  168. configure : './test-src/logo-color.conf.json',
  169. tutorials: './test-src/fixtures/tutorials/',
  170. private: true
  171. }
  172. },
  173. collapse: {
  174. src: ["README.md","test-src/fixtures/**/*.js"],
  175. options: {
  176. destination: './examples/collapse',
  177. template : './template',
  178. configure : './test-src/collapse.conf.json',
  179. tutorials: './test-src/fixtures/tutorials/',
  180. private: true
  181. }
  182. }
  183. }
  184. });
  185. grunt.loadNpmTasks('grunt-contrib-clean');
  186. grunt.loadNpmTasks('grunt-contrib-copy');
  187. grunt.loadNpmTasks('grunt-contrib-cssmin');
  188. grunt.loadNpmTasks('grunt-contrib-uglify');
  189. grunt.loadNpmTasks('grunt-contrib-handlebars');
  190. grunt.loadNpmTasks('grunt-jsdoc');
  191. grunt.registerTask('template', ['clean:template', 'handlebars', 'copy', 'uglify', 'cssmin']);
  192. grunt.registerTask('all', ['template', 'clean:examples', 'jsdoc:default', 'jsdoc:inline', 'jsdoc:logo-color', 'jsdoc:collapse', 'jsdoc:namespaced']);
  193. grunt.registerTask('default', ['template', 'jsdoc:default']);
  194. grunt.registerTask('inline', ['template', 'jsdoc:inline']);
  195. grunt.registerTask('logo-color', ['template', 'jsdoc:logo-color']);
  196. grunt.registerTask('collapse', ['template', 'jsdoc:collapse']);
  197. grunt.registerTask('namespaced', ['template', 'jsdoc:namespaced']);
  198. };