 'use strict'
 
-# Constants
-MODULES_DIR      = 'modules'
-BUILD_DIR        = 'build'
-DIST_DIR         = 'dist'
-GRUNTFILE        = 'Gruntfile.coffee'
-TMP_DIR          = 'tmp'
-PLATFORMS        = ['android', 'ios', 'ios7']
-
 module.exports = (grunt) ->
-
+  require('load-grunt-tasks') grunt
+  require('time-grunt') grunt
   grunt.initConfig
-    bower:
-      install:
-        cleanup: yes
-        copy: no
+    bp:
+      app: 'modules'
+      dist: 'dist'
+      tmp: '.tmp'
+      platforms: ['android', 'ios', 'ios7']
+
+    watch:
+      coffee:
+        files: [
+          '<%=bp.app%>/scripts/bradypodion.coffee'
+          '<%=bp.app%>/scripts/*/**/*.coffee'
+        ]
+        tasks: ['coffeelint:build', 'coffee:dist', 'karma:unit:run']
+
+      coffeeTest:
+        files: ['test/spec/**/*.coffee']
+        tasks: ['coffeelint:test', 'coffee:test', 'karma:unit:run']
+
+      gruntfile:
+        files: ['Gruntfile.coffee']
+        tasks: ['coffeelint:gruntfile']
+
+      styles:
+        files: ['<%=bp.app%>/styles/**/*.less']
+        tasks: ['cssbuild']
+
+      livereload:
+        options:
+          livereload: '<%= connect.options.livereload %>'
+
+        files: [
+          '{<%=bp.tmp%>,<%=bp.app%>}/**/*.html'
+          '{<%=bp.tmp%>,<%=bp.app%>}/**/*.css'
+          '{<%=bp.tmp%>,<%=bp.app%>}/**/*.js'
+        ]
+
+    connect:
+      options:
+        port: 9000
+        hostname: '*'
+        livereload: 35729
+
+      livereload:
+        options:
+          open: 'http://localhost:9000/'
+          base: ['<%=bp.tmp%>', '<%=bp.app%>', '<%=bp.dist%>']
+
+      dist:
+        options:
+          base: '<%=bp.dist%>'
+
+    shell:
+      options:
+        stderr : true
+        stdout : true
+        failOnError : true
+      semver:
+        command: './node_modules/semver-sync/bin/semver-sync -v'
+      hooks:
+        command: 'cp -R ./hooks ./.git/'
 
     clean:
-      build: [BUILD_DIR]
-      dist: [DIST_DIR]
-      tmp: TMP_DIR
-      lib: 'lib'
+      dist:
+        files: [
+          dot: true
+          src: [
+            '<%=bp.tmp%>/scripts/'
+            '<%=bp.tmp%>/styles/'
+            '<%=bp.dist%>/*'
+            '!<%=bp.dist%>/.git*'
+          ]
+        ]
+
+      server: '<%=bp.tmp%>/test'
 
     coffee:
-      dist:
-        options:
-          sourceMap: yes
+      options:
+        sourceMap: true
+        sourceRoot: ''
+
+      dist:
+        options:
           join: yes
         src: [
-          "#{MODULES_DIR}/bradypodion.coffee"
-          '<%= coffeelint.directives.files.src %>'
-        ]
-        dest: "#{DIST_DIR}/bradypodion.js"
-      tests:
-        options: join: yes
-        src: ["#{MODULES_DIR}/*/*/test/*.coffee"]
-        dest: "#{BUILD_DIR}/tests.js"
+          '<%=bp.app%>/scripts/bradypodion.coffee'
+          '<%=bp.app%>/scripts/*/**/*.coffee'
+        ]
+        dest: '<%=bp.dist%>/bradypodion.js'
+
+      test:
+        options:
+          join: yes
+        src: [ 'test/spec/**/*.coffee' ]
+        dest: '<%=bp.tmp%>/test/tests.js'
 
     coffeelint:
       options:

      matches = path.match(/(^(.*\/|)([a-zA-Z0-9-_.]+))\.less$/)
      platform = matches[3]
      if platform in platforms or platform is 'general'
        chunk = "@import '../#{matches[1]}';"
        chunks[platform] += chunk

    # import config and modules

        PLATFORMS.splice index, 1
    else
      platforms = PLATFORMS
      general = yes

    toBeNamespaced = platforms.length > 1
    fileContent    = grunt.file.read template
