Skip to content

Enable gist saving plus other updates #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Rewrite of TryPureScript using latest features of PS ecosystem, such as:
* Halogen Hooks
* Tailwind CSS

Lots of HTML and JS code was eliminated.

Also enables gist saving and tracking state in URL rather than local storage.

### Local Development
```
npm i
npm config set tps:configpath "config/dev/*.purs"
npm run gen-css # Create initial tailwind css files
npm run start # Launch local dev server with automatic reload/refresh.

# Optional:
npm run build # To manually rebuild if IDE does not do this automatically.
npm run lock-css # To speed up rebuilds if you're not adding new css classes.
```

### Building for production
```
npm config set tps:configpath "config/prod/*.purs"
npm run prod # Create minified production build
```
22 changes: 17 additions & 5 deletions client/config/dev/Try.Config.purs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
module Try.Config where

appDomain :: String
appDomain = "http://localhost:1234"

tokenServerUrl :: String
--tokenServerUrl = "http://localhost:7071/api/localtrigger"
tokenServerUrl = "https://localtpsfunction.azurewebsites.net/api/localtps?code=Il1fqBKydiLWqoognUIzgppwi10qfmXjkhAa75yRg5S4S10LNfsiTw=="

-- GitHub OAuth app for saving gists.
-- This is tied to a specific app domain.
clientID :: String
clientID = "6f4e10fd8cef6995ac09"

loaderUrl :: String
loaderUrl = "js/output"
--loaderUrl = "js/output"
--loaderUrl = "http://localhost:8080"
loaderUrl = "https://compile.purescript.org/output"

compileUrl :: String
compileUrl = "http://localhost:8081"

mainGist :: String
mainGist = "7ad2b2eef11ac7dcfd14aa1585dd8f69"
--compileUrl = "http://localhost:8081"
compileUrl = "https://compile.purescript.org"
1 change: 1 addition & 0 deletions client/config/dev/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("../output/Main/index.js").main();
14 changes: 11 additions & 3 deletions client/config/prod/Try.Config.purs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
module Try.Config where

appDomain :: String
appDomain = "https://try.ps.ai"

tokenServerUrl :: String
tokenServerUrl = "https://tpsfunction.azurewebsites.net/api/tps?code=JmxFIJvNG9E4qFtrwyD2v40YIWAtKUt1HDxLQ9rjmP4bRafnxWjNZg=="

-- GitHub OAuth app for saving gists.
-- This is tied to a specific app domain.
clientID :: String
clientID = "3634da383bb531261af5"

loaderUrl :: String
loaderUrl = "https://compile.purescript.org/output"

compileUrl :: String
compileUrl = "https://compile.purescript.org"

mainGist :: String
mainGist = "7ad2b2eef11ac7dcfd14aa1585dd8f69"
82 changes: 82 additions & 0 deletions client/css/css2purs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/python3
import re
import fileinput

# Usage:
# cat tailwind.css | ./css2purs.py > Tailwind.purs

# vim Regex
# /^\s*\.[^ ]*

# Using list rather than set to preserve sorted order
# Assuming that duplicates are always adjacent
cssNames = []

def process(line):
# Example input:
# line = ' .-sm\:-space-y-0-w-1\/2:hover {'
regName = re.compile('^\s*\.([^ ]*?[^\\\\])(:.*)? .*$')

m = regName.match(line)

if m:
escaped = m.group(1)
# Just escaped class name
# -sm\:-space-y-0-w-1\/2

cssStr = escaped.replace('\\', '')
# Remove escaped symbols - this is the CSS string
# -sm:-space-y-0-w-1/2

# don't add duplicates
# assuming always adjacent
if len(cssNames) and cssNames[-1] == cssStr:
return

cssNames.append(cssStr)

def cssToPs(cssStr):
# Conversion to PureScript-compatible name
# Must remove symbols

def negRepl(m):
return m.group(1) + 'neg' + m.group(3).upper()
negSub = re.sub(r'(^|:)(-)(.)', negRepl, cssStr)
# Replace leading dashes (used to represent negatives) with 'neg'
# Camel-case for next word
# negSm:negSpace-y-0-w-1/2

colonDivSub = negSub.replace(':', '-').replace('/', 'd')
# replace colon separator with dash
# replace division sign for fractions with 'd'
# negSm-negSpace-y-0-w-1d2

def dashRepl(m):
return m.group(1).upper()
dashSub = re.sub(r'-(.)', dashRepl, colonDivSub)
# Convert dash-separator to camelCase
# negSmNegSpaceY0W1d2

# Debug prints
# print('cssStr', cssStr)
# print(escaped)
# print(negSub)
# print(colonDivSub)
# print(dashSub)

