@@ -42,6 +42,18 @@ const getValidSvgPaths = async (
42
42
return validSvgPaths ;
43
43
} ;
44
44
45
+ // Parses the pattern file content (YAML) and returns the version field.
46
+ // If parsing fails or version is missing, returns the default version.
47
+ const getWorkingVersionFromPatternFile = ( patternFileContent : string ) => {
48
+ try {
49
+ const patternFile = jsyaml . load ( patternFileContent ) ;
50
+ return patternFile ?. version || DEFAULT_DESIGN_VERSION ;
51
+ } catch ( e ) {
52
+ console . error ( 'Failed to parse pattern file to get version:' , e ) ;
53
+ return DEFAULT_DESIGN_VERSION ;
54
+ }
55
+ } ;
56
+
45
57
interface HandleImageProps {
46
58
technologies : string [ ] ;
47
59
basePath ?: string ;
@@ -60,15 +72,18 @@ export const handleImage = async ({
60
72
} ;
61
73
export const DEFAULT_DESIGN_VERSION = '0.0.0' ;
62
74
75
+ // Returns the version of a design based on its visibility.
76
+ // - For 'published' designs, returns the stable published version.
77
+ // - For 'public' or 'private', returns the working version from the pattern file.
78
+ // - Defaults to the working version if visibility is unrecognized.
63
79
export const getVersion = ( design : Pattern ) => {
64
- if ( design . visibility === 'public' ) {
65
- return design ?. catalog_data ?. published_version || DEFAULT_DESIGN_VERSION ;
66
- }
67
- try {
68
- const patternFile = jsyaml . load ( design . pattern_file ) ;
69
- return patternFile ?. version || DEFAULT_DESIGN_VERSION ;
70
- } catch ( e ) {
71
- console . error ( e ) ;
72
- return DEFAULT_DESIGN_VERSION ;
80
+ switch ( design . visibility ) {
81
+ case 'published' :
82
+ return design ?. catalog_data ?. published_version || DEFAULT_DESIGN_VERSION ;
83
+ case 'public' :
84
+ case 'private' :
85
+ return getWorkingVersionFromPatternFile ( design . pattern_file ) ;
86
+ default :
87
+ return getWorkingVersionFromPatternFile ( design . pattern_file ) ;
73
88
}
74
89
} ;
0 commit comments