Skip to content

Instantly share code, notes, and snippets.

@jeshuaborges
Last active August 29, 2015 13:56
Show Gist options
  • Save jeshuaborges/9200415 to your computer and use it in GitHub Desktop.
Save jeshuaborges/9200415 to your computer and use it in GitHub Desktop.
"use strict"
# # Globbing
# for performance reasons we're only matching one level down:
# 'test/spec/{,*/}*.js'
# use this if you want to recursively match all subfolders:
# 'test/spec/**/*.js'
module.exports = (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
rewriteRulesSnippet = require('grunt-connect-rewrite/lib/utils').rewriteRequest
# Define the configuration for all the tasks
grunt.initConfig
# Project settings
yeoman:
# configurable paths
app: require("./bower.json").appPath
bower: grunt.file.readJSON('.bowerrc').directory
layout: "<%= yeoman.app %>/index.html"
dist: "./public"
# Watches files for changes and runs tasks based on the changed files
watch:
coffee:
files: ["<%= yeoman.app %>/scripts/**/*.{coffee,litcoffee,coffee.md}"]
tasks: ["newer:coffee:dist", "karma:unit:run"]
coffeeTest:
files: ["test/spec/{,*/}*.{coffee,litcoffee,coffee.md}"]
tasks: ["newer:coffee:test", "karma:unit:run"]
index:
files: ["<%= yeoman.app %>/index.html"]
tasks: ["targethtml:serve"]
sass:
files: ["<%= yeoman.app %>/styles/{,*/}*.scss"]
tasks: ["sass:dist", "autoprefixer", "styleguide:serve"]
gruntfile:
files: ["Gruntfile.coffee"]
livereload:
options:
livereload: "<%= connect.options.livereload %>"
files: [
"<%= yeoman.app %>/**/*.html",
".tmp/styles/{,*/}*.css",
".tmp/scripts/**/*.js",
"<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}"
]
# The actual grunt server settings
connect:
options:
port: 9000
# Change this to '0.0.0.0' to access the server from outside.
hostname: "localhost"
livereload: 35729
proxies: [
context: [
"/api"
"/asset_store" # development uploads
"/admin"
"/sidekiq"
"/assets" # rails assets (active admin and sidekiq)
]
port: 3100
host: "localhost"
]
rules: [
{from: '/styleguide$', to: '/styleguide/index.html'}
{from: '/\w+$', to: '/'}
]
livereload:
options:
open: true
base: [".tmp", "<%= yeoman.app %>"]
middleware: (connect, options) ->
middlewares = []
directory = options.directory or options.base[options.base.length - 1]
options.base = [options.base] unless Array.isArray(options.base)
# Setup the proxy
middlewares.push require("grunt-connect-proxy/lib/utils").proxyRequest
# Handle angular html5 mode
middlewares.push rewriteRulesSnippet
# Serve static files.
options.base.forEach (base) -> middlewares.push connect.static(base)
# Make directory browse-able.
# middlewares.push connect.directory(directory)
middlewares
test:
options:
port: 9001
base: [".tmp", "test", "<%= yeoman.app %>"]
dist:
options:
base: "<%= yeoman.dist %>"
coffeelint:
options:
max_line_length:
level: 'warn'
app: ['<%= yeoman.app %>/scripts/**/*.coffee']
# 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"]
client:
src: ['.tmp/scripts/**/*.js']
# Empties folders to start fresh
clean:
dist:
options:
force: true
files: [
dot: true
src: [".tmp", "<%= yeoman.dist %>/*", "!<%= yeoman.dist %>/.git*"]
]
cucumber: "<%= yeoman.dist %>/*"
server: ".tmp"
replace:
development:
options:
variables:
applicationMode: 'development'
intercomAppId: process.env.INTERCOM_APP_ID
cartodbMapUrl: process.env.CARTODB_URL
files: [
expand: true
flatten: true
src: ['<%= yeoman.app %>/scripts/worldly_config.js']
dest: '.tmp/scripts'
]
test:
options:
variables:
applicationMode: 'test'
cartodbMapUrl: process.env.CARTODB_URL
files: [
expand: true
flatten: true
src: ['<%= yeoman.app %>/scripts/worldly_config.js']
dest: '.tmp/scripts'
]
dist:
options:
variables:
applicationMode: 'production'
intercomAppId: process.env.INTERCOM_APP_ID
cartodbMapUrl: process.env.CARTODB_URL
files: [
expand: true
flatten: true
src: ['<%= yeoman.app %>/scripts/worldly_config.js']
dest: '.tmp/scripts'
]
targethtml:
dist:
files:
'.tmp/index.html': 'angular/index.html'
test:
files:
'.tmp/index.html': 'angular/index.html'
serve:
files:
'.tmp/index.html': 'angular/index.html'
# Add vendor prefixed styles
autoprefixer:
options:
browsers: ["last 1 version"]
dist:
files: [
expand: true
cwd: ".tmp/styles/"
src: "{,*/}*.css"
dest: ".tmp/styles/"
]
# Run `bower install`
bower:
install:
options:
targetDir: "<%= yeoman.bower %>"
# Automatically inject Bower components into the app
"bower-install":
app:
html: "<%= yeoman.layout %>"
ignorePath: "<%= yeoman.app %>/"
cssPattern: '<link href="/{{filePath}}" rel="stylesheet">'
jsPattern: '<script type="text/javascript" src="/{{filePath}}"></script>',
exclude: [
/bootstrap/ # scss is include on component basis, and js is not used
/sinon/
/blueimp-load-image/
/moment/ # breaks uglifier with language support
/angular-mocks/
/angular-unstable/
/angular-contenteditable/
]
# Compiles CoffeeScript to JavaScript
coffee:
options:
sourceMap: false
bare: false
sourceRoot: ""
dist:
files: [
expand: true
cwd: "<%= yeoman.app %>/scripts"
src: "**/*.coffee"
dest: ".tmp/scripts"
ext: ".js"
]
test:
files: [
expand: true
cwd: "test/spec"
src: "{,*/}*.coffee"
dest: ".tmp/spec"
ext: ".js"
]
sass:
dist:
files:
".tmp/styles/main.css": "angular/styles/main.scss"
options:
includePaths: ["<%= yeoman.bower %>"]
filerev_assets:
dist:
options:
dest: 'assets.json'
cwd: 'public/'
prettyPrint: true
# Renames files for browser caching purposes
filerev:
dist:
src: [
"<%= yeoman.dist %>/scripts/**/*.js"
"<%= yeoman.dist %>/styles/**/*.css"
"<%= yeoman.dist %>/views/**/*.html"
"<%= yeoman.dist %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}"
"<%= yeoman.dist %>/styles/fonts/*"
]
# 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:
html: "<%= yeoman.layout %>"
options:
dest: "<%= yeoman.dist %>"
# Performs rewrites based on rev and the useminPrepare configuration
usemin:
js: ["<%= yeoman.dist %>/scripts/scripts.*.js"]
html: ["<%= yeoman.dist %>/**/*.html"]
css: ["<%= yeoman.dist %>/styles/{,*/}*.css"]
options:
assetsDirs: ["<%= yeoman.dist %>"]
patterns:
js: [
[ /\.usemin\(['"]([^'"]*)['"]\)/gm,
'Update assets flagged by assetPath.usemin'
]
[ /templateUrl: ?['"]([^"']+)['"]/gm,
'Updating template references'
]
],
html: [
[ /<script.+src=['"]([^"']+)["']/gm,
'Update the HTML to reference our concat/min/revved script files'
]
[ /<link[^\>]+href=['"]([^"']+)["']/gm,
'Update the HTML with the new css filenames'
]
[ /<img[^\>]*\ssrc=['"]([^"']+)["']/gm,
'Update the HTML with the new img filenames'
]
[ /<ng-include[^\>]+src=['"]['"]([^"']+)['"]["']/gm,
'Update the HTML with the new ng-include element literals'
]
[ /ng-include=['"]['"]([^"']+)['"]["']/gm,
'Update the HTML with the new ng-include literals'
]
[ /template-url=['"]([^"']+)["']/gm,
'Update the HTML with the new template-url filenames'
]
]
htmlmin:
dist:
options:
collapseWhitespace: true
collapseBooleanAttributes: true
removeCommentsFromCDATA: true
removeOptionalTags: true
files: [
expand: true
cwd: "<%= yeoman.dist %>"
src: ["*.html", "views/**/*.html"]
dest: "<%= yeoman.dist %>"
]
# Allow the use of non-minsafe AngularJS files. Automatically makes it
# minsafe compatible so Uglify does not destroy the ng references
ngmin:
dist:
files: [
expand: true
cwd: ".tmp/concat/scripts"
src: "*.js"
dest: ".tmp/concat/scripts"
]
# Copies remaining files to places other tasks can use
copy:
dist:
files: [
expand: true
dot: true
cwd: "<%= yeoman.app %>"
dest: "<%= yeoman.dist %>"
src: [
"*.{ico,png,txt}"
".htaccess"
"*.html"
"views/**/*.html"
"bower_components/**/*"
# "images/{,*/}*.{webp}"
"images/**/*"
"fonts/*"
"pages/**/*"
]
,
expand: true
cwd: ".tmp/images"
dest: "<%= yeoman.dist %>/images"
src: ["generated/*"]
,
expand: true
cwd: ".tmp"
dest: "<%= yeoman.dist %>"
src: "**/*.{css,js,html}"
]
styles:
expand: true
cwd: "<%= yeoman.app %>/styles"
dest: ".tmp/styles/"
src: "{,*/}*.css"
# Emulate cssmin and uilify copy while being able to debug.
cucumber:
expand: true
cwd: ".tmp"
src: "{styles,scripts}/**/*.{js,css}"
dest: "<%= yeoman.dist %>"
# Run some tasks in parallel to speed up the build process
concurrent:
serve: ["coffee:dist", "sass:dist", "targethtml:serve"]
test: ["coffee", "sass:dist", "targethtml:test"]
dist: ["coffee:dist", "sass:dist", "targethtml:dist"]
# Test settings
karma:
options:
configFile: 'karma.conf.js',
unit:
singleRun: false
background: true
contiguous:
singleRun: true
background: false
styleguide:
options:
framework:
name: "kss"
options:
css: '.tmp/styles/main.css'
name: "Style Guide"
template:
src: 'styleguide-template'
serve:
files:
".tmp/styleguide": "angular/styles/**/*.{scss,sass}"
dist:
files:
"public/styleguide": "angular/styles/**/*.{scss,sass}"
# End config
grunt.registerTask "serve", (target) ->
if target is "dist"
return grunt.task.run ["build", "connect:dist:keepalive"]
grunt.task.run [
"clean:server"
"bower:install"
"concurrent:serve"
"autoprefixer"
"replace:development"
"styleguide:serve"
'configureProxies:server'
"connect:livereload"
"karma:unit"
"watch"
]
grunt.registerTask "server", 'Replace asset paths', ->
grunt.log.warn "The `server` task has been deprecated. Use `grunt serve` to start a server."
grunt.task.run ["serve"]
grunt.registerTask "test", [
"clean:server"
"useminPrepare"
"concurrent:test"
"autoprefixer"
"connect:test"
"usemin"
"karma:contiguous"
]
grunt.registerTask "build:cucumber", [
"clean:cucumber"
"replace:test"
"useminPrepare"
"concurrent:test"
"autoprefixer"
"concat"
# "copy:cucumber" # js and css files
"copy:dist"
"cssmin"
"uglify"
"filerev"
"usemin"
# "htmlmin" # causes features/profile.feature:34 to fail
]
grunt.registerTask "build:cucumber-debug", [
"clean:cucumber"
"replace:test"
"concurrent:test"
"autoprefixer"
# "copy:cucumber" # js and css files
"copy:dist"
]
grunt.registerTask "build", [
"clean:dist"
"bower:install"
"bower-install"
"replace:dist"
"useminPrepare"
"concurrent:dist"
"styleguide:dist"
"autoprefixer"
"concat"
# "ngmin",
"copy:dist"
"cssmin"
"uglify"
"filerev"
"usemin"
"htmlmin"
]
grunt.registerTask "default", [
"newer:jshint"
"test"
"build"
]
grunt.registerTask "heroku:production", "build"
{
"name": "angular",
"version": "0.0.0",
"dependencies": {
"grunt": "~0.4.1",
"grunt-contrib-watch": "git+https://github.com/gruntjs/grunt-contrib-watch",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-jshint": "~0.7.1",
"grunt-autoprefixer": "~0.4.0",
"grunt-bower-install": "~0.7.0",
"grunt-concurrent": "~0.4.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-uglify": "~0.2.0",
"grunt-karma": "~0.6.2",
"grunt-newer": "~0.5.4",
"grunt-ngmin": "~0.0.2",
"grunt-usemin": "~2.0.0",
"load-grunt-tasks": "~0.2.0",
"time-grunt": "~0.2.1",
"requirejs": "~2.1.10",
"grunt-sass": "~0.10.0",
"grunt-bower-task": "~0.3.4",
"grunt-cli": "~0.1.11",
"jshint-stylish": "~0.1.3",
"grunt-connect-proxy": "~0.1.7",
"bower": "~1.2.8",
"grunt-notify": "~0.2.17",
"generator-karma": "~0.6.0",
"yo": "~1.1.2",
"generator-angular": "~0.7.1",
"grunt-replace": "~0.5.1",
"grunt-targethtml": "~0.2.6",
"grunt-filerev": "~0.2.1",
"install": "~0.1.7",
"npm": "~1.3.25",
"grunt-styleguide": "~0.2.15",
"grunt-connect-rewrite": "~0.2.1",
"kss": "~0.3.6"
},
"devDependencies": {
"karma-ng-scenario": "~0.1.0",
"karma-script-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.2",
"karma-firefox-launcher": "~0.1.3",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.5",
"karma-requirejs": "~0.2.1",
"karma-coffee-preprocessor": "~0.1.2",
"karma-phantomjs-launcher": "~0.1.1",
"karma": "~0.10.9",
"karma-ng-html2js-preprocessor": "~0.1.0",
"mocha": "~1.17.0",
"karma-mocha": "~0.1.1",
"karma-sinon-chai": "~0.1.4",
"grunt-coffeelint": "0.0.8"
},
"engines": {
"node": "~0.10.24"
},
"scripts": {
"test": "grunt test"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment