aboutsummaryrefslogtreecommitdiffstats
path: root/Cakefile
blob: 97927f03b5cf42a0686dcf21416f66b7dbcc5f5c (plain)
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
fs = require "fs"
path = require "path"
child_process = require "child_process"

spawn = (procName, optArray, silent=false) ->
  proc = child_process.spawn procName, optArray
  unless silent
    proc.stdout.on 'data', (data) -> process.stdout.write data
    proc.stderr.on 'data', (data) -> process.stderr.write data
  proc

optArrayFromDict = (opts) -> "--#{key}=#{value}" for key, value of opts

task "build", "compile all coffeescript files to javascript", ->
  coffee = spawn "coffee", ["-c", __dirname]

task "clean", "removes any js files which were compiled from coffeescript", ->
  visit = (directory) ->
    fs.readdirSync(directory).forEach (filename) ->
      filepath = path.join directory, filename
      if (fs.statSync filepath).isDirectory()
        return visit filepath

      return unless (path.extname filename) == ".js" and (fs.statSync filepath).isFile()

      # Check if there exists a corresponding .coffee file
      try
        coffeeFile = fs.statSync path.join directory, "#{path.basename filepath, ".js"}.coffee"
      catch _
        return

      fs.unlinkSync filepath if coffeeFile.isFile()

  visit __dirname

task "autobuild", "continually rebuild coffeescript files using coffee --watch", ->
  coffee = spawn "coffee", ["-cw", __dirname]

task "package", "build .crx file", ->
  invoke "build"

  # ugly hack to modify our manifest file on-the-fly
  origManifestText = fs.readFileSync "manifest.json"
  manifest = JSON.parse origManifestText
  manifest.update_url = "http://philc.github.com/vimium/updates.xml"
  fs.writeFileSync "manifest.json", JSON.stringify manifest

  crxmake = spawn "crxmake", optArrayFromDict
    "pack-extension": "."
    "pack-extension-key": "vimium.pem"
    "extension-output": "vimium-latest.crx"
    "ignore-file": "(^\\.|\\.(coffee|crx|pem|un~)$)"
    "ignore-dir": "^(\\.|test)"

  crxmake.on "exit", -> fs.writeFileSync "manifest.json", origManifestText

task "test", "run all tests", ->
  console.log "Running unit tests..."
  basedir = "tests/unit_tests/"
  test_files = fs.readdirSync(basedir).filter((filename) -> filename.indexOf("_test.js") > 0)
  test_files = test_files.map((filename) -> basedir + filename)
  test_files.forEach (file) -> require "./" + file
  Tests.run()
  returnCode = if Tests.testsFailed > 0 then 1 else 0

  console.log "Running DOM tests..."
  phantom = spawn "phantomjs", ["./tests/dom_tests/phantom_runner.js"]
  phantom.on 'exit', (code) ->
    returnCode += code
    process.exit returnCode