@@ -84,6 +84,14 @@ impl Run {
84
84
self . build_renderer_raw ( interaction) . await . into ( )
85
85
}
86
86
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
+
87
95
// The 'raw' in this refers to the output type, which is an ugly representation
88
96
// of cancellation: Ok(Some(...)) means a result, Ok(None) means cancelled, Err
89
97
// means error. Why have this ugly representation? Because it makes it terser to
@@ -99,7 +107,7 @@ impl Run {
99
107
// TODO: rationalise `path` and `dir`
100
108
let to = self . generation_target_dir ( ) ;
101
109
102
- if !self . options . allow_overwrite {
110
+ if !self . allow_overwrite ( ) {
103
111
match interaction. allow_generate_into ( & to) {
104
112
Cancellable :: Cancelled => return Ok ( None ) ,
105
113
Cancellable :: Ok ( _) => ( ) ,
@@ -179,11 +187,28 @@ impl Run {
179
187
let outputs = Self :: to_output_paths ( from, to, template_contents) ;
180
188
let file_ops = outputs
181
189
. into_iter ( )
182
- . map ( |( path, content) | RenderOperation :: WriteFile ( path, content) )
190
+ . map ( |( path, content) | {
191
+ RenderOperation :: WriteFile ( Self :: templateable_path ( path, parser) , content)
192
+ } )
183
193
. collect ( ) ;
184
194
Ok ( file_ops)
185
195
}
186
196
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
+
187
212
async fn special_values ( & self ) -> HashMap < String , String > {
188
213
let mut values = HashMap :: new ( ) ;
189
214
@@ -206,10 +231,15 @@ impl Run {
206
231
fn generation_target_dir ( & self ) -> PathBuf {
207
232
match & self . options . variant {
208
233
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
+ }
213
243
}
214
244
}
215
245
0 commit comments