Skip to content

Commit ee632f2

Browse files
committed
Add postmark-templates-parse and postmark-templates-from-file.
Support both the original task target based upload that `ActiveCampaign/mailmason#34` is dependent on, as well as a stripped down version of its [`postmark-templates-generate`](ActiveCampaign/mailmason@9af44cc#diff-84d8d4faaac8ca7bfe33ab2e934307c1R9) task, which just blindly reads email template configurations and applies them as task target configuration for `postmark-templates-upload`. I'm not too keen on the duplication between this and mailmason, but I don't know how else I'd iron things out other than by making mailmason write a file in its `postmark-templates-generate`, but that seems overly wasteful.
1 parent 253a587 commit ee632f2

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

Gruntfile.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ module.exports = function (grunt) {
5757

5858
"postmark-templates-output": {
5959
options: {
60-
cleanOutput: "<%= config.templates && config.templates.cleanOutput %>",
61-
outputFile: "<%= config.templates && config.templates.outputFile %>",
62-
ephemeralUploadResultsProperty: "<%= config.templates && config.templates.ephemeralUploadResultsProperty %>"
63-
},
60+
cleanOutput: "<%= config.templates && config.templates.cleanOutput %>",
61+
outputFile: "<%= config.templates && config.templates.outputFile || config.templates && config.templates.file %>",
62+
ephemeralUploadResultsProperty: "<%= config.templates && config.templates.ephemeralUploadResultsProperty %>"
63+
}
64+
},
65+
66+
"postmark-templates-parse": {
67+
options: {
68+
inputFile: "<%= config.templates && config.templates.inputFile || config.templates && config.templates.file %>"
69+
}
6470
}
6571
});
6672

example_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"templates": {
1212
"ephemeralUploadResultsProperty": "postmark-templates-upload-results",
1313
"cleanOutput": true,
14-
"outputFile": "templates.json"
14+
"file": "templates.json"
1515
}
1616
}

example_templates.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"test_email": {
3+
"name": "testing-postmark-templates-js1",
4+
"subject": "Testing grunt-postmark-templates",
5+
"htmlSrc": "test/email.html",
6+
"textSrc": "test/email.txt"
7+
},
8+
"test_email_again": {
9+
"name": "testing-postmark-templates-js2",
10+
"subject": "Testing grunt-postmark-templates (again)",
11+
"htmlSrc": "test/email.html",
12+
"textSrc": "test/email.txt"
13+
},
14+
"test_email_inline_body": {
15+
"name": "testing-postmark-templates-js3",
16+
"subject": "Testing grunt-postmark-templates (inline body)",
17+
"htmlBody": "<html><body><h1>Another email test</h1></body></html>",
18+
"textBody": "Hello from grunt-postmark-templates\n"
19+
}
20+
}

tasks/grunt-postmark-templates.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ module.exports = function (grunt) {
1010
var DEFAULT_OUTPUT_FILE_NAME = 'templates.json';
1111
var DEFAULT_CLEAN_OUTPUT = false;
1212

13+
grunt.registerTask('postmark-templates-parse', 'Parse Postmark templates for update', function () {
14+
var options = this.options({
15+
inputFile: DEFAULT_OUTPUT_FILE_NAME
16+
});
17+
var templateObjects = grunt.file.readJSON(options.inputFile || DEFAULT_OUTPUT_FILE_NAME);
18+
19+
grunt.config.set('postmark-templates-upload', Object.assign(
20+
templateObjects,
21+
{
22+
options: grunt.config.get('postmark-templates-upload.options')
23+
}
24+
));
25+
});
26+
1327
grunt.registerMultiTask('postmark-templates-upload', 'Create or update Postmark templates', function () {
1428
var done = this.async();
1529
var options = this.options({
@@ -49,7 +63,7 @@ module.exports = function (grunt) {
4963
Subject: template.subject,
5064
HtmlBody: template.htmlBody || grunt.file.read(template.htmlSrc),
5165
TextBody: template.textBody || grunt.file.read(template.textSrc),
52-
TemplateId: template.templateId,
66+
TemplateId: template.templateId
5367
};
5468

5569
if (expanded.TemplateId) {
@@ -134,5 +148,7 @@ module.exports = function (grunt) {
134148
});
135149

136150
// you can also get a JSON report of uploaded templates
137-
grunt.registerTask('postmark-templates', ['postmark-templates-upload', 'postmark-templates-output']);
151+
grunt.registerTask('postmark-templates-from-targets', ['postmark-templates-upload', 'postmark-templates-output']);
152+
grunt.registerTask('postmark-templates-from-file', ['postmark-templates-parse', 'postmark-templates-from-targets']);
153+
grunt.registerTask('postmark-templates', ['postmark-templates-from-targets']);
138154
};

0 commit comments

Comments
 (0)