Skip to content

Instantly share code, notes, and snippets.

@djcommandline
Created May 29, 2014 17:46
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 djcommandline/1373dc5612402b2773b0 to your computer and use it in GitHub Desktop.
Save djcommandline/1373dc5612402b2773b0 to your computer and use it in GitHub Desktop.
Grunt File Setup
(function() {
'use strict';
// this function is strict...
}());
module.exports = function(grunt) {
// AUTO TASK LOADER + EXECUTION TIME LOG
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
// LOAD ASSEMBLE
grunt.loadNpmTasks('assemble');
//////////////////////////
/// //
/// TASK CONFIG //
/// //
///----------------------//
/// //
/// TODOS //
/// OPEN //
/// JSHNIT //
/// LESS //
/// UGLIFIER //
/// VERSION //
/// WEBFONT //
/// WATCH //
/// CLEAN //
/// FTP-DEPLOY /
/////////////////////////
grunt.initConfig({
//// ESTABLISH GRUNT SETUP INFO
pkg : grunt.file.readJSON('package.json'),
//// AWS DEPLOYMENT KEYS
// aws: grunt.file.readJSON(".awskey"),
// TODOS
todos: {
options: {
priorities: {
low: /TODO/,
med: /FIXME/,
urgent: /URGENT/
},
reporter: {
header: function() {
return '-- TODO LIST --\n';
},
fileTasks: function(file, tasks, options) {
var result = '';
result += 'file: ' + file + '\n';
tasks.forEach(function(task) {
result += 'LINE ' + task.lineNumber + ' - [' + task.priority + '] ' + task.line + '\n';
});
result += '\n';
return result;
},
footer: function() {
return '\n';
}
}
},
'todo.md': [
'index.html',
'assets/less/app.less'
]
},
// CHECK JS QUALITY
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
//'Gruntfile.js',
'assets/js/_main.js',
'assets/js/vendor/**/*.js',
//'!assets/js/scripts.min.js',
'!assets/js/scripts.js'
]
},
// STATIC SITE COMPILER
assemble: {
options: {
assets: '_src',
// plugins: ['permalinks'],
partials: ['_templates/partials/*.hbs'],
layout: ['_templates/layouts/default.hbs'],
ext: '.html'
// data: ['data/*.{json,yml}']
},
pages: {
expand: true,
cwd: '_templates/pages',
src: ['*.hbs'],
dest: './dist',
}
},
// RUN LOCAL DEV SERVER
connect: {
'static': {
options: {
hostname: '0.0.0.0',
port: 8001,
keepalive: false,
base: 'dist/'
}
}
},
// OPEN WEBSITE IN BROWSER
open : {
todos: {
path: 'todo.md',
app: 'Google Chrome'
},
local: {
path: 'http://0.0.0.0:8001',
app: 'Google Chrome'
},
prod: {
path: 'http://goodlifeacademy.me',
app: 'Google Chrome'
}
},
// CSS COMPILER
less: {
dist: {
files: [
{
expand: true,
cwd: '_src/less',
src: 'app.less',
dest: '_src/css',
ext: '.css'
}
],
options: {
compress: false,
yuicompress: true,
ieCompat: true,
// LESS source map
// To enable, set sourceMap to true and update sourceMapRootpath based on your install
sourceMap: true,
// sourceMapFilename: '_src/assets/css/app.min.css.map',
// sourceMapURL: 'app.min.css.map',
// sourceMapBasepath: 'dist',
// sourceMapRootpath: '/'
// sourceMapFilename: 'css/main.css.map', // where file is generated and located
sourceMapFilename: '_src/css/app.min.css.map',
sourceMapURL: '/assets/css/app.min.css.map',
sourceMapRootpath: ''
}
}
},
// DELETE DISTRIBUTION FILES
clean: {
dist: [
'dist/**/*',
]
},
// SEARCH
sed: {
version: {
pattern: '%VERSION%',
replacement: '<%= pkg.version %>',
recursive: true
},
mapfile: {
path: '_src/css/app.min.css.map',
pattern: '_src',
replacement: '/assets',
recursive: true
}
},
// COPY SRC FILES FOR DISTRIBUTION
sync: {
dist: {
files: [{
cwd: '_src/',
src: [
'**/*.html',
'css/**',
'fonts/**',
'img/**',
'js/*.js',
'less/**'
// '!**/*.txt' /* but exclude txt files */
],
dest: 'dist/assets/'
}],
verbose: true
},
seo: {
files: [{
cwd: '_src/seo',
src: [
'**', /* Include everything */
// '!**/*.txt' /* but exclude txt files */
],
dest: 'dist/'
}],
verbose: true
}
},
// COMBINE ALL JS
concat: {
options: {
separator: '',
},
srcfile: {
src: [
'_src/js/plugins/jquery/*.js',
'_src/js/plugins/*/*.js',
'_src/js/vendor/ele_*.js',
'_src/js/vendor/_*.js'
],
dest: '_src/js/scripts.js',
}
},
// MINIFY JS
uglify: {
dist : {
files: {
'_src/js/scripts.min.js': [
'_src/js/scripts.js'
]
},
options: {
// JS source map: to enable, uncomment the lines below and update sourceMappingURL based on your install
// sourceMap: 'assets/js/scripts.min.js.map',
// sourceMappingURL: '/app/themes/roots/assets/js/scripts.min.js.map'
compress: false,
}
}
},
// BUILD WEBFONTS
webfont: {
icons: {
src: 'assets/icons/*.svg',
dest: 'assets/fonts',
templateOptions: {
baseClass: 'icon',
classPrefix: 'icon-',
mixinPrefix: 'icon-'
},
options: {
font: 'fontcustom',
syntax: 'bootstrap'
}
}
},
// DEPLOY VIA FTP
'ftp-deploy': {
build: {
auth: {
host: 'server.com',
port: 21,
authKey: 'key1'
},
src: './',
dest: '/path/to/destination/folder',
exclusions: [
'./**/.DS_Store',
'./**/Thumbs.db',
'dist/tmp'
]
}
},
// DEPLOY VIA S3
s3: {
options: {
accessKeyId: "<%= aws.accessKeyId %>",
secretAccessKey: "<%= aws.secretAccessKey %>",
bucket: "goodlifeacademy.me",
dryRun: false
},
build: {
cwd: "dist/",
src: "**"
},
},
// DEV ENV WATCH TASKS
watch: {
less: {
files: [
'_src/less/*.less',
'_src/less/frontendpatterns/*.less',
'_src/less/frontendpatterns/reset/*.less',
'_src/less/frontendpatterns/ele/*.less'
],
tasks: ['less', 'sed:mapfile', 'sync']
},
js: {
files: [
'_src/js/vendor/**/*.js',
'_src/js/plugins/**/*.js'
],
tasks: ['concat', 'uglify', 'sync']
},
livereload: {
// Browser live reloading @ref :: https://github.com/gruntjs/grunt-contrib-watch#live-reloading
options: {
livereload: true
},
files: [
'dist/assets/css/app.css',
'dist/assets/js/scripts.js',
'dist/**.html'
]
},
templates: {
files: [
'_templates/**'
],
tasks: ['assemble']
}
}
});
///////////////////////////
/// //
/// TASK REGISTRATION //
/// //
///////////////////////////
// -- DEFAULT
grunt.registerTask('default', [
]);
// -- HINTERS
// JSHINT
grunt.registerTask('hintjs', [
'jshint'
]);
// -- FONTS
// WEBFONT GENERATION
grunt.registerTask('make-fonts', [
'webfont'
]);
// -- DEPLOYMENT OPTIONS
// S3 DEPLOYMENT
grunt.registerTask('deploy', [
'clean',
'less',
'concat',
'uglify',
'assemble',
'sync',
's3',
'open:prod',
]);
// -- TASKLIST GENERATION
// TODO VIEW
grunt.registerTask('show-todos', [
'todos',
'open:todos'
]);
// -- WEB BROWSER LAUNCH
// OPEN DEV SITE
grunt.registerTask('open-dev', [
'open:devsite'
]);
// OPEN PROD SITE
grunt.registerTask('open-prod', [
'open:prod'
]);
// -- STATIC SITE GENERATION
grunt.registerTask('build', [
'assemble',
'sync'
]);
// -- LOCAL DEV ENV SERVER
grunt.registerTask('local-dev', [
'clean',
'less',
'sed:mapfile',
'uglify',
'assemble',
'sync:dist',
'sync:seo',
'open:local',
'connect:static',
'watch'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment