Created
November 13, 2014 01:11
-
-
Save jeshuaborges/1f65292415303a26cb80 to your computer and use it in GitHub Desktop.
Rails gruntfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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 when they are required | |
require('jit-grunt') grunt, | |
useminPrepare: 'grunt-usemin' | |
configureProxies: 'grunt-connect-proxy' | |
configureRewriteRules: 'grunt-connect-rewrite' | |
ngconstant: 'grunt-ng-constant' | |
scsslint: 'grunt-scss-lint' | |
# 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,app}/**/*.coffee", "!<%= yeoman.app %>/{scripts,app}/**/*_spec.coffee"] | |
tasks: ["newer:coffee:dist"] | |
index: | |
files: ["<%= yeoman.app %>/index.html"] | |
tasks: ["targethtml:serve"] | |
sass: | |
files: ["<%= yeoman.app %>/styles/{,*/}*.scss"] | |
tasks: ["sass:dist", "autoprefixer"] | |
gruntfile: | |
files: ["Gruntfile.coffee"] | |
templates: | |
files: ["<%= yeoman.app %>/views/**/*.html", "<%= yeoman.app %>/app/**/*.html"] | |
tasks: ["html2js"] | |
livereload: | |
options: | |
livereload: "<%= connect.options.livereload %>" | |
files: [ | |
"<%= yeoman.app %>/**/*.html" | |
".tmp/styles/{,*/}*.css" | |
".tmp/scripts/**/*.js" | |
".tmp/styleguide/**/*.html" | |
# "<%= 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: "0.0.0.0" | |
livereload: 35729 | |
proxies: [ | |
context: [ | |
"/api" | |
"/asset_store" # development uploads | |
"/admin" | |
"/sidekiq" | |
"/pghero" | |
"/rails" | |
"/r" | |
"/signup_token" | |
"/assets" # rails assets (active admin and sidekiq) | |
] | |
port: 3100 | |
host: "localhost" | |
] | |
rules: [ | |
{from: '^(.*)?/[@\\w-]+(\\?.*)?$', to: '/index.html'} # html5 angular routes | |
] | |
livereload: | |
options: | |
open: false | |
base: [".tmp", "<%= yeoman.app %>"] | |
middleware: (connect, options, middlewares) -> | |
# Setup the proxy | |
middlewares.push require("grunt-connect-proxy/lib/utils").proxyRequest | |
# Handle angular html5 mode | |
middlewares.push rewriteRulesSnippet | |
# Serve static files. | |
for base in options.base | |
middlewares.push connect.static(base) | |
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,app}/**/*.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,app}/**/*.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" | |
ngconstant: | |
options: | |
name: 'worldly.config' | |
dest: '.tmp/scripts/worldly_config.js' | |
constants: | |
GOOGLE_ANALYTICS_TRACKING_ID: process.env.GOOGLE_ANALYTICS_TRACKING_ID | |
BITLY_ACCESS_TOKEN: process.env.BITLY_ACCESS_TOKEN | |
MIXPANEL_TOKEN: process.env.MIXPANEL_TOKEN | |
FACEBOOK_APP_ID: process.env.FACEBOOK_APP_ID | |
INTERCOM_CONFIG: | |
app_id: process.env.INTERCOM_APP_ID | |
widget: false | |
FIREBASE_ROOT: process.env.FIREBASE_ROOT | |
AUTOCOMPLETE_ENGINE_KEY: process.env.AUTOCOMPLETE_ENGINE_KEY | |
SEARCH_ENGINE_KEY: process.env.SEARCH_ENGINE_KEY | |
MAPS: | |
cartodbMapUrl: process.env.CARTODB_URL | |
tilesUrl: '//a.tiles.mapbox.com/v3/azimux.h6fkmcnb/{z}/{x}/{y}.png', | |
attribution: '<a href="http://www.mapbox.com/about/maps/" target="_blank">Map Box</a>' | |
values: | |
# This a hack to support an exsiting maps services. This should be | |
# deprecated and replaces with more explicit flags. For example | |
# MAPS: {render: false} | |
isTestMode: false | |
serve: {} | |
dist: {} | |
test: | |
value: | |
isTestMode: true | |
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/" | |
] | |
# Compiles CoffeeScript to JavaScript | |
coffee: | |
options: | |
sourceMap: false | |
bare: false | |
sourceRoot: "" | |
dist: | |
files: [ | |
expand: true | |
cwd: "<%= yeoman.app %>/scripts" | |
src: ["**/*.coffee", "!**/*_spec.coffee"] | |
dest: ".tmp/scripts" | |
ext: ".js" | |
, | |
expand: true | |
cwd: "<%= yeoman.app %>/app" | |
src: "**/*.coffee" | |
dest: ".tmp/app" | |
ext: ".js" | |
] | |
test: | |
files: [ | |
expand: true | |
cwd: "test/spec" | |
src: "{,*/}*.coffee" | |
dest: ".tmp/spec" | |
ext: ".js" | |
, | |
expand: true | |
cwd: "<%= yeoman.app %>/app" | |
src: "**/*_spec.coffee" | |
dest: ".tmp/app" | |
ext: ".js" | |
] | |
sass: | |
dist: | |
files: | |
".tmp/styles/main.css": "angular/styles/main.scss" | |
options: | |
includePaths: ["<%= yeoman.bower %>"] | |
# Renames files for browser caching purposes | |
filerev: | |
dist: | |
src: [ | |
"<%= yeoman.dist %>/{scripts,app}/*.js" | |
"<%= yeoman.dist %>/styles/*.css" | |
"<%= yeoman.dist %>/index.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: | |
html: "<%= yeoman.layout %>" | |
options: | |
dest: "<%= yeoman.dist %>" | |
# Performs rewrites based on rev and the useminPrepare configuration | |
usemin: | |
html: ["<%= yeoman.dist %>/**/*.html"] | |
css: ["<%= yeoman.dist %>/styles/{,*/}*.css"] | |
options: | |
assetsDirs: ["<%= 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" | |
"app/**/*.html" | |
"bower_components/**/*" | |
"images/**/*" | |
"fonts/*" | |
"styles/**/*.css" | |
] | |
, | |
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: | |
dist: [ | |
"coffee:dist" | |
"sass:dist" | |
"targethtml:dist" | |
"html2js" | |
] | |
# 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: [ | |
'<%= yeoman.app %>/styles/vendor/flaticon_solid.css' | |
'<%= yeoman.app %>/styles/vendor/flaticon_social.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}" | |
html2js: | |
options: | |
base: 'angular' | |
rename: (moduleName) -> "/#{moduleName}" | |
# htmlmin: | |
# collapseBooleanAttributes: true | |
# collapseWhitespace: true | |
main: | |
src: ['angular/views/**/*.html', 'angular/app/**/*.html'] | |
dest: '.tmp/scripts/views.js' | |
cdn: | |
options: | |
cdn: process.env.ASSET_CDN ? '' | |
flatten: false | |
ignorePath: ['#default#VML'] | |
dist: | |
src: ['./public/**/*.html', './public/styles/*.css'] | |
modernizr: | |
dist: | |
devFile: '<%= yeoman.bower %>/modernizr/modernizr.js' | |
outputFile: '.tmp/scripts/vendor/modernizr-custom.js' | |
tests: [ | |
'contenteditable' | |
'localstorage' | |
] | |
files: | |
src: [ | |
'.tmp/scripts/**/*.js' | |
'.tmp/app/**/*.js' | |
'.tmp/styles/**/*.css' | |
] | |
uglify: false | |
scsslint: | |
options: | |
debug: false | |
bundleExec: false | |
config: '.scss-lint.yml' | |
colorizeOutput: true | |
all: | |
src: ["<%= yeoman.app %>/styles/**/*.scss"] | |
compress: | |
dist: | |
options: | |
mode: 'gzip' | |
files: [ | |
{ | |
expand: true, | |
dest: '.compressed' | |
cwd: 'public/' | |
src: [ | |
'styles/{vendor,main}*.css' | |
'scripts/{vendor,scripts}*.js' | |
] | |
} | |
] | |
aws_s3: | |
options: | |
bucket: process.env.APP_ASSET_BUCKET, | |
accessKeyId: process.env.AWS_ACCESS_KEY_ID | |
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY | |
uploadConcurrency: 5 | |
params: | |
CacheControl: 'max-age=31556900000' | |
Expires: new Date(Date.now() + 31556900000) | |
compressed: | |
options: | |
params: | |
ContentEncoding: 'gzip' | |
files: [ | |
{ | |
expand: true | |
cwd: '.compressed/' | |
src: [ | |
'styles/{vendor,main}*.css' | |
'scripts/{vendor,scripts}*.js' | |
] | |
} | |
] | |
dist: | |
files: [ | |
{ | |
expand: true | |
cwd: 'public/' | |
src: [ | |
'images/**' | |
'favicon*' | |
'fonts/**' | |
] | |
} | |
] | |
# End config | |
grunt.registerTask "serve", (target) -> | |
if target is "dist" | |
return grunt.task.run ["build", "connect:dist:keepalive"] | |
grunt.task.run [ | |
"clean:server" | |
"coffee:dist" | |
"coffee:test" | |
"sass:dist" | |
"targethtml:serve" | |
"html2js" | |
"autoprefixer" | |
"modernizr" | |
"ngconstant:serve" | |
'configureProxies:server' | |
'configureRewriteRules' | |
"connect:livereload" | |
"karma:unit" | |
"watch" | |
] | |
grunt.registerTask "serve:styleguide", [ | |
"styleguide:serve" | |
"connect:livereload" | |
"watch" | |
] | |
grunt.registerTask "test", [ | |
"clean:cucumber" | |
"ngconstant:test" | |
"useminPrepare" | |
"concurrent:test" | |
"concat" | |
"copy:dist" | |
# "usemin" | |
"karma:contiguous" | |
] | |
grunt.registerTask "test:serve", [ | |
"newer:coffee:test" | |
"karma:contiguous" | |
] | |
grunt.registerTask "build:cucumber", [ | |
"clean:cucumber" | |
"ngconstant:test" | |
"html2js" | |
"useminPrepare" | |
"coffee:dist" | |
"coffee:test" | |
"sass:dist" | |
"targethtml:test" | |
"autoprefixer" | |
"modernizr" | |
"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:fast", [ | |
"clean:cucumber" | |
"ngconstant:test" | |
"html2js" | |
"coffee:dist" | |
"coffee:test" | |
"sass:dist" | |
"targethtml:test" | |
# "autoprefixer" | |
# "copy:cucumber" # js and css files | |
"copy:dist" | |
] | |
grunt.registerTask "build", [ | |
"clean:dist" | |
"ngconstant:dist" | |
"useminPrepare" | |
"concurrent:dist" | |
"styleguide:dist" | |
"autoprefixer" | |
"modernizr" | |
"concat" | |
"modernizr" | |
# "ngmin", | |
"copy:dist" | |
"cssmin" | |
"uglify" | |
"filerev" | |
"usemin" | |
"cdn:dist" | |
] | |
grunt.registerTask "default", [ | |
"newer:jshint" | |
"test" | |
"build" | |
] | |
grunt.registerTask "heroku:production", [ | |
"build" | |
"compress:dist" | |
"aws_s3" | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment