forked from jagenjo/litegraph.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.py
executable file
·91 lines (71 loc) · 3.29 KB
/
builder.py
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
#!/usr/bin/python
import re, os, sys, time, tempfile, shutil
import argparse
from datetime import date
compiler_path = "/usr/local/bin/compiler.jar"
root_path = "./"
#arguments
parser = argparse.ArgumentParser(description='Deploy a JS app creating a minifyed version checking for errors.')
parser.add_argument('input_file',
help='the path to the file with a list of all the JS files')
parser.add_argument('-o', dest='output_file', action='store',
default=None,
help='Specify an output for the minifyed version')
parser.add_argument('-o2', dest='fullcode_output_file', action='store',
default=None,
help='Specify an output for the full code version')
#parser.add_argument('output_file',
# help='the filename where to save the min version')
parser.add_argument('--all', dest='all_files', action='store_const',
const=True, default=False,
help='Compile all JS files individually first.')
parser.add_argument('--nomin', dest='no_minify', action='store_const',
const=True, default=False,
help='Do not minify the JS file')
args = parser.parse_args()
check_files_individually = args.all_files
output_file = args.output_file
fullcode_output_file = args.fullcode_output_file
no_minify = args.no_minify
root_path = "./" + os.path.dirname(args.input_file) + "/"
sys.stderr.write(" + Root folder: " + root_path + "\n")
def packJSCode(files):
f1, fullcode_path = tempfile.mkstemp() #create temporary file
data = "//packer version\n"
for filename in files:
filename = filename.strip()
if len(filename) == 0 or filename[0] == "#":
continue
sys.stderr.write(" + Processing... " + filename + " " )
src_file = root_path + filename
if os.path.exists(src_file) == False:
sys.stderr.write('\033[91m'+"JS File not found"+'\033[0m\n')
continue
data += open(src_file).read() + "\n"
if check_files_individually:
os.system("java -jar %s --js %s --js_output_file %s" % (compiler_path, src_file, "temp.js") )
sys.stderr.write('\033[92m' + "OK\n" + '\033[0m')
os.write(f1,data)
os.close(f1)
#print " + Compiling all..."
#os.system("java -jar %s --js %s --js_output_file %s" % (compiler_path, fullcode_path, output_file) )
#print " * Done"
return fullcode_path
def compileAndMinify(input_path, output_path):
print " + Compiling and minifying..."
if output_path != None:
os.system("java -jar %s --js %s --js_output_file %s" % (compiler_path, input_path, output_path) )
sys.stderr.write(" * Stored in " + output_path + "\n");
else:
os.system("java -jar %s --js %s" % (compiler_path, input_path) )
#load project info
if os.path.exists(args.input_file) == False:
sys.stderr.write("\033[91m Error, input file not found: " + args.input_file + "\033[0m\n")
exit(0)
js_files = open(args.input_file).read().splitlines()
fullcode_path = packJSCode(js_files)
if fullcode_output_file != None:
shutil.copy2(fullcode_path, fullcode_output_file)
sys.stderr.write(" * Fullcode Stored in " + fullcode_output_file + "\n");
if not no_minify:
compileAndMinify( fullcode_path, output_file )