Skip to content

Instantly share code, notes, and snippets.

@mwawrusch
Created August 19, 2014 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwawrusch/183116d1b6aed4495b39 to your computer and use it in GitHub Desktop.
Save mwawrusch/183116d1b6aed4495b39 to your computer and use it in GitHub Desktop.
_ = require 'underscore'
modRewrite = require('connect-modrewrite')
module.exports = (grunt) ->
filterGrunt = ->
gruntFiles = require("matchdep").filterDev("grunt-*")
_.reject gruntFiles, (x) -> x is 'grunt-cli'
filterGrunt().forEach grunt.loadNpmTasks
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
DEPLOY: 'deploy'
DEV: 'dev'
banner: [
'/*',
'* <%= pkg.name %>',
'* Version <%= pkg.version %> released <%= grunt.template.today("yyyy-mm-dd") %>',
'* Development by Martin Wawrusch for asokoinsight.com',
'* Copyright (c) <%= grunt.template.today("yyyy") %> Martin Wawrusch (martin@wawrusch.com) and asokoinsight.com. All Rights Reserved',
'*/'
]
env:
dev:
NODE_ENV : 'development'
deploy:
NODE_ENV : 'production'
s3:
options:
region: "us-east-1"
access: "public-read"
encodePaths: false
deploy:
# These options override the defaults
options:
maxOperations: 1
headers:
'Cache-Control': 'max-age=155520000, public'
# Files to be uploaded.
upload: [
src: 'deploy/js/**/*.*'
dest: ''
rel: 'deploy'
,
src: 'deploy/css/**/*.*'
dest: ''
rel: 'deploy'
,
src: 'deploy/lib/**/*.*'
dest: ''
rel: 'deploy'
,
src: 'deploy/img/**/*.*'
dest: ''
rel: 'deploy'
]
deploy_index:
options:
maxOperations: 1
headers:
'Cache-Control': 'max-age=0, public'
# Index file / no caching
upload: [
src: 'deploy/index.*'
dest: ''
rel: 'deploy'
]
release:
options:
npm: false
shell:
options:
stdout: true
npm_install:
command: "npm install"
bower_install:
command: "./node_modules/.bin/bower install"
connect:
options:
base: "www/"
middleware: (connect,options) ->
directory = options.directory || options.base[options.base.length - 1]
if (!Array.isArray(options.base))
options.base = [options.base]
# custom middleware
middlewares = [
connect.static(options.base[0])
connect.directory(options.base[0])
# mod rewrite
modRewrite(['^[^\\.]*$ /index.html [L]'])
connect.static(options.base[0])
]
# same as in grunt-contrib-connect
options.base.forEach( (base) ->
middlewares.push(connect.static(base))
)
middlewares.push(connect.directory(directory))
middlewares
dev:
options:
hostname: 'localhost'
port: 7201
keepalive: true
lifereload: false
concurrent:
dev:
tasks: [ 'watch','connect:dev'] # 'node-inspector',
options:
logConcurrentOutput: true
open:
dev:
path: 'http://localhost:7201'
stylus:
dev:
files:
'www/css/style.css': ['src/css/*.styl']
deploy:
files:
'deploy/css/style.css': ['src/css/*.styl']
jade:
dev:
options:
data:
debug: true
pretty: true
files: [
expand: true
flatten: true
cwd: 'src'
src: ['*.jade']
dest: 'www/'
ext: '.html'
]
deploy:
options:
data:
debug: false
pretty: true #IMPORTANT FOR USE MIN
files: [
expand: true
flatten: true
cwd: 'src'
src: ['*.jade']
dest: 'deploy/'
ext: '.html'
]
coffee:
dev:
options:
sourceMap: true
files: [
expand: true
flatten: true
cwd: 'src/js'
src: ['*.coffee']
dest: 'www/js/'
ext: '.js'
]
deploy:
options:
sourceMap: false
files: [
expand: true
flatten: true
cwd: 'src/js'
src: ['*.coffee']
dest: 'deploy/js/'
ext: '.js'
]
html2js:
options:
rename: (moduleName) ->
'/' + moduleName.replace('.html', '').replace('.jade','')
#target: "coffee"
htmlmin:
collapseBooleanAttributes: true
collapseWhitespace: true
removeAttributeQuotes: true
removeComments: false
removeEmptyAttributes: true
removeRedundantAttributes: true
removeScriptTypeAttributes: true
removeStyleLinkTypeAttributes: true
dev:
options:
base: "src/templates"
module: 'templates-dev'
src: ["src/templates/*.jade"]
dest: "www/js/precompiled-templates.js"
deploy:
options:
module: 'templates-dev'
base: "src/templates"
src: ["src/templates/*.jade"]
dest: "deploy/js/precompiled-templates.js"
watch:
dev:
files: [
'src/css/*.styl'
'src/js/*.coffee'
'src/*.jade'
'src/templates/*.jade'
]
options:
lifereload: false
tasks: 'compile-dev'
clean:
bower: ['www/components']
deploy: ['deploy']
post_deploy: ['.tmp','.tmp2']
concat_deploy: [
'deploy/css/style.css'
'deploy/lib/css'
'deploy/lib/js/ionic.bundle.js'
'deploy/lib/js/underscore.js'
'deploy/js/asokoinsight.js'
'deploy/js/precompiled-templates.js'
'deploy/js/shared-asokoinsight-api-client.js'
'deploy/js/shared-directive-gravatar.js'
]
copy:
bower:
files:
[
expand: true
flatten: true
src: [
'bower_components/underscore/underscore.js'
'bower_components/modernizr/modernizr.js'
'bower_components/moment/moment.js'
'bower_components/bootstrap/dist/js/bootstrap.js'
'bower_components/angular-animate/angular-animate.js'
'bower_components/angular-cookies/angular-cookies.js'
'bower_components/angular-messages/angular-messages.js'
'bower_components/angular-mocks/angular-mocks.js'
'bower_components/angular-sanitize/angular-sanitize.js'
'bower_components/angular-touch/angular-touch.js'
'bower_components/angular-ui-router/release/angular-ui-router.js'
'bower_components/angular-loading-bar/build/loading-bar.js'
'bower_components/angularjs-viewhead/angularjs-viewhead.js'
'bower_components/AngularJS-Toaster/toaster.js'
]
dest: 'www/lib/js'
,
expand: true
flatten: true
src: [
'bower_components/bootstrap/dist/css/bootstrap.css'
'bower_components/bootstrap/dist/css/bootstrap.css.map'
'bower_components/animate.css/animate.css'
'bower_components/angular-loading-bar/build/loading-bar.css'
'bower_components/AngularJS-Toaster/toaster.css'
]
dest: 'www/lib/css'
,
expand: true
flatten: true
src: [
'bower_components/bootstrap/dist/fonts/*'
]
dest: 'www/lib/fonts'
]
deploy:
files: [
expand: true
flatten: false
cwd: 'www/lib'
src: ['**']
dest: 'deploy/lib'
,
expand: true
flatten: false
cwd: 'www/img'
src: ['**']
dest: 'deploy/img'
]
preprocess:
dev:
options:
inline: true
context:
DEVELOPMENT: true
files:
'www/index.html' : 'www/index.html'
deploy:
options:
inline: true
context:
PRODUCTION: true
files:
'deploy/index.html' : 'deploy/index.html'
useminPrepare:
html: ['deploy/index.html']
options:
dest: 'deploy'
###
REMOVE THOSE OPTIONS FOR PRODUCTION
###
###
uglify:
options:
mangle: false
compress: false
beautify: true
###
'divshot:push:production':
options:
token: 'custom_access_token'
root: './deploy'
clean_urls: true
routes:
'*.html': 'index.html'
'**/*.html': 'index.html'
cache_control: {}
exclude: []
usemin:
html: 'deploy/index.html'
css: ['deploy/css/**/*.css','deploy/lib/css/**/*.css']
js: ['deploy/js/**/*.js','deploy/lib/js/**/*.js']
options:
dirs: ['deploy']
assetsDirs: [ # List ALL asset containing dirs here
'deploy'
'deploy/js'
'deploy/css'
'deploy/lib/css'
'deploy/lib/js'
'deploy/lib/fonts'
]
patterns: # regexes might be fucked up
js: [
#[/["']([^:"']+\.(?:png|gif|jpe?g))["']/img, 'Image replacement in js files']
[/((..)?[\w\-\/]+\.(?:png|gif|ico|jpe?g))/igm, 'Font replacement in css files']
[/((..)?[\w\-\/]+\.(?:eot|woff|ttf|svg))/igm, 'Font replacement in css files']
]
css: [
[/([\w\-\/]+\.(?:eot|woff|ttf|svg))/igm, 'Font replacement in css files']
#[/["']([^:"']+\.(?:png|gif|jpe?g))["']/img, 'Image replacement in css files']
[/((..)?[\w\-\/]+\.(?:png|gif|ico|jpe?g))/igm, 'Font replacement in css files']
#[/((..)?[\w\-\/]+\.(?:eot|woff|ttf|svg))/igm, 'Font replacement in css files']
]
"regex-replace":
deploy:
src: ['deploy/lib/css/*.css'],
actions: [
name: 'fontref',
search: /\.\.\/fonts\//img,
replace: '/lib/fonts/',
flags: 'g'
]
usebanner:
deploy:
options:
position: 'top',
banner: '<%= banner.join("\\n") %>'
linebreak: true
files: [
src: [ 'deploy/js/**/*.js' ]
]
htmlmin:
deploy:
options:
removeComments: true
collapseWhitespace: true
files:
'deploy/index.html' : 'deploy/index.html'
filerev:
options:
encoding: 'utf8'
algorithm: 'md5'
length: 12
source:
files: [
src: [
'deploy/js/**/*.js'
'deploy/css/**/*.css'
'deploy/img/**/*.{jpg,jpeg,gif,png,ico}'
'deploy/lib/js/**/*.js'
'deploy/lib/css/**/*.css'
'deploy/lib/fonts/**/*.{eot,svg,ttf,woff}'
]
]
codo:
options:
undocumented: true
private: true
analytics: false
src: ['src/**/*.coffee']
imagemin:
deploy:
options:
optimizationLevel: 10
files: [
expand: true
cwd: 'deploy/img',
src: ['**/*.{png,jpg,jpeg,gif}']
dest: 'deploy/img'
]
grunt.registerTask "compile-dev", [
"env:dev"
"stylus:dev"
"jade:dev"
"html2js:dev"
"coffee:dev"
"preprocess:dev"
'codo'
]
grunt.registerTask "test-deploy", []
grunt.registerTask "compile-deploy", [
"clean:deploy"
"env:deploy"
"stylus:deploy"
"jade:deploy"
"coffee:deploy"
"html2js:deploy"
"copy:deploy"
'regex-replace:deploy'
"imagemin"
"preprocess:deploy"
"useminPrepare"
'concat'
'clean:concat_deploy'
'uglify'
'cssmin'
'filerev'
"usemin"
"htmlmin:deploy"
"test-deploy"
"release"
"usebanner"
'clean:post_deploy'
]
grunt.registerTask "deploy", [
"compile-deploy"
"s3:deploy"
"s3:deploy_index"
]
grunt.registerTask "bower", [
"shell:bower_install"
"clean:bower"
"copy:bower"
]
grunt.registerTask 'default', ['compile-dev', 'concurrent:dev']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment