@@ -3,7 +3,6 @@ package spec
3
3
import (
4
4
"fmt"
5
5
6
- "github.com/apigear-io/cli/pkg/cfg"
7
6
"github.com/apigear-io/cli/pkg/helper"
8
7
)
9
8
@@ -17,20 +16,8 @@ type SolutionLayer struct {
17
16
Force bool `json:"force" yaml:"force"`
18
17
expandedInputs []string `json:"-"` // expanded inputs
19
18
dependencies []string `json:"-"` // dependencies of the layer
20
- }
21
-
22
- // ResolveTemplateDir resolves the template dir.
23
- // The template dir can be a relative path to the root dir of the solution.
24
- // If the template dir is not a relative path, it is considered as a template name.
25
- // The template name is used to find the template dir in the template cache dir.
26
- func (l * SolutionLayer ) ResolveTemplateDir (rootDir string ) string {
27
- if helper .IsDir (helper .Join (rootDir , l .Template )) {
28
- return helper .Join (rootDir , l .Template )
29
- }
30
- if helper .IsDir (helper .Join (cfg .CacheDir (), l .Template )) {
31
- return helper .Join (cfg .CacheDir (), l .Template )
32
- }
33
- return ""
19
+ templateDir string `json:"-"` // template dir
20
+ rulesFile string `json:"-"` // rules file
34
21
}
35
22
36
23
// GetOutputDir returns the output dir.
@@ -39,26 +26,6 @@ func (l *SolutionLayer) GetOutputDir(rootDir string) string {
39
26
return helper .Join (rootDir , l .Output )
40
27
}
41
28
42
- // GetTemplatesDir returns the templates dir.
43
- // The templates dir is a sub directory of the template dir.
44
- func (l * SolutionLayer ) GetTemplatesDir (rootDir string ) string {
45
- tDir := l .ResolveTemplateDir (rootDir )
46
- if tDir == "" {
47
- return ""
48
- }
49
- return helper .Join (tDir , "templates" )
50
- }
51
-
52
- // GetRulesFile returns the rules file.
53
- // The rules file is a file in the template dir.
54
- func (l * SolutionLayer ) GetRulesFile (rootDir string ) string {
55
- tDir := l .ResolveTemplateDir (rootDir )
56
- if tDir == "" {
57
- return ""
58
- }
59
- return helper .Join (tDir , "rules.yaml" )
60
- }
61
-
62
29
func (l * SolutionLayer ) Validate () error {
63
30
if l .Output == "" {
64
31
return fmt .Errorf ("layer output is required" )
@@ -76,25 +43,31 @@ func (l *SolutionLayer) Validate() error {
76
43
return nil
77
44
}
78
45
46
+ // ComputeDependencies computes the dependencies of a layer.
47
+ // The dependencies are used for file system watchers.
48
+ // The dependencies of a layer are the rules file, the templates dir and the expanded inputs.
49
+ // The rules file is a file in the template dir.
50
+ // The templates dir is a sub directory of the template dir.
51
+ // The expanded inputs are the inputs with the variables expanded.
79
52
func (l * SolutionLayer ) ComputeDependencies (rootDir string ) []string {
80
53
if l .dependencies == nil {
81
54
l .dependencies = make ([]string , 0 )
82
55
}
83
56
if len (l .dependencies ) == 0 {
84
- rulesFile := l .GetRulesFile (rootDir )
85
- if rulesFile != "" {
86
- l .dependencies = append (l .dependencies , rulesFile )
57
+ if l .templateDir != "" {
58
+ l .dependencies = append (l .dependencies , l .templateDir )
87
59
}
88
- tplsDir := l .GetTemplatesDir (rootDir )
89
- if tplsDir != "" {
90
- l .dependencies = append (l .dependencies , tplsDir )
60
+ if l .rulesFile != "" {
61
+ l .dependencies = append (l .dependencies , l .rulesFile )
91
62
}
92
63
inputs := l .ComputeExpandedInputs (rootDir )
93
64
l .dependencies = append (l .dependencies , inputs ... )
94
65
}
95
66
return l .dependencies
96
67
}
97
68
69
+ // ComputeExpandedInputs computes the expanded inputs of a layer.
70
+ // The expanded inputs are the inputs with the variables expanded.
98
71
func (l * SolutionLayer ) ComputeExpandedInputs (rootDir string ) []string {
99
72
if l .expandedInputs == nil {
100
73
l .expandedInputs = make ([]string , 0 )
@@ -115,3 +88,9 @@ func (l *SolutionLayer) Compute(rootDir string) error {
115
88
l .ComputeExpandedInputs (rootDir )
116
89
return nil
117
90
}
91
+
92
+ // UpdateTemplateDependencies updates the template dir and rules file of a layer.
93
+ func (l * SolutionLayer ) UpdateTemplateDependencies (templateDir , rulesFile string ) {
94
+ l .templateDir = templateDir
95
+ l .rulesFile = rulesFile
96
+ }
0 commit comments