Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix npm cache #356

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions cmd/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,11 @@ func (p *Project) CreateViteReactProject(projectPath string) error {
}

// the interactive vite command will not work as we can't interact with it
fmt.Println("Installing create-vite...")
cmd := exec.Command("npm", "create", "vite@latest", "frontend", "--", "--template", "react-ts")
fmt.Println("Installing create-vite (using cache if available)...")
cmd := exec.Command("npm", "create", "vite@latest", "frontend", "--",
"--template", "react-ts",
"--prefer-offline",
"--no-fund")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -881,16 +884,22 @@ func (p *Project) CreateViteReactProject(projectPath string) error {
if err := os.WriteFile(filepath.Join(frontendPath, ".env"), []byte(frontendEnvContent), 0644); err != nil {
return fmt.Errorf("failed to create frontend .env file: %w", err)
}

// Handle Tailwind configuration if selected
if p.AdvancedOptions[string(flags.Tailwind)] {
fmt.Println("Tailwind selected. Configuring with React...")
cmd := exec.Command("npm", "install", "-D", "tailwindcss", "postcss", "autoprefixer")
fmt.Println("Installing Tailwind dependencies (using cache if available)...")
cmd := exec.Command("npm", "install",
"--prefer-offline",
"--no-fund",
"tailwindcss", "postcss", "autoprefixer")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to install Tailwind: %w", err)
}
cmd = exec.Command("npx", "tailwindcss", "init", "-p")

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 {
Expand Down Expand Up @@ -930,7 +939,6 @@ func (p *Project) CreateViteReactProject(projectPath string) error {

return nil
}

func (p *Project) CreateHtmxTemplates() {
routesPlaceHolder := ""
importsPlaceHolder := ""
Expand Down
2 changes: 1 addition & 1 deletion cmd/template/framework/files/makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ build:{{- if and .AdvancedOptions.tailwind (not .AdvancedOptions.react) }} tailw
# Run the application
run:
@go run cmd/api/main.go{{- if .AdvancedOptions.react }} &
@npm install --prefix ./frontend
@npm install --prefer-offline --no-fund --prefix ./frontend
@npm run dev --prefix ./frontend
{{- end }}

Expand Down
21 changes: 20 additions & 1 deletion docs/docs/advanced-flag/react-vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,23 @@ networks:

## Environment Variables

The `VITE_PORT` in .env refers `PORT` from .env in project root ( for backend ). If value of `PORT` is changed than `VITE_PORT` must also be changed so that requests to backend work fine and have no conflicts.
The `VITE_PORT` in .env refers `PORT` from .env in project root ( for backend ). If value of `PORT` is changed than `VITE_PORT` must also be changed so that requests to backend work fine and have no conflicts.

## Notes

- First time running the project creation with Tailwind can take longer (~10 mins) as npm needs to download and cache all packages

- Subsequent runs will be faster as they utilize npm's cache, which we enforce during project creation.

- If encountering issues with package installation, try these npm commands:

```bash
# Check cache status
npm cache verify

# View cache contents
npm cache ls

# Clean cache if needed
npm cache clean --force
```
Loading