forked from Jivings/jsJVM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCakefile
More file actions
126 lines (108 loc) · 4.17 KB
/
Cakefile
File metadata and controls
126 lines (108 loc) · 4.17 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
JAVA_HOME = '/usr/lib/jvm/java-6-openjdk/'
fs = require 'fs'
util = require 'util'
{spawn, exec} = require 'child_process'
appFiles = [
'src/jvm/JVM.coffee',
'src/jvm/InternalObjects.coffee'
]
javaFiles = [
]
workers = [
'src/jvm/Thread.coffee'
]
task 'watch', 'Build project from src/*.coffee to bin/*.js', ->
exec 'mkdir -p bin/js/'
coffee = spawn 'coffee', ['-cw', '-o', 'bin/js', 'src']
coffee.stdout.on 'data', (data) -> console.log data.toString().trim()
task 'clean', 'Clean /bin/*.js files', ->
exec 'ls bin/js/*.js', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
task 'coffeeFiles', 'how much coffee you got?!', ->
traverseFileSystem = (currentPath) ->
files = fs.readdirSync currentPath
for file in files
do (file) ->
currentFile = currentPath + '/' + file
stats = fs.statSync(currentFile)
if stats.isFile() and currentFile.indexOf('.coffee') > 1 and appFiles.join('=').indexOf("#{currentFile}=") < 0
if workers.join('=').indexOf("#{currentFile}") < 0
#util.log currentFile
appFiles.push currentFile
else if stats.isDirectory()
traverseFileSystem currentFile
traverseFileSystem 'src'
util.log "#{appFiles.length} coffee files found."
return appFiles
task 'javaFiles', 'Compile custom Java API files', ->
traverseFileSystem = (currentPath) ->
files = fs.readdirSync currentPath
for file in files
do (file) ->
currentFile = currentPath + '/' + file
stats = fs.statSync(currentFile)
if stats.isFile() and currentFile.indexOf('.java') > 1 and appFiles.join('=').indexOf("#{currentFile}=") < 0
if workers.join('=').indexOf("#{currentFile}") < 0
javaFiles.push currentFile
else if stats.isDirectory()
traverseFileSystem currentFile
traverseFileSystem 'src'
util.log "#{javaFiles.length} java files found."
return appFiles
task 'compile', 'Compile', ->
invoke 'javaFiles'
len = javaFiles.length
util.log 'Compiling...'
try
stats = fs.lstatSync('deploy/jre/rt')
catch e # catch if the dir doesn't exist
fs.mkdir 'deploy/jre/rt', 0755
for file, index in javaFiles then do (file, index) ->
exec "javac -cp src/lib/rt -d deploy/jre/rt " + file, (err, stdout, stderr) ->
if err
util.log "Error! #{err}"
#else
# util.log "Compiled Java Class #{file}"
task 'dist', 'Zip that stuff', ->
util.log "Creating tarball..."
date = new Date()
day = date.getDate()
month = date.getMonth()
year = date.getFullYear()
# zip that awesome shit up
exec "tar -cf builds/jvm-latest.tar deploy/*", (err, stdout, stderr) ->
if err then util.log err
exec "bzip2 -f builds/jvm-latest.tar", (err, stdout, stderr) ->
if err then util.log err
exec "cp builds/jvm-latest.tar.bz2 builds/jvm-#{day}-#{month}-#{year}.tar.bz2", (err, stdout, stderr) ->
if err then util.log err
else util.log "Brewed successfully."
task 'build', 'Build single application file from source files', ->
invoke 'coffeeFiles'
util.log 'Building...'
appContents = new Array remaining = appFiles.length
for file, index in appFiles then do (file, index) ->
fs.readFile file, 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
process() if --remaining is 0
util.log "Creating workers..."
for file, index in workers then do (file, index) ->
exec "coffee --compile -o deploy/jre/workers #{file}", (err, stdout, stderr) ->
if err
util.log 'Error compiling src.'
util.log err
invoke "compile"
process = ->
fs.writeFile 'deploy/jre/jvm.coffee', appContents.join('\n\n'), 'utf8', (err) ->
throw err if err
exec 'coffee --compile deploy/jre/jvm.coffee', (err, stdout, stderr) ->
if err
util.log err
util.log 'Error compiling coffee file.'
else
fs.unlink 'deploy/jre/jvm.coffee', (err) ->
if err
util.log 'Couldn\'t delete the app.coffee file/'
util.log 'Done brewing coffee.'