Skip to content

Commit f3a673e

Browse files
committed
Added Auto Compile on change script
1 parent 53d1609 commit f3a673e

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

WriteIt.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,19 @@ class WriteItNode {
585585
}
586586
}
587587
const WriteItJS = new WriteIt();
588+
588589
// Automatically start Animation if writeit-auto-start attribute is present,
589590
// this is not related with the animation of node
590591
// but, it starts parsing each node which has "writeit-animate"
591592
if (document.querySelector("*[" + WriteItJS.WRITEIT_AUTO_START + "]")) {
592593
WriteItJS.startAnimation();
593594
}
595+
594596
// add other WriteItJS function as an array object so they don't get ignored by Closure ADVANCE settings.
595597
window["WriteItJS"] = WriteItJS;
596598
window["WriteItJS"]["startAnimation"] = WriteItJS.startAnimation;
597599
window["WriteItJS"]["pauseAnimation"] = WriteItJS.pauseAnimation;
598600
window["WriteItJS"]["resumeAnimation"] = WriteItJS.resumeAnimation;
599601
window["WriteItJS"]["startAnimationOfNode"] = WriteItJS.startAnimationOfNode;
600602
// other functions are not necessary for users[programmers].
601-
console.log("WriteIt.js v2.0 loaded!👍, visit https://github.com/khushit-shah/WriteIt.js");
603+
console.log("WriteIt.js v2.0 loaded!, visit https://github.com/khushit-shah/WriteIt.js");

WriteIt.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/terminal-app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@
244244
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
245245
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/easing/EasePack.min.js"></script>
246246
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenLite.min.js"></script>
247+
247248
<script src="https://cdn.jsdelivr.net/gh/khushit-shah/WriteIt.js@latest/WriteIt.js"></script>
249+
<!-- DEVELOPMENT <script src="/WriteIt.js"></script> -->
248250
<script src="js/script.min.js"></script>
249251
<script>
250252
let scroll = () => { window.scroll(0, 10000); }

scripts/compile.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
On Every change:
3+
send request to google closure compiler!
4+
download the compiled script and write it to WriteIt.min.js
5+
"""
6+
import os
7+
import time
8+
import requests
9+
10+
FILE_PATH = "../WriteIt.js"
11+
OUT_FILE_PATH = "../WriteIt.min.js"
12+
CLOSURE_API_URL = "https://closure-compiler.appspot.com/compile"
13+
COMPILATION_LEVEL = "ADVANCED_OPTIMIZATIONS"
14+
15+
16+
def getCompiledCode(jscode):
17+
params = {
18+
"js_code": jscode,
19+
"compilation_level": COMPILATION_LEVEL,
20+
"output_format": "text",
21+
"output_info": "compiled_code"
22+
}
23+
result = requests.post(CLOSURE_API_URL, data = params)
24+
25+
if(result.status_code < 200 or result.status_code >= 300):
26+
print(result.status_code, result.text)
27+
raise Exception("Some Error Occured!")
28+
29+
return result.text
30+
31+
32+
def compileAndSave():
33+
jscode = open(FILE_PATH, 'r+').read()
34+
compiledCode = getCompiledCode(jscode)
35+
open(OUT_FILE_PATH, "w+").write(compiledCode)
36+
37+
fileStamp = os.stat(FILE_PATH).st_mtime
38+
39+
while True:
40+
time.sleep(1)
41+
if fileStamp != os.stat(FILE_PATH).st_mtime:
42+
compileAndSave()
43+
fileStamp = os.stat(FILE_PATH).st_mtime

scripts/compile.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)