fix fragile hak packing (#36)
Reviewed-on: #36 Reviewed-by: xtul <mpiasecki720@protonmail.com> Co-authored-by: vickydotbat <vickydotbat@tutamail.com> Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit was merged in pull request #36.
This commit is contained in:
@@ -211,11 +211,12 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if strings.HasPrefix(filepath.Base(path), ".") {
|
||||
return nil
|
||||
rel, err := filepath.Rel(assetsDir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.EqualFold(filepath.Ext(path), ".md") {
|
||||
return nil // docs (AGENTS.md, README.md, ...) are never HAK resources
|
||||
if skipTopPackageAsset(rel) {
|
||||
return nil
|
||||
}
|
||||
resource, err := topPackageResourceFromPath(path)
|
||||
if err != nil {
|
||||
@@ -388,6 +389,25 @@ func newestMatchingAutogenOverrideInput(scanRoot string, include []string) (time
|
||||
return newest, newestPath, nil
|
||||
}
|
||||
|
||||
// skipTopPackageAsset reports whether a file under assets/ is not a HAK
|
||||
// resource and must be ignored by both validation and packing: anything in a
|
||||
// hidden or underscore-prefixed directory (working dirs like _candidates),
|
||||
// hidden files, docs, and any extension that is not a known NWN ResType
|
||||
// (erf.extensionTypes is the whitelist). rel is the path relative to assets/.
|
||||
func skipTopPackageAsset(rel string) bool {
|
||||
for _, part := range strings.Split(filepath.ToSlash(rel), "/") {
|
||||
if strings.HasPrefix(part, ".") || strings.HasPrefix(part, "_") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if strings.EqualFold(filepath.Ext(rel), ".md") {
|
||||
return true
|
||||
}
|
||||
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(rel)), ".")
|
||||
_, ok := erf.HAKResourceTypeForExtension(ext)
|
||||
return !ok
|
||||
}
|
||||
|
||||
func topPackageResourceFromPath(path string) (erf.Resource, error) {
|
||||
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
||||
resourceType, ok := erf.HAKResourceTypeForExtension(extension)
|
||||
|
||||
Reference in New Issue
Block a user