Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-schwenk committed Feb 17, 2024
1 parent d011584 commit d4de256
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 65 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
"skipFiles": ["<node_internals>/**"],
"type": "node",
"console": "integratedTerminal"
},
{
"name": "Python: current file",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceFolder}"
}
}
]
}
80 changes: 69 additions & 11 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,75 @@
#!/usr/bin/env python3

"""
pySELL - Python based Simple E-Learning Language for the simple creation of
interactive courses
AUTHOR: Andreas Schwenk <mailto:[email protected]>
LICENSE: GPLv3
This script is only intended for pySELL development.
Users just use file 'sell.py'
Users just use file 'sell.py' (python sell.py QUESTION_FILE.txt)
"""

import subprocess

try:
res = subprocess.run(["npm", "install"], cwd="web")
res = subprocess.run(["node", "build.js"], cwd="web")
except Exception as e:
print(e)
print("pySELL dependencies: npm+nodejs")
print(" https://www.npmjs.com, https://nodejs.org/")
print(" https://nodejs.org/en/download/package-manager")
print("[Debian] sudo apt install nodejs npm")
print("[macOS] brew install node")
print("pySELL builder - 2024 by Andreas Schwenk")

if __name__ == "__main__":
# build web
try:
# install web dependencies
res = subprocess.run(["npm", "install"], cwd="web")
# build web
res = subprocess.run(["node", "build.js"], cwd="web")
except Exception as e:
print(e)
print("pySELL dependencies: npm+nodejs")
print(" https://www.npmjs.com, https://nodejs.org/")
print(" https://nodejs.org/en/download/package-manager")
print("[Debian] sudo apt install nodejs npm")
print("[macOS] brew install node")
# build html template and update sell.py
f = open("web/index.html")
index_html_lines = f.readlines()
f.close()
f = open("web/dist/sell.min.js")
js = f.read().strip()
f.close()
f = open("sell.py")
sell_py_lines = f.readlines()
f.close()
# remove code between @begin(test) and @end(test)
html = ""
skip = False
for line in index_html_lines:
if "@begin(test)" in line:
skip = True
elif "@end(test)" in line:
skip = False
elif skip is False:
html += line
# remove white spaces
html = html.replace(" ", "").replace("\n", " ")
# insert javascript code
html = html.replace(
"</body>",
"<script>let debug = false; let quizSrc = {};"
+ js
+ "sell.init(quizSrc,debug);</script>",
)
# update file "sell.py" between "# @begin(html" and "# @end(html)"
py = ""
skip = False
for line in sell_py_lines:
if "@begin(html)" in line:
skip = True
elif "@end(html)" in line:
skip = False
py += "# @begin(html)\n"
py += 'html = """' + html.strip() + '\n"""\n'
py += "# @end(html)\n"
elif skip is False:
py += line
# write new version of sell.py
f = open("sell__TESTXXX.py", "w")
f.write(py.strip() + "\n")
24 changes: 19 additions & 5 deletions sell.py

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

# TODO: publish python package

# TODO: include description from README.md into sell.py preamble

# TODO: test "\n" in Windows (must replace "\r" after reading file??)

# TODO: large feedback text "awesome, try again, ..."
Expand Down
41 changes: 1 addition & 40 deletions web/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from "fs";
import esbuild from "esbuild";

// build javascript
// build minified javascript file dist/sell.min.js
esbuild.buildSync({
platform: "browser",
globalName: "sell",
Expand All @@ -11,41 +10,3 @@ esbuild.buildSync({
bundle: true,
outfile: "dist/sell.min.js",
});

process.exit(0);

// build html template and update sell.py
let lines = fs.readFileSync("index.html", "utf-8").split("\n");
let js = fs.readFileSync("dist/sell.min.js", "utf-8").trim();
// remove code between @begin(test) and @end(test)
let html = "";
let skip = false;
for (let line of lines) {
if (line.includes("@begin(test)")) skip = true;
else if (line.includes("@end(test)")) skip = false;
else if (skip == false) html += line + "\n";
}
// remove white spaces
html = html.replaceAll(" ", "").replaceAll("\n", " ");
// insert javascript code
html = html.replace(
"</body>",
"<script>let debug = false; let quizSrc = {};" +
js +
"sell.init(quizSrc,debug);</script>"
);
// update file "sell.py" between "# @begin(html" and "# @end(html)"
lines = fs.readFileSync("sell.py", "utf-8").split("\n");
let py = "";
skip = false;
for (let line of lines) {
if (line.includes("@begin(html)")) skip = true;
else if (line.includes("@end(html)")) {
skip = false;
py += "# @begin(html)\n";
py += 'html = """' + html + '\n"""\n';
py += "# @end(html)\n";
} else if (skip == false) py += line + "\n";
}
// write new version of sell.py
fs.writeFileSync("sell.py", py.trim() + "\n");
2 changes: 1 addition & 1 deletion web/src/dom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* SELL - Simple E-Learning Language
* pySELL - Python based Simple E-Learning Language
* AUTHOR: Andreas Schwenk <mailto:[email protected]>
* LICENSE: GPLv3
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion web/src/icons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* SELL - Simple E-Learning Language
* pySELL - Python based Simple E-Learning Language
* AUTHOR: Andreas Schwenk <mailto:[email protected]>
* LICENSE: GPLv3
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion web/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* SELL - Simple E-Learning Language
* pySELL - Python based Simple E-Learning Language
* AUTHOR: Andreas Schwenk <mailto:[email protected]>
* LICENSE: GPLv3
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion web/src/lang.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* SELL - Simple E-Learning Language
* pySELL - Python based Simple E-Learning Language
* AUTHOR: Andreas Schwenk <mailto:[email protected]>
* LICENSE: GPLv3
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion web/src/math.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* SELL - Simple E-Learning Language
* pySELL - Python based Simple E-Learning Language
* AUTHOR: Andreas Schwenk <mailto:[email protected]>
* LICENSE: GPLv3
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion web/src/math_TEST.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* SELL - Simple E-Learning Language
* pySELL - Python based Simple E-Learning Language
* AUTHOR: Andreas Schwenk <mailto:[email protected]>
* LICENSE: GPLv3
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion web/src/question.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* SELL - Simple E-Learning Language
* pySELL - Python based Simple E-Learning Language
* AUTHOR: Andreas Schwenk <mailto:[email protected]>
* LICENSE: GPLv3
******************************************************************************/
Expand Down

0 comments on commit d4de256

Please sign in to comment.