'use strict'

module.exports = function(grunt) {
	require('load-grunt-tasks')(grunt, {
		pattern: ['grunt-*', '!grunt-template-jasmine-istanbul']
	})
	require('time-grunt')(grunt)

	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),

		paths: {
			test: 'test',
			testSpecs: 'test/spec/*.spec.js',
			testVendor: 'test/vendor',
			testCoverage: 'test/coverage',
			sourceDir: 'src'
		},

		clean: {
			lib: 'lib/',
			testVendor: '<%= paths.testVendor %>',
			testIndex: '<%= paths.test %>/index.html',
			testCoverage: '<%= paths.testCoverage %>',
			dotGrunt: '.grunt'
		},

		curl: {
			jquery: {
				src: 'http://code.jquery.com/jquery-2.2.3.min.js',
				dest: '<%= paths.testVendor%>/jquery.js'
			},
			jasmineJquery: {
				src: 'https://raw.githubusercontent.com/velesin/jasmine-jquery/2.1.1/lib/jasmine-jquery.js',
				dest: '<%= paths.testVendor%>/jasmine-jquery.js'
			}
		},

		eslint: {
			target: [
				'Gruntfile.js',
				'<%= paths.sourceDir %>/<%= pkg.name %>.js',
				'<%= paths.testSpecs %>'
			]
		},

		jasmine: {
			src: '<%= paths.sourceDir %>/<%= pkg.name %>.js',
			options: {
				vendor: [
					'<%= paths.testVendor %>/jquery.js',
					'<%= paths.testVendor %>/jasmine-jquery.js',
				],
				specs: '<%= paths.testSpecs %>',
				outfile: '<%= paths.test %>/index.html',
				keepRunner: true,
				template: require('grunt-template-jasmine-istanbul'),
				templateOptions: {
					coverage: '<%= paths.testCoverage %>/coverage.json',
					report: '<%= paths.testCoverage %>',
					thresholds: {
						lines: 75,
						statements: 75,
						branches: 75,
						functions: 90
					}
				}
			}
		},

		uglify: {
			lib: {
				options: {
					beautify: false,
					mangle: true,
					banner: '/* <%= pkg.name %> <%= pkg.version %> - ' +
						'<%= grunt.template.today("yyyy-mm-dd") %> - ' +
						'<%= pkg.license %> licence */\n',
					sourceMap: true,
					enclose: {
						'window': 'exports'
					}
				},
				files: {
					'lib/<%= pkg.name %>.min.js':
						'<%= paths.sourceDir %>/*.js'
				}
			}
		},

		jsdoc: {
			pub: {
				src: ['src/audiochart.js'],
				options: {
					'destination': 'doc/public',
					'private': false,
					'readme': 'README.md'
				}
			},
			internal: {
				src: ['src/audiochart.js'],
				options: {
					'destination': 'doc/internal',
					'private': true,
					'readme': 'README.md'
				}
			}
		},

		open: {
			jasmineJqueryReleases: {
				path: 'https://github.com/velesin/jasmine-jquery/releases'
			}
		}
	})

	grunt.registerTask('default', [
		'clean:lib',
		'if-missing:curl:jquery',
		'if-missing:curl:jasmineJquery',
		'eslint',
		'jasmine',
		'uglify',
		'jsdoc'
	])

	// This task allows us to quickly check if there has been a new relase
	// of the jasmine-jquery library (`grunt open` would also do it).
	grunt.registerTask('check', ['open:jasmineJquery_releases'])

	// The 'clean' task is defined wholly above.
}

@@ -387,16 +387,155 @@
 r: 'src'
+,%0A%09%09%09lib: 'lib',%0A%09%09%09dotGrunt: '.grunt',%0A%09%09%09doc: 'doc',%0A%09%09%09docPublic: '%3C%25= paths.doc %25%3E/public',%0A%09%09%09docInternal: '%3C%25= paths.doc %25%3E/internal'
 %0A%09%09%7D,%0A%0A%09
@@ -553,20 +553,32 @@
 %09%09lib: '
-lib/
+%3C%25= paths.lib %25%3E
 ',%0A%09%09%09te
@@ -720,22 +720,65 @@
 Grunt: '
-.grunt
+%3C%25= paths.dotGrunt %25%3E',%0A%09%09%09doc: '%3C%25= paths.doc %25%3E
 '%0A%09%09%7D,%0A%0A
@@ -882,24 +882,25 @@
 s.testVendor
+ 
 %25%3E/jquery.js
@@ -1055,16 +1055,17 @@
 stVendor
+ 
 %25%3E/jasmi
@@ -2262,38 +2262,62 @@
 %0A%09%09%09%09src: %5B'
-src/audiochart
+%3C%25= paths.sourceDir %25%3E/%3C%25= pkg.name %25%3E
 .js'%5D,%0A%09%09%09%09o
@@ -2351,18 +2351,30 @@
 ': '
+%3C%25= paths.
 doc
-/p
+P
 ublic
+ %25%3E
 ',%0A%09
@@ -2464,22 +2464,46 @@
 : %5B'
-src/audiochart
+%3C%25= paths.sourceDir %25%3E/%3C%25= pkg.name %25%3E
 .js'
@@ -2545,20 +2545,32 @@
 ': '
+%3C%25= paths.
 doc
-/i
+I
 nternal
+ %25%3E
 ',%0A%09

Use more path params in Gruntfile