Skip to content

Commit

Permalink
Merge pull request #12 from Defacto2/now-online
Browse files Browse the repository at this point in the history
Now online
  • Loading branch information
bengarrett authored Jun 11, 2024
2 parents e5b0b86 + ef05cd8 commit 786093b
Show file tree
Hide file tree
Showing 50 changed files with 2,013 additions and 1,991 deletions.
67 changes: 0 additions & 67 deletions .air.windows.toml

This file was deleted.

5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
},
"editor.formatOnSave": true,
"files.associations": {
"*.env.local": "ini",
"*.gohtml": "html",
"*.tmpl": "html",
"*.env.local": "ini"
"*.service": "ini",
"*.tmpl": "html"
},
"files.eol": "\n",
"runOnSave.statusMessageTimeout": 3000,
Expand Down
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

61 changes: 16 additions & 45 deletions Taskfile.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@
version: "3"

vars:
BINNAME: df2-server # build output, binary filename (without any extensions)
BINNAME: dist/df2-server # build output, binary filename (without any extensions)

dotenv: [".env.local"]
dotenv: ["./init/.env.local"]

tasks:
default:
desc: "Task runner for the Defacto2 web server source code."
cmds:
- task --list-all
silent: true
file-sync:
desc: "Sync the source code to the remote server."
cmds:
- rsync --info=progress2 --recursive --human-readable [email protected]:/opt/assets-defacto2/downloads /home/ben/defacto2-assets/
- rsync --info=progress2 --recursive --human-readable [email protected]:/opt/assets-defacto2/images000 /home/ben/defacto2-assets/
- rsync --info=progress2 --recursive --human-readable [email protected]:/opt/assets-defacto2/images400 /home/ben/defacto2-assets/
doc:
desc: "Generate and browse the application module documentation."
cmds:
Expand All @@ -41,7 +35,7 @@ tasks:
- cmd: gofumpt -l -w .
- cmd: pnpm exec eslint assets/js/*.js
- cmd: pnpm exec stylelint assets/css/*.css
- cmd: golangci-lint run
- cmd: golangci-lint run -c init/.golangci.yaml
lint+:
silent: false
desc: Runs the deadcode and betteralign linters on the source code.
Expand All @@ -58,9 +52,6 @@ tasks:
- cmd: echo "Building..."
- cmd: go build -o {{.BINNAME}} -v server.go
platforms: [linux, darwin, freebsd]
- cmd: go build -o {{.BINNAME}}.exe -v server.go
platforms: [windows]
- cmd: echo "Done!"
build-race:
aliases:
- "buildx"
Expand All @@ -70,12 +61,8 @@ tasks:
- cmd: echo "Building with race conditions..."
- cmd: go build -o {{.BINNAME}} -race -v server.go
platforms: [linux, darwin, freebsd]
- cmd: go build -o {{.BINNAME}}.exe -race -v server.go
platforms: [windows]
- cmd: ./{{.BINNAME}} --version
platforms: [linux, darwin]
- cmd: ./{{.BINNAME}}.exe --version
platforms: [windows]
- cmd: echo "Done!"
build-snapshot:
aliases:
Expand All @@ -84,18 +71,18 @@ tasks:
deps: [assets]
cmds:
- cmd: echo "Building snapshot..."
- cmd: goreleaser build --snapshot --clean
- cmd: goreleaser build --snapshot --clean --config init/.goreleaser.yaml
- cmd: echo "Done!"
build-release:
aliases:
- "buildr"
- "release"
desc: "Build the release binary of the web server embeded with the git version tag."
deps: [assets]
cmds:
- cmd: echo "Git status results:"
- cmd: git status
- cmd: echo "Building snapshot..."
- cmd: goreleaser build --clean
- cmd: goreleaser build --clean --config init/.goreleaser.yaml
- cmd: echo "Done!"
assets:
desc: "Build, compile and compress the web serve CSS and JS assets."
Expand All @@ -117,50 +104,34 @@ tasks:
cmds:
#- set -o pipefail && go test ./... -json | tparse -all
- go test -count 1 -race ./...
serve:
serve-dev:
aliases:
- "serve"
desc: "Run the internal web server in development mode with live reload."
cmds:
- task: serve-linux
- task: serve-windows
serve-prod:
aliases:
- "server"
desc: "Run the internal web server with live reload."
cmds:
- task: serve-linux
- task: serve-windows-prod
- task: serve-air-prod
serve-linux:
internal: true
platforms: [linux, freebsd, darwin] # other supported os can be added here
platforms: [linux, freebsd, darwin]
env:
D2_PRODUCTION: false
D2_PROD_MODE: false
PS_HOST: localhost
deps: [assets]
cmds:
- air
- air -c init/.air.toml
serve-air-prod:
internal: true
platforms: [darwin, linux, freebsd] # other supported os can be added here
env:
D2_PRODUCTION: true
cmds:
- air
serve-windows:
internal: true
platforms: [windows]
env:
D2_PRODUCTION: false
deps: [assets]
cmds:
- air -c .air.windows.toml
serve-windows-prod:
internal: true
platforms: [windows]
platforms: [darwin, linux, freebsd]
env:
D2_PRODUCTION: true
deps: [assets]
D2_PROD_MODE: true
cmds:
- air -c .air.windows.toml
- air -c init/.air.toml
pkg-patch:
silent: false
desc: Update and apply patches to the web server dependencies.
Expand Down
83 changes: 42 additions & 41 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"

"github.com/Defacto2/server/internal/config"
"github.com/Defacto2/server/internal/postgres"
"github.com/carlmjohnson/versioninfo"
"github.com/urfave/cli/v2"
"golang.org/x/text/cases"
Expand All @@ -29,24 +28,6 @@ const (

var ErrCmd = errors.New("cannot run command as config is nil")

// Address is the `address` command help and action.
func Address(c *config.Config) *cli.Command {
return &cli.Command{
Name: "address",
Aliases: []string{"a"},
Usage: "list the server addresses",
Description: "List the IP, hostname and port addresses the server is most probably listening on.",
Action: func(_ *cli.Context) error {
s, err := c.AddressesCLI()
if err != nil {
return fmt.Errorf("c.AddressesCLI: %w", err)
}
defer fmt.Fprintf(os.Stdout, "%s\n", s)
return nil
},
}
}

// App returns the command line interface for this program.
// It uses the [github.com/urfave.cli] package.
func App(ver string, c *config.Config) *cli.App {
Expand All @@ -68,11 +49,50 @@ func App(ver string, c *config.Config) *cli.App {
Email: Email,
},
},
Commands: []*cli.Command{Config(c), Address(c)},
Commands: []*cli.Command{
Config(c),
Address(c),
},
}
return app
}

// Address is the `address` command help and action.
func Address(c *config.Config) *cli.Command {
return &cli.Command{
Name: "address",
Aliases: []string{"a"},
Usage: "list the server addresses",
Description: "List the IP, hostname and port addresses the server is most probably listening on.",
Action: func(_ *cli.Context) error {
s, err := c.AddressesCLI()
if err != nil {
return fmt.Errorf("c.AddressesCLI: %w", err)
}
defer fmt.Fprintf(os.Stdout, "%s\n", s)
return nil
},
}
}

// Config is the `config` command help and action.
func Config(c *config.Config) *cli.Command {
return &cli.Command{
Name: "config",
Aliases: []string{"c"},
Usage: "list the server configuration",
Description: "List the available server configuration options and the settings.",
Action: func(_ *cli.Context) error {
defer fmt.Fprintf(os.Stdout, "%s\n", c.String())
defer func() {
b := new(strings.Builder)
fmt.Fprintf(os.Stdout, "%s\n", b.String())
}()
return nil
},
}
}

// Arch returns the program CPU architecture.
func Arch() string {
switch strings.ToLower(runtime.GOARCH) {
Expand Down Expand Up @@ -110,26 +130,6 @@ func Commit(ver string) string {
return strings.Join(x, ", ")
}

// Config is the `config` command help and action.
func Config(c *config.Config) *cli.Command {
return &cli.Command{
Name: "config",
Aliases: []string{"c"},
Usage: "list the server configuration",
Description: "List the available server configuration options and the settings.",
Action: func(_ *cli.Context) error {
defer fmt.Fprintf(os.Stdout, "%s\n", c.String())
defer func() {
ds, _ := postgres.New()
b := new(strings.Builder)
ds.Configurations(b)
fmt.Fprintf(os.Stdout, "%s\n", b.String())
}()
return nil
},
}
}

// Copyright returns the © symbol, years and author of this program.
// The final year is generated from the last commit date.
func Copyright() string {
Expand Down Expand Up @@ -210,7 +210,8 @@ func Run(ver string, c *config.Config) (ExitCode, error) {
if c == nil {
return UsageError, ErrCmd
}
useArguments := len(os.Args[1:]) > 0
args := os.Args[1:]
useArguments := len(args) > 0
if useArguments {
return setup(ver, c)
}
Expand Down
Loading

0 comments on commit 786093b

Please sign in to comment.