Move Generation Destinations
This commit is contained in:
@@ -22,26 +22,35 @@ const (
|
||||
)
|
||||
|
||||
func compiled2DAOutputDir(p *project.Project) string {
|
||||
if useDedicatedTopDataBuildDir(p) {
|
||||
return filepath.Join(p.TopDataBuildDir(), "2da")
|
||||
}
|
||||
return filepath.Join(p.TopDataSourceDir(), "assets", "2da")
|
||||
return filepath.Join(p.TopDataBuildDir(), "2da")
|
||||
}
|
||||
|
||||
func compiledTLKOutputPath(p *project.Project) string {
|
||||
if useDedicatedTopDataBuildDir(p) {
|
||||
return filepath.Join(p.TopDataBuildDir(), "tlk", defaultTLKName)
|
||||
}
|
||||
return filepath.Join(p.BuildDir(), defaultTLKName)
|
||||
return filepath.Join(p.TopDataBuildDir(), "tlk", defaultTLKName)
|
||||
}
|
||||
|
||||
func compiledTLKOutputDir(p *project.Project) string {
|
||||
return filepath.Dir(compiledTLKOutputPath(p))
|
||||
}
|
||||
|
||||
func useDedicatedTopDataBuildDir(p *project.Project) bool {
|
||||
defaultBuildDir := filepath.Join(p.BuildDir(), "topdata")
|
||||
return p.TopDataBuildDir() != defaultBuildDir
|
||||
func wikiOutputRootDir(p *project.Project) string {
|
||||
return filepath.Join(p.TopDataBuildDir(), wikiRootDirName)
|
||||
}
|
||||
|
||||
func wikiOutputPagesDir(p *project.Project) string {
|
||||
return filepath.Join(wikiOutputRootDir(p), wikiPagesDirName)
|
||||
}
|
||||
|
||||
func wikiOutputStatePath(p *project.Project) string {
|
||||
return filepath.Join(wikiOutputRootDir(p), wikiStateFileName)
|
||||
}
|
||||
|
||||
func legacyCompiled2DAOutputDir(p *project.Project) string {
|
||||
return filepath.Join(p.TopDataSourceDir(), "assets", "2da")
|
||||
}
|
||||
|
||||
func legacyWikiOutputRootDir(p *project.Project) string {
|
||||
return filepath.Join(p.TopDataSourceDir(), legacyWikiRootDirName)
|
||||
}
|
||||
|
||||
func BuildPackage(p *project.Project, progress func(string)) (PackageResult, error) {
|
||||
@@ -172,15 +181,20 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
|
||||
assetFiles := 0
|
||||
assetsDir := filepath.Join(p.TopDataSourceDir(), "assets")
|
||||
skipDir := compiled2DAOutputDir(p)
|
||||
skipDirs := map[string]struct{}{
|
||||
filepath.Clean(compiled2DADir): {},
|
||||
filepath.Clean(legacyCompiled2DAOutputDir(p)): {},
|
||||
}
|
||||
info, err := os.Stat(assetsDir)
|
||||
if err == nil && info.IsDir() {
|
||||
err = filepath.WalkDir(assetsDir, func(path string, d os.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if d.IsDir() && path == skipDir {
|
||||
return filepath.SkipDir
|
||||
if d.IsDir() {
|
||||
if _, ok := skipDirs[filepath.Clean(path)]; ok {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
@@ -220,6 +234,51 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
return resources, assetFiles, nil
|
||||
}
|
||||
|
||||
func shouldSkipTopDataSourceDir(path string, skipDirs map[string]struct{}) bool {
|
||||
_, ok := skipDirs[filepath.Clean(path)]
|
||||
return ok
|
||||
}
|
||||
|
||||
func topDataSourceSkipDirs(p *project.Project) map[string]struct{} {
|
||||
return map[string]struct{}{
|
||||
filepath.Clean(filepath.Join(p.TopDataSourceDir(), "templates")): {},
|
||||
filepath.Clean(legacyWikiOutputRootDir(p)): {},
|
||||
filepath.Clean(legacyCompiled2DAOutputDir(p)): {},
|
||||
filepath.Clean(wikiOutputRootDir(p)): {},
|
||||
}
|
||||
}
|
||||
|
||||
func newestTopDataSource(p *project.Project) (time.Time, string, error) {
|
||||
newest := time.Time{}
|
||||
newestPath := ""
|
||||
skipDirs := topDataSourceSkipDirs(p)
|
||||
sourceDir := p.TopDataSourceDir()
|
||||
err := filepath.WalkDir(sourceDir, func(path string, d fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if d.IsDir() && shouldSkipTopDataSourceDir(path, skipDirs) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
info, err := d.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if newest.IsZero() || info.ModTime().After(newest) {
|
||||
newest = info.ModTime()
|
||||
newestPath = path
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return time.Time{}, "", fmt.Errorf("scan topdata sources: %w", err)
|
||||
}
|
||||
return newest, newestPath, nil
|
||||
}
|
||||
|
||||
func topPackageResourceFromPath(path string) (erf.Resource, error) {
|
||||
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
||||
resourceType, ok := erf.HAKResourceTypeForExtension(extension)
|
||||
@@ -335,7 +394,7 @@ func packagedBuildResult(p *project.Project) (BuildResult, error) {
|
||||
return BuildResult{}, fmt.Errorf("topdata build output missing: run build-topdata first")
|
||||
}
|
||||
|
||||
newestSource, newestPath, err := newestTopDataSource(p.TopDataSourceDir())
|
||||
newestSource, newestPath, err := newestTopDataSource(p)
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
@@ -390,7 +449,7 @@ func currentTopPackageResult(p *project.Project) (PackageResult, bool, error) {
|
||||
return PackageResult{}, false, fmt.Errorf("stat top package tlk %s: %w", outputTLK, err)
|
||||
}
|
||||
|
||||
newestSource, _, err := newestTopDataSource(p.TopDataSourceDir())
|
||||
newestSource, _, err := newestTopDataSource(p)
|
||||
if err != nil {
|
||||
return PackageResult{}, false, err
|
||||
}
|
||||
@@ -481,41 +540,3 @@ func countCompiledFiles(dir, extension string) (int, time.Time, error) {
|
||||
}
|
||||
return count, oldest, nil
|
||||
}
|
||||
|
||||
func newestTopDataSource(sourceDir string) (time.Time, string, error) {
|
||||
newest := time.Time{}
|
||||
newestPath := ""
|
||||
templatesDir := filepath.Join(sourceDir, "templates")
|
||||
wikiDir := filepath.Join(sourceDir, wikiRootDirName)
|
||||
generated2DADir := filepath.Join(sourceDir, "assets", "2da")
|
||||
err := filepath.WalkDir(sourceDir, func(path string, d fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if d.IsDir() && path == templatesDir {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if d.IsDir() && path == wikiDir {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if d.IsDir() && path == generated2DADir {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
info, err := d.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if newest.IsZero() || info.ModTime().After(newest) {
|
||||
newest = info.ModTime()
|
||||
newestPath = path
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return time.Time{}, "", fmt.Errorf("scan topdata sources: %w", err)
|
||||
}
|
||||
return newest, newestPath, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user