module.exports = function (grunt) {

    var appConfig = {
        components: 'components',
        javascripts: 'app',

        stylesheets: 'stylesheets',
        images: 'assets/images',
        fonts: 'assets/fonts',
        tsd: 'src/d.ts',
        app: {
            typescripts: 'src/main/typescripts',
            libs: 'src/main/libs',
            views: 'src/main/views',
            images: 'src/main/images'
        },
        test: {
            typescripts: 'src/test/typescripts',
            scripts: 'src/test/scripts',
            libs: 'src/test/libs',
            stylesheets: 'src/test/stylesheets'
        },
        dist: {
            scripts: '../public/scripts',
            libs: '../public/scripts/libs',
            stylesheets: '../public/stylesheets',
            views: '../public/views',
            images: '../public/images',
            fonts: '../public/fonts'
        }
    };

    grunt.initConfig({
        conf: appConfig,
        typescript: {
            main: {
                src: ['<%= conf.app.typescripts %>/App.ts'],
                dest: '<%= conf.dist.scripts %>',
                options: {
                    target: 'es5',
                    base_path: '<%= conf.app.typescripts %>',
                    sourcemap: false,
                    declaration: false
                }
            },
            test: {
                src: ['<%= conf.test.typescripts %>/AppSpec.ts'],
                dest: '<%= conf.test.scripts %>/AppSpec.js',
                options: {
                    target: 'es5',
                    sourcemap: false,
                    declaration: false
                }
            }
        },
        watch: {
            "typescript-main": {
                files: ['<%= conf.app.typescripts %>/**/*.ts'],
                tasks: ['typescript:main', 'uglify:dev']
            },
            "typescript-test": {
                files: [ '<%= conf.test.typescripts %>/**/*.ts'],
                tasks: ['typescript']
            },
            views: {
                files: ['<%= conf.app.views %>/**/*.html'],
                tasks: ['copy:static']
            }
        },
        bower: {
            install: {
                options: {
                    targetDir: '../',
                    layout: 'byType',
                    install: true,
                    verbose: true,
                    cleanTargetDir: false,
                    cleanBowerDir: false
                }
            }
        },
        copy: {
            static: {
                files: [
                    {expand: true, flatten: true, cwd: '', src: ['<%= conf.app.views %>/*.html'], dest: '<%= conf.dist.views %>'},
                    {expand: true, flatten: true, cwd: '', src: ['<%= conf.app.images %>/*.*'], dest: '<%= conf.dist.images %>'}
                ]
            }
        },
        uglify: {
            dev: {
                options: {
                    report: 'min',
                    beautify:true,
                    mangle: false,
                    preserveComments: 'some',

                    sourceMap: '<%= conf.dist.scripts %>/source.js.map',
                    sourceMapRoot: '',
                    sourceMappingURL: 'source.js.map'
                },
                files: {
                    '<%= conf.dist.scripts %>/main.min.js': [
                        '<%= conf.dist.libs %>/jquery/jquery.js',
                        '<%= conf.dist.libs %>/angular/angular.js',
                        '<%= conf.dist.libs %>/angular-resource/angular-resource.js',
                        '<%= conf.dist.libs %>/angular-ui-utils/keypress.js',
                        '<%= conf.dist.libs %>/bootstrap/bootstrap.js',
                        '<%= conf.dist.libs %>/highlightjs/highlight.pack.js',
                        '<%= conf.dist.libs %>/marked/marked.js',
                        '<%= conf.dist.scripts %>/models/*.js',
                        '<%= conf.dist.scripts %>/controllers/*.js',
                        '<%= conf.dist.scripts %>/App.js'
                    ]
                }
            }
        },
        clean: {
            public: {
                src: [
                    '../public/*'
                ],
                options: {
                    force: true
                }
            },
            tsd: {
                src: [
                    '<%= conf.tsd %>'
                ]
            },
            bower: {
                src: [
                    'bower_components'
                ]
            }
        },
        karma: {
            unit: {
                options: {
                    configFile: 'karma.conf.js',
                    autoWatch: false,
                    browsers: ['Chrome'],
                    reporters: ['progress', 'junit'],
                    singleRun: true,
                    keepalive: true
                }
            }
        },
        exec: {
            tsd: {
                cmd: function () {
                    return "tsd install jquery angular angular-resource marked jasmine angular-mocks";
                }
            }
        }
    });

    grunt.registerTask(
        'setup',
        "Setup project",
        ['clean', 'bower', 'exec:tsd']);

    grunt.registerTask(
        'default',
        "compile",
        ['clean:public', 'bower', 'copy:static', 'typescript:main', 'uglify:dev']);

    grunt.registerTask(
        'run',
        "compile and watch",
        ['clean:public', 'bower', 'copy:static', 'typescript:main', 'uglify:dev', 'watch']);

    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
};
@@ -4151,22 +4151,20 @@
         
-public
+dist
 : %7B%0A    
@@ -4286,32 +4286,32 @@
     force: true%0A
-
                 
@@ -4319,32 +4319,258 @@
 %0A            %7D,%0A
+            test: %7B%0A                src: %5B%0A                    '%3C%25= conf.test.scripts %25%3E/*',%0A                    '%3C%25= conf.test.libs %25%3E/*',%0A                    '%3C%25= conf.test.stylesheets %25%3E/*'%0A                %5D%0A            %7D,%0A
             tsd:
@@ -5557,38 +5557,36 @@
         %5B'clean:
-public
+dist
 ', 'bower', 'cop
@@ -5716,22 +5716,20 @@
 %5B'clean:
-public
+dist
 ', 'bowe
@@ -5788,24 +5788,161 @@
 'watch'%5D);%0A%0A
+    grunt.registerTask(%0A        'test',%0A        %22test by karma%22,%0A        %5B'clean:dist', 'clean:test', 'bower', 'typescript', 'karma'%5D);%0A%0A
     require(

add task "grunt test"