-
Notifications
You must be signed in to change notification settings - Fork 132
/
Cakefile
53 lines (44 loc) · 1.57 KB
/
Cakefile
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
{spawn, exec} = require 'child_process'
fs = require('fs')
require('coffee-script/register')
run = (args, cb) ->
proc = spawn './node_modules/.bin/coffee', args
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
proc.on 'exit', (status) ->
process.exit(1) if status != 0
cb() if typeof cb is 'function'
build = (cb) ->
files = fs.readdirSync 'src'
files = ('src/' + file for file in files when file.match(/\.coffee$/))
run ['-c', '-o', 'lib'].concat(files), cb
task 'build', 'Run full build', ->
invoke 'build:compile'
invoke 'build:parser'
setTimeout (-> invoke 'build:browser'), 100
task 'build:compile', 'Compile all coffee files to js',
build
task 'build:parser', 'rebuild the Jison parser', ->
parser = require('./src/grammar').parser
fs.writeFileSync 'lib/compiled_parser.js', parser.generate()
task 'build:browser', 'Build a single JS file suitable for use in the browser', ->
code = ''
for name in ['lexer', 'compiled_parser', 'nodes', 'parser', 'sql_parser']
code += """
require['./#{name}'] = new function() {
var exports = this;
#{fs.readFileSync "lib/#{name}.js"}
};
"""
code = """
(function(root) {
var SQLParser = function() {
function require(path){ return require[path]; }
#{code}
return require['./sql_parser']
}();
if(typeof define === 'function' && define.amd) {
define(function() { return SQLParser });
} else { root.SQLParser = SQLParser }
}(this));
"""
fs.writeFileSync './browser/sql-parser.js', code