Skip to content

Commit

Permalink
Merge pull request #8 from wildbit/feature/layout-support
Browse files Browse the repository at this point in the history
Layout support
  • Loading branch information
derekrushforth authored Jun 27, 2019
2 parents 0325a1f + bc57e61 commit a098d5f
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
'no-console': 'off',
eqeqeq: ['error', 'always'],
'linebreak-style': ['error', 'unix'],
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/indent': 'off',
'@typescript-eslint/member-delimiter-style': [
'error',
{ multiline: { delimiter: 'none' } },
Expand Down
Binary file modified media/push-confirm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 14 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "postmark-cli",
"version": "1.0.0",
"version": "1.1.0",
"description": "A CLI tool for managing templates, sending emails, and fetching servers on Postmark.",
"main": "./dist/index.js",
"dependencies": {
"@types/traverse": "^0.6.32",
"chalk": "^2.4.2",
"fs-extra": "^7.0.1",
"inquirer": "^6.2.1",
"lodash": "^4.17.11",
"ora": "^3.0.0",
"postmark": "^2.2.4",
"postmark": "^2.2.7",
"request": "^2.88.0",
"table": "^5.2.0",
"traverse": "^0.6.6",
"untildify": "^4.0.0",
"yargonaut": "^1.1.4",
"yargs": "^13.2.4"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/cheats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const cheatInput = (hideMessage: boolean): Promise<string> =>
choices: choices,
message: hideMessage ? '\n' : title,
},
]).then((answer: { code?: string }) => {
]).then((answer: any) => {
return resolve(answer.code)
})
})
Expand Down
38 changes: 16 additions & 22 deletions src/commands/templates/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Template,
TemplateListOptions,
TemplatePullArguments,
MetaFile,
} from '../../types'
import { log, validateToken, pluralize } from '../../utils'

Expand Down Expand Up @@ -66,9 +67,9 @@ const overwritePrompt = (serverToken: string, outputdirectory: string) => {
type: 'confirm',
name: 'overwrite',
default: false,
message: `Are you sure you want to overwrite the files in ${outputdirectory}?`,
message: `Overwrite the files in ${outputdirectory}?`,
},
]).then((answer: { overwrite?: boolean }) => {
]).then((answer: any) => {
if (answer.overwrite) {
return fetchTemplateList({
sourceServer: serverToken,
Expand Down Expand Up @@ -140,7 +141,7 @@ const processTemplates = (options: ProcessTemplatesOptions) => {
}

client
.getTemplate(template.TemplateId)
.getTemplate(template.Alias)
.then((response: Template) => {
requestCount++

Expand Down Expand Up @@ -174,9 +175,8 @@ const processTemplates = (options: ProcessTemplatesOptions) => {
* @return An object containing the HTML and Text body
*/
const saveTemplate = (outputDir: string, template: Template) => {
template = pruneTemplateObject(template)

// Create the directory
outputDir =
template.TemplateType === 'Layout' ? join(outputDir, '_layouts') : outputDir
const path: string = untildify(join(outputDir, template.Alias))

ensureDirSync(path)
Expand All @@ -191,21 +191,15 @@ const saveTemplate = (outputDir: string, template: Template) => {
outputFileSync(join(path, 'content.txt'), template.TextBody)
}

// Create metadata JSON
delete template.HtmlBody
delete template.TextBody

outputFileSync(join(path, 'meta.json'), JSON.stringify(template, null, 2))
}

/**
* Remove unneeded fields on the template object
* @returns the pruned object
*/
const pruneTemplateObject = (template: Template) => {
delete template.AssociatedServerId
delete template.Active
delete template.TemplateId
const meta: MetaFile = {
Name: template.Name,
Alias: template.Alias,
...(template.Subject && { Subject: template.Subject }),
TemplateType: template.TemplateType,
...(template.TemplateType === 'Standard' && {
LayoutTemplate: template.LayoutTemplate,
}),
}

return template
outputFileSync(join(path, 'meta.json'), JSON.stringify(meta, null, 2))
}
Loading

0 comments on commit a098d5f

Please sign in to comment.