Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions cmd/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,6 @@ func (p *Project) CreateMainFile() error {
// select htmx option automatically since tailwind is selected
p.AdvancedOptions[string(flags.Htmx)] = true

tailwindConfigFile, err := os.Create(fmt.Sprintf("%s/tailwind.config.js", projectPath))
if err != nil {
return err
}
defer tailwindConfigFile.Close()

tailwindConfigTemplate := advanced.TailwindConfigTemplate()
err = os.WriteFile(fmt.Sprintf("%s/tailwind.config.js", projectPath), tailwindConfigTemplate, 0o644)
if err != nil {
return err
}

err = os.MkdirAll(fmt.Sprintf("%s/%s/assets/css", projectPath, cmdWebPath), 0o755)
if err != nil {
return err
Expand Down Expand Up @@ -891,25 +879,16 @@ func (p *Project) CreateViteReactProject(projectPath string) error {
cmd := exec.Command("npm", "install",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think installing @tailwindcss/vite that has a dependency of needing tailwind v4 will make it force install v4+ so maybe we are good to go using --prefer-offline

"--prefer-offline",
"--no-fund",
"tailwindcss", "postcss", "autoprefixer")
"tailwindcss", "@tailwindcss/vite")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to install Tailwind: %w", err)
}

fmt.Println("Initializing Tailwind...")
cmd = exec.Command("npx", "--prefer-offline", "tailwindcss", "init", "-p")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to initialize Tailwind: %w", err)
}

