Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout support #8

Merged
merged 25 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d4fc52
Ability to pull and push layouts [WIP]
derekrushforth Jun 19, 2019
b4fef10
Update tests [WIP]
derekrushforth Jun 20, 2019
6df5816
Check if template or layout directory exists before parsing
derekrushforth Jun 20, 2019
a1a7144
Disable indentation errors in ESLint due to conflicts with Prettier
derekrushforth Jun 20, 2019
e8e5d8a
Improve process for pushing templates and layouts
derekrushforth Jun 20, 2019
84c7f5f
Minor formatting tweak
derekrushforth Jun 20, 2019
8fd74da
Improve review table when pushing
derekrushforth Jun 21, 2019
a91c1b1
Remove unneeded types
derekrushforth Jun 24, 2019
01f8990
Update test
derekrushforth Jun 24, 2019
09c5d2e
Update types
derekrushforth Jun 24, 2019
c30c98a
Update push confirmation screenshot
derekrushforth Jun 24, 2019
d49d425
Bump version
derekrushforth Jun 24, 2019
575bf05
Update postmark.js package
derekrushforth Jun 25, 2019
ff63f99
Fix test
derekrushforth Jun 25, 2019
b33f308
Fix expected return value
derekrushforth Jun 25, 2019
c399ebf
Fix incompatible types in node 7
derekrushforth Jun 25, 2019
0caa91f
added layouts tests for pushes and pulls
ibalosh Jun 26, 2019
140357e
Only store layouts in separate folder
derekrushforth Jun 26, 2019
e28e55d
v1.1.0
derekrushforth Jun 26, 2019
613e79a
Format with Prettier
derekrushforth Jun 26, 2019
1c01bab
Update tests to work with new folder structure
derekrushforth Jun 26, 2019
1c69bb7
Pushing templates no longer determines template type based on directo…
derekrushforth Jun 26, 2019
43e684e
Clean up
derekrushforth Jun 26, 2019
9a6cfb5
More clean up
derekrushforth Jun 26, 2019
bc57e61
Code refactor
derekrushforth Jun 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason specifying a type on the answer value doesn't work in node 7.

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