import os, zipfile
from compile_templates import compile_jMatic

package_entities = [
  'css',
  'img',
  'js',
  'lib',
  'index.html'
]

def zipdir(path, zip):
    for root, dirs, files in os.walk(path):
        for file in files:
            zip.write(os.path.join(root, file))

def package_jMatic():
    zipf = zipfile.ZipFile('jMatic.zip', 'w')
    for entity in package_entities:
      if os.path.isfile(entity):
        zipf.write(entity)
      elif os.path.isdir(entity):
        zipdir(entity, zipf)
    zipf.close()

if __name__=='__main__':
  compile_jMatic()
  package_jMatic()
@@ -1,12 +1,126 @@
+# package all files needed for a standalone release version,%0A# zip them up and put them into the build directory.%0A
 import os, z
@@ -125,16 +125,24 @@
  zipfile
+, shutil
 %0Afrom co
@@ -427,54 +427,227 @@
     
-zipf = zipfile.ZipFile('jMatic.zip', 'w')%0A
+# clean build dir%0A    build_dir = './build/'%0A    shutil.rmtree(build_dir, True)%0A    os.makedirs(build_dir)%0A    %0A    zipped_release = build_dir + 'jMatic.zip'%0A    with zipfile.ZipFile(zipped_release, 'w') as zipf:%0A 
     
+ 
 for 
@@ -670,24 +670,26 @@
 e_entities:%0A
+  
       if os.
@@ -713,24 +713,26 @@
 y):%0A        
+  
 zipf.write(e
@@ -744,16 +744,18 @@
 )%0A      
+ 
+ 
 elif os.
@@ -782,16 +782,18 @@
         
+  
 zipdir(e
@@ -805,16 +805,18 @@
 , zipf)%0A
+  
     zipf
@@ -823,16 +823,152 @@
 .close()
+%0A    %0A    # also extract to build dir%0A    with zipfile.ZipFile(zipped_release, 'r') as zipf:%0A      zipf.extractall(build_dir + 'jMatic')
 %0A%0Aif __n

package application in build directory