Initial commit

This commit is contained in:
Daniel Bulant 2020-12-05 18:10:57 +01:00
commit c0f7aa402a
19 changed files with 2591 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/node_modules/
/public/build/
.DS_Store

105
README.md Normal file
View file

@ -0,0 +1,105 @@
*Looking for a shareable component template? Go here --> [sveltejs/component-template](https://github.com/sveltejs/component-template)*
---
# 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:5000](http://localhost:5000). 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
```
## 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
```

1788
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

22
package.json Normal file
View file

@ -0,0 +1,22 @@
{
"name": "svelte-app",
"version": "1.0.0",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.0.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": "^1.0.0"
}
}

BIN
public/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

71
public/global.css Normal file
View file

@ -0,0 +1,71 @@
html, body {
position: relative;
width: 100%;
height: 100%;
}
body {
color: #333;
margin: 0;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
h1 {
margin-block-start: 0em;
margin-block-end: 0em;
margin-inline-start: 0px;
margin-inline-end: 0px;
padding-block-start: 0.67em;
padding-block-end: 0.67em;
}
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;
}

18
public/index.html Normal file
View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<title>Svelte app</title>
<link rel='icon' type='image/png' href='/favicon.png'>
<link rel='stylesheet' href='/global.css'>
<link rel='stylesheet' href='/build/bundle.css'>
<script defer src='/build/bundle.js'></script>
</head>
<body>
</body>
</html>

BIN
public/thetutorials.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

76
rollup.config.js Normal file
View file

@ -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.js',
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
}
};

117
scripts/setupTypeScript.js Normal file
View file

@ -0,0 +1,117 @@
// @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": "^1.0.0",
"svelte-preprocess": "^4.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"typescript": "^3.9.3",
"tslib": "^2.0.0",
"@tsconfig/svelte": "^1.0.0"
})
// Add script for checking
packageJSON.scripts = Object.assign(packageJSON.scripts, {
"validate": "svelte-check"
})
// 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(),\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)
// 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"))
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.")
}

77
src/App.svelte Normal file
View file

@ -0,0 +1,77 @@
<script>
import Button from "./components/button.svelte";
import Link from "./components/link.svelte";
import Navbar from "./components/navbar.svelte";
import Project from "./components/project.svelte";
import Separator from "./components/separator.svelte";
import darkmode from "./stores/darkmode";
</script>
<svelte:head>
<title>Daniel Bulant design</title>
</svelte:head>
<Navbar darkmode={$darkmode}>
<Link href="/" colored>
Daniel Bulant
</Link>
<Separator />
<Button bind:value={$darkmode} outline={$darkmode}>{$darkmode ? "Dark" : "Light"} mode</Button>
</Navbar>
<main class:darkmode={$darkmode}>
<h1 class="center">Daniel Bulant</h1>
<section>
<h2 class="center">Projects</h2>
<Project title="igni">
<p slot="description">
igni is a universal discord bot with advanced moderation, advanced configuration and unique command handling. It can replace majority of other bots and is being actively worked on.
</p>
<img class="preview" src="https://cdn.discordapp.com/avatars/739864286775738399/1da650ca04e3e4b113756258d65efe09.png?size=2048" alt="igni avatar" slot="preview">
<div slot="actions">
<Button href="https://discordbotlist.com/bots/igni">More information</Button>
<Button outline href="https://discord.com/oauth2/authorize?client_id=739864286775738399&scope=bot&permissions=1039199350">Add igni to your server</Button>
</div>
</Project>
<Project title="The Tutorials">
<p slot="description">
Czech tutorials, blog and news about node, php and scratch for everyone.
</p>
<img class="preview thetutorials" src="thetutorials.jpg" alt="The Tutorials logo" slot="preview">
<div slot="actions">
<Button href="https://thetutorials.cz">Website</Button>
<Button outline href="https://youtube.com/thetutorials">Youtube channel</Button>
</div>
</Project>
</section>
</main>
<style>
main {
min-height: calc(100vh - 50px);
}
.darkmode {
background: #242423;
color: #E8EDDF;
}
.center {
text-align: center;
}
img.preview {
width: 100%;
}
img.preview.thetutorials {
border-radius: 50%;
height: 200px;
width: auto;
}
img.logo {
padding: 5px;
height: calc(100% - 10px);
}
</style>

View file

