Skip to content

Commit

Permalink
Dodging potential lawsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
baalimago committed Aug 18, 2024
1 parent 32dfd84 commit 2e00556
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
uses: baalimago/simple-go-pipeline/.github/workflows/[email protected]
with:
go-version: '1.22'
project-name: wd-40
project-name: wd-41
branch: main
version-var: "github.com/baalimago/wd-40/cmd/version.BUILD_VERSION"
version-var: "github.com/baalimago/wd-41/cmd/version.BUILD_VERSION"

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# (w)eb (d)evelopment-(40)
[![Go Report Card](https://goreportcard.com/badge/github.com/baalimago/wd-40)](https://goreportcard.com/report/github.com/baalimago/wd-40)
[![Go Report Card](https://goreportcard.com/badge/github.com/baalimago/wd-41)](https://goreportcard.com/report/github.com/baalimago/wd-41)
[![wakatime](https://wakatime.com/badge/user/018cc8d2-3fd9-47ef-81dc-e4ad645d5f34/project/3bc921ec-dc23-4222-bf00-578f2eda0cbd.svg)](https://wakatime.com/badge/user/018cc8d2-3fd9-47ef-81dc-e4ad645d5f34/project/3bc921ec-dc23-4222-bf00-578f2eda0cbd)

Test coverage: 73.640% 😌👏

This is a very simple static webserver which hot-reloads your web-browser on changes to the statically hosted webserver.

## Usage
`wd-40 s|serve <relative directory>` or `wd-40 s|serve`
`wd-41 s|serve <relative directory>` or `wd-41 s|serve`

## Getting started
```bash
go install github.com/baalimago/wd-40@latest
go install github.com/baalimago/wd-41@latest
```

You may also use the setup script:
```bash
curl -fsSL https://raw.githubusercontent.com/baalimago/wd-40/main/setup.sh | sh
curl -fsSL https://raw.githubusercontent.com/baalimago/wd-41/main/setup.sh | sh
```

## Architecture
1. First the content of the website is copied to a temporary directory, this is the _mirrored content_
1. Every mirrored file is inspectd for type, if it's text/html, a `delta-streamer.js` script is injected
1. The web server is started, hosting the _mirrored_ content
1. The `delta-streamer.js` in turn sets up a websocket connection to the wd-40 webserver
1. The `delta-streamer.js` in turn sets up a websocket connection to the wd-41 webserver
1. The original file system is monitored, on any file changes:
1. the new file is copied to the mirror (including injections)
1. the file name is propagated to the browser via the websocket
Expand Down
4 changes: 2 additions & 2 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path"

"github.com/baalimago/go_away_boilerplate/pkg/ancli"
"github.com/baalimago/wd-40/internal/wsinject"
"github.com/baalimago/wd-41/internal/wsinject"
"golang.org/x/net/websocket"
)

Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *command) Run(ctx context.Context) error {
}

func (c *command) Help() string {
return "Serve some filesystem. Set the directory as the second argument: wd-40 serve <dir>. If omitted, current wd will be used."
return "Serve some filesystem. Set the directory as the second argument: wd-41 serve <dir>. If omitted, current wd will be used."
}

func (c *command) Describe() string {
Expand Down
4 changes: 2 additions & 2 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"text/tabwriter"

"github.com/baalimago/wd-40/cmd/serve"
"github.com/baalimago/wd-40/cmd/version"
"github.com/baalimago/wd-41/cmd/serve"
"github.com/baalimago/wd-41/cmd/version"
)

var commands = map[string]Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/baalimago/wd-40/cmd/serve"
"github.com/baalimago/wd-41/cmd/serve"
)

func Test_Parse(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type command struct {

// Describe the version *command
func (c *command) Describe() string {
return "print the version of wd-40"
return "print the version of wd-41"
}

// Flagset for version, currently empty
Expand All @@ -30,7 +30,7 @@ func (c *command) Flagset() *flag.FlagSet {

// Help by printing out help
func (c *command) Help() string {
return "Print the version of wd-40"
return "Print the version of wd-41"
}

// Run the *command, printing the version using either the debugbuild or tagged version
Expand Down
4 changes: 2 additions & 2 deletions cmd/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestCommand(t *testing.T) {
t.Fatal("Expected command to be non-nil")
}

if cmd.Describe() != "print the version of wd-40" {
if cmd.Describe() != "print the version of wd-41" {
t.Fatalf("Unexpected describe: %v", cmd.Describe())
}

Expand All @@ -25,7 +25,7 @@ func TestCommand(t *testing.T) {
}

help := cmd.Help()
if help != "Print the version of wd-40" {
if help != "Print the version of wd-41" {
t.Fatalf("Unexpected help output: %v", help)
}
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/baalimago/wd-40
module github.com/baalimago/wd-41

go 1.22.2

require github.com/baalimago/go_away_boilerplate v1.3.32

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.7.0
golang.org/x/net v0.28.0
golang.org/x/sys v0.23.0 // indirect
)
2 changes: 1 addition & 1 deletion internal/wsinject/delta_streamer.ws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package wsinject

const DeltaStreamerSourceCode = `/**
* This file has been injected by the wd-40 web development
* This file has been injected by the wd-41 web development
* hot reload tool.
*/
Expand Down
4 changes: 2 additions & 2 deletions internal/wsinject/wsinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type Fileserver struct {

var ErrNoHeaderTagFound = errors.New("no header tag found")

const deltaStreamer = `<!-- This script has been injected by wd-40 and allows hot reloads -->
const deltaStreamer = `<!-- This script has been injected by wd-41 and allows hot reloads -->
<script type="module" src="delta-streamer.js"></script>`

func NewFileServer(wsPort int, wsPath string) *Fileserver {
mirrorDir, err := os.MkdirTemp("", "wd-40_*")
mirrorDir, err := os.MkdirTemp("", "wd-41_*")
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/wsinject/wsinject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func Test_Setup(t *testing.T) {
if err != nil {
t.Fatalf("failed to find delta-streamer.js: %v", err)
}
// Whatever happens in the delta streamre source code, it should mention wd-40
if !strings.Contains(string(b), "wd-40") {
t.Fatal("expected delta-streamer.js file to conain string 'wd-40'")
// Whatever happens in the delta streamre source code, it should mention wd-41
if !strings.Contains(string(b), "wd-41") {
t.Fatal("expected delta-streamer.js file to conain string 'wd-41'")
}
}
t.Run("it should write the delta streamer file to root of mirror", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/baalimago/go_away_boilerplate/pkg/ancli"
"github.com/baalimago/go_away_boilerplate/pkg/shutdown"
"github.com/baalimago/wd-40/cmd"
"github.com/baalimago/wd-41/cmd"
)

func printHelp(command cmd.Command, err error, printUsage cmd.UsagePrinter) int {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/baalimago/go_away_boilerplate/pkg/testboil"
"github.com/baalimago/wd-40/cmd"
"github.com/baalimago/wd-41/cmd"
)

type MockCommand struct {
Expand Down
8 changes: 4 additions & 4 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Function to get the latest release download URL for the specified OS and architecture
get_latest_release_url() {
repo="baalimago/wd-40"
repo="baalimago/wd-41"
os="$1"
arch="$2"

Expand Down Expand Up @@ -79,9 +79,9 @@ fi
printf "OK!\n"

# Move the binary to /usr/local/bin and handle permission errors
if ! mv "$tmp_file" /usr/local/bin/wd-40; then
echo "Failed to move the binary to /usr/local/bin/wd-40, see error above. Try running the script with sudo, or run 'mv $tmp_file <desired-position>'."
if ! mv "$tmp_file" /usr/local/bin/wd-41; then
echo "Failed to move the binary to /usr/local/bin/wd-41, see error above. Try running the script with sudo, or run 'mv $tmp_file <desired-position>'."
exit 1
fi

echo "wd-40 installed successfully in /usr/local/bin, try it out with 'wd-40 h'"
echo "wd-41 installed successfully in /usr/local/bin, try it out with 'wd-41 h'"

0 comments on commit 2e00556

Please sign in to comment.