Created
November 19, 2013 15:01
-
-
Save l04m33/7546640 to your computer and use it in GitHub Desktop.
Automatic Grunt layout
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
#!/bin/sh | |
function eject() { | |
local msg=$1 | |
echo "$msg" 1>&2 | |
exit 1 | |
} | |
npm init || eject "'npm init' failed" | |
packages="grunt grunt-contrib-uglify grunt-contrib-concat \ | |
grunt-contrib-jshint grunt-contrib-watch" | |
for p in $packages; do | |
npm install --save-dev "$p" || eject "Failed to install '$p'" | |
done | |
cat << EOF > Gruntfile.js | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
concat: { | |
options: { | |
separator: ';' | |
}, | |
dist: { | |
src: ['src/**/*.js'], | |
dest: 'build/<%= pkg.name %>.cat.js' | |
} | |
}, | |
uglify: { | |
options: { | |
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' | |
}, | |
build: { | |
src: '<%= concat.dist.dest %>', | |
dest: 'build/<%= pkg.name %>.min.js' | |
} | |
}, | |
jshint: { | |
files: ['src/**/*.js'], | |
options: { | |
globals: { | |
jQuery: true, | |
console: true, | |
module: true | |
} | |
} | |
}, | |
watch: { | |
files: ['<%= jshint.files %>'], | |
tasks: ['jshint'] | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.registerTask('default', ['concat', 'uglify']); | |
}; | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment