@@ -84,6 +84,14 @@ impl Run {
8484 self . build_renderer_raw ( interaction) . await . into ( )
8585 }
8686
87+ fn allow_overwrite ( & self ) -> bool {
88+ // If the template variant asks to be generated into the app root,
89+ // we assume that it knows what it's doing and intends to avoid
90+ // overwriting. This is true for the one use case we have, although
91+ // we need to track if it's a flawed assumption in general cases.
92+ self . options . allow_overwrite || self . template . use_root ( & self . options . variant )
93+ }
94+
8795 // The 'raw' in this refers to the output type, which is an ugly representation
8896 // of cancellation: Ok(Some(...)) means a result, Ok(None) means cancelled, Err
8997 // means error. Why have this ugly representation? Because it makes it terser to
@@ -99,7 +107,7 @@ impl Run {
99107 // TODO: rationalise `path` and `dir`
100108 let to = self . generation_target_dir ( ) ;
101109
102- if !self . options . allow_overwrite {
110+ if !self . allow_overwrite ( ) {
103111 match interaction. allow_generate_into ( & to) {
104112 Cancellable :: Cancelled => return Ok ( None ) ,
105113 Cancellable :: Ok ( _) => ( ) ,
@@ -179,11 +187,28 @@ impl Run {
179187 let outputs = Self :: to_output_paths ( from, to, template_contents) ;
180188 let file_ops = outputs
181189 . into_iter ( )
182- . map ( |( path, content) | RenderOperation :: WriteFile ( path, content) )
190+ . map ( |( path, content) | {
191+ RenderOperation :: WriteFile ( Self :: templateable_path ( path, parser) , content)
192+ } )
183193 . collect ( ) ;
184194 Ok ( file_ops)
185195 }
186196
197+ fn templateable_path (
198+ path : PathBuf ,
199+ parser : & liquid:: Parser ,
200+ ) -> crate :: renderer:: TemplateablePath {
201+ let path_str = path. display ( ) . to_string ( ) ;
202+ if !path_str. contains ( "{{" ) {
203+ return crate :: renderer:: TemplateablePath :: Plain ( path) ;
204+ }
205+
206+ match parser. parse ( & path_str) {
207+ Ok ( t) => crate :: renderer:: TemplateablePath :: Template ( t) ,
208+ Err ( _) => crate :: renderer:: TemplateablePath :: Plain ( path) ,
209+ }
210+ }
211+
187212 async fn special_values ( & self ) -> HashMap < String , String > {
188213 let mut values = HashMap :: new ( ) ;
189214
@@ -206,10 +231,15 @@ impl Run {
206231 fn generation_target_dir ( & self ) -> PathBuf {
207232 match & self . options . variant {
208233 TemplateVariantInfo :: NewApplication => self . options . output_path . clone ( ) ,
209- TemplateVariantInfo :: AddComponent { manifest_path } => manifest_path
210- . parent ( )
211- . unwrap ( )
212- . join ( & self . options . output_path ) ,
234+ TemplateVariantInfo :: AddComponent { manifest_path } => {
235+ let root = manifest_path. parent ( ) . unwrap ( ) ;
236+
237+ if self . template . use_root ( & self . options . variant ) {
238+ root. to_owned ( )
239+ } else {
240+ root. join ( & self . options . output_path )
241+ }
242+ }
213243 }
214244 }
215245
0 commit comments