psName = dashSub
print()
print('-- | ' + cssStr)
print(psName + ' :: ClassName')
print(psName + ' = ClassName "' + cssStr + '"')

for line in fileinput.input():
process(line)

print('-- | Autogenerated from tailwind.css')
print('module Tailwind where')
print()
print('import Halogen.HTML.Core (ClassName(..))')

for cssName in cssNames:
cssToPs(cssName)
3 changes: 3 additions & 0 deletions client/css/tailwind_inputs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
53 changes: 46 additions & 7 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
{
"name": "trypurescript-client",
"name": "tps",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed from trypurescript-client to make changing configs with these commands a bit less verbose:

npm config set tps:configpath "config/dev/*.purs"
npm config set tps:configpath "config/prod/*.purs"

"private": true,
"config": {
"configpath": "config/dev/*.purs"
},
"scripts": {
"clean": "rimraf output",
"build": "spago bundle-app --path $npm_package_config_configpath --purs-args '--censor-lib --strict' --to public/js/index.js"
"c-user-facing": "# --------- user facing scripts -------",

"c-gen-css": "# -- Generate tailwind css AND purs css wrapper",
"gen-css": "npm run build-css-only && npm run css2purs",

"c1-lock-css": "# -- Strip away unused css from autogenerated purs files.",
"c2-lock-css": "# -- This improves rebuild times, but won't allow adding new css.",
"c3-lock-css": "# -- So re-run gen-css before making additional css changes.",
"lock-css": "npm run bundle && npm run css-purge && npm run css2purs",

Comment on lines +12 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that npm i will reformat this file and remove the unnecessary newlines I added for readability. Really terrible that you can't add comments to json files without workaround like this. Would like to migrate to something better if it exists.

"c-build": "# -- Build purs code in project",
"build": "spago build --path $npm_package_config_configpath",

"c-start": "# -- Launch development server in web browser",
"start": "npm run build && cp config/dev/index.js public && webpack-dev-server --port 1234 --open --config webpack.dev.js",

"c-prod": "# -- Create minified production build",
"prod": "npm run bundle && npm run css-purge && webpack --config webpack.prod.js",

"c-wp-dev-build": "# -- Create unminified dev build. This is useful for troubleshooting the production build.",
"wp-dev-build": "cp config/dev/index.js public && webpack --config webpack.dev.js",

"c-serve-static": "# -- serves static files locally. For checking if everything was bundled correctly.",
"serve-static": "http-server dist/ -c-1 -o tps --port 1234 -P http://localhost:1234\\?",

"c-internal": "# -------- internal helper scripts -------",

"bundle": "spago bundle-app --path $npm_package_config_configpath --to public/index.js",
"build-css-only": "tailwindcss build css/tailwind_inputs.css -o public/tailwind.css",
"css2purs": "cat public/tailwind.css | ./css/css2purs.py > src/Tailwind.purs",
"css-purge": "NODE_ENV=production npm run build-css-only"
},
"devDependencies": {
"purescript": "^0.13.6",
"purescript-psa": "^0.7.3",
"rimraf": "^2.5.4",
"spago": "^0.14.0"
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^6.0.3",
"css-loader": "^3.6.0",
"cssnano": "^4.1.10",
"exports-loader": "^1.1.0",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.3.0",
"style-loader": "^1.2.1",
"tailwindcss": "^1.4.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0",
"webpack-merge": "^5.0.9",
"xhr2": "^0.2.0"
}
}
7 changes: 5 additions & 2 deletions client/packages.dhall
Original file line number Diff line number Diff line change
@@ -119,9 +119,12 @@ let additions =


let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.6-20200404/packages.dhall sha256:f239f2e215d0cbd5c203307701748581938f74c4c78f4aeffa32c11c131ef7b6
https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200724/packages.dhall sha256:bb941d30820a49345a0e88937094d2b9983d939c9fd3a46969b85ce44953d7d9

let overrides = {=}
let overrides =
{ halogen-hooks-extra =
upstream.halogen-hooks-extra // { version = "v0.7.1" }
}

let additions = {=}

1 change: 1 addition & 0 deletions client/public/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
try.ps.ai
18 changes: 18 additions & 0 deletions client/public/ace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.error {
position: absolute;
z-index: 20;
border-bottom: 2px dotted red;
}

/* Currently unsued, but can re-enable. Assuming it's spammy */
.warning {
position: absolute;
z-index: 20;
border-bottom: 2px dotted #c4953a;
}

/* Can re-enable if there's an issue without this option
.ace_gutter-tooltip {
white-space: pre-wrap;
}
*/
Loading