aboutsummaryrefslogtreecommitdiffhomepage
path: root/Gruntfile.js
blob: fa0c2026c1cac691a8e6e546e196c975c200de43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict'

module.exports = function (grunt) {
  var paths = {
    dist: 'dist',
    jade: 'views/**/**/*.jade',
    css: 'public/stylesheets/*.css',
    vendor: 'public/stylesheets/vendor',
    js: 'public/javascripts/*.js',
    src: 'src/*.js',
    routes: 'routes/**/*.js',
    main: './server.js',
    browserified: 'public/javascripts/bundle.js',
    img: 'public/images/*.{png,jpg,jpeg,gif,webp,svg}',
    test: 'tests',
    server: 'server.js'
  }

  require('time-grunt')(grunt)

  // Project Configuration
  grunt.initConfig({
    paths: paths,
    pkg: grunt.file.readJSON('package.json'),
    browserify: {
      dev: {
        src: [ paths.js, '!public/javascripts/bundle.js' ],
        dest: paths.browserified,
        options: {
          browserifyOptions: { 'debug': true },
          watch: true
        }
      }
    },
    copy: {
      dev: {
        cwd: 'node_modules/bootstrap/dist/',
        src: [ 'css/*', 'fonts/*' ],
        expand: true,
        dest: paths.vendor
      }
    },
    clean: {
      dev: {
        files: [{
          dot: true,
          src: [
            paths.browserified
          ]
        }]
      }
    },
    express: {
      dev: {
        options: {
          script: paths.server,
          harmony: true,
          port: 9000,
          node_env: 'development',
          debug: true,
          background: true
        }
      }
    },
    watch: {
      express: {
        files: [ paths.main, paths.routes, paths.src ],
        tasks: [ 'express:dev' ],
        options: {
          livereload: true,
          spawn: false
        }
      },
      dev: {
        files: [ paths.jade, paths.css, paths.browserified ],
        options: {
          livereload: true,
          nospawn: false
        }
      }
    }
  })

  // Build client javascript and copy bootstrap dependencies
  grunt.registerTask('build', [], function () {
    grunt.loadNpmTasks('grunt-browserify')
    grunt.loadNpmTasks('grunt-contrib-copy')
    grunt.loadNpmTasks('grunt-newer')

    grunt.task.run(
      'newer:browserify:dev',
      'newer:copy:dev'
    )
  })

  // Start in dev mode (reload front end files without refresh)
  grunt.registerTask('dev', [], function () {
    grunt.loadNpmTasks('grunt-browserify')
    grunt.loadNpmTasks('grunt-contrib-watch')
    grunt.loadNpmTasks('grunt-express-server')
    grunt.loadNpmTasks('grunt-contrib-copy')
    grunt.loadNpmTasks('grunt-newer')

    grunt.task.run(
      'newer:browserify:dev',
      'newer:copy:dev',
      'express:dev',
      'watch'
    )
  })

  // Clean build
  grunt.registerTask('clean', [], function () {
    grunt.loadNpmTasks('grunt-contrib-clean')

    grunt.task.run(
      'clean:dev'
    )
  })
}