Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9dffdfa
configuration for tests
hybernaut Dec 14, 2016
abb4d27
more test config cleanup
hybernaut Dec 14, 2016
86c4d29
basic grunt task implemented
hybernaut Dec 14, 2016
e8ae024
read template files from filesystem
hybernaut Dec 15, 2016
4057b64
remove debug
hybernaut Dec 15, 2016
d988011
TODO for validating htmlBody/htmlFile etc.
hybernaut Dec 15, 2016
aac24c8
pretty good support for creating a server
hybernaut Dec 15, 2016
0873473
make create server task idempotent
hybernaut Dec 16, 2016
bcef316
refactor postmark-servers task using more idiomatic grunt usage
hybernaut Dec 16, 2016
71ccf91
duplicate test requires only one additional iteration, not two
hybernaut Dec 16, 2016
d3331ca
collect serverToken from secrets.json
hybernaut Dec 23, 2016
a48658c
read template config from templates.json
hybernaut Dec 23, 2016
a650a90
clean up example template files
hybernaut Dec 23, 2016
d87365d
simplify configuration
hybernaut Dec 23, 2016
bb51efc
use more canonical htmlBody and textBody
hybernaut Dec 23, 2016
3967d29
read templates.json in the postmark-templates task
hybernaut Dec 23, 2016
82fb13c
checkpoint: making progress toward saving templateID output
hybernaut Jan 3, 2017
a0a6f6d
output template info (including IDs) in templates.json format
hybernaut Jan 4, 2017
8fb62e5
update existing templates if templateID is present
hybernaut Jan 4, 2017
a518367
if update fails with bad Id, then revert to create
hybernaut Jan 4, 2017
6131196
move postmark-servers task to separate PR
hybernaut Jan 4, 2017
ac17e37
remove references to postmark-servers (for another PR)
hybernaut Jan 4, 2017
f3a7f7e
one last comment
hybernaut Jan 4, 2017
4a0b60c
node.js style callback
hybernaut Jan 13, 2017
aa3194b
simplify configuration following suggestions from @derekrushforth
hybernaut Jan 13, 2017
90ec805
log "created" vs "updated"
hybernaut Jan 13, 2017
315fd19
sample Gruntfile reads templates.json or defaults to inline config
hybernaut Jan 13, 2017
19fc6c4
Add the ability for `mailmason` to generate and upload/update templates.
randytarampi Jul 8, 2017
253a587
Further decouple `grunt-postmark` from `mailmason`.
randytarampi Dec 11, 2017
ee632f2
Add `postmark-templates-parse` and `postmark-templates-from-file`.
randytarampi Jan 8, 2018
b7e7a42
Add some documentation around `postmark-templates`.
randytarampi Jan 8, 2018
2cfb716
Bump version to `0.0.8`.
randytarampi Jan 8, 2018
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.idea
secrets.json
config.json
secrets.json
71 changes: 56 additions & 15 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,76 @@
* https://github.com/wildbit/grunt-postmark.git
*/

