Skip to content

Commit f15faac

Browse files
committed
Initial
0 parents  commit f15faac

19 files changed

+325
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
*.iml

README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Devathon Website
2+
3+
## Client
4+
5+
The client code is written in Svelte, which is compiled before it's downloaded.
6+
7+
### Scripts
8+
9+
Build for production:
10+
11+
```bash
12+
npm run build
13+
```
14+
15+
Watch for development:
16+
17+
```bash
18+
npm run dev
19+
```
20+
21+
## Server
22+
23+
The server code is written in TypeScript, using the Express framework for routing.
24+
In the future the server will use svelte-ssr to prerender our components.
25+
26+
### Setup
27+
28+
In order to run the server, you must copy `server/config/config.default.ts` to `config.ts`.
29+
30+
### Scripts
31+
32+
Run production:
33+
34+
```bash
35+
npm run build # run this every time you pull
36+
npm run run
37+
```
38+
39+
Run development:
40+
41+
```bash
42+
npm run dev
43+
```

client/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
npm-debug.log
3+
build/

client/components/header/header-main.html

Whitespace-only changes.

client/components/header/header.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="header">
2+
{{yield}}
3+
</div>

client/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "client",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "export PRODUCTION=; export WATCH=true; node rollup.js",
8+
"build": "export PRODUCTION=true; export WATCH=; node rollup.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"rollup": "^0.36.4",
15+
"rollup-plugin-commonjs": "^5.0.5",
16+
"rollup-plugin-node-resolve": "^2.0.0",
17+
"rollup-plugin-replace": "^1.1.1",
18+
"rollup-plugin-svelte": "^1.0.0",
19+
"rollup-pluginutils": "^1.5.2"
20+
},
21+
"devDependencies": {
22+
"rollup-watch": "^2.5.0"
23+
}
24+
}

client/rollup.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const rollup = require('rollup');
2+
const svelte = require('rollup-plugin-svelte');
3+
const replace = require('rollup-plugin-replace');
4+
const resolve = require('rollup-plugin-node-resolve');
5+
const common = require('rollup-plugin-commonjs');
6+
7+
const routes = [
8+
'home'
9+
];
10+
11+
function getOptions(route) {
12+
const plugins = [
13+
svelte()
14+
];
15+
if (!process.env.PRODUCTION) {
16+
// plugins.push(replace({
17+
// }));
18+
}
19+
plugins.push(resolve({
20+
include: ['node_modules/**'],
21+
jsnext: true,
22+
main: true,
23+
browser: true
24+
}));
25+
plugins.push(common({
26+
include: ['node_modules/**']
27+
}));
28+
return {
29+
entry: `routes/${route}/index.js`,
30+
dest: `build/${route}.js`,
31+
format: 'iife',
32+
sourceMap: true,
33+
plugins,
34+
};
35+
}
36+
37+
if (process.env.WATCH) {
38+
const watch = require('rollup-watch');
39+
routes.forEach(route => {
40+
watch(rollup, getOptions(route))
41+
.on('event', event => console.log(`routes/${route}: ${event.code} ${event.error ? event.error : ''}`))
42+
})
43+
} else {
44+
routes.forEach(route => {
45+
rollup.rollup(getOptions(route))
46+
.then(bundle => bundle.write(getOptions(route)))
47+
.catch(err => console.error(`Failed to compile route ${route}`, err));
48+
});
49+
}
50+

client/routes/common.js

Whitespace-only changes.

client/routes/home/home.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Header>
2+
<h1>Wow!</h1>
3+
</Header>
4+
5+
<script>
6+
import Header from '../../components/header/header.html';
7+
8+
export default {
9+
components: {
10+
Header
11+
}
12+
}
13+
</script>

client/routes/home/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import '../common';
2+
import Home from './home.html';
3+
4+
new Home({
5+
target: document.getElementById('container'),
6+
data: {
7+
world: 'World'
8+
}
9+
});

