Start mithril app with bun for the frontend

This commit is contained in:
Dave Smith-Hayes 2024-02-24 22:12:57 -05:00
parent 27a9cea714
commit 523197902f
24 changed files with 2599 additions and 39 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -55,19 +55,20 @@
"laminas/laminas-diactoros": "^3.0.0", "laminas/laminas-diactoros": "^3.0.0",
"laminas/laminas-stdlib": "^3.6", "laminas/laminas-stdlib": "^3.6",
"mezzio/mezzio": "^3.7", "mezzio/mezzio": "^3.7",
"mezzio/mezzio-authentication-session": "^1.9",
"mezzio/mezzio-fastroute": "^3.11.0", "mezzio/mezzio-fastroute": "^3.11.0",
"mezzio/mezzio-helpers": "^5.7", "mezzio/mezzio-helpers": "^5.7",
"mezzio/mezzio-platesrenderer": "^2.10" "mezzio/mezzio-platesrenderer": "^2.10"
}, },
"require-dev": { "require-dev": {
"filp/whoops": "^2.15.4",
"laminas/laminas-coding-standard": "~2.5.0", "laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-development-mode": "^3.12.0", "laminas/laminas-development-mode": "^3.12.0",
"mezzio/mezzio-tooling": "^2.9", "mezzio/mezzio-tooling": "^2.9",
"phpunit/phpunit": "^10.5.5", "phpunit/phpunit": "^10.5.5",
"psalm/plugin-phpunit": "^0.18.4", "psalm/plugin-phpunit": "^0.18.4",
"roave/security-advisories": "dev-master", "roave/security-advisories": "dev-master",
"vimeo/psalm": "^5.18", "vimeo/psalm": "^5.18"
"filp/whoops": "^2.15.4"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

292
app/composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "ac40ea0195435e6db97e4041dd7b543c", "content-hash": "e4a4cfd4117c44efbf1503d8c2d5beb0",
"packages": [ "packages": [
{ {
"name": "brick/varexporter", "name": "brick/varexporter",
@ -128,6 +128,68 @@
], ],
"time": "2022-01-17T14:14:24+00:00" "time": "2022-01-17T14:14:24+00:00"
}, },
{
"name": "dflydev/fig-cookies",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/dflydev/dflydev-fig-cookies.git",
"reference": "ebe6c15c9895fc490efe620ad734c8ef4a85bdb0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dflydev/dflydev-fig-cookies/zipball/ebe6c15c9895fc490efe620ad734c8ef4a85bdb0",
"reference": "ebe6c15c9895fc490efe620ad734c8ef4a85bdb0",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"php": "^7.2 || ^8.0",
"psr/http-message": "^1.0.1 || ^2"
},
"require-dev": {
"doctrine/coding-standard": "^8",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpunit/phpunit": "^7.2.6 || ^9",
"scrutinizer/ocular": "^1.8",
"squizlabs/php_codesniffer": "^3.3",
"vimeo/psalm": "^4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Dflydev\\FigCookies\\": "src/Dflydev/FigCookies"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Beau Simensen",
"email": "beau@dflydev.com"
}
],
"description": "Cookies for PSR-7 HTTP Message Interface.",
"keywords": [
"cookies",
"psr-7",
"psr7"
],
"support": {
"issues": "https://github.com/dflydev/dflydev-fig-cookies/issues",
"source": "https://github.com/dflydev/dflydev-fig-cookies/tree/v3.1.0"
},
"time": "2023-07-18T20:41:43+00:00"
},
{ {
"name": "elie29/zend-phpdi-config", "name": "elie29/zend-phpdi-config",
"version": "v9.0.1", "version": "v9.0.1",
@ -969,6 +1031,158 @@
], ],
"time": "2024-02-14T10:42:11+00:00" "time": "2024-02-14T10:42:11+00:00"
}, },
{
"name": "mezzio/mezzio-authentication",
"version": "1.9.0",
"source": {
"type": "git",
"url": "https://github.com/mezzio/mezzio-authentication.git",
"reference": "2e232154ea7ea44800b4706a9242220bf16958e5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mezzio/mezzio-authentication/zipball/2e232154ea7ea44800b4706a9242220bf16958e5",
"reference": "2e232154ea7ea44800b4706a9242220bf16958e5",
"shasum": ""
},
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"psr/container": "^1.0 || ^2.0",
"psr/http-message": "^1.0.1 || ^2.0.0",
"psr/http-server-middleware": "^1.0",
"webmozart/assert": "^1.11.0"
},
"conflict": {
"container-interop/container-interop": "<1.2.0",
"zendframework/zend-expressive-authentication": "*"
},
"require-dev": {
"ext-sqlite3": "*",
"laminas/laminas-coding-standard": "~2.5.0",
"phpunit/phpunit": "^10.4.2",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.16"
},
"suggest": {
"ext-pdo": "*: for use with the PDO-backed UserRepositoryInterface implementation",
"mezzio/mezzio-authentication-basic": "Provides an HTTP Basic Authentication AuthenticationInterface implementation",
"mezzio/mezzio-authentication-laminasauthentication": "Provides a laminas-authentication AuthenticationInterface implementation",
"mezzio/mezzio-authentication-session": "Provides a username/password + session AuthenticationInterface implementation"
},
"type": "library",
"extra": {
"laminas": {
"config-provider": "Mezzio\\Authentication\\ConfigProvider"
}
},
"autoload": {
"psr-4": {
"Mezzio\\Authentication\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Authentication middleware for Mezzio and PSR-7 applications",
"homepage": "https://mezzio.dev",
"keywords": [
"Authentication",
"http",
"laminas",
"mezzio",
"middleware",
"psr-15",
"psr-7"
],
"support": {
"chat": "https://laminas.dev/chat",
"docs": "https://docs.mezzio.dev/mezzio-authentication/",
"forum": "https://discourse.laminas.dev",
"issues": "https://github.com/mezzio/mezzio-authentication/issues",
"rss": "https://github.com/mezzio/mezzio-authentication/releases.atom",
"source": "https://github.com/mezzio/mezzio-authentication"
},
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2023-11-28T15:52:34+00:00"
},
{
"name": "mezzio/mezzio-authentication-session",
"version": "1.9.0",
"source": {
"type": "git",
"url": "https://github.com/mezzio/mezzio-authentication-session.git",
"reference": "19ff41fa09808b7fce968e14faf31c5c4fbec788"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mezzio/mezzio-authentication-session/zipball/19ff41fa09808b7fce968e14faf31c5c4fbec788",
"reference": "19ff41fa09808b7fce968e14faf31c5c4fbec788",
"shasum": ""
},
"require": {
"mezzio/mezzio-authentication": "^1.3",
"mezzio/mezzio-session": "^1.6",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"psr/container": "^1.0 || ^2.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0.1 || ^2.0.0",
"webmozart/assert": "^1.10"
},
"conflict": {
"zendframework/zend-expressive-authentication-session": "*"
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-diactoros": "^3.3",
"phpunit/phpunit": "^10.5.5",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.18.0"
},
"type": "library",
"extra": {
"laminas": {
"config-provider": "Mezzio\\Authentication\\Session\\ConfigProvider"
}
},
"autoload": {
"psr-4": {
"Mezzio\\Authentication\\Session\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Username/password, session-backed authentication adapter for mezzio-authentication.",
"homepage": "https://mezzio.dev",
"keywords": [
"Authentication",
"laminas",
"mezzio",
"session"
],
"support": {
"chat": "https://laminas.dev/chat",
"docs": "https://docs.mezzio.dev/mezzio-authentication-session/",
"forum": "https://discourse.laminas.dev",
"issues": "https://github.com/mezzio/mezzio-authentication-session/issues",
"rss": "https://github.com/mezzio/mezzio-authentication-session/releases.atom",
"source": "https://github.com/mezzio/mezzio-authentication-session"
},
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2024-01-01T21:20:46+00:00"
},
{ {
"name": "mezzio/mezzio-fastroute", "name": "mezzio/mezzio-fastroute",
"version": "3.11.0", "version": "3.11.0",
@ -1280,6 +1494,82 @@
], ],
"time": "2023-10-31T17:23:17+00:00" "time": "2023-10-31T17:23:17+00:00"
}, },
{
"name": "mezzio/mezzio-session",
"version": "1.14.1",
"source": {
"type": "git",
"url": "https://github.com/mezzio/mezzio-session.git",
"reference": "8e5d85644c6749149e3ef2de91a82ae0bd363b3d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mezzio/mezzio-session/zipball/8e5d85644c6749149e3ef2de91a82ae0bd363b3d",
"reference": "8e5d85644c6749149e3ef2de91a82ae0bd363b3d",
"shasum": ""
},
"require": {
"dflydev/fig-cookies": "^3.0",
"ext-json": "*",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"psr/container": "^1.0 || ^2.0",
"psr/http-server-middleware": "^1.0"
},
"conflict": {
"zendframework/zend-expressive-session": "*"
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-diactoros": "^3.3.0",
"phpunit/phpunit": "^10.4.2",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.15"
},
"suggest": {
"mezzio/mezzio-csrf": "^1.0 || ^1.0-dev for CSRF protection capabilities",
"mezzio/mezzio-flash": "^1.0 || ^1.0-dev for flash message capabilities",
"mezzio/mezzio-session-ext": "^1.0 || ^1.0-dev for an ext-session persistence adapter"
},
"type": "library",
"extra": {
"laminas": {
"config-provider": "Mezzio\\Session\\ConfigProvider"
}
},
"autoload": {
"psr-4": {
"Mezzio\\Session\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Session container and middleware for PSR-7 applications",
"homepage": "https://mezzio.dev",
"keywords": [
"laminas",
"mezzio",
"middleware",
"psr-7",
"session"
],
"support": {
"chat": "https://laminas.dev/chat",
"docs": "https://docs.mezzio.dev/mezzio-session/",
"forum": "https://discourse.laminas.dev",
"issues": "https://github.com/mezzio/mezzio-session/issues",
"rss": "https://github.com/mezzio/mezzio-session/releases.atom",
"source": "https://github.com/mezzio/mezzio-session"
},
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2024-01-13T12:11:07+00:00"
},
{ {
"name": "mezzio/mezzio-template", "name": "mezzio/mezzio-template",
"version": "2.10.0", "version": "2.10.0",

View File

@ -2,6 +2,11 @@
declare(strict_types=1); declare(strict_types=1);
use Mezzio\Authentication\AuthenticationInterface;
use Mezzio\Authentication\Session\PhpSession;
use Mezzio\Authentication\UserRepository\PdoDatabase;
use Mezzio\Authentication\UserRepositoryInterface;
return [ return [
// Provides application-wide services. // Provides application-wide services.
// We recommend using fully-qualified class names whenever possible as // We recommend using fully-qualified class names whenever possible as
@ -10,7 +15,8 @@ return [
// Use 'aliases' to alias a service name to another service. The // Use 'aliases' to alias a service name to another service. The
// key is the alias name, the value is the service to which it points. // key is the alias name, the value is the service to which it points.
'aliases' => [ 'aliases' => [
// Fully\Qualified\ClassOrInterfaceName::class => Fully\Qualified\ClassName::class, AuthenticationInterface::class => PhpSession::class,
UserRepositoryInterface::class => PdoDatabase::class,
], ],
// Use 'invokables' for constructor-less services, or services that do // Use 'invokables' for constructor-less services, or services that do
// not require arguments to the constructor. Map a service name to the // not require arguments to the constructor. Map a service name to the

View File

@ -0,0 +1,19 @@
<?php
/**
* This file generated by Mezzio\Tooling\Factory\ConfigInjector.
*
* Modifications should be kept at a minimum, and restricted to adding or
* removing factory definitions; other dependency types may be overwritten
* when regenerating this file via mezzio-tooling commands.
*/
declare(strict_types=1);
return [
'dependencies' => [
'factories' => [
App\Login\LoginHandler::class => App\Login\LoginHandlerFactory::class,
],
],
];

View File

@ -21,4 +21,7 @@ return [
'template_error' => 'error::error', 'template_error' => 'error::error',
], ],
], ],
'authentication' => [
'redirect' => '/login',
],
]; ];

View File

@ -14,6 +14,9 @@ $cacheConfig = [
]; ];
$aggregator = new ConfigAggregator([ $aggregator = new ConfigAggregator([
\Mezzio\Authentication\Session\ConfigProvider::class,
\Mezzio\Authentication\ConfigProvider::class,
\Mezzio\Session\ConfigProvider::class,
\Mezzio\Tooling\ConfigProvider::class, \Mezzio\Tooling\ConfigProvider::class,
\Mezzio\Plates\ConfigProvider::class, \Mezzio\Plates\ConfigProvider::class,
\Mezzio\Helper\ConfigProvider::class, \Mezzio\Helper\ConfigProvider::class,

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Login;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Laminas\Diactoros\Response\HtmlResponse;
use Mezzio\Template\TemplateRendererInterface;
class LoginHandler implements RequestHandlerInterface
{
/**
* @var TemplateRendererInterface
*/
private $renderer;
public function __construct(TemplateRendererInterface $renderer)
{
$this->renderer = $renderer;
}
public function handle(ServerRequestInterface $request) : ResponseInterface
{
// Do some work...
// Render and return a response:
return new HtmlResponse($this->renderer->render(
'app::login',
[] // parameters to pass to template
));
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace App\Login;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerInterface;
class LoginHandlerFactory
{
public function __invoke(ContainerInterface $container) : LoginHandler
{
return new LoginHandler($container->get(TemplateRendererInterface::class));
}
}

View File

@ -1,17 +0,0 @@
<?php $this->layout('layout::default', ['title' => 'Home']) ?>
<div>
<form action="/action" method="POST">
<div>
<label for="username" name="username">Username</label>
<input type="text" name="username" required />
</div>
<div>
<label for="password" name="password">Password</label>
<input type="password" name="password" required />
</div>
<div>
<input type="submit" name="submit" value="Submit" />
</div>
</form>
</div>

View File

@ -0,0 +1 @@
Template for App\Login\LoginHandler

View File

@ -1,18 +0,0 @@
<form action="/login" action="POST">
<div>
<div>
<label for="username" name="username">Username</label>
</div>
<div>
<input type="text" name="username" require />
</div>
</div>
<div>
<div>
<label for="password" name="password">Password</label>
</div>
<div>
<input type="password" name="password" require />
</div>
</div>
</form>

3
frontend/.editorconfig Normal file
View File

@ -0,0 +1,3 @@
[*.{html,js,jsx,ts,tsx}]
indent_type = space
indent_size = 2

175
frontend/.gitignore vendored Normal file
View File

@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Caches
.cache
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Runtime data
pids
_.pid
_.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store

15
frontend/README.md Normal file
View File

@ -0,0 +1,15 @@
# slovocast-frontend
To install dependencies:
```bash
bun install
```
To run:
```bash
bun run index.ts
```
This project was created using `bun init` in bun v1.0.24. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

4
frontend/build.ts Normal file
View File

@ -0,0 +1,4 @@
await Bun.build({
entrypoints: [ './src/index.ts' ],
outdir: './public/js'
});

BIN
frontend/bun.lockb Executable file

Binary file not shown.

16
frontend/package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "slovocast-frontend",
"module": "index.ts",
"type": "module",
"devDependencies": {
"@types/bun": "latest",
"@types/mithril": "^2.2.6"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"bun": "^1.0.29",
"mithril": "^2.2.2"
}
}

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Slovocast</title>
</head>
<body>
<script src="js/index.js" ></script>
</body>
</html>

1934
frontend/public/js/index.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
import m from 'mithril';
import User from '../models/User';
const users: User[] = [
new User('U1'),
new User('U2'),
new User('U3')
];
export default const UserList = {
getList: function () {
return users.map(u => m('li', u.getUsername()));
},
view: function () {
return m('li', { id: 'UserList' }, this.getList());
}
};

13
frontend/src/index.ts Normal file
View File

@ -0,0 +1,13 @@
import m from 'mithril';
import UserList from './components/UserList';
const App = {
view: function() {
return m('body', [
UserList
]);
}
}
//@ts-ignore This will be rendered and run on the DOM of a web page
m.mount(document.body, App);

View File

@ -0,0 +1,12 @@
export default class User {
private username: string;
public constructor(username: string) {
this.username = username;
}
public getUsername(): string {
return this.username;
}
}

22
frontend/tsconfig.json Normal file
View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
/* Linting */
"skipLibCheck": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true
}
}