Skip to content

Commit

Permalink
Hackily integrated tnoodle-ui with the tmt build infrastructure. Please
Browse files Browse the repository at this point in the history
ignore this mess.
  • Loading branch information
jfly committed Jan 5, 2018
1 parent bb9a3c1 commit 7018d92
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 64 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -11,3 +11,5 @@ tmtc
*.pyc
*.log.*
node_modules/

webscrambles/WebContent/wca/new-ui/
19 changes: 0 additions & 19 deletions README.md
Expand Up @@ -57,25 +57,6 @@ android sdk and setting up an ANDROID_HOME environment variable.
- Bump the version number in `bower.json`.
- `./tmt release`

### TNoodle Timer (TNT) and Other Projects

TNoodle contains other distributions, like TNoodle Timer (TNT) as `timer`.

You can build the `timer` distribution similarly to `wca`:

# Build and run directly.
./tmt make run -p timer

# Build to .jar file.
./tmt make dist -p timer

# Run .jar file from commandline
java -jar timer/dist/TNoodle-timer.jar

When TNoodle is running, TNT will be available at <http://localhost:2014/tnt>.

Other projects can be run similarly, too. Run `./tmt graph --descriptions` to see the current list.

### Notes

- Each project is a full fledged Eclipse project (they each have a `.classpath` and `.project` file). Furthermore, the whole tnoodle directory can be opened as an Eclipse workspace. Simply go to File > Import > Existing Projects into Workspace, and enter your tnoodle directory under "Select root directory". Eclipse should automagically detect all the tnoodle projects.
Expand Down
3 changes: 2 additions & 1 deletion git-tools/lint.py
Expand Up @@ -16,7 +16,8 @@
'winstone/src/javax/',
'min2phase/src/cs/min2phase/',
'threephase/src/cs/threephase/',
'cubecomps/WebContent/cubecomps/'
'cubecomps/WebContent/cubecomps/',
'tnoodle-ui/',
]

# This file is automatically produced by GWT, and it does all sorts
Expand Down
3 changes: 3 additions & 0 deletions tmt
Expand Up @@ -371,6 +371,7 @@ class tmt:
# files.
wcaProjectName = 'wca'
tmt.args.project = wcaProjectName # yuck =(

# We can't run a dist until after we create the tag. This way
# the version number of the resulting file will be correct.
wcaProject = tmt.TmtProject.projects[wcaProjectName]
Expand Down Expand Up @@ -1077,6 +1078,8 @@ class EclipseProject(TmtProject):
os.makedirs(self.distDir)

if not noRemake:
rebuildTNoodleUiCmd = "(cd tnoodle-ui; ./build-and-symlink.sh)"
assert 0 == os.system(rebuildTNoodleUiCmd)
tmt._make(projectName=self.name, command='compile')

if self.webContent:
Expand Down
2 changes: 1 addition & 1 deletion tnoodle-ui/README.md
Expand Up @@ -6,5 +6,5 @@ to minimize repeated data entry.
This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).

- `yarn install` - Install dependencies.
- `yarn start` - Starts a server accessible at http://localhost:3000/.
- `yarn start` - Starts a server accessible at http://localhost:3001/.
- `yarn build` - Compiles to `build/` directory.
19 changes: 19 additions & 0 deletions tnoodle-ui/build-and-symlink.sh
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

cd "$(dirname "$0")"

yarn install
yarn build

cd build

base_dir=../../webscrambles/WebContent/wca/new-ui
rm -rf $base_dir
for file in `find static` index.html; do
if [ -f $file ]; then
name=$base_dir/$file
mkdir -p `dirname $name`
name_parent=`dirname $name`
ln -s `realpath --relative-to="$name_parent" "$file"` $name
fi
done
5 changes: 3 additions & 2 deletions tnoodle-ui/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "tnoodle-ui",
"version": "0.1.0",
"private": true,
"homepage": "http://localhost:2014/scramble-new-ui/",
"dependencies": {
"classnames": "^2.2.5",
"node-sass": "^4.5.1",
Expand All @@ -25,8 +26,8 @@
"watch-css": "npm run build-css && node-sass src/ -o src/ --watch --recursive",
"start-js": "NODE_PATH=src react-scripts start",

"start": "npm-run-all -p watch-css start-js",
"build": "NODE_PATH=src yarn run build-css && react-scripts build",
"start": "PORT=3001 BROWSER=none npm-run-all -p watch-css start-js",
"build": "yarn run build-css && NODE_PATH=src react-scripts build",
"test": "NODE_PATH=src react-scripts test --env=jsdom",
"eject": "NODE_PATH=src react-scripts eject"
}
Expand Down
6 changes: 5 additions & 1 deletion tnoodle-ui/src/App.js
Expand Up @@ -12,7 +12,11 @@ import * as WcaApi from 'WcaApi';
import Home from 'Home';
import ManageCompetition from 'ManageCompetition';

