Skip to content

Commit

Permalink
Added Auto Compile on change script
Browse files Browse the repository at this point in the history
  • Loading branch information
khushit-shah committed Jun 16, 2020
1 parent 53d1609 commit f3a673e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
4 changes: 3 additions & 1 deletion WriteIt.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,19 @@ class WriteItNode {
}
}
const WriteItJS = new WriteIt();

// Automatically start Animation if writeit-auto-start attribute is present,
// this is not related with the animation of node
// but, it starts parsing each node which has "writeit-animate"
if (document.querySelector("*[" + WriteItJS.WRITEIT_AUTO_START + "]")) {
WriteItJS.startAnimation();
}

// add other WriteItJS function as an array object so they don't get ignored by Closure ADVANCE settings.
window["WriteItJS"] = WriteItJS;
window["WriteItJS"]["startAnimation"] = WriteItJS.startAnimation;
window["WriteItJS"]["pauseAnimation"] = WriteItJS.pauseAnimation;
window["WriteItJS"]["resumeAnimation"] = WriteItJS.resumeAnimation;
window["WriteItJS"]["startAnimationOfNode"] = WriteItJS.startAnimationOfNode;
// other functions are not necessary for users[programmers].
console.log("WriteIt.js v2.0 loaded!👍, visit https://github.com/khushit-shah/WriteIt.js");
console.log("WriteIt.js v2.0 loaded!, visit https://github.com/khushit-shah/WriteIt.js");
2 changes: 1 addition & 1 deletion WriteIt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/terminal-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/easing/EasePack.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenLite.min.js"></script>

<script src="https://cdn.jsdelivr.net/gh/khushit-shah/WriteIt.js@latest/WriteIt.js"></script>
<!-- DEVELOPMENT <script src="/WriteIt.js"></script> -->
<script src="js/script.min.js"></script>
<script>
let scroll = () => { window.scroll(0, 10000); }
Expand Down
43 changes: 43 additions & 0 deletions scripts/compile.py
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 removed scripts/compile.sh
Empty file.

0 comments on commit f3a673e

Please sign in to comment.