// use the tailwind config file
err = os.WriteFile("tailwind.config.js", advanced.ReactTailwindConfigTemplate(), 0644)
if err != nil {
return fmt.Errorf("failed to write tailwind config: %w", err)
// Create the vite + react + Tailwind v4 configuration
if err := os.WriteFile(filepath.Join(frontendPath, "vite.config.ts"), advanced.ViteTailwindConfigFile(), 0644); err != nil {
return fmt.Errorf("failed to write vite.config.ts: %w", err)
}

srcDir := filepath.Join(frontendPath, "src")
Expand Down
2 changes: 1 addition & 1 deletion cmd/template/advanced/files/docker/dockerfile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN go install github.com/a-h/templ/cmd/templ@latest && \
{{- end}}

{{- if .AdvancedOptions.tailwind}}
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-linux-x64 -o tailwindcss && \
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss && \
chmod +x tailwindcss && \
./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css
{{- end }}
Expand Down
4 changes: 1 addition & 3 deletions cmd/template/advanced/files/react/tailwind/index.css.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@import "tailwindcss";
11 changes: 0 additions & 11 deletions cmd/template/advanced/files/react/tailwind/tailwind.config.js.tmpl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'

// https://vite.dev/config/
export default defineConfig({
plugins: [react(),tailwindcss()],
})
4 changes: 1 addition & 3 deletions cmd/template/advanced/files/tailwind/input.css.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@import "tailwindcss"
11 changes: 0 additions & 11 deletions cmd/template/advanced/files/tailwind/tailwind.config.js.tmpl

This file was deleted.

21 changes: 7 additions & 14 deletions cmd/template/advanced/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ var helloTemplTemplate []byte
//go:embed files/htmx/base.templ.tmpl
var baseTemplTemplate []byte

//go:embed files/tailwind/tailwind.config.js.tmpl
var tailwindConfigTemplate []byte

//go:embed files/react/tailwind/tailwind.config.js.tmpl
var reactTailwindConfigTemplate []byte

//go:embed files/react/tailwind/index.css.tmpl
var inputCssTemplateReact []byte

//go:embed files/react/tailwind/vite.config.ts.tmpl
var viteTailwindConfigFile []byte

//go:embed files/react/tailwind/app.tsx.tmpl
var reactTailwindAppFile []byte

Expand Down Expand Up @@ -119,14 +116,6 @@ func BaseTemplTemplate() []byte {
return baseTemplTemplate
}

func TailwindConfigTemplate() []byte {
return tailwindConfigTemplate
}

func ReactTailwindConfigTemplate() []byte {
return reactTailwindConfigTemplate
}

func ReactTailwindAppfile() []byte {
return reactTailwindAppFile
}
Expand All @@ -139,6 +128,10 @@ func InputCssTemplateReact() []byte {
return inputCssTemplateReact
}

func ViteTailwindConfigFile() []byte {
return viteTailwindConfigFile
}

func InputCssTemplate() []byte {
return inputCssTemplate
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/template/framework/files/makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ templ-install:
{{- if and .AdvancedOptions.tailwind (not .AdvancedOptions.react) }}
{{- if .OSCheck.UnixBased}}
tailwind-install:
{{ if .OSCheck.linux }}@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-linux-x64 -o tailwindcss; fi{{- end }}
{{ if .OSCheck.darwin }}@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-macos-x64 -o tailwindcss; fi{{- end }}
{{ if .OSCheck.linux }}@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss; fi{{- end }}
{{ if .OSCheck.darwin }}@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-x64 -o tailwindcss; fi{{- end }}
@chmod +x tailwindcss
{{- else }}
tailwind-install:
@if not exist tailwindcss.exe powershell -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri 'https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-windows-x64.exe' -OutFile 'tailwindcss.exe'"{{- end }}
@if not exist tailwindcss.exe powershell -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri 'https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-windows-x64.exe' -OutFile 'tailwindcss.exe'"{{- end }}
{{- end }}

build:{{- if and .AdvancedOptions.tailwind (not .AdvancedOptions.react) }} tailwind-install{{- end }}{{- if and (or .AdvancedOptions.htmx .AdvancedOptions.tailwind) (not .AdvancedOptions.react) }} templ-install{{- end }}
Expand Down
7 changes: 3 additions & 4 deletions docs/docs/advanced-flag/tailwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Tailwind is closely coupled with the advanced HTMX flag, and HTMX will be automa
We do not introduce outside dependencies automatically, and you need compile output.css (file is empty by default) with the Tailwind CLI tool.

The project tree would look like this:

```bash
/ (Root)
├── cmd/
Expand Down Expand Up @@ -30,8 +31,7 @@ The project tree would look like this:
├── go.mod
├── go.sum
├── Makefile
├── README.md
└── tailwind.config.js
└── README.md
```

## Standalone Tailwind CLI
Expand All @@ -41,6 +41,7 @@ The The idea is to avoid using Node.js and npm to build output.css.
The Makefile will have entries for downloading and compiling CSS. It will automatically detect the OS and download the latest release from the [official repository](https://github.com/tailwindlabs/tailwindcss/releases).

## Linux Makefile Example

```bash
all: build
templ-install:
Expand Down Expand Up @@ -75,5 +76,3 @@ By default, simple CSS examples are included in the codebase.
Update base.templ and hello.templ, then rerun templ generate to see the changes at the `localhost:PORT/web` endpoint.

![Tailwind](../public/tailwind.png)


3 changes: 1 addition & 2 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
hide:
- toc
---

## Go Blueprint - Ultimate Golang Blueprint Library

![logo](./public/logo.png)


Powerful CLI tool designed to streamline the process of creating Go projects with a robust and standardized structure. Not only does Go Blueprint facilitate project initialization, but it also offers seamless integration with popular Go frameworks, allowing you to focus on your application's code from the very beginning.

## Why Choose Go Blueprint?
Expand Down Expand Up @@ -87,7 +87,6 @@ Here's an overview of the project structure created by Go Blueprint when all opt
├── .goreleaser.yml # Configuration file for GoReleaser, a tool for building and releasing binaries.
├── go.sum # Go module file containing checksums for dependencies.
├── Makefile # Makefile for defining and running commands.
├── tailwind.config.js # Tailwind CSS configuration file for HTMX.
└── README.md # Project's README file containing essential information about the project.

```
Expand Down