@@ -74,6 +74,32 @@ public static function getOptions() {
74
74
return self ::$ options ;
75
75
}
76
76
77
+ /**
78
+ * Review the given styleguideKitPath to handle pre-2.1.0 backwards compatibility
79
+ * @param {String} styleguideKitPath from config.yml
80
+ *
81
+ * @return {String} the final, post-2.1.0-style styleguideKitPath
82
+ */
83
+ protected static function getStyleguideKitPath ($ styleguideKitPath ) {
84
+
85
+ $ styleguideKitPathFinal = "" ;
86
+ if ($ styleguideKitPath [0 ] == DIRECTORY_SEPARATOR ) {
87
+ if (strpos ($ styleguideKitPath , DIRECTORY_SEPARATOR ."vendor " .DIRECTORY_SEPARATOR === 0 )) {
88
+ $ styleguideKitPathFinal = $ styleguideKitPath ; // mistaken set-up, pass to final for clean-up
89
+ } else if (strpos ($ styleguideKitPath , self ::$ options ["baseDir " ]) === 0 ) {
90
+ $ styleguideKitPathFinal = str_replace (self ::$ options ["baseDir " ], "" , $ styleguideKitPath ); // just need to peel off the base
91
+ } else if (strpos ($ styleguideKitPath , DIRECTORY_SEPARATOR ."vendor " ) !== false ) {
92
+ $ parts = explode (DIRECTORY_SEPARATOR ."vendor " .DIRECTORY_SEPARATOR , $ styleguideKitPath ); // set on another machine's config.yml? try to be smart about it
93
+ $ styleguideKitPathFinal = "vendor " .DIRECTORY_SEPARATOR .$ parts [1 ];
94
+ Console::writeInfo ("Please double-check the styleguideKitPath option in <path>./config/config.yml</path>. It should be a path relative to the root of your Pattern Lab project... " );
95
+ }
96
+ }
97
+
98
+ Console::writeInfo ($ styleguideKitPathFinal );
99
+ return $ styleguideKitPathFinal ;
100
+
101
+ }
102
+
77
103
/**
78
104
* Adds the config options to a var to be accessed from the rest of the system
79
105
* If it's an old config or no config exists this will update and generate it.
@@ -172,17 +198,20 @@ public static function init($baseDir = "", $verbose = true) {
172
198
}
173
199
174
200
// set-up the various dirs
175
- self ::$ options ["configDir " ] = self ::$ userConfigDir ;
176
- self ::$ options ["coreDir " ] = is_dir (self ::$ options ["baseDir " ]."_core " ) ? self ::$ options ["baseDir " ]."_core " : self ::$ options ["baseDir " ]."core " ;
177
- self ::$ options ["exportDir " ] = isset (self ::$ options ["exportDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["exportDir " ]) : self ::$ options ["baseDir " ]."exports " ;
178
- self ::$ options ["publicDir " ] = isset (self ::$ options ["publicDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["publicDir " ]) : self ::$ options ["baseDir " ]."public " ;
179
- self ::$ options ["scriptsDir " ] = isset (self ::$ options ["scriptsDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["scriptsDir " ]) : self ::$ options ["baseDir " ]."scripts " ;
180
- self ::$ options ["sourceDir " ] = isset (self ::$ options ["sourceDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["sourceDir " ]) : self ::$ options ["baseDir " ]."source " ;
181
- self ::$ options ["componentDir " ] = self ::$ options ["publicDir " ]."/patternlab-components " ;
182
- self ::$ options ["dataDir " ] = self ::$ options ["sourceDir " ]."/_data " ;
183
- self ::$ options ["patternExportDir " ] = self ::$ options ["exportDir " ]."/patterns " ;
184
- self ::$ options ["patternPublicDir " ] = self ::$ options ["publicDir " ]."/patterns " ;
185
- self ::$ options ["patternSourceDir " ] = self ::$ options ["sourceDir " ]."/_patterns " ;
201
+ self ::$ options ["configDir " ] = self ::$ userConfigDir ;
202
+ self ::$ options ["coreDir " ] = is_dir (self ::$ options ["baseDir " ]."_core " ) ? self ::$ options ["baseDir " ]."_core " : self ::$ options ["baseDir " ]."core " ;
203
+ self ::$ options ["exportDir " ] = isset (self ::$ options ["exportDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["exportDir " ]) : self ::$ options ["baseDir " ]."exports " ;
204
+ self ::$ options ["publicDir " ] = isset (self ::$ options ["publicDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["publicDir " ]) : self ::$ options ["baseDir " ]."public " ;
205
+ self ::$ options ["scriptsDir " ] = isset (self ::$ options ["scriptsDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["scriptsDir " ]) : self ::$ options ["baseDir " ]."scripts " ;
206
+ self ::$ options ["sourceDir " ] = isset (self ::$ options ["sourceDir " ]) ? self ::$ options ["baseDir " ].self ::cleanDir (self ::$ options ["sourceDir " ]) : self ::$ options ["baseDir " ]."source " ;
207
+ self ::$ options ["componentDir " ] = self ::$ options ["publicDir " ]."/patternlab-components " ;
208
+ self ::$ options ["dataDir " ] = self ::$ options ["sourceDir " ]."/_data " ;
209
+ self ::$ options ["patternExportDir " ] = self ::$ options ["exportDir " ]."/patterns " ;
210
+ self ::$ options ["patternPublicDir " ] = self ::$ options ["publicDir " ]."/patterns " ;
211
+ self ::$ options ["patternSourceDir " ] = self ::$ options ["sourceDir " ]."/_patterns " ;
212
+
213
+ // handle a pre-2.1.0 styleguideKitPath before saving it
214
+ self ::$ options ["styleguideKitPath " ] = self ::$ options ["baseDir " ].self ::cleanDir (self ::getStyleguideKitPath (self ::$ options ["styleguideKitPath " ]));
186
215
187
216
// make sure styleguideExcludes is set to an array even if it's empty
188
217
if (is_string (self ::$ options ["styleGuideExcludes " ])) {
0 commit comments