const history = createHistory();
export const BASE_PATH = process.env.PUBLIC_URL;

const history = createHistory({
basename: BASE_PATH,
});

const middleware = routerMiddleware(history);

Expand Down
12 changes: 8 additions & 4 deletions tnoodle-ui/src/WcaApi.js
@@ -1,3 +1,7 @@
import { BASE_PATH } from 'App';

const WCA_ORIGIN = 'http://kaladin:3000';

let wcaAccessToken = getHashParameter('access_token', null);
if(wcaAccessToken) {
location.hash = "";
Expand All @@ -7,9 +11,9 @@ if(wcaAccessToken) {
}

export function logIn() {
let redirectUri = location.origin + '/oauth/wca';
let logInUrl = `http://kaladin:3000/oauth/authorize?client_id=e00488e5f685aca8b1f375d9eded764247f070bccb235903ce20f8e437123eac&redirect_uri=${redirectUri}&response_type=token&scope=public+manage_competitions`;
localStorage['TNoodle.preLoginPath'] = location.pathname;
let redirectUri = location.origin + BASE_PATH + '/oauth/wca';
let logInUrl = `${WCA_ORIGIN}/oauth/authorize?client_id=e00488e5f685aca8b1f375d9eded764247f070bccb235903ce20f8e437123eac&redirect_uri=${redirectUri}&response_type=token&scope=public+manage_competitions`;
localStorage['TNoodle.preLoginPath'] = location.pathname.substring(BASE_PATH.length);
document.location = logInUrl;
}

Expand Down Expand Up @@ -56,7 +60,7 @@ function getHashParameter(name, alt) {

function wcaApiFetch(path, fetchOptions) {
// TODO - <<< refresh token https://github.com/doorkeeper-gem/doorkeeper/wiki/Enable-Refresh-Token-Credentials
var baseApiUrl = 'http://kaladin:3000/api/v0';
var baseApiUrl = `${WCA_ORIGIN}/api/v0`;
fetchOptions = Object.assign({}, fetchOptions, {
headers: new Headers({
"Authorization": `Bearer ${wcaAccessToken}`,
Expand Down
84 changes: 48 additions & 36 deletions webscrambles/WebContent/WEB-INF/urlrewrite.xml
@@ -1,36 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">

<urlrewrite>

<rule>
<from>^/$</from>
<to type="redirect" last="true">/scramble/</to>
</rule>

<rule>
<from>^/favicon.ico$</from>
<to type="redirect" last="true">/wca/favicon.ico</to>
</rule>

<rule>
<from>^/scramble/$</from>
<to type="forward">/wca/scramblegen.html</to>
</rule>

<rule>
<from>^/scramble$</from>
<to type="redirect">/scramble/</to>
</rule>

<rule>
<from>^/readme$</from>
<to type="forward">/wca/readme-tnoodle.md</to>
</rule>
<rule>
<from>^/readme.md$</from>
<to type="forward">/wca/readme-tnoodle.md</to>
</rule>

</urlrewrite>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">

<urlrewrite>

<rule>
<from>^/$</from>
<to type="redirect" last="true">/scramble/</to>
</rule>

<rule>
<from>^/favicon.ico$</from>
<to type="redirect" last="true">/wca/favicon.ico</to>
</rule>

<rule>
<from>^/scramble-new-ui$</from>
<to type="redirect">/scramble-new-ui/</to>
</rule>
<rule>
<from>^/scramble-new-ui/static</from>
<to type="forward">/wca/new-ui/static</to>
</rule>
<rule>
<from>^/scramble-new-ui/.*</from>
<to type="forward">/wca/new-ui/index.html</to>
</rule>

<rule>
<from>^/scramble$</from>
<to type="redirect">/scramble/</to>
</rule>
<rule>
<from>^/scramble/$</from>
<to type="forward">/wca/scramblegen.html</to>
</rule>

<rule>
<from>^/readme$</from>
<to type="forward">/wca/readme-tnoodle.md</to>
</rule>
<rule>
<from>^/readme.md$</from>
<to type="forward">/wca/readme-tnoodle.md</to>
</rule>

</urlrewrite>

0 comments on commit 7018d92

Please sign in to comment.