UNPKG

1.75 kBtext/coffeescriptView Raw
1#!/usr/bin/env coffee
2
3compile = (file, cb) ->
4 browserify = require 'browserify'
5
6 opts = {
7 debug: false
8 insertGlobalVars: {
9 global: (row, basedir) ->
10 return 'global || window'
11 }
12 }
13
14 b = browserify(opts)
15
16 b.add require('path').resolve file
17 b.transform require('coffeeify')
18 b.transform require('browserify-shim')
19 b.transform require('node-lessify')
20 b.transform require('brfs')
21
22 try
23 b.bundle (err, data) ->
24 return cb(err, null) if err
25
26 data = data?.toString?('utf8').replace?(/use strict/gm, "use strict-disabled")
27 # Make the global variable consistently and accurately defined in all contexts.
28 data = """
29 (function(global) {
30 if(!global) {
31 global = window || this;
32 }
33 // Make window. references in the RhinoJS environment still work.
34 if(global.window !== global && typeof global.window !== "undefined") {
35 for(prop in global.window) {
36 global[prop] = global.window[prop];
37 }
38 global.window = global;
39 }
40 global.global = global;
41 if(typeof global["setTimeout"] === 'undefined') {
42 global["setTimeout"] = function(f, to) {
43 f();
44 }
45 }
46 if(typeof global["clearTimeout"] === 'undefined') {
47 global["clearTimeout"] = function() {};
48 }
49 #{data}
50 })(this);
51 """
52
53 cb(null, data)
54 catch e
55 cb(e, null)
56
57if require.main == module
58 path = process.argv[2]
59 throw "Usage: compile.coffee <path>" unless path
60 compile path, (err, data) ->
61 if err
62 console.log "Error :(\n#{err}"
63 console.log data
64
65module.exports = compile