fix: ensure frontend dist directory exists for lint and fmt commands

Extract ensureFrontendDistExists() from Build.Build and add it as a
dependency to Fmt, lint, and lint:fix so they no longer fail when the
frontend dist folder is missing.
This commit is contained in:
kolaente 2026-03-19 12:56:11 +01:00
parent e74265d921
commit c62b7e680f
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
1 changed files with 22 additions and 21 deletions

View File

@ -381,9 +381,28 @@ func waitForHTTP(ctx context.Context, url string, timeout time.Duration) error {
return fmt.Errorf("timed out waiting for %s after %s", url, timeout)
}
func ensureFrontendDistExists() error {
distPath := filepath.Join("frontend", "dist")
if _, err := os.Stat(distPath); os.IsNotExist(err) {
if err := os.MkdirAll(distPath, 0o755); err != nil {
return fmt.Errorf("error creating %s: %w", distPath, err)
}
}
indexFile := filepath.Join(distPath, "index.html")
if _, err := os.Stat(indexFile); os.IsNotExist(err) {
f, err := os.Create(indexFile)
if err != nil {
return fmt.Errorf("error creating %s: %w", indexFile, err)
}
f.Close()
}
return nil
}
// Fmt formats the code using go fmt
func Fmt(ctx context.Context) error {
mg.Deps(initVars)
mg.Deps(initVars, ensureFrontendDistExists)
out, err := exec.CommandContext(ctx, "git", "ls-files", "--cached", "--others", "--exclude-standard", "*.go").Output()
if err != nil {
return fmt.Errorf("failed to list go files from git: %w", err)
@ -792,7 +811,7 @@ func extractTranslationKeysFromFile(filePath string) ([]TranslationKey, error) {
}
func checkGolangCiLintInstalled(ctx context.Context) error {
mg.Deps(initVars)
mg.Deps(initVars, ensureFrontendDistExists)
if err := exec.CommandContext(ctx, "golangci-lint").Run(); err != nil && strings.Contains(err.Error(), "executable file not found") {
return fmt.Errorf("golangci-lint executable failed to run, please manually install golangci-lint by running the command: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.4.0")
}
@ -845,25 +864,7 @@ func (Build) Clean(ctx context.Context) error {
// Build builds a vikunja binary, ready to run
func (Build) Build(ctx context.Context) error {
mg.Deps(initVars)
// Check if the frontend dist folder exists
distPath := filepath.Join("frontend", "dist")
if _, err := os.Stat(distPath); os.IsNotExist(err) {
if err := os.MkdirAll(distPath, 0o755); err != nil {
return fmt.Errorf("error creating %s: %w", distPath, err)
}
}
indexFile := filepath.Join(distPath, "index.html")
if _, err := os.Stat(indexFile); os.IsNotExist(err) {
f, err := os.Create(indexFile)
if err != nil {
return fmt.Errorf("error creating %s: %w", indexFile, err)
}
f.Close()
fmt.Printf("Warning: %s not found, created empty file\n", indexFile)
}
mg.Deps(initVars, ensureFrontendDistExists)
return runAndStreamOutput(ctx, "go", "build", goDetectVerboseFlag(), "-tags", Tags, "-ldflags", "-s -w "+Ldflags, "-o", Executable)
}