Skip to content

Instantly share code, notes, and snippets.

@ddragosd
Last active December 20, 2015 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddragosd/6152020 to your computer and use it in GitHub Desktop.
Save ddragosd/6152020 to your computer and use it in GitHub Desktop.
Grunt JS script for Apache Sling with CoffeeScript
module.exports = (grunt) ->
# load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks)
# configurable paths
buildProperties = {
app: 'target/js',
dist: 'target/coffee/js',
sling_url: grunt.option('sling_url') || 'http://localhost:8080/content/js',
sling_username: grunt.option('sling_username') || 'admin',
sling_password : grunt.option('sling_password') || 'admin'
}
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config : buildProperties,
watch: {
coffee: {
files: [
'src/main/coffee/*.coffee',
'src/main/coffee/**/*.coffee',
],
# compile and deploy into Apache Sling
tasks: ['coffee:dist','concat','exec:sling_upload'],
},
coffeeTest: {
files: ['src/test/coffee/**/*.coffee'],
tasks: ['coffee:test']
},
less: {
files: ['src/main/resources/css/**/*.{less}'],
tasks: ['less']
},
options: {
livereload: 35729
}
},
open: {
server: {
url: 'localhost:8080/content/mediacenter/widgets/stats-widget.widget.html/content/channel/demo'
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'<%= config.dist %>/*',
]
}]
}
},
jshint: {
all: [
'<%= config.dist %>/**/*.js'
]
}
,coffee: {
dist: {
options: { sourceMap: true, sourceRoot: '' },
files: [{
expand: true,
join: true, # When compiling multiple .coffee files into a single .js file, concatenate first.
cwd: 'src/main/coffee',
src: '**/*.coffee',
dest: '<%= config.dist %>',
ext: '.js'
}]
}
,test: {
options: { sourceMap: true },
files: [{
expand: true,
cwd: 'src/test/coffee',
src: '**/*.coffee',
dest: 'target/test-classes/js',
ext: '.js'
}]
}
}
,less: {
server: {
files: {
'.tmp/styles/bootstrap.css' :'<%= config.app %>/components/bootstrap/less/bootstrap.less'
}
}
}
,concat:{
options:
separator: ';'
,dist:
# the files to concatenate
src: ['<%= config.dist %>/**/*.js']
# the location of the resulting JS file
dest: '<%= config.dist %>/mediacenter/<%= pkg.name %>-<%= pkg.version %>-SNAPSHOT.js'
}
,uglify: {
options:
# the banner is inserted at the top of the output
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
,dist:
files:
'<%= config.dist %>/mediacenter/<%= pkg.name %>-<%= pkg.version %>-SNAPSHOT.min.js': ['<%= concat.dist.dest %>']
}
# upload files into Apache Sling JCR
,'exec': {
sling_upload:
'cmd': ->
config = this.config('config')
pkg = this.config('pkg')
jsFile = this.config('concat').dist.dest
jsFileName = "#{pkg.name}-#{pkg.version}-SNAPSHOT.js"
c = """curl -i -X POST -F ":http-equiv-accept=application/json,*/*;q=0.9" -F#{jsFileName}=@#{jsFile}"""
c += " -u #{config.sling_username}:#{config.sling_password} #{config.sling_url}"
# grunt.log.write("this=#{this.config('concat').dist.dest}")
grunt.log.write("Executing : #{c}:")
return c
'stdout': false
'stderr':true
}
})
grunt.registerTask('live-dev', [
'clean:dist',
'coffee',
'concat',
'uglify',
'watch'
])
grunt.registerTask('build', [
'clean:dist',
'coffee'
'concat',
'uglify'
])
grunt.registerTask('default', ['build'])
{
"name": "stats_widget",
"version": "1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-less": "~0.5.0",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-exec": "~0.4.2",
"matchdep": "~0.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment