Skip to content

Commit 4d2d398

Browse files
committed
files added back
1 parent 556530e commit 4d2d398

File tree

19 files changed

+21556
-0
lines changed

19 files changed

+21556
-0
lines changed

build.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python3
2+
import os, shutil, glob, sys, subprocess, re
3+
from os.path import join as j
4+
5+
6+
# update version numbers in pyreact.py and pyreact-js.js
7+
VERSION = "1.0.0"
8+
9+
# to build this, you need a `js-npm` folder where you've done the following:
10+
# npm install -g browserify
11+
# npm install -g uglify
12+
# npm install jsx-transform
13+
# pyreact-js.js should be in the directory
14+
# package.json should have: "main": "PyReact.js",
15+
16+
SROOT = 'src'
17+
SSTYLES = 'styles'
18+
SSCRIPTS = 'scripts'
19+
SSCRIPTS_PY = j('scripts', '__javascript__')
20+
SSCRIPTS_EXT = 'scripts-ext'
21+
22+
DROOT = 'dist'
23+
DSTYLES = 'styles'
24+
DSCRIPTS = 'scripts'
25+
26+
27+
#########################
28+
### Main program
29+
30+
def main():
31+
32+
# dist folder
33+
print('Initialize {} folder'.format(DROOT))
34+
if os.path.exists(DROOT):
35+
shutil.rmtree(DROOT)
36+
os.mkdir(DROOT)
37+
os.mkdir(j(DROOT, DSTYLES))
38+
os.mkdir(j(DROOT, DSCRIPTS))
39+
40+
# html files
41+
log('Copy HTML')
42+
for src in glob.glob(j(SROOT, '*.html')):
43+
_, dest = os.path.split(src)
44+
with open(src, 'r') as fin:
45+
with open(j(DROOT, dest), 'w') as fout:
46+
for line in fin:
47+
line = re.sub(j(SSCRIPTS, '([^/]+)\.js'), j(DSCRIPTS, '\\1.min.js'), line)
48+
line = re.sub(j(SSCRIPTS_EXT, '([^/]+)\.js'), j(DSCRIPTS, '\\1.min.js'), line)
49+
line = re.sub(j(SSCRIPTS_PY, '([^/]+)\.js'), j(DSCRIPTS, '\\1.min.js'), line)
50+
fout.write(line)
51+
52+
# css files
53+
log('Copy CSS')
54+
for src in glob.glob(j(SROOT, SSTYLES, '*.css')):
55+
shutil.copy(src, j(DROOT, DSTYLES))
56+
57+
# js files
58+
log('Copy JS')
59+
for src in glob.glob(j(SROOT, SSCRIPTS, '*.js')):
60+
shutil.copy(src, j(DROOT, DSCRIPTS))
61+
for src in glob.glob(j(SROOT, SSCRIPTS_EXT, '*.min.js')):
62+
shutil.copy(src, j(DROOT, DSCRIPTS))
63+
64+
# transcrypt files
65+
log('Transpile .py scripts')
66+
cwd = os.getcwd()
67+
os.chdir(SROOT)
68+
for src in glob.glob(j(SSCRIPTS, '*.py')):
69+
run('transcrypt --map --build --esv 6 {}'.format(src))
70+
os.chdir(cwd)
71+
shutil.move(j(SROOT, SSCRIPTS_PY, 'index.min.js'), j(DROOT, DSCRIPTS))
72+
shutil.rmtree(j(SROOT, SSCRIPTS_PY))
73+
74+
75+
76+
77+
#########################
78+
### Helper functions
79+
80+
def log(msg):
81+
print()
82+
print('=== {} ==='.format(msg))
83+
84+
def run(cmd):
85+
print('\t' + cmd)
86+
subprocess.run(cmd, shell=True, check=True)
87+
88+
def minext(fn):
89+
filename, ext = os.path.splitext(os.path.split(fn)[1])
90+
return filename + '.min' + ext
91+
92+
93+
94+
#########################
95+
### Start the program
96+
97+
if __name__ == '__main__':
98+
main()

dist/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>PyReact Demo</title>
6+
7+
<link rel="stylesheet" href="styles/index.css" />
8+
9+
<script src="scripts/react-16.0.0.min.js"></script>
10+
<script src="scripts/react-dom-16.0.0.min.js"></script>
11+
<script src="scripts/index.min.js"></script>
12+
</head>
13+
<body>
14+
<header>
15+
Welcome to PyReact
16+
</header>
17+
<main>
18+
<div id="approot"></div>
19+
<p>(click the clock for a new random color)</p>
20+
</main>
21+
</body>
22+
</html>

dist/scripts/index.min.js

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/scripts/react-16.0.0.min.js

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)