Explorar el Código

Added wnJSCompiler that does the js preprocessing for ondemand js

version-14
Pratik Vyas hace 14 años
padre
commit
5aacd1ea75
Se han modificado 2 ficheros con 75 adiciones y 1 borrados
  1. +74
    -0
      cgi-bin/compilejs.py
  2. +1
    -1
      cgi-bin/webnotes/utils/jstimestamp.py

+ 74
- 0
cgi-bin/compilejs.py Ver fichero

@@ -0,0 +1,74 @@
class wnJSCompiler:
def concate_files_in_subdirs(self,path,dest):
"""
Concatenates all files in a subdir (recursive)
"""
import os
allfiles = []
for root, subdir, files in os.walk(path):
for filename in files:
allfiles.append(os.path.join(root,filename))
print path
print allfiles
print '----'
fout = open(dest,'w')
for filename in allfiles:
f = open(filename)
fout.write(f.read())
f.close
fout.close
def getsubs(self,path):
"""
gets all the sub directories of a directory (recursive)
"""
import os
subs = []
for root, subd, files in os.walk(path):
for i in subd:
subs.append(os.path.join(root,i))
return subs
def compilejs(self,path):
"""
Compiles the js tree for ondemand import
"""
import os
subs = self.getsubs(path)
for subdir in subs:
modname = self.getmodname(subdir)
self.concate_files_in_subdirs(subdir,os.path.join(subdir, modname))
self.minifyjs(os.path.join(subdir, modname))

def minifyjs(self,modpath):
"""
Stub to minify js
"""
pass
def getmodname(self,modpath,ext='.js'):
"""
returns filename for the stiched file
"""
import os
b = modpath.split(os.sep)
modname = b[-1] + ext
return modname


def gentsfile(self,spath,dpath):
"""
function to generate timestamps of all files in spath
dpath is the file in which the timestamps JSON is stored
"""
import webnotes.utils.jstimestamp as jst
import json
a = jst.generateTimestamp()
f = open(dpath,'w')
f.write('wn = {}\n')
f.write('wn.timestamp = ')
f.write(json.dumps(a.gents(spath)))
f.close()
if __name__=="__main__":
a = wnJSCompiler()
print a.compilejs('../js/wntest')

+ 1
- 1
cgi-bin/webnotes/utils/jstimestamp.py Ver fichero

@@ -5,6 +5,7 @@ class generateTimestamp:
nono = ['./tiny_mce','./jquery']
oldcwd = os.getcwd()
os.chdir(jsdir)
# TODO Sanitize the loop below
for root, subfolders, files in os.walk('.'):
if self.is_allowed(nono,root):
for filename in files:
@@ -36,7 +37,6 @@ class generateTimestamp:
filename = filename.lstrip('./')
filename = filename.rstrip('.js')
filename = filename.replace('/','.')
print filename
tsdict[filename] = ts
os.chdir(oldcwd)
return tsdict


Cargando…
Cancelar
Guardar