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

Layout support #8

merged 25 commits into from
Jun 27, 2019

Conversation

derekrushforth
Copy link
Contributor

@derekrushforth derekrushforth commented Jun 25, 2019

Hey @ibalosh and @matt-west,

This pull request adds layout support to our templates pull and templates push commands. Looking for whatever feedback you guys have about the code and changes to the workflow. I'd love to release this by EOD Thursday (6/27).

templates pull

The folder structure downloaded from this command is a little different now. Templates and layouts are now organized into separate folders:

my-emails
├── layouts
│   └── plain
│       ├── content.html
│       ├── content.txt
│       └── meta.json
└── templates
    ├── password-reset
    │   ├── content.html
    │   ├── content.txt
    │   └── meta.json
    └── welcome
        ├── content.html
        └── meta.json

Changes to meta.json
There are a couple minor differences between the meta.json files for templates versus layouts.

  • templates - Has a new field called LayoutTemplate that lets people specify the layout alias being used for that particular standard template. It's not required. If users don't include this in the push command, we simply insert LayoutTemplate: null into the API request. This ensures that the layout is not changed at all. If you want to remove the layout being used on a template completely, pass an empty string to LayoutTemplate. This is how our public API works.
  • layouts - Only the Name and Alias are required. Does not include the Subject field.

templates push

This command now requires that the directory structure matches what you see above. Since this is a breaking change for anybody using the old version, I've bumped the major to 2.0.0.

Here's what pushing a template looks like now:
Screen Shot 2019-06-25 at 11 26 56 AM

  • Two separate lists for templates and layouts. I kept it similar to the push screen in our UI.
  • You can see if a template is now using a different layout than what's on the server (see the welcome alias in the screenshot)
  • Minor tweaks to the copy to account for layouts

Tests

I've modified the tests a bit so they work with the new folders. The tests for the pull command also now check for an empty layout directory. This was only so I could get the tests to pass for now.

@ibalosh, can you tweak these so that we account for layouts on the test server?

cc @rianvdm

@@ -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.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "postmark-cli",
"version": "1.0.0",
"version": "2.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this version bump is too high. First digit is reserved for major changes, we could probably go by something like 1.1.0 since there is a new feature being released.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, though I just noticed you introduced it due folder structure.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to do this without breaking existing integrations? Perhaps putting the "layouts" folder inside of the root download folder, or specifying the type as "Layout" within the metadata.json for the template? I think there are probably some other benefits to not splitting them into separate folders at the root.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with not breaking existing integrations. Also my concern here is already having version 2 for app that is 1 month old. The feature is not that big in terms of CLI to justify that big change.

I do like though the folder split, since it follows the UI, and makes search through the list and separation easier. Although from what I see it would be easy to have them all in single folder since the name seems Alias based, therefore unique.

If we would like current new structure, there should be though an easy migration. All that would need to be done is check current folder structure (whether there is templates folder with subfolders) and provide a message to user that the files are migrated to new format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that 2.0.0 is a huge bump for something so new, so I was reluctant about doing this.

We should still strive for separation between standard templates and layouts somehow to make layouts easy to find and avoid additional configuration in meta.json. I often find myself needing to quickly do spot fixes in the layout, so this would be helpful. I suggest that we go with Andrew's suggestion and just add a layouts folder to the list of standard templates in the root, so it's not a breaking change.

my-emails
├── _layouts
│   └── plain
│       ├── content.html
│       ├── content.txt
│       └── meta.json
└── password-reset
│   ├── content.html
│   ├── content.txt
│   └── meta.json
└── welcome
    ├── content.html
    └── meta.json

The reason for the underscore in the layouts folder name is so that it's more likely to appear at the top of the list. It's also to reduce the likelihood that it will conflict with existing aliases.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for being flexible, @derekrushforth. I do think that as a convention, placing files in these folders

_layouts, _partials, etc. will be useful.

However, for a newcomer it may be non-obvious that the name of the folder is going to affect the type of template that gets saved. It also brings in another complication with moving templates, as changing the folder structure could cause the template type to change, which would be bad. If we think of each folder as being a "self contained" template, with all the info needed inside of it, maybe the problem gets easier...

By default, when we "pull" templates, this structure could work, but when "pushing" we're simply looking for directories that have the meta.json, content.html, and content.txt files.

From there, meta.json handles any extra properties that need to be included, including type, but the _layouts directory is purely a default convention we provide, rather than a requirement to maintain template information.

It's certainly more complicated to resolve all of the templates when pushing/pulling, but this would give a lot of flexibility in the customer grouping these templates into sub-groups, etc on their end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@atheken definitely get what you're saying here. I like the idea of letting people change the folder structure to whatever they want, but yeah, this complicates things quite a bit.

My biggest concern is how we handle the process for pulling templates. We will need to figure out where each template is specifically located if they decided not to use our default folder structure.

I'm not so concerned about pushing, though. It's easier for me to rely on the template's metadata file instead of assuming template types based on the folder structure.

I'll give this a shot and let you know how it goes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the big take away for the moment is that we don't "move" templates to new locations compared to the 1.0 release and we should include the template type in meta.json -- Standard would be assumed when not set.

Beyond that, defaulting to using a "_layouts" folder for new layouts is a good option.

We can layer on the "make your own folder structure later."

Copy link

@matt-west matt-west left a comment

Choose a reason for hiding this comment

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

The code looks good @derekrushforth! I tested pulling/pushing templates + layouts and it worked perfectly.

@ibalosh
Copy link
Contributor

ibalosh commented Jun 26, 2019

@derekrushforth added base tests which should be good for release, for stuff like pulling layouts, pushing them with changes, etc

Continue storing templates in root so that we don’t introduce breaking changes.
…ry structure

- Read TemplateType field from meta.json
- Ability to traverse any folder structure
@derekrushforth
Copy link
Contributor Author

derekrushforth commented Jun 26, 2019

Hey folks,

I've updated the workflow based on the feedback. Here's a rundown:

  • TemplateType is now determined by what's specified in meta.json, instead of assuming based on the folder structure
  • Pushing no longer requires a strict folder structure. The command will traverse the folders so that you can organize templates and layouts however you want. As long as a single meta.json file and either HTML or Text content files are present in the same folder, it's good.
  • Pulling templates adds the layouts to a _layouts folder and standard templates will remain in the root directory. This is so that we do not introduce breaking changes. The only caveat is that we are not doing anything to detect whether the user has a custom folder structure. If you pull, then make major changes to your structure, then pull again, it's going to use our default structure. I'll look into introducing this as a separate feature release.
my-emails
├── _layouts
│   └── plain
│       ├── content.html
│       ├── content.txt
│       └── meta.json
└── password-reset
│   ├── content.html
│   ├── content.txt
│   └── meta.json
└── welcome
    ├── content.html
    └── meta.json
  • Version changed to 1.1.0
  • @ibalosh I also tweaked the tests so that they work with the new folder structure. Feel free to make any changes there.

Let me know what you guys think. If we're good, please approve the PR.

Copy link
Contributor

@ibalosh ibalosh left a comment

Choose a reason for hiding this comment

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

good to go @derekrushforth

@derekrushforth derekrushforth merged commit a098d5f into master Jun 27, 2019
@derekrushforth derekrushforth deleted the feature/layout-support branch June 27, 2019 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants