Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 87 lines (69 sloc) 2.335 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
browserify = require 'browserify'
fs = require 'fs'
sp = require('uglify-js').parser
pro = require('uglify-js').uglify
{series} = require 'async'
{exec} = require 'child_process'

process.env['PATH'] = "node_modules/.bin:#{ process.env['PATH'] }"

bold = '\x1b[0;1m'
red = '\x1b[0;31m'
green = '\x1b[0;32m'
reset = '\x1b[0m'

log = (message, color = green) -> console.log "#{ color }#{ message }#{ reset }"

onerror = (err) ->
  if err
    process.stdout.write "#{ red }#{ err.stack }#{ reset }\n"
    process.exit -1

test = (cb) ->
  exec 'jasmine-node --coffee spec', (err, stdout, stderr) ->
    msg = /(\d+) tests?, (\d+) assertions?, (\d+) failures?/
    matches = stdout.match msg || stderr.match msg
    cb new Error('Tests failed') if matches[3] != '0'
    log matches[0]
    cb err

task 'test', 'Run all tests', -> test onerror

publish = (cb) ->

  browserPackage = (cb) ->
    fs.readFile 'package.json', 'utf8', (err, p) ->
      onerror err
      p = JSON.parse p
      throw new Exception 'Invalid package.json' if !p.version

      log "Update compiler dist for #{ p.version }"
      b = browserify()
      b.require "#{ __dirname }/lib/haml-coffee"

      code = b.bundle()
      fs.writeFileSync 'dist/compiler/hamlcoffee.js', code

      ast = sp.parse code
      ast = pro.ast_mangle ast
      ast = pro.ast_squeeze ast

      min = pro.gen_code ast
      fs.writeFileSync 'dist/compiler/hamlcoffee.min.js', min

      exec "git commit -am 'Update compiler dist for #{ p.version }'", (err, stdout, stderr) ->
        log stdout
        cb err

  npmPublish = (cb) ->
    log 'Publishing to NPM'
    exec 'npm publish', (err, stdout, stderr) ->
      log stdout
      cb err

  tagVersion = (cb) ->
    fs.readFile 'package.json', 'utf8', (err, p) ->
      onerror err
      p = JSON.parse p
      throw new Exception 'Invalid package.json' if !p.version
      log "Tagging v#{ p.version }"
      exec "git tag v#{ p.version }", (err, stdout, stderr) ->
        log stdout
        cb err

  pushGithub = (cb) ->
    exec 'git push --tag origin master', (err, stdout, stderr) ->
      log stdout
      cb err

  series [
    test
    browserPackage
    tagVersion
    pushGithub
    npmPublish
  ], cb

task 'publish', 'Prepare build and push new version to NPM', -> publish onerror
Something went wrong with that request. Please try again.