Gruntfile.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. 'use strict';
  2. module.exports = function(grunt) {
  3. // Load all grunt tasks automatically
  4. require('load-grunt-tasks')(grunt);
  5. // Time how long grunt task take. Can help when optimizing build times
  6. require('time-grunt')(grunt);
  7. //Configure grunt
  8. grunt.initConfig({
  9. pkg: grunt.file.readJSON('package.json'),
  10. less: {
  11. options: {
  12. banner: grunt.file.read('src/banner')
  13. },
  14. main: {
  15. files: {
  16. 'dist/css/nya-bs-select.css': 'less/nya-bs-select.less'
  17. }
  18. },
  19. docs: {
  20. files: {
  21. 'docs/dist/css/main.css': 'docs/src/less/main.less'
  22. }
  23. }
  24. },
  25. // The actual grunt server settings
  26. connect: {
  27. options: {
  28. port: 9000,
  29. // Change this to '0.0.0.0' to access the server from outside.
  30. hostname: '0.0.0.0',
  31. livereload: 35729
  32. },
  33. livereload: {
  34. options: {
  35. open: true,
  36. base: [
  37. '.',
  38. 'examples'
  39. ]
  40. }
  41. },
  42. docs: {
  43. options: {
  44. open: true,
  45. base: [
  46. 'docs/dist'
  47. ]
  48. }
  49. }
  50. },
  51. //Watch files for changes, and run tasks base on the changed files.
  52. watch: {
  53. css: {
  54. files: ['less/*.less'],
  55. tasks: ['newer:less:main'],
  56. options: {
  57. livereload: true
  58. }
  59. },
  60. js: {
  61. files: ['src/*.js'],
  62. tasks: ['newer:jshint:all'],
  63. options: {
  64. livereload: true
  65. }
  66. },
  67. livereload: {
  68. options: {
  69. livereload: '<%= connect.options.livereload %>'
  70. },
  71. files: [
  72. 'examples/*.html',
  73. 'examples/{,*/*.js}',
  74. 'examples{,*/}*.css',
  75. 'examples/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
  76. 'docs/dist/*.html',
  77. 'docs/dist/partials/*.html'
  78. ]
  79. },
  80. 'docs-less': {
  81. files: ['docs/src/less/*.less'],
  82. tasks: ['newer:less:docs'],
  83. options: {
  84. livereload: true
  85. }
  86. },
  87. 'docs-js': {
  88. files: ['docs/dist/js/*.js'],
  89. options: {
  90. livereload: true
  91. }
  92. },
  93. 'docs-md': {
  94. files: ['docs/src/content/{,*/}*.md'],
  95. tasks: ['newer:markdown:docs'],
  96. options: {
  97. livereload: true
  98. }
  99. }
  100. },
  101. // Make sure code styles are up to par and there are no obvious mistakes
  102. jshint: {
  103. options: {
  104. jshintrc: '.jshintrc',
  105. reporter: require('jshint-stylish')
  106. },
  107. all: [
  108. 'Gruntfile.js',
  109. 'src/*.js',
  110. 'examples/{,*/}*.js'
  111. ],
  112. docs: [
  113. 'docs/dist/js/*.js'
  114. ]
  115. },
  116. // Test
  117. karma: {
  118. unit: {
  119. configFile: 'test/karma.conf.js',
  120. autoWatch: false,
  121. singleRun: true
  122. },
  123. locally: {
  124. configFile: 'test/karma.conf.js',
  125. autoWatch: false,
  126. singleRun: true,
  127. browsers: ['Chrome', 'Firefox', 'PhantomJS']
  128. }
  129. },
  130. concat: {
  131. options:{
  132. banner: grunt.file.read('src/banner')
  133. },
  134. dist: {
  135. src: ['src/nya.prefix', 'src/nya-bs-public.js', 'src/nya-bs-config.js', 'src/nya-bs-select-ctrl.js', 'src/nya-bs-select.js', 'src/nya-bs-option.js', 'src/nya.suffix'],
  136. dest: 'dist/js/nya-bs-select.js'
  137. }
  138. },
  139. uglify: {
  140. options: {
  141. banner: grunt.file.read('src/banner')
  142. },
  143. dist: {
  144. src: ['dist/js/nya-bs-select.js'],
  145. dest: 'dist/js/nya-bs-select.min.js'
  146. }
  147. },
  148. cssmin: {
  149. options: {
  150. banner: grunt.file.read('src/banner')
  151. },
  152. dist: {
  153. src: ['dist/css/nya-bs-select.css'],
  154. dest: 'dist/css/nya-bs-select.min.css'
  155. }
  156. },
  157. copy: {
  158. docs: {
  159. files:[
  160. {
  161. expand: true,
  162. cwd: 'bower_components/',
  163. flatten: true,
  164. src: [
  165. 'angular/angular.js',
  166. 'angular-ui-router/release/angular-ui-router.js',
  167. 'jquery/dist/jquery.js',
  168. 'bootstrap/dist/js/bootstrap.js'
  169. ],
  170. dest: 'docs/dist/js/'
  171. },
  172. {
  173. expand: true,
  174. cwd: 'bower_components',
  175. flatten: true,
  176. src: [
  177. 'bootstrap/dist/fonts/*'
  178. ],
  179. dest: 'docs/dist/fonts/'
  180. },
  181. {
  182. expand: true,
  183. flatten: true,
  184. src: ['dist/js/nya-bs-select.js'],
  185. dest: 'docs/dist/js/'
  186. },
  187. {
  188. expand: true,
  189. flatten: true,
  190. src: ['dist/css/nya-bs-select.css'],
  191. dest: 'docs/dist/css/'
  192. },
  193. {
  194. expand: true,
  195. cwd: 'bower_components/svg-loaders',
  196. src: ['svg-loaders/*'],
  197. dest: 'docs/dist/'
  198. }
  199. ]
  200. }
  201. },
  202. markdown: {
  203. docs: {
  204. options:{
  205. template: 'docs/src/markdown-template.html'
  206. },
  207. files: [
  208. {
  209. expand: true,
  210. cwd: 'docs/src/content/',
  211. src: '**/*.md',
  212. dest: 'docs/dist/partials/',
  213. ext: '.html'
  214. }
  215. ]
  216. }
  217. },
  218. 'gh-pages': {
  219. options: {
  220. base: 'docs/dist',
  221. dotfiles: true
  222. },
  223. src: ['**']
  224. },
  225. 'remove-logging': {
  226. dist: {
  227. src: ['dist/js/nya-bs-select.js'],
  228. dest: 'dist/js/nya-bs-select.js'
  229. }
  230. }
  231. });
  232. require('./docs/tasks/markdown')(grunt);
  233. require('./tasks/remove-logging')(grunt);
  234. // Creates the 'serve' task
  235. grunt.registerTask('serve', [
  236. 'less:main',
  237. 'connect:livereload',
  238. 'watch'
  239. ]);
  240. // Creates the 'test' task
  241. grunt.registerTask('test', ['karma:unit']);
  242. // Creates the 'test-local' task
  243. grunt.registerTask('test-local', ['karma:locally']);
  244. // Build distribution files
  245. grunt.registerTask('build', [
  246. 'less:main',
  247. 'test',
  248. 'concat:dist',
  249. 'remove-logging:dist',
  250. 'uglify:dist',
  251. 'cssmin:dist'
  252. ]);
  253. grunt.registerTask('buildDocs', [
  254. 'copy:docs',
  255. 'markdown',
  256. 'less:docs',
  257. 'gh-pages'
  258. ]);
  259. grunt.registerTask('serveDocs', [
  260. 'copy:docs',
  261. 'markdown',
  262. 'less:docs',
  263. 'connect:docs',
  264. 'watch'
  265. ]);
  266. };