/
t3
/
cli
Обзор
Документация
Войти
/
t3
/
cli
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
internal/controller/build.go
56 строк
1 KB
Ivan
fix output bundle path
02 июл 2026, 11:28
02 июл 2026, 11:28
cc3fd9e
Код
Авторство
О чём код?
package controller import ( "fmt" "os" "os/exec" "path/filepath" "gitverse.ru/t3/cli/internal/config" ) func Build(cfg *config.Config, workingDir, cfgFile, scriptFile string) ([]byte, error) { targetPath := filepath.Join(filepath.Dir(cfgFile), scriptFile) info, err := os.Stat(targetPath) if err != nil || info.IsDir() { return nil, fmt.Errorf("cannot open script file: %w", err) } esbuild, err := exec.LookPath("esbuild") if err != nil { esbuild = filepath.Join(workingDir, "node_modules", ".bin", "esbuild") _, err = os.Stat(esbuild) if err != nil { return nil, fmt.Errorf("cannot find esbuild, please install it: `npm install -g esbuild`") } } bundleFile := filepath.Join(filepath.Dir(cfgFile), cfg.Output, "bundle.js") cmd := exec.Command(esbuild, targetPath, "--bundle", "--platform=node", "--target=es2020", "--format=iife", "--minify", "--global-name=script", fmt.Sprintf("--outfile=%s", bundleFile), ) output, err := cmd.CombinedOutput() if err != nil { return nil, fmt.Errorf("esbuild failed: %v\noutput: %s", err, output) } finalScript, err := os.ReadFile(bundleFile) if err != nil { return nil, fmt.Errorf("failed to read compiled JS: %v", err) } if len(finalScript) == 0 { return nil, fmt.Errorf("empty js bundle") } return finalScript, nil }