client/styles/common.css

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
body, html, #container {
2+
height: 100%;
3+
}
4+
5+
body {
6+
margin: 0;
7+
}
8+
9+
h1, h2, h3, h4, h5, a {
10+
font-family: 'Roboto Slab', serif;
11+
margin: 0;
12+
}
13+
14+
h1 {
15+
padding-top: 10px;
16+
padding-bottom: 20px;
17+
}
18+
19+
p, b, i, li, label, small, span {
20+
font-family: 'Roboto', serif;
21+
font-size: 20px;
22+
}
23+
24+
small, span {
25+
font-size: 12px;
26+
}
27+
28+
a {
29+
color: #DDA0DD;
30+
}
31+
32+
label {
33+
display: block;
34+
font-size: 18px;
35+
}
36+
37+
input, select, button {
38+
margin-bottom: 30px;
39+
font-size: 28px;
40+
width: 100%;
41+
box-sizing: border-box;
42+
}
43+
44+
button {
45+
padding: 4px 6px;
46+
}
47+
48+
img {
49+
max-width: 100%;
50+
}

server/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
npm-debug.log
3+
4+
config/config.ts
5+
build/

server/config/config.default.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
port: 3000,
3+
host: '127.0.0.1'
4+
};

server/index.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Devathon</title>
7+
<link href="https://fonts.googleapis.com/css?family=Roboto+Slab|Roboto" rel="stylesheet">
8+
<link rel="stylesheet" href="/public/css/common.css"/>
9+
CSSSTUFF
10+
</head>
11+
<body>
12+
<div id="container">
13+
14+
</div>
15+
JSSTUFF
16+
</body>
17+
</html>

server/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {install} from 'source-map-support';
2+
import * as express from 'express';
3+
import {Express} from 'express';
4+
import * as serveStatic from 'serve-static';
5+
6+
import pages from './src/routes/pages';
7+
8+
import config from './config/config';
9+
10+
install();
11+
12+
const app: Express = express();
13+
14+
app.use('/public/js', serveStatic('../client/build'));
15+
app.use('/public/css', serveStatic('../client/styles'));
16+
17+
app.use(pages);
18+
19+
app.listen(config.port, config.host, () => console.log(`Listening on ${config.host}:${config.port}`));

server/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "server",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "tsc",
9+
"run": "node build/",
10+
"dev": "export DEBUG=Devathon:*; tsc && node build/"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"@types/express": "^4.0.34",
17+
"@types/source-map-support": "^0.2.28",
18+
"express": "^4.14.0",
19+
"serve-static": "^1.11.1",
20+
"source-map-support": "^0.4.6",
21+
"svelte": "^1.1.2",
22+
"svelte-ssr": "git://github.com/PaulBGD/svelte-ssr.git",
23+
"typescript": "2.1.1"
24+
}
25+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module "svelte-ssr/register" {
2+
}

server/src/routes/pages.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {Router, Request, Response, RequestHandler} from 'express';
2+
import {readFileSync} from 'fs';
3+
import { join } from 'path';
4+
import 'svelte-ssr/register';
5+
6+
const router: Router = Router();
7+
8+
const routes: {[key: string]: string[]} = {
9+
'home': ['/', '/home']
10+
};
11+
12+
const compiled: {[key: string]: any} = {};
13+
14+
for (let property in routes) {
15+
if (routes.hasOwnProperty(property)) {
16+
compiled[property] = require(join(process.cwd(), '../', 'client', 'routes', property, `${property}.html`));
17+
registerRoute(property, routes[property]);
18+
}
19+
}
20+
21+
let template: string;
22+
23+
function getTemplate(): string {
24+
const path = join(process.cwd(), 'index.html');
25+
if (!template || !process.env.PRODUCTION) {
26+
return template = readFileSync(path, 'utf8');
27+
}
28+
return template;
29+
}
30+
31+
function registerRoute(name: string, routes: string[]) {
32+
const handler = (req: Request, res: Response) => {
33+
let template: string = getTemplate();
34+
template = template.replace('CSSSTUFF', `
35+
`);
36+
template = template.replace('JSSTUFF', `
37+
<script src="/public/js/${name}.js"></script>
38+
`);
39+
res.end(template);
40+
};
41+
routes.forEach(route => router.get(route, handler));
42+
}
43+
44+
export default router;

server/tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"noImplicitAny": true,
6+
"sourceMap": true,
7+
"outDir": "build"
8+
},
9+
"exclude": [
10+
"node_modules"
11+
]
12+
}

0 commit comments

Comments
 (0)