Instantly share code, notes, and snippets.
Created
April 9, 2017 14:36
-
Save zealfire/270ef33cb6f7f89339c0cb0729e44c61 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
/*! | |
* FireShell Gruntfile | |
* http://getfireshell.com | |
* @author Todd Motto | |
*/ | |
'use strict'; | |
/** | |
* Livereload and connect variables | |
*/ | |
var LIVERELOAD_PORT = 35729; | |
var lrSnippet = require('connect-livereload')({ | |
port: LIVERELOAD_PORT | |
}); | |
var mountFolder = function(connect, dir) { | |
return require('serve-static')(require('path').resolve(dir)); | |
}; | |
/** | |
* Grunt module | |
*/ | |
module.exports = function(grunt) { | |
/** | |
* Dynamically load npm tasks | |
*/ | |
require('load-grunt-tasks')(grunt); | |
grunt.loadNpmTasks('grunt-contrib-requirejs'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
var fileName = grunt.option('fileName'); | |
/** | |
* FireShell Grunt config | |
*/ | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
/** | |
* Set project info | |
*/ | |
project: { | |
src: 'src', | |
app: 'webapp', | |
assets: '<%= project.app %>/static/assets', | |
css: [ | |
'<%= project.assets %>/css/scss/base.scss' | |
], | |
js: [ | |
'<%= project.src %>/js/**/*.js' | |
] | |
}, | |
/** | |
* Project banner | |
* Dynamically prepand to CSS/JS files | |
* Inherits text from package.json | |
*/ | |
tag: { | |
banner: '/*!\n' + | |
' * <%= pkg.name %>\n' + | |
' * <%= pkg.title %>\n' + | |
' * <%= pkg.url %>\n' + | |
' * @author <%= pkg.author %>\n' + | |
' * @version <%= pkg.version %>\n' + | |
' * Copyright <%= pkg.copyright %>. <%= pkg.license %> licensed.\n' + | |
' */\n' | |
}, | |
usebanner: { | |
taskName: { | |
options: { | |
position: 'top', | |
banner: '<%= tag.banner %>', | |
linebreak: true | |
}, | |
files: { | |
src: ['<%= project.assets %>/css/style.min.css', | |
'<%= project.assets %>/js/scripts.min.js' | |
] | |
} | |
} | |
}, | |
/** | |
* Connect port/livereload | |
* https://github.com/gruntjs/grunt-contrib-connect | |
* Starts a local webserver and injects | |
* livereload snippet | |
*/ | |
connect: { | |
options: { | |
port: 9992, | |
hostname: '*' | |
}, | |
livereload: { | |
options: { | |
middleware: function(connect) { | |
return [lrSnippet, mountFolder(connect, 'webapp')]; | |
} | |
} | |
} | |
}, | |
/** | |
* Clean files and folders | |
* https://github.com/gruntjs/grunt-contrib-clean | |
* Remove generated files for clean deploy | |
*/ | |
clean: { | |
dist: [ | |
'<%= project.assets %>/css/style.unprefixed.css', | |
'<%= project.assets %>/css/style.prefixed.css' | |
] | |
}, | |
/** | |
* JSHint | |
* https://github.com/gruntjs/grunt-contrib-jshint | |
* Manage the options inside .jshintrc file | |
*/ | |
jshint: { | |
files: [ | |
'src/js/**/*.js', | |
'Gruntfile.js' | |
], | |
options: { | |
jshintrc: '.jshintrc' | |
} | |
}, | |
/** | |
* Concatenate JavaScript files | |
* https://github.com/gruntjs/grunt-contrib-concat | |
* Imports all .js files and appends project banner | |
*/ | |
concat: { | |
dev: { | |
files: { | |
'<%= project.assets %>/js/scripts.min.js': '<%= project.js %>' | |
} | |
}, | |
options: { | |
stripBanners: true, | |
nonull: true, | |
} | |
}, | |
/** | |
* Uglify (minify) JavaScript files | |
* https://github.com/gruntjs/grunt-contrib-uglify | |
* Compresses and minifies all JavaScript files into one | |
*/ | |
uglify: { | |
bonita: { | |
options: { | |
mangle: false | |
}, | |
files: [{ | |
expand: true, // Enable dynamic expansion. | |
cwd: '<%= project.app %>/static/bpm/', // Src matches are relative to this path. | |
src: [ | |
[fileName + '/resources/widgets/custom_widget.js'] | |
], // Actual pattern(s) to match. | |
dest: '<%= project.app %>/static/bpm/', // Destination path prefix. | |
ext: '.min.js', // Dest filepaths will have this extension. | |
rename: function(dest, src) { // The `dest` and `src` values can be passed into the function | |
return dest + src; // The `src` is being renamed; the `dest` remains the same | |
} | |
}, ] | |
} | |
}, | |
/** | |
* Compile Sass/SCSS files | |
* https://github.com/gruntjs/grunt-contrib-sass | |
* Compiles all Sass/SCSS files and appends project banner | |
*/ | |
sass: { | |
dev: { | |
options: { | |
style: 'expanded' | |
}, | |
files: { | |
'<%= project.assets %>/css/style.unprefixed.css': '<%= project.css %>' | |
} | |
}, | |
dist: { | |
options: { | |
style: 'expanded' | |
}, | |
files: { | |
'<%= project.assets %>/css/style.unprefixed.css': '<%= project.css %>' | |
} | |
} | |
}, | |
/** | |
* Autoprefixer | |
* Adds vendor prefixes automatically | |
* https://github.com/nDmitry/grunt-autoprefixer | |
*/ | |
autoprefixer: { | |
options: { | |
browsers: [ | |
'last 2 version', | |
'safari 6', | |
'ie 9', | |
'opera 12.1', | |
'ios 6', | |
'android 4' | |
] | |
}, | |
dev: { | |
files: { | |
'<%= project.assets %>/css/style.min.css': [ | |
'<%= project.assets %>/css/style.unprefixed.css' | |
] | |
} | |
}, | |
dist: { | |
files: { | |
'<%= project.assets %>/css/style.prefixed.css': [ | |
'<%= project.assets %>/css/style.unprefixed.css' | |
] | |
} | |
} | |
}, | |
/** | |
* CSSMin | |
* CSS minification | |
* https://github.com/gruntjs/grunt-contrib-cssmin | |
*/ | |
cssmin: { | |
bonita: { | |
options: { | |
style: 'expanded' | |
}, | |
files: [{ | |
expand: true, // Enable dynamic expansion. | |
cwd: '<%= project.app %>/static/bpm/', // Src matches are relative to this path. | |
src: [ | |
[fileName + '/resources/assets/css/custom_widget_css.css'] | |
], // Actual pattern(s) to match. | |
dest: '<%= project.app %>/static/bpm/', // Destination path prefix. | |
ext: '.min.css', // Dest filepaths will have this extension. | |
rename: function(dest, src) { // The `dest` and `src` values can be passed into the function | |
return dest + src; // The `src` is being renamed; the `dest` remains the same | |
} | |
}, ] | |
} | |
}, | |
/** | |
* Opens the web server in the browser | |
* https://github.com/jsoverson/grunt-open | |
*/ | |
open: { | |
server: { | |
path: 'http://localhost:<%= connect.options.port %>' | |
} | |
} | |
}); | |
grunt.option('fileName'); | |
grunt.registerTask('minifyBonita', 'helps to minify js coming from bonita generated forms', function() { | |
grunt.task.run('uglify:bonita'); | |
}); | |
grunt.registerTask('minifyBonitaCss', 'helps to minify css coming from bonita generated forms', function() { | |
grunt.task.run('cssmin:bonita'); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment