Skip to content

Instantly share code, notes, and snippets.

@beraldo
Last active August 29, 2015 14:05
Show Gist options
  • Save beraldo/1495a6b10d336b679412 to your computer and use it in GitHub Desktop.
Save beraldo/1495a6b10d336b679412 to your computer and use it in GitHub Desktop.
Creates a Gruntfile.js, uglifying all .js files in a given dir. All <file>.js will be uglified and saved as <file>.min.js, in the same dir
#!/bin/bash
#
# Creates a Gruntfile.js, uglifying all .js files in a given dir
# All <file>.js will be uglified and saved as <file>.min.js, in the same dir
#
# EXECUTE THIS SCRIPT IN THE ROOT OF YOUR PROJECT, WHERE THE Gruntfile.js SHALL BE PLACED
# Path to JS dir, from where the files will be uglified
JS_DIR="public/js"
IFS='' read -r -d '' CONTENT <<'EOF'
module.exports = function( grunt )
{
grunt.initConfig(
{
uglify : {
options : {
mangle : false
},
targets : {
files : {
_files_
}
}
} // uglify
});
// Grunt Plugins
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
// register default task
grunt.registerTask( 'default', [ 'uglify' ] );
};
EOF
files=$(find $JS_DIR -maxdepth 1 -type f | egrep '\.js$' | grep -v 'min\.js')
filesString=""
for file in $files
do
uglyfiedFile=${file/.js/.min.js}
filesString=$filesString"\t\t\t\t'$uglyfiedFile' : [ '${file}' ],\n"
done
len=${#filesString}
filesString=${filesString:0:len-3}
CONTENT=${CONTENT/_files_/$filesString}
echo -e "$CONTENT" > Gruntfile.js
echo "OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment