Skip to content

Commit

Permalink
fix cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujstor committed Dec 16, 2024
1 parent f13c8b7 commit f970444
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
28 changes: 22 additions & 6 deletions cmd/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,19 @@ func (p *Project) CreateViteReactProject(projectPath string) error {
fmt.Println("failed to change into project directory: %w", err)
}

// Configure npm to prefer offline and use cache
configCmd := exec.Command("npm", "config", "set", "prefer-offline", "true")
if err := configCmd.Run(); err != nil {
fmt.Println("Warning: Failed to set npm offline preference:", err)
}

// 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("Running create-vite (using cache if available)...")
cmd := exec.Command("npm", "create", "vite@latest", "frontend", "--",
"--template", "react-ts",
"--prefer-offline",
"--no-audit",
"--no-fund")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down Expand Up @@ -881,16 +891,23 @@ 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", "-D",
"--prefer-offline",
"--no-audit",
"--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 +947,6 @@ func (p *Project) CreateViteReactProject(projectPath string) error {

return nil
}

func (p *Project) CreateHtmxTemplates() {
routesPlaceHolder := ""
importsPlaceHolder := ""
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
```

0 comments on commit f970444

Please sign in to comment.