Skip to content

Instantly share code, notes, and snippets.

@pantaluna
Created March 4, 2014 09:00
Show Gist options
  • Save pantaluna/9342755 to your computer and use it in GitHub Desktop.
Save pantaluna/9342755 to your computer and use it in GitHub Desktop.
/*global module:false, require:false */
var pause = require("grunt-pause");
module.exports = function(grunt) {
pause.init(grunt);
// Project configuration.
grunt.initConfig({
// Extra Variables
mjdconfig: {
deploydir: "_build/deploy/root/" /* Format: Without leading slash, With trailing slash.*/
},
pkg:
grunt.file.readJSON('package.json'),
// http://gruntjs.com/api/grunt.file
// http://gruntjs.com/configuring-tasks#globbing-patterns
// https://github.com/jharding/grunt-exec
exec: {
cd: { cmd: 'cd' },
dir_files: { cmd: 'dir' },
echo_grunt_version: { cmd: function() { return 'echo ' + this.version; } },
multiple_commands: { command: ['cd','dir'].join('&&') },
prepare_build: {
cwd: '_build',
cmd: 'preparebuild.cmd'
}
},
// https://github.com/gruntjs/grunt-contrib-jshint
jshint: {
options: {
'-W003': true, // W003: 'name' was used before it was defined.
'-W079': true, // W079: Redefinition of ('console' in my error report)
'-W099': true, // W099: Mixed spaces and tabs.
curly: true,
//eqeqeq: true,
latedef: true,
newcap: false,
trailing: false,
undef: true,
laxcomma: true,
smarttabs: true,
sub: true,
browser: true,
devel: true,
jquery: true,
node: true,
nonstandard: true,
globals: {
"_gaq": false,
'ActiveXObject': false,
'Back': false,
'changeStatus': false,
'cbpAnimatedHeader': false,
'cbpScroller': false,
'createElement': false,
'DOMParse': false,
'GetObject': false,
'NProgress': false,
'TimelineMax': false
}
},
dev: {
src: [
'Gruntfile.js',
'assets/js/ga.js',
'assets/js/jqm-global.js',
'assets/js/jqm-mobileinit.js',
'assets/js/jqm-page-logic.js',
'assets/js/jsrender-helpers.js',
'assets/js/lib-mjd.js',
'assets/js/loader.js',
'assets/js/mjdtwitterserviceapi.js',
'assets/js/mysettings-mgr.js',
'assets/js/mytweets-mgr.js'
]
}
},
// https://github.com/gruntjs/grunt-contrib-clean
clean: {
build: ['<%= mjdconfig.deploydir %>']
},
// https://github.com/gruntjs/grunt-contrib-htmlmin
htmlmin: {
build: {
options: {
removeComments: true
},
files: {
'<%= mjdconfig.deploydir %>none.php':
'<%= mjdconfig.deploydir %>none.php'
}
}
},
// https://github.com/gruntjs/grunt-contrib-uglify
uglify: {
build: {
options: {
banner: '/*! MJD Uglify <%= grunt.template.today("yyyy-mm-dd") %> */\n',
compress: {
unused: false
},
mangle: true, // 1. Mangle AFTER Compress. | 2. If the mangled JS does not work anymore Then set mangle=false!
report: 'min'
},
files: [
{
expand: true,
cwd: '<%= mjdconfig.deploydir %>',
src:['assets/js/**/*.js','!**/*.min.js'],
dest:'<%= mjdconfig.deploydir %>',
ext: '.min.js'
},
]
}
},
uglify_post_delete_sources: {
build: {
files: [
{
expand: true,
cwd: '<%= mjdconfig.deploydir %>',
src:['assets/js/**/*.js','!**/*.min.js'],
dest:'<%= mjdconfig.deploydir %>', // This line has no effect, it is a duplicate of the uglify section.
ext: '.min.js'
},
]
}
},
cssmin: {
build: {
options: {
banner: '/*! MJD cssmin <%= grunt.template.today("yyyy-mm-dd") %> */\n',
compress: {
unused: false
},
report: 'min'
},
files: [
{
expand: true,
cwd: '<%= mjdconfig.deploydir %>',
src:['assets/css/**/*.css','!**/*.min.css'],
dest:'<%= mjdconfig.deploydir %>',
ext: '.min.css'
},
]
}
},
cssmin_post_delete_sources: {
build: {
files: [
{
expand: true,
cwd: '<%= mjdconfig.deploydir %>',
src:['assets/css/**/*.css','!**/*.min.css'],
dest:'<%= mjdconfig.deploydir %>', // This line has no effect, it is a duplicate of the cssmin section.
ext: '.min.css'
},
]
}
},
replace: {
htmlheaderphp: {
overwrite: true,
src: ['<%= mjdconfig.deploydir %>assets/templates/_html_header.php'],
replacements: [
// CSS
{from: 'assets/css/custom1.css', to: 'assets/css/custom1.min.css'},
{from: 'assets/css/nprogress/component.css', to: 'assets/css/nprogress/component.min.css'},
// JS
{from: 'assets/js/loader.js', to: 'assets/js/loader.min.js'}
]
},
mypageclassphp: {
overwrite: true,
src: ['<%= mjdconfig.deploydir %>assets/php-classes/mypage.class.php'],
replacements: [
// PHP /* Keep debuglog enabled for the moment! */
{from: 'XXXXX_objMjdLib->debugEnable()', to: 'XXXXX_objMjdLib->debugDisable()'}
// CSS
// JS
]
},
loaderminjs: {
overwrite: true,
src: ['<%= mjdconfig.deploydir %>assets/js/loader.min.js'],
replacements: [
// JS SPECIALS
{from: 'strEnvironmentType:mjdApp.myConstants.environmentType.DEVELOPMENT',
to: 'strEnvironmentType:mjdApp.myConstants.environmentType.PRODUCTION'
},
// CSS
// JS
{from: 'assets/js/vendor/json2-20130526.js', to: 'assets/js/vendor/json2-20130526.min.js'},
{from: 'assets/js/vendor/nprogress/component.js', to: 'assets/js/vendor/nprogress/component.min.js'},
{from: 'assets/js/ga.js', to: 'assets/js/ga.min.js'},
{from: 'assets/js/jqm-global.js', to: 'assets/js/jqm-global.min.js'},
{from: 'assets/js/jqm-mobileinit.js', to: 'assets/js/jqm-mobileinit.min.js'},
{from: 'assets/js/jqm-page-logic.js', to: 'assets/js/jqm-page-logic.min.js'},
{from: 'assets/js/jsrender-helpers.js', to: 'assets/js/jsrender-helpers.min.js'},
{from: 'assets/js/lib-mjd.js', to: 'assets/js/lib-mjd.min.js'},
{from: 'assets/js/mjdtwitterserviceapi.js', to: 'assets/js/mjdtwitterserviceapi.min.js'},
{from: 'assets/js/mysettings-mgr.js', to: 'assets/js/mysettings-mgr.min.js'},
{from: 'assets/js/mytweets-mgr.js', to: 'assets/js/mytweets-mgr.min.js'}
]
}
}
});
// Load Grunt plugins.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-text-replace');
// Define my custom tasks
grunt.registerMultiTask("uglify_post_delete_sources", "JS Uglify - Post Actions", function() {
//grunt.log.writeln([this.name,this.target]);
this.files.forEach( function(pOneFileItem) {
grunt.file.delete(pOneFileItem.src);
grunt.log.writeln('Executing grunt.file.delete ' + pOneFileItem.src);
});
});
grunt.registerMultiTask("cssmin_post_delete_sources", "CSSmin - Post Actions", function() {
//grunt.log.writeln([this.name,this.target]);
this.files.forEach( function(pOneFileItem) {
grunt.file.delete(pOneFileItem.src);
grunt.log.writeln('Executing grunt.file.delete ' + pOneFileItem.src);
});
});
// Register the default tasks.
grunt.registerTask('default',[
'jshint:dev',
'clean:build','exec:prepare_build',
'uglify:build','uglify_post_delete_sources:build',
'cssmin:build','cssmin_post_delete_sources:build',
'replace:htmlheaderphp','replace:mypageclassphp','replace:loaderminjs'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment