mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 18:40:34 +07:00
feat: autoformatter
This commit is contained in:
26
utils/prettier.go
Normal file
26
utils/prettier.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func FormatFilesWithPrettier(files []string) error {
|
||||
if len(files) == 0 {
|
||||
return fmt.Errorf("empty file list")
|
||||
}
|
||||
|
||||
args := append([]string{"prettier", "--write"}, files...)
|
||||
|
||||
cmd := exec.Command("npx", args...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("formatter error: %s\nOutput: %s", err, output)
|
||||
}
|
||||
|
||||
log.Println("prettier was applied")
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user