Skip to content

Instantly share code, notes, and snippets.

@danhper
Created November 5, 2014 17:28
Show Gist options
  • Save danhper/9218085eefd691ecf846 to your computer and use it in GitHub Desktop.
Save danhper/9218085eefd691ecf846 to your computer and use it in GitHub Desktop.
Leaves hooks for Dart.
path = require 'path'
fs = require 'fs-extra'
_ = require 'lodash'
request = require 'request'
baseOutput = path.join __dirname, '.build'
module.exports = (grunt) ->
reloadPort = grunt.config.get('watch.livereload.options.livereload.port')
_.each ['watch.assets.files', 'watch.assetsGlob.files'], (key) ->
watched = grunt.config.get(key)
watched.push('!assets/**/*.dart')
grunt.config.set(key, watched)
grunt.config.set 'watch.dart',
files: ['assets/dart/**/*']
tasks: ['brerror:compileDart:tmp']
grunt.registerTask 'beforeCoffee', 'Compile dart', (env) ->
grunt.task.run "compileDart:#{env}"
grunt.registerTask 'compileDart', 'Compile Dart', (env) ->
output = path.join((if env == 'tmp' then 'tmp' else 'dist'), 'dart')
fs.removeSync output
done = @async()
grunt.util.spawn
cmd: 'pub'
args: ['build', '-o', baseOutput]
opts:
cwd: path.join(__dirname, 'assets', 'dart')
, (err, res, code) ->
if err?
grunt.fail.warn(err.message)
else
fs.copySync path.join(baseOutput, 'web'), path.join(output)
request.get 'http://localhost:' + reloadPort + '/changed?files=main.dart.js', (err, res) ->
done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment