Files
ant-black 70132417ad publish: 1.2.0 snapshot (f3d7ec5)
channel: master

version: 1.2.0

source-ref: D:\code\open_source\ant-chrome master

source-commit: f3d7ec5

merged-public-base: 3d264eb
2026-05-05 18:08:10 +08:00

35 lines
1.1 KiB
Go

package automation
import (
"fmt"
"os"
"path/filepath"
"strings"
)
func ImportBundleFromFile(path string, sourceLabel string) (ImportedBundle, error) {
return ImportBundleFromFileWithOptions(path, sourceLabel, ImportOptions{})
}
func ImportBundleFromFileWithOptions(path string, sourceLabel string, options ImportOptions) (ImportedBundle, error) {
normalizedPath := strings.TrimSpace(path)
if normalizedPath == "" {
return ImportedBundle{}, fmt.Errorf("script file path is required")
}
for _, candidate := range importManifestCandidates {
if strings.EqualFold(filepath.Base(normalizedPath), candidate) {
return ImportBundleFromDirectoryWithOptions(filepath.Dir(normalizedPath), "", sourceLabel, options)
}
}
if strings.EqualFold(filepath.Ext(normalizedPath), ".zip") {
return ImportBundleFromZipWithOptions(normalizedPath, sourceLabel, options)
}
data, err := os.ReadFile(normalizedPath)
if err != nil {
return ImportedBundle{}, fmt.Errorf("read script file failed: %w", err)
}
return ImportBundleFromBytesWithOptions(filepath.Base(normalizedPath), data, sourceLabel, options)
}