diff --git a/Gruntfile.js b/Gruntfile.js index 66a1109..c3d46f0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,306 +8,266 @@ module.exports = function (grunt) { - // Load grunt tasks automatically - require('load-grunt-tasks')(grunt); + // Load grunt tasks automatically + require('load-grunt-tasks')(grunt); - // Time how long tasks take. Can help when optimizing build times - require('time-grunt')(grunt); + // Time how long tasks take. Can help when optimizing build times + require('time-grunt')(grunt); - // Configurable paths - var config = { - app: 'app.safariextension', - dist: 'dist.safariextension' - }; + // Configurable paths + var config = { + app: 'app.safariextension', + dist: 'dist.safariextension' + }; - grunt.initConfig({ + grunt.initConfig({ - // Project settings - config: config, + // Project settings + config: config, - // Watches files for changes and runs tasks based on the changed files - watch: { - bower: { - files: ['bower.json'], - tasks: ['bower:install', 'wiredep'] - }, - coffee: { - files: ['<%= config.app %>/scripts/{,*/}*.{coffee,litcoffee,coffee.md}'], - tasks: ['coffee:app'], - options: { - livereload: true - } - }, - compass: { - files: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'], - tasks: ['compass:app'] - }, - gruntfile: { - files: ['Gruntfile.js'] - }, - styles: { - files: ['<%= config.app %>/styles/{,*/}*.css'], - tasks: [], - options: { - livereload: true - } - }, - livereload: { - options: { - livereload: '<%= connect.options.livereload %>' - }, - files: [ - '<%= config.app %>/*.html', - '<%= config.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}', - '<%= config.app %>/manifest.json', - '<%= config.app %>/_locales/{,*/}*.json' - ] - } - }, + // Watches files for changes and runs tasks based on the changed files + watch: { + bower: { + files: ['bower.json'], + tasks: ['bower:install', 'wiredep'] + }, + coffee: { + files: ['<%= config.app %>/scripts/{,*/}*.{coffee,litcoffee,coffee.md}'], + tasks: ['coffee:app'], + options: { + } + }, + compass: { + files: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'], + tasks: ['compass:app'] + }, + gruntfile: { + files: ['Gruntfile.js'] + }, + styles: { + files: ['<%= config.app %>/styles/{,*/}*.css'], + tasks: [], + options: { + } + } + }, - // Compiles CoffeeScript to JavaScript - coffee: { - app: { - files: [{ - expand: true, - cwd: '<%= config.app %>/scripts', - src: '{,*/}*.{coffee,litcoffee,coffee.md}', - dest: '<%= config.app %>/scripts', - ext: '.js' - }] - }, - dist: { - files: [{ - expand: true, - cwd: '<%= config.app %>/scripts', - src: '{,*/}*.{coffee,litcoffee,coffee.md}', - dest: '<%= config.app %>/scripts', - ext: '.js' - }] - }, - test: { - files: [{ - expand: true, - cwd: 'test/spec', - src: '{,*/}*.coffee', - dest: './spec', - ext: '.js' - }] - } - }, + // Compiles CoffeeScript to JavaScript + coffee: { + app: { + files: [{ + expand: true, + cwd: '<%= config.app %>/scripts', + src: '{,*/}*.{coffee,litcoffee,coffee.md}', + dest: '<%= config.app %>/scripts', + ext: '.js' + }] + }, + dist: { + files: [{ + expand: true, + cwd: '<%= config.app %>/scripts', + src: '{,*/}*.{coffee,litcoffee,coffee.md}', + dest: '<%= config.app %>/scripts', + ext: '.js' + }] + }, + test: { + files: [{ + expand: true, + cwd: 'test/spec', + src: '{,*/}*.coffee', + dest: './spec', + ext: '.js' + }] + } + }, - // Compiles Sass to CSS and generates necessary files if requested - compass: { - options: { - sassDir: '<%= config.app %>/styles', - cssDir: '<%= config.app %>/styles', - generatedImagesDir: '<%= config.app %>/images/generated', - imagesDir: '<%= config.app %>/images', - javascriptsDir: '<%= config.app %>/scripts', - fontsDir: '<%= config.app %>/styles/fonts', - httpImagesPath: '/images', - httpGeneratedImagesPath: '/images/generated', - httpFontsPath: '/styles/fonts', - relativeAssets: false, - assetCacheBuster: false - }, - app: { - options: { - debugInfo: true - } - }, - dist: { - options: { - force: true - } - }, - test: { - } - }, + // Compiles Sass to CSS and generates necessary files if requested + compass: { + options: { + sassDir: '<%= config.app %>/styles', + cssDir: '<%= config.app %>/styles', + generatedImagesDir: '<%= config.app %>/images/generated', + imagesDir: '<%= config.app %>/images', + javascriptsDir: '<%= config.app %>/scripts', + fontsDir: '<%= config.app %>/styles/fonts', + httpImagesPath: '/images', + httpGeneratedImagesPath: '/images/generated', + httpFontsPath: '/styles/fonts', + relativeAssets: false, + assetCacheBuster: false + }, + app: { + options: { + debugInfo: true + } + }, + dist: { + options: { + force: true + } + }, + test: { + } + }, - // Install Bower packages - bower: { - install: { - } - }, + // Install Bower packages + bower: { + install: { + } + }, - // Automatically inject Bower components into the HTML file - wiredep: { - app: { - src: [ - '<%= config.app %>/options.html' - ] - }, - sass: { - src: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'], - ignorePath: '<%= config.app %>/bower_components/' - } - }, + // Automatically inject Bower components into the HTML file + wiredep: { + app: { + src: [ + '<%= config.app %>/options.html' + ] + }, + sass: { + src: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'], + ignorePath: '<%= config.app %>/bower_components/' + } + }, - uglify: { - dist: { - files: { - '<%= config.dist %>/scripts/redirector.js': [ - '<%= config.app %>/scripts/redirector.js' - ] - } - } - }, + uglify: { + dist: { + files: { + '<%= config.dist %>/scripts/redirector.js': [ + '<%= config.app %>/scripts/redirector.js' + ] + } + } + }, - // Reads HTML for usemin blocks to enable smart builds that automatically - // concat, minify and revision files. Creates configurations in memory so - // additional tasks can operate on them - useminPrepare: { - options: { - dest: '<%= config.dist %>' - }, - html: [ - '<%= config.app %>/global.html', - '<%= config.app %>/options.html' - ] - }, + // Reads HTML for usemin blocks to enable smart builds that automatically + // concat, minify and revision files. Creates configurations in memory so + // additional tasks can operate on them + useminPrepare: { + options: { + dest: '<%= config.dist %>' + }, + html: [ + '<%= config.app %>/global.html', + '<%= config.app %>/options.html' + ] + }, - // Performs rewrites based on rev and the useminPrepare configuration - usemin: { - options: { - assetsDirs: ['<%= config.dist %>', '<%= config.dist %>/images'] - }, - html: ['<%= config.dist %>/{,*/}*.html'], - css: ['<%= config.dist %>/styles/{,*/}*.css'] - }, + // Performs rewrites based on rev and the useminPrepare configuration + usemin: { + options: { + assetsDirs: ['<%= config.dist %>', '<%= config.dist %>/images'] + }, + html: ['<%= config.dist %>/{,*/}*.html'], + css: ['<%= config.dist %>/styles/{,*/}*.css'] + }, - // The following *-min tasks produce minifies files in the dist folder - imagemin: { - icon: { - files: { - '<%= config.dist %>/icon.png': '<%= config.app %>/icon.png' - } - }, - dist: { - files: [{ - expand: true, - cwd: '<%= config.app %>/images', - src: '{,*/}*.{gif,jpeg,jpg,png}', - dest: '<%= config.dist %>/images' - }] - } - }, + // The following *-min tasks produce minifies files in the dist folder + imagemin: { + icon: { + files: { + '<%= config.dist %>/icon.png': '<%= config.app %>/icon.png' + } + }, + dist: { + files: [{ + expand: true, + cwd: '<%= config.app %>/images', + src: '{,*/}*.{gif,jpeg,jpg,png}', + dest: '<%= config.dist %>/images' + }] + } + }, - // Empties folders to start fresh - clean: { - app: { - }, - dist: { - files: [{ - dot: true, - src: [ - '<%= config.dist %>/*', - '!<%= config.dist %>/.git*' - ] - }] - } - }, + // Empties folders to start fresh + clean: { + app: { + }, + dist: { + files: [{ + dot: true, + src: [ + '<%= config.dist %>/*', + '!<%= config.dist %>/.git*' + ] + }] + } + }, - // Make sure code styles are up to par and there are no obvious mistakes - jshint: { - options: { - jshintrc: '.jshintrc', - reporter: require('jshint-stylish') - }, - all: [ - 'Gruntfile.js', - '<%= config.app %>/scripts/{,*/}*.js', - '!<%= config.app %>/scripts/vendor/*', - 'test/spec/{,*/}*.js' - ] - }, + // Make sure code styles are up to par and there are no obvious mistakes + jshint: { + options: { + jshintrc: '.jshintrc', + reporter: require('jshint-stylish') + }, + all: [ + 'Gruntfile.js', + '<%= config.app %>/scripts/{,*/}*.js', + '!<%= config.app %>/scripts/vendor/*', + 'test/spec/{,*/}*.js' + ] + }, - // Copies remaining files to places other tasks can use - copy: { - dist: { - files: [{ - expand: true, - dot: true, - cwd: '<%= config.app %>', - dest: '<%= config.dist %>', - src: [ - '*.{ico,txt}', - 'images/{,*/}*.{webp,gif}', - '{,*/}*.html', - 'styles/fonts/{,*/}*.*', - '{,*/}*.plist', - ] - }] - } - }, + // Copies remaining files to places other tasks can use + copy: { + dist: { + files: [{ + expand: true, + dot: true, + cwd: '<%= config.app %>', + dest: '<%= config.dist %>', + src: [ + '*.{ico,txt}', + 'images/{,*/}*.{webp,gif}', + '{,*/}*.html', + 'styles/fonts/{,*/}*.*', + '{,*/}*.plist', + ] + }] + } + }, - // Run some tasks in parallel to speed up build process - concurrent: { - app: [ - 'coffee:app', - 'compass:app', - ], - dist: [ - 'coffee:dist', - 'imagemin', - 'compass:dist' - ], - test: [ - 'coffee:test', - 'compass:test', - ] - }, + // Run some tasks in parallel to speed up build process + concurrent: { + app: [ + 'coffee:app', + 'compass:app', + ], + dist: [ + 'coffee:dist', + 'imagemin', + 'compass:dist' + ], + test: [ + 'coffee:test', + 'compass:test', + ] + }, + }); - // Grunt server and debug server setting - connect: { - options: { - port: 9000, - livereload: 35729, - // change this to '0.0.0.0' to access the server from outside - hostname: 'localhost' - }, - app: { - options: { - open: false, - base: [ - '<%= config.app %>' - ] - } - }, - test: { - options: { - open: false, - base: [ - 'test', - '<%= config.app %>' - ] - } - } - }, - }); - - grunt.registerTask('debug', function () { - grunt.task.run([ - 'jshint', - 'concurrent:app', - 'watch' - ]); - }); - - grunt.registerTask('build', [ - 'clean:dist', - 'concurrent:dist', - 'useminPrepare', - 'concat', - 'cssmin', - 'uglify', - 'copy', - 'usemin' + grunt.registerTask('debug', function () { + grunt.task.run([ + 'jshint', + 'concurrent:app', + 'watch' ]); + }); - grunt.registerTask('default', [ - 'jshint', - 'build' - ]); + grunt.registerTask('build', [ + 'clean:dist', + 'concurrent:dist', + 'useminPrepare', + 'concat', + 'cssmin', + 'uglify', + 'copy', + 'usemin' + ]); + + grunt.registerTask('default', [ + 'jshint', + 'build' + ]); };