module.exports = function(grunt) {
module.exports = function (grunt) {
var secret = grunt.file.readJSON('secrets.json');
var config = grunt.file.readJSON('config.json');

grunt.initConfig({
secrets: grunt.file.readJSON('secrets.json'),
secret: secret,
config: config,

/* Postmark
------------------------------------------------- */
------------------------------------------------- */
postmark: {
options: {
serverToken: '<%= secrets.serverToken %>'
serverToken: "<%= secret.postmark.server_token %>"
},
email: {
from: '[email protected]',
to: '[email protected]',
subject: 'Yo',
src: ['test/email.html']
from: "<%= config.postmark.from %>",
to: "<%= config.postmark.to %>",
subject: "<%= config.postmark.subject %>",
src: ["test/email.html"]
},
bulk: {
from: '[email protected]',
to: '[email protected]',
subject: 'Hey',
src: ['test/*.html']
from: "<%= config.postmark.from %>",
to: "<%= config.postmark.to %>",
subject: "<%= config.postmark.subject %>",
src: ["test/*.html"]
}
}
},

"postmark-templates-upload": {
options: {
ephemeralUploadResultsProperty: "<%= config.templates && config.templates.ephemeralUploadResultsProperty %>",
serverToken: "<%= secret.postmark.server_token %>"
},
test_email: {
name: "testing-postmark-templates-js1-" + new Date().valueOf(),
subject: "Testing grunt-postmark-templates",
htmlSrc: "test/email.html",
textSrc: "test/email.txt"
},
test_email_again: {
name: "testing-postmark-templates-js2-" + new Date().valueOf(),
subject: "Testing grunt-postmark-templates (again)",
htmlSrc: "test/email.html",
textSrc: "test/email.txt"
},
test_email_inline_body: {
name: "testing-postmark-templates-js3-" + new Date().valueOf(),
subject: "Testing grunt-postmark-templates (inline body)",
htmlBody: "<html><body><h1>Another email test</h1></body></html>",
textBody: "Hello from grunt-postmark-templates\n"
}
},

"postmark-templates-output": {
options: {
cleanOutput: "<%= config.templates && config.templates.cleanOutput %>",
outputFile: "<%= config.templates && config.templates.outputFile || config.templates && config.templates.file %>",
ephemeralUploadResultsProperty: "<%= config.templates && config.templates.ephemeralUploadResultsProperty %>"
}
},

"postmark-templates-parse": {
options: {
inputFile: "<%= config.templates && config.templates.inputFile || config.templates && config.templates.file %>"
}
}
});

grunt.loadTasks('tasks');
grunt.loadTasks("tasks");

grunt.registerTask('default', ['postmark']);
grunt.registerTask("default", ["postmark", "postmark-templates"]);

};
196 changes: 187 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,39 @@ After the plugin is installed, it can be enabled in your Gruntfile:
grunt.loadNpmTasks('grunt-postmark');
```

You'll need to add a [`config.json`](https://github.com/wildbit/mailmason/wiki/Getting-Started#create-configjson-required) and a [`secrets.json`](https://github.com/wildbit/mailmason/wiki/Getting-Started#create-secretsjson-optional) per the `mailmason` configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

There are several details in this wiki entry that aren't relevant to grunt-postmark so this might confuse people who aren't using MailMason.

We should replace this with setup instructions specific to grunt-postmark. I can create the wiki page and link it once we've merged this PR.


## Postmark task
_Run this task with the `grunt postmark` command._

## Options

### Options

### serverToken
#### serverToken
Your server token can be found on your server’s credentials page on [Postmark’s](http://postmarkapp.com) app.

Type: `String`


### from
#### from
This is the from address you are using to send the email. This must be a confirmed address that's set up on [Postmark’s](http://postmarkapp.com) sender signatures.

Type: `String`


### to
#### to
The address you’re sending to.

Type: `String`


### subject
#### subject

Type: `String`


## Examples
### Examples

### Options specified through target
#### Options specified through target

```javascript
grunt.initConfig({
Expand All @@ -67,7 +68,7 @@ grunt.initConfig({
});
```

### Specify options through targets or globally
#### Specify options through targets or globally
Options specified through a target will always take precedence over global options.

```javascript
Expand All @@ -89,4 +90,181 @@ grunt.initConfig({
}
}
});
```

## Postmark templates task
_Run this task with the `grunt postmark-templates` command._

The `postmark-templates` task is an alias of the `postmark-templates-from-targets` task which is itself a two stepped task – `postmark-templates-upload` followed by `postmark-templates-output`.

`postmark-templates` (`postmark-templates-from-targets`) is intended for programmatic usage from other grunt tasks.

### `postmark-templates-upload` Targets

#### name
The name of your template.

Type: `String`


#### subject
The subject line of your template.

Type: `String`

#### htmlSrc
A path to the generated HTML for your template. *Not used if `htmlBody` is specified.*

Type: `String`


#### textSrc
A path to the generated plain text for your template. *Not used if `textBody` is specified.*

Type: `String`

#### htmlBody
The generated HTML content of your template. *Not required if `htmlSrc` is specified.*

Type: `String`


#### textBody
The generated plain text content of your template. *Not required if `textSrc` is specified.*

Type: `String`


### `postmark-templates-upload` Options

#### serverToken
Your server token can be found on your server’s credentials page on [Postmark’s](http://postmarkapp.com) app.

Type: `String`


#### ephemeralUploadResultsProperty
This is the name of a temporary grunt task configuration property used to communicate the upload results between `postmark-templates-upload` and `postmark-templates-output` without having to write a temporary file. **This should be the same value as `ephemeralUploadResultsProperty` for `postmark-templates-output`.**

Type: `String`


### `postmark-templates-output` Options

#### outputFile
The name of a file to output the results of the upload to Postmark.

Type: `String`


#### cleanOutput
If `true`, do not export `htmlBody`, `htmlSrc`, `textBody` or `textSrc` in the specified `outputFile`.

Type: `Boolean`


#### ephemeralUploadResultsProperty
This is the name of a temporary grunt task configuration property used to communicate the upload results between `postmark-templates-upload` and `postmark-templates-output` without having to write a temporary file. **This should be the same value as `ephemeralUploadResultsProperty` for `postmark-templates-upload`.**

Type: `String`


### Example

```javascript
grunt.initConfig({
'postmark-templates-upload': {
options: {
serverToken: 'POSTMARK_API_TEST',
ephemeralUploadResultsProperty: 'temp'
},
test_email: {
name: 'testing-postmark-templates-js1',
subject: 'Testing grunt-postmark-templates',
htmlSrc: 'test/email.html',
textSrc: 'test/email.txt'
},
test_email_inline_body: {
name: 'testing-postmark-templates-js3',
subject: 'Testing grunt-postmark-templates (inline body)',
htmlBody: '<html><body><h1>Another email test</h1></body></html>',
textBody: 'Hello from grunt-postmark-templates\n'
}
},
'postmark-templates-output': {
options: {
cleanOutput: true,
outputFile: 'templates.json',
ephemeralUploadResultsProperty: 'temp'
}
}
});
```

## Postmark templates (from file) task
_Run this task with the `grunt postmark-templates-from-file` command._

The `postmark-templates-from-file` task invokes the `postmark-templates` task with targets read from a JSON file (via `postmark-templates-parse`).

This task is intended for standalone, manual usage.


### `postmark-templates-parse` Options

#### inputFile
The name of a file that specifies templates for uploading to Postmark. These templates take the same shape as defined by `postmark-templates-upload`. This should usually be the same value as `outputFile` for `postmark-templates-output`.

Type: `String`


### Example

In your `Gruntfile`:

```javascript
grunt.initConfig({
'postmark-templates-parse': {
options: {
inputFile: 'templates.json'
}
},
'postmark-templates-upload': {
options: {
serverToken: 'POSTMARK_API_TEST',
ephemeralUploadResultsProperty: 'temp'
}
},
'postmark-templates-output': {
options: {
cleanOutput: true,
outputFile: 'templates.json',
ephemeralUploadResultsProperty: 'temp'
}
}
});
```

In the file specified by `inputFile`, in this case, `templates.json`:

```json
{
"test_email": {
"name": "testing-postmark-templates-js1",
"subject": "Testing grunt-postmark-templates",
"htmlSrc": "test/email.html",
"textSrc": "test/email.txt"
},
"test_email_again": {
"name": "testing-postmark-templates-js2",
"subject": "Testing grunt-postmark-templates (again)",
"htmlSrc": "test/email.html",
"textSrc": "test/email.txt"
},
"test_email_inline_body": {
"name": "testing-postmark-templates-js3",
"subject": "Testing grunt-postmark-templates (inline body)",
"htmlBody": "<html><body><h1>Another email test</h1></body></html>",
"textBody": "Hello from grunt-postmark-templates\n"
}
}
```
16 changes: 16 additions & 0 deletions example_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 1. Copy this file to "config.json" for your own version that won't be
// tracked in source control.
//
// 2. Delete these comments from the configuration so Grunt doesn't get confused
{
"postmark": {
"from": "[email protected]",
"to": "[email protected]",
"subject": "Test Email"
},
"templates": {
"ephemeralUploadResultsProperty": "postmark-templates-upload-results",
"cleanOutput": true,
"file": "templates.json"
}
}
9 changes: 9 additions & 0 deletions example_secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 1. Copy this file to "secrets.json" for your own version that won't be
// tracked in source control.
//
// 2. Delete these comments from the configuration so Grunt doesn't get confused
{
"postmark": {
"server_token": "YOUR_POSTMARK_SERVER_TOKEN_HERE"
}
}
20 changes: 20 additions & 0 deletions example_templates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"test_email": {
"name": "testing-postmark-templates-js1",
"subject": "Testing grunt-postmark-templates",
"htmlSrc": "test/email.html",
"textSrc": "test/email.txt"
},
"test_email_again": {
"name": "testing-postmark-templates-js2",
"subject": "Testing grunt-postmark-templates (again)",
"htmlSrc": "test/email.html",
"textSrc": "test/email.txt"
},
"test_email_inline_body": {
"name": "testing-postmark-templates-js3",
"subject": "Testing grunt-postmark-templates (inline body)",
"htmlBody": "<html><body><h1>Another email test</h1></body></html>",
"textBody": "Hello from grunt-postmark-templates\n"
}
}
Loading