From 62084378f1d5d28da3abc9844709bbef47b1cfed Mon Sep 17 00:00:00 2001 From: Derek Rushforth Date: Tue, 7 Jan 2020 00:52:07 -0700 Subject: [PATCH 1/7] Save suggested template model when pulling --- src/commands/templates/pull.ts | 21 +++++++++++++++++---- src/types/Template.ts | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/commands/templates/pull.ts b/src/commands/templates/pull.ts index c88bd4e..3b1fee0 100644 --- a/src/commands/templates/pull.ts +++ b/src/commands/templates/pull.ts @@ -157,7 +157,7 @@ const processTemplates = (options: ProcessTemplatesOptions) => { requestCount++ // Save template to file system - saveTemplate(outputDir, response) + saveTemplate(outputDir, response, client) totalDownloaded++ // Show feedback when finished saving templates @@ -185,7 +185,7 @@ const processTemplates = (options: ProcessTemplatesOptions) => { * Save template * @return An object containing the HTML and Text body */ -const saveTemplate = (outputDir: string, template: Template) => { +const saveTemplate = (outputDir: string, template: Template, client: any) => { outputDir = template.TemplateType === 'Layout' ? join(outputDir, '_layouts') : outputDir const path: string = untildify(join(outputDir, template.Alias)) @@ -202,7 +202,7 @@ const saveTemplate = (outputDir: string, template: Template) => { outputFileSync(join(path, 'content.txt'), template.TextBody) } - const meta: MetaFile = { + let meta: MetaFile = { Name: template.Name, Alias: template.Alias, ...(template.Subject && { Subject: template.Subject }), @@ -210,7 +210,20 @@ const saveTemplate = (outputDir: string, template: Template) => { ...(template.TemplateType === 'Standard' && { LayoutTemplate: template.LayoutTemplate, }), + ...(template.HtmlBody && { HtmlBody: template.HtmlBody }), + ...(template.TextBody && { TextBody: template.TextBody }), } - outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2)) + // Save suggested template model + client + .validateTemplate(meta) + .then((result: any) => { + meta.TestRenderModel = result.SuggestedTemplateModel + outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2)) + }) + .catch((error: any) => { + console.error('Error fetching suggested template model') + console.error(error) + outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2)) + }) } diff --git a/src/types/Template.ts b/src/types/Template.ts index 5c740c6..09905c2 100644 --- a/src/types/Template.ts +++ b/src/types/Template.ts @@ -83,6 +83,7 @@ export interface MetaFile { LayoutTemplate?: string | null HtmlBody?: string TextBody?: string + TestRenderModel?: any } export interface MetaFileTraverse { From f57eddaba63228f00c9253c8f7731e817a98d721 Mon Sep 17 00:00:00 2001 From: Derek Rushforth Date: Tue, 7 Jan 2020 00:52:37 -0700 Subject: [PATCH 2/7] Support test model when previewing templates --- src/commands/templates/preview.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/templates/preview.ts b/src/commands/templates/preview.ts index a2c6fb1..3b8bf49 100644 --- a/src/commands/templates/preview.ts +++ b/src/commands/templates/preview.ts @@ -134,9 +134,11 @@ const preview = (serverToken: string, args: TemplatePreviewArguments) => { if (layout && !layout.HtmlBody) return renderTemplateInvalid(res, layoutError) + const { TemplateType, TestRenderModel } = template const payload = { HtmlBody: getSource('html', template, layout), - TemplateType: template.TemplateType, + TemplateType, + TestRenderModel, } return validateTemplateRequest('html', payload, res) @@ -157,9 +159,11 @@ const preview = (serverToken: string, args: TemplatePreviewArguments) => { if (layout && !layout.TextBody) return renderTemplateInvalid(res, layoutError) + const { TemplateType, TestRenderModel } = template const payload = { TextBody: getSource('text', template, layout), - TemplateType: template.TemplateType, + TemplateType, + TestRenderModel, } return validateTemplateRequest('text', payload, res) From 1c0b251f3e87265ac8586867ad4820f190bbd2ef Mon Sep 17 00:00:00 2001 From: Derek Rushforth Date: Tue, 7 Jan 2020 17:12:05 -0700 Subject: [PATCH 3/7] =?UTF-8?q?Don=E2=80=99t=20include=20HTML=20and=20Text?= =?UTF-8?q?=20bodies=20in=20meta=20data=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/templates/pull.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/commands/templates/pull.ts b/src/commands/templates/pull.ts index 3b1fee0..ceeafb7 100644 --- a/src/commands/templates/pull.ts +++ b/src/commands/templates/pull.ts @@ -210,13 +210,15 @@ const saveTemplate = (outputDir: string, template: Template, client: any) => { ...(template.TemplateType === 'Standard' && { LayoutTemplate: template.LayoutTemplate, }), - ...(template.HtmlBody && { HtmlBody: template.HtmlBody }), - ...(template.TextBody && { TextBody: template.TextBody }), } // Save suggested template model client - .validateTemplate(meta) + .validateTemplate({ + ...(template.HtmlBody && { HtmlBody: template.HtmlBody }), + ...(template.TextBody && { TextBody: template.TextBody }), + ...meta, + }) .then((result: any) => { meta.TestRenderModel = result.SuggestedTemplateModel outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2)) From 164d5f0253b4425855e96c57bc33204074b0468b Mon Sep 17 00:00:00 2001 From: Derek Rushforth Date: Thu, 23 Jan 2020 13:50:58 -0700 Subject: [PATCH 4/7] Bump version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 563a2e5..66b9f17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "postmark-cli", - "version": "1.3.6", + "version": "1.4.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 319694d..9735948 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postmark-cli", - "version": "1.3.6", + "version": "1.4.6", "description": "A CLI tool for managing templates, sending emails, and fetching servers on Postmark.", "main": "./dist/index.js", "dependencies": { From d9aed9e575b1cc6b745e06ad2c04f50cc578cb96 Mon Sep 17 00:00:00 2001 From: Derek Rushforth Date: Thu, 23 Jan 2020 13:51:11 -0700 Subject: [PATCH 5/7] Update copyright year --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index 9652b97..723ab10 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 [Wildbit](https://wildbit.com) +Copyright (c) 2020 [Wildbit](https://wildbit.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 1e075be4c13475bea2d0f72fbc387da52e13583f Mon Sep 17 00:00:00 2001 From: Derek Rushforth Date: Thu, 23 Jan 2020 14:03:29 -0700 Subject: [PATCH 6/7] Save the metadata file when operation is complete --- src/commands/templates/pull.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/templates/pull.ts b/src/commands/templates/pull.ts index ceeafb7..32309ec 100644 --- a/src/commands/templates/pull.ts +++ b/src/commands/templates/pull.ts @@ -221,11 +221,12 @@ const saveTemplate = (outputDir: string, template: Template, client: any) => { }) .then((result: any) => { meta.TestRenderModel = result.SuggestedTemplateModel - outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2)) }) .catch((error: any) => { - console.error('Error fetching suggested template model') - console.error(error) + log('Error fetching suggested template model', { error: true }) + log(error, { error: true }) + }) + .finally(() => { outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2)) }) } From da216d17b6950dae123802b34d7ec7fada370c8c Mon Sep 17 00:00:00 2001 From: Derek Rushforth Date: Thu, 23 Jan 2020 14:54:29 -0700 Subject: [PATCH 7/7] Use then instead of finally --- src/commands/templates/pull.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/templates/pull.ts b/src/commands/templates/pull.ts index 32309ec..4182dc3 100644 --- a/src/commands/templates/pull.ts +++ b/src/commands/templates/pull.ts @@ -226,7 +226,8 @@ const saveTemplate = (outputDir: string, template: Template, client: any) => { log('Error fetching suggested template model', { error: true }) log(error, { error: true }) }) - .finally(() => { + .then(() => { + // Save the file regardless of success or error when fetching suggested model outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2)) }) }