Compare commits

...

9 Commits

9 changed files with 165 additions and 10 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
tmp
server
dist
index.html

62
Makefile Normal file
View File

@ -0,0 +1,62 @@
all: build
nil:
reactNextJS/out/*: reactNextJS/app/* reactNextJS/*.js reactNextJS/*.json
cd reactNextJS && npm install && npm run build
nextjs: reactNextJS/out/*
cleanNext:
rm -rf reactNextJS/out
vuejs/dist/*: vuejs/src/*
cd vuejs && npm install && npm run build
vuejs: vuejs/dist/*
cleanVue:
rm -rf ./vuejs/dist
svelte/dist/*: svelte/src/*
cd svelte && npm install && npm run build
svelte: svelte/dist/*
cleanSvelte:
rm -rf ./svelte/dist
cleandist:
rm -rf dist
dist:
mkdir -p dist
dist/vanillaJS: dist vanillaJS/index.html
rm -rf dist/vanillaJS && \
cp -r ./vanillaJS ./dist/vanillaJS
dist/react: dist react/index.html
rm -rf dist/react && \
cp -r ./react ./dist/react
dist/alpinejs: dist alpinejs/index.html
rm -rf dist/alpinejs && \
cp -r ./alpinejs ./dist/alpinejs
dist/reactNextJS: dist reactNextJS/out/*
rm -rf ./dist/reactNextJS && \
cp -r ./reactNextJS/out ./dist/reactNextJS
dist/vuejs: dist vuejs/dist/*
rm -rf ./dist/vuejs && \
cp -r ./vuejs/dist ./dist/vuejs
dist/svelte: dist svelte/dist/*
rm -rf ./dist/svelte && \
cp -r ./svelte/dist ./dist/svelte
dist/index.html: dist index.tmpl
go run server.go generate
mv index.html dist/
export: dist/vanillaJS dist/react dist/alpinejs dist/reactNextJS dist/assets dist/vuejs dist/svelte dist/index.html
web: ./svelte/dist/* ./vuejs/dist/* ./reactNextJS/out/* vanillaJS/index.html react/index.html alpinejs/index.html
build: web server.go
go build server.go
run: web server.go
go run server.go
air: nil web server.go
air server.go
clean: cleanNext cleanVue cleanSvelte cleandist
rm -rf tmp
rm -f server
rm -f index.html
.PHONY: all build clean cleanbuild nextjs vuejs svelte run air nil web export

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module frontends
go 1.22.3

View File

@ -1,9 +0,0 @@
<html>
<body>
<h1>Frontends</h1>
<ul>
<li><a href="react/index.html">React</a></li>
<li><a href="vanillaJS/index.html">vanillaJS</a></li>
</ul>
</body>
</html>

10
index.tmpl Normal file
View File

@ -0,0 +1,10 @@
<html>
<body>
<h1>Frontends</h1>
<ul>
{{range .}}
<li><a href="{{.Mountpoint}}">{{.Name}}</a></li>
{{end}}
</ul>
</body>
</html>

View File

@ -3,6 +3,7 @@
*/ */
const nextConfig = { const nextConfig = {
output: 'export', output: 'export',
basePath: '/reactNextJS',
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html` // Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
// trailingSlash: true, // trailingSlash: true,

82
server.go Normal file
View File

@ -0,0 +1,82 @@
package main
import (
"embed"
"fmt"
"html/template"
"io/fs"
"net/http"
"os"
)
const PORT = 3003
type frontendInfo struct {
Name, Mountpoint string
}
//go:embed "all:vuejs/dist"
var vueFiles embed.FS
//go:embed "all:reactNextJS/out"
var nextFiles embed.FS
//go:embed "all:svelte/dist"
var svelteFiles embed.FS
//go:embed "vanillaJS"
var vanillaFiles embed.FS
//go:embed "alpinejs"
var alpineFiles embed.FS
//go:embed "react"
var reactFiles embed.FS
func addFrontend(files embed.FS, mountpoint string, subfs string, name string) frontendInfo {
subFiles, _ := fs.Sub(files, subfs)
fileServer := http.FileServerFS(subFiles)
http.Handle(mountpoint, http.StripPrefix(mountpoint, fileServer))
return frontendInfo{name, mountpoint}
}
func outputIndexAndExit(indexTemplate template.Template, frontends []frontendInfo) {
file, err := os.OpenFile("index.html", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
panic(err) // Handle error
}
defer file.Close()
indexTemplate.Execute(file, frontends)
os.Exit(0)
}
func main() {
args := os.Args
home_template, err := template.ParseFiles("index.tmpl")
if err != nil {
panic(fmt.Sprintf("Error parsing homepage template\n%s", err))
}
frontends := []frontendInfo{
addFrontend(vanillaFiles, "/vanillaJS/", "vanillaJS", "JS Only"),
addFrontend(alpineFiles, "/alpinejs/", "alpinejs", "Alpine.js"),
addFrontend(reactFiles, "/react/", "react", "React"),
addFrontend(nextFiles, "/reactNextJS/", "reactNextJS/out", "React (Next.js)"),
addFrontend(vueFiles, "/vuejs/", "vuejs/dist", "Vue.js"),
addFrontend(svelteFiles, "/svelte/", "svelte/dist", "Svelte"),
}
if len(args) == 2 && args[1] == "generate" {
outputIndexAndExit(*home_template, frontends)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
err = home_template.Execute(w, frontends)
})
err = http.ListenAndServe(fmt.Sprintf(":%d", PORT), nil)
if err != nil {
panic(fmt.Sprintf("Error starting server: %s", err))
}
}

View File

@ -4,4 +4,5 @@ import { svelte } from '@sveltejs/vite-plugin-svelte'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [svelte()], plugins: [svelte()],
base: '/svelte/'
}) })

View File

@ -14,5 +14,6 @@ export default defineConfig({
alias: { alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)) '@': fileURLToPath(new URL('./src', import.meta.url))
} }
} },
base: '/vuejs/'
}) })