@ -0,0 +1,64 @@
<script>
import darkmode from "../stores/darkmode";
export var outline = false;
export var href;
export var value = null;
function click() {
value = !value;
}
</script>
{#if href}
<a {href} class:darkmode on:click={click} {...$$restProps} class:outline>
<slot />
</a>
{:else}
<button class:darkmode on:click={click} {...$$restProps} class:outline>
<slot />
</button>
{/if}
<style>
button.darkmode, a.darkmode {
color: #f4f4f4;
}
button, a {
color: #333;
background-color: #f4f4f4;
border: 1px solid #ccc;
border-radius: 5px;
padding: 5px 10px;
box-shadow: 0 0 0 black;
background: #F5CB5C;
transition: box-shadow 0.1s, background 0.3s;
}
.outline {
position: relative;
background: transparent;
z-index: 1;
}
.outline::before {
content: "";
position: absolute;
top: 0;
left: 0;
background-color: #F5CB5C;
width: 0;
height: 100%;
border-radius: 0;
transition: width .3s, border-radius .3s;
z-index: -1;
}
.outline:hover::before {
width: 100%;
}
a:hover, button:hover {
background-color: #e0a500;
text-decoration: none;
box-shadow: 0 0 3px black;
}
a.outline:hover, button.outline:hover {
background: transparent;
}
</style>

View file

@ -0,0 +1,47 @@
<script>
export var navbar = false;
</script>
<section class="hero" class:navbar>
{#if $$slots.content}
<div class="title">
<slot name="title" />
</div>
<div class="content">
<slot name="content" />
</div>
{:else}
<div class="title full">
<slot name="title" />
</div>
{/if}
<slot />
</section>
<style>
.hero {
display: flex;
height: 100%;
max-height: 720px;
max-width: 1080px;
margin: auto;
padding: 0 5px;
position: relative;
}
.navbar {
height: calc(100% - 50px);
}
.title {
width: 50%;
text-align: center;
}
.title.full {
width: 100%;
}
.content {
width: 50%;
text-align: center;
}
</style>

View file

@ -0,0 +1,95 @@
<script>
export var colored = true;
</script>
<span>
<a {...$$restProps} class:colored>
<slot />
</a>
</span>
<style>
*, *:after, *:before {
box-sizing: border-box;
-moz-box-sizing: border-box;
}
* {
margin:0;
padding:0;
border:0 none;
position: relative;
outline: none;
}
a {
color: inherit;
text-decoration: none;
}
a:hover {
text-decoration: none;
}
.colored {
color: #e0a500;
}
a.colored:before {
background: #e0a500;
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
bottom: -2px;
left: 0;
background: black;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
opacity: 0.1;
transition: .25s linear, .4s opacity;
}
a:hover:before,
a:focus:before {
visibility: visible;
opacity: 1;
transform: scaleX(1);
}
@keyframes hover-v {
0% {
transform: scaleX(0);
height: 5px;
}
45% {
transform: scaleX(1.05);
height: 5px;
}
55% {
height: 5px;
}
100% {
transform: scaleX(1.05);
height: 3.8rem;
}
}
@keyframes no-hover-v {
0% {
transform: scaleX(1.05);
height: 3.8rem;
}
45% {
height: 5px;
}
55% {
transform: scaleX(1.05);
height: 5px;
opacity: 1;
}
100% {
transform: scaleX(0);
height: 5px;
opacity: .02;
}
}
</style>

View file

@ -0,0 +1,39 @@
<script>
export var darkmode;
</script>
<nav class="bar" class:darkmode>
<div class="inner">
<slot />
</div>
</nav>
<div class="spacer"></div>
<style>
.spacer {
height: 50px;
}
.darkmode {
background: #242423;
}
nav.bar .inner {
max-width: 1024px;
margin: auto;
display: flex;
justify-content: space-between;
vertical-align: middle;
align-items: center;
height: 100%;
width: calc(100% - 40px);
padding: 0 20px;
}
nav.bar {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 50px;
box-shadow: 0 0 5px black;
}
</style>

View file

@ -0,0 +1,45 @@
<script>
export var title;
export var left = false;
</script>
<article>
<div class="line" class:left>
<div class="info">
<h3>{title}</h3>
<p><slot name="description" /></p>
<div class="actions">
<slot name="actions" />
</div>
</div>
<div class="preview">
<slot name="preview" />
</div>
</div>
</article>
<style>
.line {
display: flex;
justify-content: space-between;
max-width: 720px;
width: 100%;
margin: auto;
}
.info {
width: calc(100% - 192px);
flex-grow: 1;
flex-shrink: 0;
}
.left .preview {
float: left;
}
.left .info {
float: right;
}
.preview {
width: 50%;
flex-shrink: 1;
flex-grow: 0;
}
</style>

View file

@ -0,0 +1,8 @@
<div></div>
<style>
div {
flex-grow: 1;
}
</style>

10
src/main.js Normal file
View file

@ -0,0 +1,10 @@
import App from './App.svelte';
const app = new App({
target: document.body,
props: {
name: 'world'
}
});
export default app;

5
src/stores/darkmode.js Normal file
View file

@ -0,0 +1,5 @@
import { writable } from "svelte/store";
const darkmode = writable(localStorage.getItem("darkmode") || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
export default darkmode;