-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53d1609
commit f3a673e
Showing
5 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
On Every change: | ||
send request to google closure compiler! | ||
download the compiled script and write it to WriteIt.min.js | ||
""" | ||
import os | ||
import time | ||
import requests | ||
|
||
FILE_PATH = "../WriteIt.js" | ||
OUT_FILE_PATH = "../WriteIt.min.js" | ||
CLOSURE_API_URL = "https://closure-compiler.appspot.com/compile" | ||
COMPILATION_LEVEL = "ADVANCED_OPTIMIZATIONS" | ||
|
||
|
||
def getCompiledCode(jscode): | ||
params = { | ||
"js_code": jscode, | ||
"compilation_level": COMPILATION_LEVEL, | ||
"output_format": "text", | ||
"output_info": "compiled_code" | ||
} | ||
result = requests.post(CLOSURE_API_URL, data = params) | ||
|
||
if(result.status_code < 200 or result.status_code >= 300): | ||
print(result.status_code, result.text) | ||
raise Exception("Some Error Occured!") | ||
|
||
return result.text | ||
|
||
|
||
def compileAndSave(): | ||
jscode = open(FILE_PATH, 'r+').read() | ||
compiledCode = getCompiledCode(jscode) | ||
open(OUT_FILE_PATH, "w+").write(compiledCode) | ||
|
||
fileStamp = os.stat(FILE_PATH).st_mtime | ||
|
||
while True: | ||
time.sleep(1) | ||
if fileStamp != os.stat(FILE_PATH).st_mtime: | ||
compileAndSave() | ||
fileStamp = os.stat(FILE_PATH).st_mtime |
Empty file.