Gruntfile.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. // Generated on 2016-08-01 using generator-angular 0.15.1
  2. 'use strict';
  3. // # Globbing
  4. // for performance reasons we're only matching one level down:
  5. // 'test/spec/{,*/}*.js'
  6. // use this if you want to recursively match all subfolders:
  7. // 'test/spec/**/*.js'
  8. module.exports = function (grunt) {
  9. // Time how long tasks take. Can help when optimizing build times
  10. require('time-grunt')(grunt);
  11. // Automatically load required Grunt tasks
  12. require('jit-grunt')(grunt, {
  13. useminPrepare: 'grunt-usemin',
  14. ngtemplates: 'grunt-angular-templates',
  15. cdnify: 'grunt-google-cdn'
  16. });
  17. // Configurable paths for the application
  18. var appConfig = {
  19. app: require('./bower.json').appPath || 'app',
  20. dist: 'dist'
  21. };
  22. // Define the configuration for all the tasks
  23. grunt.initConfig({
  24. // Project settings
  25. yeoman: appConfig,
  26. // Watches files for changes and runs tasks based on the changed files
  27. watch: {
  28. bower: {
  29. files: ['bower.json'],
  30. tasks: ['wiredep']
  31. },
  32. js: {
  33. files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],
  34. tasks: ['newer:jshint:all', 'newer:jscs:all'],
  35. options: {
  36. livereload: '<%= connect.options.livereload %>'
  37. }
  38. },
  39. jsTest: {
  40. files: ['test/spec/{,*/}*.js'],
  41. tasks: ['newer:jshint:test', 'newer:jscs:test', 'karma']
  42. },
  43. styles: {
  44. files: ['<%= yeoman.app %>/styles/{,*/}*.css'],
  45. tasks: ['newer:copy:styles', 'postcss']
  46. },
  47. gruntfile: {
  48. files: ['Gruntfile.js']
  49. },
  50. livereload: {
  51. options: {
  52. livereload: '<%= connect.options.livereload %>'
  53. },
  54. files: [
  55. '<%= yeoman.app %>/{,*/}*.html',
  56. '.tmp/styles/{,*/}*.css',
  57. '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
  58. ]
  59. }
  60. },
  61. // The actual grunt server settings
  62. connect: {
  63. options: {
  64. port: 9000,
  65. // Change this to '0.0.0.0' to access the server from outside.
  66. hostname: 'localhost',
  67. livereload: 35729
  68. },
  69. livereload: {
  70. options: {
  71. open: true,
  72. middleware: function (connect) {
  73. return [
  74. connect.static('.tmp'),
  75. connect().use(
  76. '/bower_components',
  77. connect.static('./bower_components')
  78. ),
  79. connect().use(
  80. '/app/styles',
  81. connect.static('./app/styles')
  82. ),
  83. connect.static(appConfig.app)
  84. ];
  85. }
  86. }
  87. },
  88. test: {
  89. options: {
  90. port: 9001,
  91. middleware: function (connect) {
  92. return [
  93. connect.static('.tmp'),
  94. connect.static('test'),
  95. connect().use(
  96. '/bower_components',
  97. connect.static('./bower_components')
  98. ),
  99. connect.static(appConfig.app)
  100. ];
  101. }
  102. }
  103. },
  104. dist: {
  105. options: {
  106. open: true,
  107. base: '<%= yeoman.dist %>'
  108. }
  109. }
  110. },
  111. // Make sure there are no obvious mistakes
  112. jshint: {
  113. options: {
  114. jshintrc: '.jshintrc',
  115. reporter: require('jshint-stylish')
  116. },
  117. all: {
  118. src: [
  119. 'Gruntfile.js',
  120. '<%= yeoman.app %>/scripts/{,*/}*.js'
  121. ]
  122. },
  123. test: {
  124. options: {
  125. jshintrc: 'test/.jshintrc'
  126. },
  127. src: ['test/spec/{,*/}*.js']
  128. }
  129. },
  130. // Make sure code styles are up to par
  131. jscs: {
  132. options: {
  133. config: '.jscsrc',
  134. verbose: true
  135. },
  136. all: {
  137. src: [
  138. 'Gruntfile.js',
  139. '<%= yeoman.app %>/scripts/{,*/}*.js'
  140. ]
  141. },
  142. test: {
  143. src: ['test/spec/{,*/}*.js']
  144. }
  145. },
  146. // Empties folders to start fresh
  147. clean: {
  148. dist: {
  149. files: [{
  150. dot: true,
  151. src: [
  152. '.tmp',
  153. '<%= yeoman.dist %>/{,*/}*',
  154. '!<%= yeoman.dist %>/.git{,*/}*'
  155. ]
  156. }]
  157. },
  158. server: '.tmp'
  159. },
  160. // Add vendor prefixed styles
  161. postcss: {
  162. options: {
  163. processors: [
  164. require('autoprefixer-core')({browsers: ['last 1 version']})
  165. ]
  166. },
  167. server: {
  168. options: {
  169. map: true
  170. },
  171. files: [{
  172. expand: true,
  173. cwd: '.tmp/styles/',
  174. src: '{,*/}*.css',
  175. dest: '.tmp/styles/'
  176. }]
  177. },
  178. dist: {
  179. files: [{
  180. expand: true,
  181. cwd: '.tmp/styles/',
  182. src: '{,*/}*.css',
  183. dest: '.tmp/styles/'
  184. }]
  185. }
  186. },
  187. // Automatically inject Bower components into the app
  188. wiredep: {
  189. app: {
  190. src: ['<%= yeoman.app %>/index.html'],
  191. ignorePath: /\.\.\//
  192. },
  193. test: {
  194. devDependencies: true,
  195. src: '<%= karma.unit.configFile %>',
  196. ignorePath: /\.\.\//,
  197. fileTypes:{
  198. js: {
  199. block: /(([\s\t]*)\/{2}\s*?bower:\s*?(\S*))(\n|\r|.)*?(\/{2}\s*endbower)/gi,
  200. detect: {
  201. js: /'(.*\.js)'/gi
  202. },
  203. replace: {
  204. js: '\'{{filePath}}\','
  205. }
  206. }
  207. }
  208. }
  209. },
  210. // Renames files for browser caching purposes
  211. filerev: {
  212. dist: {
  213. src: [
  214. '<%= yeoman.dist %>/scripts/{,*/}*.js',
  215. '<%= yeoman.dist %>/styles/{,*/}*.css',
  216. '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
  217. '<%= yeoman.dist %>/styles/fonts/*'
  218. ]
  219. }
  220. },
  221. // Reads HTML for usemin blocks to enable smart builds that automatically
  222. // concat, minify and revision files. Creates configurations in memory so
  223. // additional tasks can operate on them
  224. useminPrepare: {
  225. html: '<%= yeoman.app %>/index.html',
  226. options: {
  227. dest: '<%= yeoman.dist %>',
  228. flow: {
  229. html: {
  230. steps: {
  231. js: ['concat', 'uglifyjs'],
  232. css: ['cssmin']
  233. },
  234. post: {}
  235. }
  236. }
  237. }
  238. },
  239. // Performs rewrites based on filerev and the useminPrepare configuration
  240. usemin: {
  241. html: ['<%= yeoman.dist %>/{,*/}*.html'],
  242. css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
  243. js: ['<%= yeoman.dist %>/scripts/{,*/}*.js'],
  244. options: {
  245. assetsDirs: [
  246. '<%= yeoman.dist %>',
  247. '<%= yeoman.dist %>/images',
  248. '<%= yeoman.dist %>/styles'
  249. ],
  250. patterns: {
  251. js: [[/(images\/[^''""]*\.(png|jpg|jpeg|gif|webp|svg))/g, 'Replacing references to images']]
  252. }
  253. }
  254. },
  255. // The following *-min tasks will produce minified files in the dist folder
  256. // By default, your `index.html`'s <!-- Usemin block --> will take care of
  257. // minification. These next options are pre-configured if you do not wish
  258. // to use the Usemin blocks.
  259. // cssmin: {
  260. // dist: {
  261. // files: {
  262. // '<%= yeoman.dist %>/styles/main.css': [
  263. // '.tmp/styles/{,*/}*.css'
  264. // ]
  265. // }
  266. // }
  267. // },
  268. // uglify: {
  269. // dist: {
  270. // files: {
  271. // '<%= yeoman.dist %>/scripts/scripts.js': [
  272. // '<%= yeoman.dist %>/scripts/scripts.js'
  273. // ]
  274. // }
  275. // }
  276. // },
  277. // concat: {
  278. // dist: {}
  279. // },
  280. imagemin: {
  281. dist: {
  282. files: [{
  283. expand: true,
  284. cwd: '<%= yeoman.app %>/images',
  285. src: '{,*/}*.{png,jpg,jpeg,gif}',
  286. dest: '<%= yeoman.dist %>/images'
  287. }]
  288. }
  289. },
  290. svgmin: {
  291. dist: {
  292. files: [{
  293. expand: true,
  294. cwd: '<%= yeoman.app %>/images',
  295. src: '{,*/}*.svg',
  296. dest: '<%= yeoman.dist %>/images'
  297. }]
  298. }
  299. },
  300. htmlmin: {
  301. dist: {
  302. options: {
  303. collapseWhitespace: true,
  304. conservativeCollapse: true,
  305. collapseBooleanAttributes: true,
  306. removeCommentsFromCDATA: true
  307. },
  308. files: [{
  309. expand: true,
  310. cwd: '<%= yeoman.dist %>',
  311. src: ['*.html'],
  312. dest: '<%= yeoman.dist %>'
  313. }]
  314. }
  315. },
  316. ngtemplates: {
  317. dist: {
  318. options: {
  319. module: 'odooMobileDocsApp',
  320. htmlmin: '<%= htmlmin.dist.options %>',
  321. usemin: 'scripts/scripts.js'
  322. },
  323. cwd: '<%= yeoman.app %>',
  324. src: 'views/{,*/}*.html',
  325. dest: '.tmp/templateCache.js'
  326. }
  327. },
  328. // ng-annotate tries to make the code safe for minification automatically
  329. // by using the Angular long form for dependency injection.
  330. ngAnnotate: {
  331. dist: {
  332. files: [{
  333. expand: true,
  334. cwd: '.tmp/concat/scripts',
  335. src: '*.js',
  336. dest: '.tmp/concat/scripts'
  337. }]
  338. }
  339. },
  340. // Replace Google CDN references
  341. cdnify: {
  342. dist: {
  343. html: ['<%= yeoman.dist %>/*.html']
  344. }
  345. },
  346. // Copies remaining files to places other tasks can use
  347. copy: {
  348. dist: {
  349. files: [{
  350. expand: true,
  351. dot: true,
  352. cwd: '<%= yeoman.app %>',
  353. dest: '<%= yeoman.dist %>',
  354. src: [
  355. '*.{ico,png,txt}',
  356. '*.html',
  357. 'images/{,*/}*.{webp}',
  358. 'styles/fonts/{,*/}*.*'
  359. ]
  360. }, {
  361. expand: true,
  362. cwd: '.tmp/images',
  363. dest: '<%= yeoman.dist %>/images',
  364. src: ['generated/*']
  365. }, {
  366. expand: true,
  367. cwd: 'bower_components/bootstrap/dist',
  368. src: 'fonts/*',
  369. dest: '<%= yeoman.dist %>'
  370. }]
  371. },
  372. styles: {
  373. expand: true,
  374. cwd: '<%= yeoman.app %>/styles',
  375. dest: '.tmp/styles/',
  376. src: '{,*/}*.css'
  377. }
  378. },
  379. // Run some tasks in parallel to speed up the build process
  380. concurrent: {
  381. server: [
  382. 'copy:styles'
  383. ],
  384. test: [
  385. 'copy:styles'
  386. ],
  387. dist: [
  388. 'copy:styles',
  389. 'imagemin',
  390. 'svgmin'
  391. ]
  392. },
  393. // Test settings
  394. karma: {
  395. unit: {
  396. configFile: 'test/karma.conf.js',
  397. singleRun: true
  398. }
  399. }
  400. });
  401. grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
  402. if (target === 'dist') {
  403. return grunt.task.run(['build', 'connect:dist:keepalive']);
  404. }
  405. grunt.task.run([
  406. 'clean:server',
  407. 'wiredep',
  408. 'concurrent:server',
  409. 'postcss:server',
  410. 'connect:livereload',
  411. 'watch'
  412. ]);
  413. });
  414. grunt.registerTask('server', 'DEPRECATED TASK. Use the "serve" task instead', function (target) {
  415. grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
  416. grunt.task.run(['serve:' + target]);
  417. });
  418. grunt.registerTask('test', [
  419. 'clean:server',
  420. 'wiredep',
  421. 'concurrent:test',
  422. 'postcss',
  423. 'connect:test',
  424. 'karma'
  425. ]);
  426. grunt.registerTask('build', [
  427. 'clean:dist',
  428. 'wiredep',
  429. 'useminPrepare',
  430. 'concurrent:dist',
  431. 'postcss',
  432. 'ngtemplates',
  433. 'concat',
  434. 'ngAnnotate',
  435. 'copy:dist',
  436. 'cdnify',
  437. 'cssmin',
  438. 'uglify',
  439. 'filerev',
  440. 'usemin',
  441. 'htmlmin'
  442. ]);
  443. grunt.registerTask('default', [
  444. 'newer:jshint',
  445. 'newer:jscs',
  446. 'test',
  447. 'build'
  448. ]);
  449. };