@@ -157,7 +157,7 @@ const processTemplates = (options: ProcessTemplatesOptions) => {
157157 requestCount ++
158158
159159 // Save template to file system
160- saveTemplate ( outputDir , response )
160+ saveTemplate ( outputDir , response , client )
161161 totalDownloaded ++
162162
163163 // Show feedback when finished saving templates
@@ -185,7 +185,7 @@ const processTemplates = (options: ProcessTemplatesOptions) => {
185185 * Save template
186186 * @return An object containing the HTML and Text body
187187 */
188- const saveTemplate = ( outputDir : string , template : Template ) => {
188+ const saveTemplate = ( outputDir : string , template : Template , client : any ) => {
189189 outputDir =
190190 template . TemplateType === 'Layout' ? join ( outputDir , '_layouts' ) : outputDir
191191 const path : string = untildify ( join ( outputDir , template . Alias ) )
@@ -202,7 +202,7 @@ const saveTemplate = (outputDir: string, template: Template) => {
202202 outputFileSync ( join ( path , 'content.txt' ) , template . TextBody )
203203 }
204204
205- const meta : MetaFile = {
205+ let meta : MetaFile = {
206206 Name : template . Name ,
207207 Alias : template . Alias ,
208208 ...( template . Subject && { Subject : template . Subject } ) ,
@@ -212,5 +212,22 @@ const saveTemplate = (outputDir: string, template: Template) => {
212212 } ) ,
213213 }
214214
215- outputFileSync ( join ( path , 'meta.json' ) , JSON . stringify ( meta , null , 2 ) )
215+ // Save suggested template model
216+ client
217+ . validateTemplate ( {
218+ ...( template . HtmlBody && { HtmlBody : template . HtmlBody } ) ,
219+ ...( template . TextBody && { TextBody : template . TextBody } ) ,
220+ ...meta ,
221+ } )
222+ . then ( ( result : any ) => {
223+ meta . TestRenderModel = result . SuggestedTemplateModel
224+ } )
225+ . catch ( ( error : any ) => {
226+ log ( 'Error fetching suggested template model' , { error : true } )
227+ log ( error , { error : true } )
228+ } )
229+ . then ( ( ) => {
230+ // Save the file regardless of success or error when fetching suggested model
231+ outputFileSync ( join ( path , 'meta.json' ) , JSON . stringify ( meta , null , 2 ) )
232+ } )
216233}
0 commit comments