lib/entityjs/commands/build.rb in entityjs-0.3.0 vs lib/entityjs/commands/build.rb in entityjs-0.3.1
- old
+ new
@@ -12,12 +12,10 @@
return 2
end
Config.instance.reload
- license = Config.instance.license
-
if name.nil? || name.empty?
date = Time.now.strftime('%s')
name = "build-#{date}"
else
name = name.first
@@ -27,10 +25,13 @@
assets_folder = Config.assets_folder
images_folder = Config.images_folder
sounds_folder = Config.sounds_folder
scripts_folder = Config.scripts_folder
+ final_name = 'game.min.js'
+ html_name = 'play.html'
+
#build if it doesn't exist
Dirc.create_dir('builds', true)
#create new directory
if Dir.exists?(name)
@@ -58,55 +59,36 @@
end
#append all files into one big file
puts "Compiling code"
- out = ''
- scripts = Dirc.find_scripts(Config.instance.scripts_ignore, Config.instance.scripts_order)
- entities = Dirc.find_entity_src(Config.instance.entity_ignore)
+ entity_src = self.compile_entity(Config.instance.entity_ignore)
+ scripts = self.compile_scripts(Config.instance.scripts_ignore, Config.instance.scripts_order)
- entities.each do |i|
- out += "\n"
- out += IO.read(i)
- out += "\n"
- end
+ out = entity_src+scripts
- #add version
- out = out.gsub(/\$VERSION/, Entityjs::VERSION)
-
- scripts.each do |i|
- out += "\n"
- out += IO.read(i)
- out += "\n"
- end
-
- #add levels, animations etc data
- out += Assets.to_js
-
-
#minify
puts "Almost done..."
#save
- File.open('game.min.js', 'w') do |f|
- f.write(license)
+ File.open(final_name, 'w') do |f|
- f.write(Uglifier.compile(out, :copyright=>false))
+ f.write(self.minify(out))
f.close
end
-
#create play.html
puts "Creating play page"
- File.open('play.html', 'w') do |f|
+ File.open(html_name, 'w') do |f|
f.write(%Q(<!DOCTYPE html>
<html>
<head>
- <script src='game.min.js' type='text/javascript'></script>
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
+ <script src='#{final_name}' type='text/javascript'></script>
</head>
<body>
<canvas id='#{Config.instance.canvas_id}' width='#{Config.instance.width}' height='#{Config.instance.height}'>Error browser does not support canvas element.</canvas>
</body>
</html>
@@ -119,9 +101,56 @@
puts " #{builds_folder}/#{name}"
Dirc.to_game_root
return 0
+ end
+
+ #compiles all entity source and returns it
+ def self.compile_entity(ignore = nil)
+ out = ''
+ entities = Dirc.find_entity_src(ignore)
+ entities.each do |i|
+ out += "\n"
+ out += IO.read(i)
+ out += "\n"
+ end
+
+ #add version
+ out = out.gsub(/\$VERSION/, Entityjs::VERSION)
+
+ return out
+ end
+
+ #compiles all game source and returns it
+ def self.compile_scripts(ignore = nil, order=nil)
+ scripts = Dirc.find_scripts(ignore, order)
+
+ out = ''
+
+ scripts.each do |i|
+ out += "\n"
+ out += IO.read(i)
+ out += "\n"
+ end
+
+ #add levels, animations etc data
+ out += Assets.to_js
+
+ return out
+ end
+
+ #minifies source and returns it
+ def self.minify(code, license=true)
+
+ code = Uglifier.compile(code, :copyright=>false)
+
+ #add entity license statement
+ if license
+ code = Config.instance.license + code
+ end
+
+ return code
end
end
end
\ No newline at end of file