Skip to content

Commit

Permalink
Add build stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bvisness committed Feb 15, 2021
1 parent 7bd3f19 commit be3acca
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Regular Express

![An example regular expression](screenshot.png)

A tool that allows you to build regular expressions completely visually. Use the power of regular expressions without getting bogged down by the syntax!

View the [task tracker](https://www.notion.so/bvisness/3708fea1fb9d43f1b51b7512d685f963?v=c0b80b9cebc843f5b95dac1370bfa76b) to see what's in the works.
38 changes: 35 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import os
import re
import subprocess
import random
import shutil
import string

clang = 'clang'
wasmld = 'wasm-ld'
Expand All @@ -20,12 +23,10 @@
except FileNotFoundError:
pass

shutil.rmtree('build')
os.makedirs('build', exist_ok=True)
os.chdir('build')

for f in glob.glob('*'):
os.remove(f)

flags = [
'--target=wasm32',
'-c', '-O2', '-flto',
Expand Down Expand Up @@ -59,3 +60,34 @@
] + ofiles)

# subprocess.run(['wasm2wat', 'regex.wasm'], stdout=open('regex.wat', 'w'))

# Output the dist folder for upload

os.chdir('..')
os.makedirs('build/dist', exist_ok=True)

buildId = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8)) # so beautiful. so pythonic.

root = 'src/index.html';
assets = [
'src/normalize.css',
'build/regex.wasm',
'build/sys.wasm',
];

rootContents = open(root).read();

def addId(filename, id):
parts = filename.split('.')
parts.insert(-1, buildId)
return '.'.join(parts)

for asset in assets:
basename = os.path.basename(asset)
newFilename = addId(basename, buildId)
shutil.copy(asset, 'build/dist/{}'.format(newFilename))

rootContents = rootContents.replace(basename, newFilename)

with open('build/dist/index.html', 'w') as f:
f.write(rootContents)
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/regex.html → src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ <h2>What is this?</h2>
buf[ptr + i] = 0;
}

const sysFetch = fetch("/build/sys.wasm");
const mainFetch = fetch("/build/regex.wasm");
const sysFetch = fetch("sys.wasm");
const mainFetch = fetch("regex.wasm");

const { instance: sys } = await WebAssembly.instantiateStreaming(
sysFetch,
Expand Down

0 comments on commit be3acca

Please sign in to comment.