WalidMoovin
2 years ago
commit
191985915a
15 changed files with 1758 additions and 0 deletions
@ -0,0 +1,107 @@ |
|||
# This repo is no longer maintained. Consider using `npm init vite` and selecting the `svelte` option or — if you want a full-fledged app framework and don't mind using pre-1.0 software — use [SvelteKit](https://kit.svelte.dev), the official application framework for Svelte. |
|||
|
|||
--- |
|||
|
|||
# svelte app |
|||
|
|||
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template. |
|||
|
|||
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit): |
|||
|
|||
```bash |
|||
npx degit sveltejs/template svelte-app |
|||
cd svelte-app |
|||
``` |
|||
|
|||
*Note that you will need to have [Node.js](https://nodejs.org) installed.* |
|||
|
|||
|
|||
## Get started |
|||
|
|||
Install the dependencies... |
|||
|
|||
```bash |
|||
cd svelte-app |
|||
npm install |
|||
``` |
|||
|
|||
...then start [Rollup](https://rollupjs.org): |
|||
|
|||
```bash |
|||
npm run dev |
|||
``` |
|||
|
|||
Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. |
|||
|
|||
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. |
|||
|
|||
If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense. |
|||
|
|||
## Building and running in production mode |
|||
|
|||
To create an optimised version of the app: |
|||
|
|||
```bash |
|||
npm run build |
|||
``` |
|||
|
|||
You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com). |
|||
|
|||
|
|||
## Single-page app mode |
|||
|
|||
By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere. |
|||
|
|||
If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json: |
|||
|
|||
```js |
|||
"start": "sirv public --single" |
|||
``` |
|||
|
|||
## Using TypeScript |
|||
|
|||
This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with: |
|||
|
|||
```bash |
|||
node scripts/setupTypeScript.js |
|||
``` |
|||
|
|||
Or remove the script via: |
|||
|
|||
```bash |
|||
rm scripts/setupTypeScript.js |
|||
``` |
|||
|
|||
If you want to use `baseUrl` or `path` aliases within your `tsconfig`, you need to set up `@rollup/plugin-alias` to tell Rollup to resolve the aliases. For more info, see [this StackOverflow question](https://stackoverflow.com/questions/63427935/setup-tsconfig-path-in-svelte). |
|||
|
|||
## Deploying to the web |
|||
|
|||
### With [Vercel](https://vercel.com) |
|||
|
|||
Install `vercel` if you haven't already: |
|||
|
|||
```bash |
|||
npm install -g vercel |
|||
``` |
|||
|
|||
Then, from within your project folder: |
|||
|
|||
```bash |
|||
cd public |
|||
vercel deploy --name my-project |
|||
``` |
|||
|
|||
### With [surge](https://surge.sh/) |
|||
|
|||
Install `surge` if you haven't already: |
|||
|
|||
```bash |
|||
npm install -g surge |
|||
``` |
|||
|
|||
Then, from within your project folder: |
|||
|
|||
```bash |
|||
npm run build |
|||
surge public my-project.surge.sh |
|||
``` |
File diff suppressed because it is too large
@ -0,0 +1,24 @@ |
|||
{ |
|||
"name": "svelte-app", |
|||
"version": "1.0.0", |
|||
"private": true, |
|||
"scripts": { |
|||
"build": "rollup -c", |
|||
"dev": "rollup -c -w", |
|||
"start": "sirv public --no-clear" |
|||
}, |
|||
"devDependencies": { |
|||
"@rollup/plugin-commonjs": "^17.0.0", |
|||
"@rollup/plugin-node-resolve": "^11.0.0", |
|||
"@tsconfig/svelte": "^3.0.0", |
|||
"rollup": "^2.3.4", |
|||
"rollup-plugin-css-only": "^3.1.0", |
|||
"rollup-plugin-livereload": "^2.0.0", |
|||
"rollup-plugin-svelte": "^7.0.0", |
|||
"rollup-plugin-terser": "^7.0.0", |
|||
"svelte": "^3.0.0" |
|||
}, |
|||
"dependencies": { |
|||
"sirv-cli": "^2.0.0" |
|||
} |
|||
} |
@ -0,0 +1,63 @@ |
|||
html, body { |
|||
position: relative; |
|||
width: 100%; |
|||
height: 100%; |
|||
} |
|||
|
|||
body { |
|||
color: #333; |
|||
margin: 0; |
|||
padding: 8px; |
|||
box-sizing: border-box; |
|||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; |
|||
} |
|||
|
|||
a { |
|||
color: rgb(0,100,200); |
|||
text-decoration: none; |
|||
} |
|||
|
|||
a:hover { |
|||
text-decoration: underline; |
|||
} |
|||
|
|||
a:visited { |
|||
color: rgb(0,80,160); |
|||
} |
|||
|
|||
label { |
|||
display: block; |
|||
} |
|||
|
|||
input, button, select, textarea { |
|||
font-family: inherit; |
|||
font-size: inherit; |
|||
-webkit-padding: 0.4em 0; |
|||
padding: 0.4em; |
|||
margin: 0 0 0.5em 0; |
|||
box-sizing: border-box; |
|||
border: 1px solid #ccc; |
|||
border-radius: 2px; |
|||
} |
|||
|
|||
input:disabled { |
|||
color: #ccc; |
|||
} |
|||
|
|||
button { |
|||
color: #333; |
|||
background-color: #f4f4f4; |
|||
outline: none; |
|||
} |
|||
|
|||
button:disabled { |
|||
color: #999; |
|||
} |
|||
|
|||
button:not(:disabled):active { |
|||
background-color: #ddd; |
|||
} |
|||
|
|||
button:focus { |
|||
border-color: #666; |
|||
} |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 9.0 KiB |
@ -0,0 +1,17 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset='utf-8'> |
|||
<meta name='viewport' content='width=device-width,initial-scale=1'> |
|||
|
|||
<title>Pong</title> |
|||
|
|||
<link rel='icon' type='image/png' href='/img/pog.jpg'> |
|||
<link rel='stylesheet' href='/global.css'> |
|||
<link rel='stylesheet' href='/build/bundle.css'> |
|||
<script defer src='/build/bundle.js'></script> |
|||
</head> |
|||
|
|||
<body> |
|||
</body> |
|||
</html> |
@ -0,0 +1,76 @@ |
|||
import svelte from 'rollup-plugin-svelte'; |
|||
import commonjs from '@rollup/plugin-commonjs'; |
|||
import resolve from '@rollup/plugin-node-resolve'; |
|||
import livereload from 'rollup-plugin-livereload'; |
|||
import { terser } from 'rollup-plugin-terser'; |
|||
import css from 'rollup-plugin-css-only'; |
|||
|
|||
const production = !process.env.ROLLUP_WATCH; |
|||
|
|||
function serve() { |
|||
let server; |
|||
|
|||
function toExit() { |
|||
if (server) server.kill(0); |
|||
} |
|||
|
|||
return { |
|||
writeBundle() { |
|||
if (server) return; |
|||
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { |
|||
stdio: ['ignore', 'inherit', 'inherit'], |
|||
shell: true |
|||
}); |
|||
|
|||
process.on('SIGTERM', toExit); |
|||
process.on('exit', toExit); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
export default { |
|||
input: 'src/main.ts', |
|||
output: { |
|||
sourcemap: true, |
|||
format: 'iife', |
|||
name: 'app', |
|||
file: 'public/build/bundle.js' |
|||
}, |
|||
plugins: [ |
|||
svelte({ |
|||
compilerOptions: { |
|||
// enable run-time checks when not in production
|
|||
dev: !production |
|||
} |
|||
}), |
|||
// we'll extract any component CSS out into
|
|||
// a separate file - better for performance
|
|||
css({ output: 'bundle.css' }), |
|||
|
|||
// If you have external dependencies installed from
|
|||
// npm, you'll most likely need these plugins. In
|
|||
// some cases you'll need additional configuration -
|
|||
// consult the documentation for details:
|
|||
// https://github.com/rollup/plugins/tree/master/packages/commonjs
|
|||
resolve({ |
|||
browser: true, |
|||
dedupe: ['svelte'] |
|||
}), |
|||
commonjs(), |
|||
|
|||
// In dev mode, call `npm run start` once
|
|||
// the bundle has been generated
|
|||
!production && serve(), |
|||
|
|||
// Watch the `public` directory and refresh the
|
|||
// browser on changes when not in production
|
|||
!production && livereload('public'), |
|||
|
|||
// If we're building for production (npm run build
|
|||
// instead of npm run dev), minify
|
|||
production && terser() |
|||
], |
|||
watch: { |
|||
clearScreen: false |
|||
} |
|||
}; |
@ -0,0 +1,121 @@ |
|||
// @ts-check
|
|||
|
|||
/** This script modifies the project to support TS code in .svelte files like: |
|||
|
|||
<script lang="ts"> |
|||
export let name: string; |
|||
</script> |
|||
|
|||
As well as validating the code for CI. |
|||
*/ |
|||
|
|||
/** To work on this script: |
|||
rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template |
|||
*/ |
|||
|
|||
const fs = require("fs") |
|||
const path = require("path") |
|||
const { argv } = require("process") |
|||
|
|||
const projectRoot = argv[2] || path.join(__dirname, "..") |
|||
|
|||
// Add deps to pkg.json
|
|||
const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8")) |
|||
packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, { |
|||
"svelte-check": "^2.0.0", |
|||
"svelte-preprocess": "^4.0.0", |
|||
"@rollup/plugin-typescript": "^8.0.0", |
|||
"typescript": "^4.0.0", |
|||
"tslib": "^2.0.0", |
|||
"@tsconfig/svelte": "^2.0.0" |
|||
}) |
|||
|
|||
// Add script for checking
|
|||
packageJSON.scripts = Object.assign(packageJSON.scripts, { |
|||
"check": "svelte-check --tsconfig ./tsconfig.json" |
|||
}) |
|||
|
|||
// Write the package JSON
|
|||
fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " ")) |
|||
|
|||
// mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too
|
|||
const beforeMainJSPath = path.join(projectRoot, "src", "main.js") |
|||
const afterMainTSPath = path.join(projectRoot, "src", "main.ts") |
|||
fs.renameSync(beforeMainJSPath, afterMainTSPath) |
|||
|
|||
// Switch the app.svelte file to use TS
|
|||
const appSveltePath = path.join(projectRoot, "src", "App.svelte") |
|||
let appFile = fs.readFileSync(appSveltePath, "utf8") |
|||
appFile = appFile.replace("<script>", '<script lang="ts">') |
|||
appFile = appFile.replace("export let name;", 'export let name: string;') |
|||
fs.writeFileSync(appSveltePath, appFile) |
|||
|
|||
// Edit rollup config
|
|||
const rollupConfigPath = path.join(projectRoot, "rollup.config.js") |
|||
let rollupConfig = fs.readFileSync(rollupConfigPath, "utf8") |
|||
|
|||
// Edit imports
|
|||
rollupConfig = rollupConfig.replace(`'rollup-plugin-terser';`, `'rollup-plugin-terser';
|
|||
import sveltePreprocess from 'svelte-preprocess'; |
|||
import typescript from '@rollup/plugin-typescript';`)
|
|||
|
|||
// Replace name of entry point
|
|||
rollupConfig = rollupConfig.replace(`'src/main.js'`, `'src/main.ts'`) |
|||
|
|||
// Add preprocessor
|
|||
rollupConfig = rollupConfig.replace( |
|||
'compilerOptions:', |
|||
'preprocess: sveltePreprocess({ sourceMap: !production }),\n\t\t\tcompilerOptions:' |
|||
); |
|||
|
|||
// Add TypeScript
|
|||
rollupConfig = rollupConfig.replace( |
|||
'commonjs(),', |
|||
'commonjs(),\n\t\ttypescript({\n\t\t\tsourceMap: !production,\n\t\t\tinlineSources: !production\n\t\t}),' |
|||
); |
|||
fs.writeFileSync(rollupConfigPath, rollupConfig) |
|||
|
|||
// Add TSConfig
|
|||
const tsconfig = `{
|
|||
"extends": "@tsconfig/svelte/tsconfig.json", |
|||
|
|||
"include": ["src/**/*"], |
|||
"exclude": ["node_modules/*", "__sapper__/*", "public/*"] |
|||
}` |
|||
const tsconfigPath = path.join(projectRoot, "tsconfig.json") |
|||
fs.writeFileSync(tsconfigPath, tsconfig) |
|||
|
|||
// Add global.d.ts
|
|||
const dtsPath = path.join(projectRoot, "src", "global.d.ts") |
|||
fs.writeFileSync(dtsPath, `/// <reference types="svelte" />`) |
|||
|
|||
// Delete this script, but not during testing
|
|||
if (!argv[2]) { |
|||
// Remove the script
|
|||
fs.unlinkSync(path.join(__filename)) |
|||
|
|||
// Check for Mac's DS_store file, and if it's the only one left remove it
|
|||
const remainingFiles = fs.readdirSync(path.join(__dirname)) |
|||
if (remainingFiles.length === 1 && remainingFiles[0] === '.DS_store') { |
|||
fs.unlinkSync(path.join(__dirname, '.DS_store')) |
|||
} |
|||
|
|||
// Check if the scripts folder is empty
|
|||
if (fs.readdirSync(path.join(__dirname)).length === 0) { |
|||
// Remove the scripts folder
|
|||
fs.rmdirSync(path.join(__dirname)) |
|||
} |
|||
} |
|||
|
|||
// Adds the extension recommendation
|
|||
fs.mkdirSync(path.join(projectRoot, ".vscode"), { recursive: true }) |
|||
fs.writeFileSync(path.join(projectRoot, ".vscode", "extensions.json"), `{
|
|||
"recommendations": ["svelte.svelte-vscode"] |
|||
} |
|||
`)
|
|||
|
|||
console.log("Converted to TypeScript.") |
|||
|
|||
if (fs.existsSync(path.join(projectRoot, "node_modules"))) { |
|||
console.log("\nYou will need to re-run your dependency manager to get started.") |
|||
} |
@ -0,0 +1,27 @@ |
|||
<script> |
|||
import Navbar from './components/NavBar.svelte'; |
|||
import Profile from './components/Profile.svelte'; |
|||
import MatchHistory from './components/MatchHistory.svelte'; |
|||
const matches = [ |
|||
{ winner: 'Alice', loser: 'Bob', time: new Date('2023-02-13T15:30:00Z') }, |
|||
{ winner: 'Charlie', loser: 'David', time: new Date('2023-02-12T18:45:00Z') }, |
|||
{ winner: 'Alice', loser: 'Charlie', time: new Date('2023-02-11T21:15:00Z') }, |
|||
] |
|||
let isProfileOpen = false; |
|||
function clickProfile() { |
|||
isProfileOpen = true; |
|||
} |
|||
</script> |
|||
|
|||
<main> |
|||
<Navbar clickProfile={clickProfile} /> |
|||
{#if isProfileOpen} |
|||
<div on:click={() => isProfileOpen = false} on:keydown={() => isProfileOpen = false}> |
|||
<Profile username="Alice" wins={10} losses={5} is2faEnabled={false} /> |
|||
</div> |
|||
{/if} |
|||
<MatchHistory matches={matches} /> |
|||
</main> |
|||
|
|||
<style> |
|||
</style> |
@ -0,0 +1,24 @@ |
|||
<script lang="ts"> |
|||
export let matches: Match[] = []; |
|||
interface Match { |
|||
winner: string; |
|||
loser: string; |
|||
time: Date; |
|||
} |
|||
</script> |
|||
|
|||
<main> |
|||
{#if matches.length > 0} |
|||
<ul> |
|||
{#each matches as match} |
|||
<li> |
|||
<span>{match.winner} vs {match.loser}</span> |
|||
<span>{match.winner} won 1-0</span> |
|||
<span>{match.time.toLocaleString()}</span> |
|||
</li> |
|||
{/each} |
|||
</ul> |
|||
{:else} |
|||
<p>No matches to display</p> |
|||
{/if} |
|||
</main> |
@ -0,0 +1,80 @@ |
|||
<script lang="ts"> |
|||
export let links = [ |
|||
{ text: "Home", url: "/" }, |
|||
{ text: "Play", url: "/Play" }, |
|||
{ text: "Spectate", url: "/Spectate"}, |
|||
{ text: "Chat", url: "/Chat"}, |
|||
{ text: "History", url: "/History"}, |
|||
{ text: "Profile", url: "/Profile" } |
|||
]; |
|||
export let clickProfile; |
|||
</script> |
|||
|
|||
<nav class="navigation-bar"> |
|||
<ul> |
|||
{#each links as link} |
|||
{#if link.text === "Profile"} |
|||
<li> |
|||
<button on:click={clickProfile}> |
|||
<img src="img/profileicon.png" alt="profile icon"> |
|||
</button> |
|||
</li> |
|||
{:else} |
|||
<li> |
|||
<a href={link.url}>{link.text}</a> |
|||
</li> |
|||
{/if} |
|||
{/each} |
|||
</ul> |
|||
</nav> |
|||
|
|||
<style> |
|||
.navigation-bar { |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
background-color: #f5f5f5; |
|||
padding: 1rem; |
|||
} |
|||
|
|||
.navigation-bar ul { |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
list-style: none; |
|||
padding: 0; |
|||
} |
|||
|
|||
.navigation-bar li { |
|||
margin: 0 1rem; |
|||
} |
|||
|
|||
.navigation-bar a { |
|||
text-decoration: none; |
|||
color: #333; |
|||
} |
|||
|
|||
.navigation-bar img { |
|||
width: 2rem; |
|||
height: 2rem; |
|||
} |
|||
|
|||
@media (max-width: 768px) { |
|||
.navigation-bar { |
|||
flex-direction: column; |
|||
align-items: stretch; |
|||
} |
|||
|
|||
.navigation-bar ul { |
|||
flex-direction: column; |
|||
align-items: center; |
|||
justify-content: center; |
|||
} |
|||
|
|||
.navigation-bar li { |
|||
margin: 0; |
|||
padding: 1rem; |
|||
text-align: center; |
|||
} |
|||
} |
|||
</style> |
@ -0,0 +1,64 @@ |
|||
<script> |
|||
export let username = ''; |
|||
export let wins = 0; |
|||
export let losses = 0; |
|||
export let is2faEnabled = false; |
|||
function toggle2fa() { |
|||
is2faEnabled = !is2faEnabled; |
|||
} |
|||
</script> |
|||
|
|||
<div class="overlay"> |
|||
<div class="profile"> |
|||
<div class="profile-header"> |
|||
<img class="profile-img" src="img/profileicon.png" alt="Profile Icon"> |
|||
<h3>{username}</h3> |
|||
</div> |
|||
<div class="profile-body"> |
|||
<p>Wins: {wins}</p> |
|||
<p>Losses: {losses}</p> |
|||
<div class="two-factor-auth"> |
|||
<input type="checkbox" id="2fa-toggle" bind:checked={is2faEnabled} on:change={toggle2fa}> |
|||
<label for="2fa-toggle">Enable 2fa</label> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<style> |
|||
.overlay { |
|||
position: fixed; |
|||
top: 0; |
|||
left: 0; |
|||
width: 100%; |
|||
height: 100%; |
|||
background-color: rgba(0, 0, 0, 0.5); |
|||
z-index: 9998; |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
} |
|||
|
|||
.profile { |
|||
background-color: #fff; |
|||
border: 1px solid #ccc; |
|||
border-radius: 5px; |
|||
padding: 1rem; |
|||
width: 300px; |
|||
} |
|||
|
|||
.profile-header { |
|||
display: flex; |
|||
align-items: center; |
|||
} |
|||
|
|||
.profile-img { |
|||
width: 50px; |
|||
height: 50px; |
|||
margin-right: 1rem; |
|||
} |
|||
|
|||
.two-factor-auth { |
|||
margin-top: 1rem; |
|||
} |
|||
</style> |
@ -0,0 +1,7 @@ |
|||
import App from './App.svelte'; |
|||
|
|||
const app = new App({ |
|||
target: document.body, |
|||
}); |
|||
|
|||
export default app; |
@ -0,0 +1,24 @@ |
|||
{ |
|||
"compilerOptions": { |
|||
"target": "es6", |
|||
"module": "es6", |
|||
"strict": true, |
|||
"noImplicitAny": true, |
|||
"jsx": "preserve", |
|||
"importHelpers": true, |
|||
"moduleResolution": "node", |
|||
"esModuleInterop": true, |
|||
"allowSyntheticDefaultImports": true, |
|||
"sourceMap": true, |
|||
"baseUrl": ".", |
|||
"types": ["svelte"], |
|||
"experimentalDecorators": true, |
|||
"emitDecoratorMetadata": true, |
|||
"skipDefaultLibCheck": true, |
|||
"strictNullChecks": false, |
|||
"declaration": false, |
|||
"downlevelIteration": true |
|||
}, |
|||
"include": ["src/**/*.ts"], |
|||
"exclude": ["node_modules/*", "public/*"] |
|||
} |
Loading…
Reference in new issue