namespace :build do

    desc 'Run BlankketJS test coverage'
    task :coverage do
        `mocha -r blanket -R html-cov > public/blanket.html test/mocha/`
    end

    desc 'Run mocha tests'
    task :mocha_test do
        `gulp test`
    end

    desc 'Clear node cache'
    task :clear_cache do
        `npm cache clean -f -q`
    end

    desc 'Install all local npm modules'
    task :npm_install_local do
        `npm i -q`
    end

    desc 'Install all local global modules'
    task :npm_install_global do
        `npm install jshint@2.4.2 -g -q`
        `npm install gulp@4.0.2 -g -q`
        `npm install mocha@1.17.1 -g -q`
    end

    desc 'Make public folders'
    task :mk_public_folders do
        `mkdir -p ./public/js`
        `mkdir -p ./public/js/dev`
        `mkdir -p ./public/js/releases`
    end

    task :config do
        if !File.exist? './config/config.json'
            `cp ./config/config.shadow.json ./config/config.json`
        end
    end

    desc 'Run a full build'
    task :all => [:config, :mk_public_folders, :clear_cache, :npm_install_global, :npm_install_local, :mocha_test]

end

namespace :jenkins do

    desc 'Remove all globally installed npm modules'
    task :npm_remove_global do
        `npm remove jshint gulp mocha -g -q`
    end

    desc 'Export mocha tests to XUnit'
    task :mocha_test do
         `mkdir -p ../build/logs/mocha/reports`
         `mocha -R xunit test/mocha/ > ../build/logs/mocha/reports/mocha-report.xml`
    end

    desc 'Build and commit any modified JS and CSS in frontend'
    task :deploy_js do
        puts `./deploy.sh`
        raise 'deploy_js failed' if $? != 0
    end

    desc 'Run PR build for jenkins'
    task :pr => [:npm_remove_global, 'build:config', 'build:clear_cache', 'build:npm_install_global', 'build:npm_install_local', :mocha_test]

    desc 'Run a full build for jenkins'
    task :all => [:pr, :deploy_js]

    desc 'Create and deploy static files'
    task :build_static_files => [:npm_remove_global, 'build:config', 'build:clear_cache', 'build:npm_install_global', 'build:npm_install_local', :deploy_js]
end
