-
-
Save eporroa/b66b766071b0b4a907bf to your computer and use it in GitHub Desktop.
This file contains 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
gruntFunction = (grunt)-> | |
if grunt.option('dev') | |
env = 'development' | |
else if grunt.option('deploy') | |
env = 'deployment' | |
else if grunt.option('prod') | |
env = 'production' | |
else | |
env = grunt.option('env') || 'development' | |
timestamp = new Date().getTime() | |
datestamp = new Date().toISOString().replace(/[^\d]/g,'').substr(0,8) | |
ENVIROMENT = | |
# Pruebas mientras se desarrolla | |
# minimized : false | |
# logs : true | |
# sourcemaps: false | |
development: | |
url : 'http://yolo.ftw/2.0-dev/' | |
path : '../2.0-dev' | |
debug: true | |
cache: timestamp | |
# Release Candidate. Para pasar a revision (QA). Si es aprobada pasa a Produccion. | |
# minimized : true | |
# logs : false | |
# sourcemaps: true | |
deployment: | |
url : 'http://yolo.ftw/2.0-deploy/' | |
path : '../2.0-deploy' | |
debug: false | |
cache: datestamp | |
# PRODUCTION! "que el cielo nos ampare" | |
# minimized : true | |
# logs : false | |
# sourcemaps: false | |
production: | |
url : 'http://yolo.ftw/2.0/' | |
path : '../2.0' | |
debug: false | |
cache: datestamp | |
# alias | |
ENVIROMENT.dev = ENVIROMENT.development | |
ENVIROMENT.deploy = ENVIROMENT.deployment | |
ENVIROMENT.prod = ENVIROMENT.production | |
# load all grunt tasks | |
#require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); | |
grunt.loadNpmTasks 'grunt-contrib-coffee' | |
#grunt.loadNpmTasks 'grunt-contrib-concat' | |
grunt.loadNpmTasks 'grunt-contrib-copy' | |
grunt.loadNpmTasks 'grunt-contrib-stylus' | |
grunt.loadNpmTasks 'grunt-contrib-watch' | |
# grunt.loadNpmTasks 'grunt-cat' | |
#grunt.loadNpmTasks 'grunt-grep' | |
grunt.loadNpmTasks 'grunt-newer' | |
grunt.loadNpmTasks 'grunt-notify' | |
grunt.loadNpmTasks 'grunt-string-replace' | |
grunt.loadNpmTasks 'grunt-angular-templates' | |
console = log: grunt.log.writeln | |
_pkg = grunt.file.readJSON 'package.json' | |
_notifyTaskConfig = | |
done: | |
options: | |
image : __dirname + '\\grunt_components\\appicon.png' | |
title : '<%= pkg.name %>' | |
message: 'Done! ┌( ಠ‿ಠ)┘' | |
# TODO: ENVIROMENT config for deployment and production | |
ENVIROMENT.deployment.config = | |
pkg: _pkg | |
notify: _notifyTaskConfig | |
# . . . | |
# coming soon | |
ENVIROMENT.development.config = | |
pkg: _pkg | |
notify: _notifyTaskConfig | |
stylus: | |
core: | |
options: | |
compress: false | |
import : ['nib'] | |
files: [ | |
src : 'app/core/assets/styles/index.styl' | |
dest: ENVIROMENT.development.path + '/core/assets/styles.css' | |
] | |
modules: | |
options: | |
compress: false | |
import : ['nib'] | |
files: [ | |
expand: true | |
cwd : 'app/modules' | |
src : '**/index.styl' | |
dest : ENVIROMENT.development.path + '/modules' | |
ext : '.css' | |
extDot: 'last' | |
] | |
coffee: | |
core: | |
options: | |
sourceMap: false | |
files: [ | |
expand: true | |
cwd : 'app' | |
src : 'core/**/*.coffee' | |
dest : ENVIROMENT.development.path | |
ext : '.js' | |
extDot: 'last' | |
] | |
modules: | |
options: | |
sourceMap: false | |
files: [ | |
expand: true | |
cwd : 'app' | |
src : 'modules/**/*.coffee' | |
dest : ENVIROMENT.development.path | |
ext : '.js' | |
extDot: 'last' | |
] | |
copy: | |
views: | |
files: [ | |
expand: true | |
cwd : "app" | |
src : [ | |
'**/*.tpl.cfm' | |
'**/*.tpl.html' | |
'**/*.cfm' | |
'**/*.html' | |
'!**/*-dev.*cfm' | |
'!**/*-dev.*html' | |
] | |
dest : ENVIROMENT.development.path | |
] | |
assets: | |
files: [ | |
expand: true | |
cwd : "app" | |
src : [ | |
'**/*.jpg' | |
'**/*.png' | |
'**/*.svg' | |
] | |
dest : ENVIROMENT.development.path | |
] | |
modules_js: | |
files: [ | |
expand: true | |
cwd : "app" | |
src : ['modules/**/*.js'] | |
dest : ENVIROMENT.development.path | |
] | |
# *-dev.cfm, *-dev.inc.cfm | |
'string-replace': | |
all: | |
options: | |
replacements: [ | |
pattern: /\{?\{\{\s*(.*?)\s*\}\}\}?/g, | |
replacement: (found, $1, index, raw)-> | |
try | |
pattern_secure = /[^\w.]/g | |
#result = ENVIROMENT.development[($1.replace pattern_secure, '')] | |
result = eval 'ENVIROMENT.development.' + $1.replace pattern_secure, '' | |
catch err | |
result = `undefined` | |
result | |
] | |
files: [ | |
expand: true | |
cwd : "app" | |
src : ["**/*-dev.*cfm", "**/*-dev.*html"] | |
dest : ENVIROMENT.development.path | |
rename: (dest, src)-> | |
(dest + '/').replace(/\/\//g, '/') + src.replace('-dev.', '.') | |
] | |
watch: | |
options: livereload: true | |
grunt: | |
files: ['Gruntfile.coffee'] | |
options: reload: true | |
stylus_core: | |
files: ['app/core/**/*.styl'] | |
tasks: ['stylus:core', 'notify:done'] | |
stylus_module: | |
files: ['app/modules/**/*.styl'] | |
tasks: ['stylus:modules', 'notify:done'] | |
coffee_core: | |
files: ['app/core/**/*.coffee'] | |
tasks: ['newer:coffee:core', 'notify:done'] | |
coffee_modules: | |
files: ['app/modules/**/*.coffee'] | |
tasks: ['newer:coffee:modules', 'notify:done'] | |
# --------------------------------------------------------------------- | |
# copy: It will generated in registerTasksForWatch function | |
# --------------------------------------------------------------------- | |
#'string-replace': It will generated in registerTasksForWatch function | |
# --------------------------------------------------------------------- | |
registerTasksForWatch = (config, task)-> | |
for section of config[task] | |
if section is 'options' then continue | |
config.watch = config.watch || {} | |
config.watch[task + '_' + section] = files:[], tasks:['newer:' + task + ':' + section, 'notify:done'] | |
config[task][section].files.forEach (taskFile, index)-> | |
taskFile.src.forEach (item, index)-> | |
file = if item.substr(0, 1) is '!' then '!' + taskFile.cwd + '/' + item.substr(1) else taskFile.cwd + '/' + item | |
config.watch[task + '_' + section].files.push file | |
registerTasksForWatch ENVIROMENT[env].config, 'copy' | |
registerTasksForWatch ENVIROMENT[env].config, 'string-replace' | |
# set config in grunt | |
#grunt.initConfig ENVIROMENT[env].config | |
grunt.config.init ENVIROMENT[env].config | |
switch env | |
when 'development' | |
grunt.registerTask 'build', [ | |
'copy' | |
'stylus' | |
'coffee' | |
'string-replace' | |
'notify:done' | |
] | |
# TODO: deployment and production | |
else | |
grunt.registerTask 'build', [] | |
#/switch | |
grunt.registerTask 'default', ['build', 'watch'] | |
null | |
module.exports = gruntFunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment