Skip to content

Commit e901238

Browse files
committed
feat: added ability to change template (closes #6)
1 parent 7373139 commit e901238

File tree

7 files changed

+3323
-2823
lines changed

7 files changed

+3323
-2823
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"presets": [
3-
["env", {
3+
["@babel/env", {
44
"targets": {
55
"node": "6.4.0"
66
}
77
}]
88
],
9+
"plugins": ["@babel/plugin-transform-runtime"],
910
"sourceMaps": "inline"
1011
}

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": ["eslint:recommended", "plugin:node/recommended"],
3+
"rules": {
4+
"no-unused-vars": "off"
5+
}
6+
}

README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99

1010
> Automatically opens your browser to preview [Node.js][node] email messages sent with [Nodemailer][]. Made for [Lad][]!
1111
12-
**[VIEW THE DEMO](demo.png)**
13-
1412

1513
## Table of Contents
1614

15+
* [Screenshot](#screenshot)
1716
* [Install](#install)
1817
* [Usage](#usage)
18+
* [Custom Preview Template and Stylesheets](#custom-preview-template-and-stylesheets)
19+
* [Debugging](#debugging)
1920
* [Options](#options)
2021
* [Contributors](#contributors)
2122
* [License](#license)
2223

2324

25+
## Screenshot
26+
27+
![demo screenshot](demo.png)
28+
29+
2430
## Install
2531

2632
[npm][]:
@@ -40,7 +46,7 @@ yarn add preview-email
4046

4147
> **NOTE**: You should probably just use [email-templates][] directly instead of using this package.
4248
43-
The function `previewEmail` returns a `Promise` which resolves with a URL. We automatically open the browser to this URL unless you specify the third argument `open` as `false` (see [Options](#options) for more info).
49+
The function `previewEmail` returns a `Promise` which resolves with a URL. We automatically open the browser to this URL unless you specify `options.open` as `false` (see [Options](#options) for more info).
4450

4551
```js
4652
const previewEmail = require('preview-email');
@@ -70,17 +76,38 @@ transport.sendMail(message).then(console.log).catch(console.error);
7076
```
7177

7278

73-
## Options
79+
## Custom Preview Template and Stylesheets
80+
81+
Using the `options.template` object, you can define your own template for rendering (e.g. get inspiration from [template.pug](template.pug) and write your own!):
82+
83+
```js
84+
const path = require('path');
7485

75-
Note that you can also pass three additional arguments to `previewEmail` function.
86+
// ...
7687

77-
These arguments are `id`, `open`, and `options` (e.g. `previewEmail(message, id, open, options)`).
88+
previewEmail(message, { template: path.join(__dirname, 'my-custom-preview-template.pug') })
89+
.then(console.log)
90+
.catch(console.error);
91+
```
92+
93+
94+
## Debugging
95+
96+
Thanks to the [debug][] package, you can easily debug output from `preview-email`:
7897

79-
By default we automatically set an `id` using `uuid.v4()` (see [uuid][] for more info).
98+
```sh
99+
DEBUG=preview-email node app.js
100+
```
80101

81-
Also, `open` is set to `true` by default - this means that we automatically open the browser for you.
82102

83-
The `options` argument is an Object which defaults to `{ wait: false }`. This object is passed along to [opn][]'s [options][opn-options].
103+
## Options
104+
105+
* `message` (Object) - a [Nodemailer message configuration object](https://nodemailer.com/message/)
106+
* `options` (Object) - an object with the following two properties:
107+
* `id` (String) - a unique ID for the file name created for the preview in `dir` (defaults to `uuid.v4()` from [uuid][])
108+
* `dir` (String) - a path to a directory for saving the generated email previews (defaults to `os.tmpdir()`, see [os docs](https://nodejs.org/api/os.html#os_os_tmpdir) for more insight)
109+
* `open` (Object or Boolean) - an options object that is passed to [open][] (defaults to `{ wait: false }`) - if set to `false` then it will not open the email automaitcally in the browser using [open][], and if set to `true` then it will default to `{ wait: false }`
110+
* `template` (String) - a file path to a `pug` template file (defaults to preview-email's [template.pug](template.pug) by default) - **this is where you can pass a custom template for rendering email previews, e.g. your own stylesheet**
84111

85112

86113
## Contributors
@@ -111,6 +138,6 @@ The `options` argument is an Object which defaults to `{ wait: false }`. This o
111138

112139
[lad]: https://lad.js.org
113140

114-
[opn]: https://github.com/sindresorhus/opn
141+
[open]: https://github.com/sindresorhus/open
115142

116-
[opn-options]: https://github.com/sindresorhus/opn#options
143+
[debug]: https://github.com/visionmedia/debug

package.json

Lines changed: 98 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,123 @@
33
"description": "Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!",
44
"version": "0.0.10",
55
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
6+
"ava": {
7+
"failFast": true,
8+
"verbose": true
9+
},
610
"bugs": {
711
"url": "https://github.com/niftylettuce/preview-email/issues",
812
"email": "niftylettuce@gmail.com"
913
},
14+
"commitlint": {
15+
"extends": [
16+
"@commitlint/config-conventional"
17+
]
18+
},
1019
"contributors": [
1120
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
1221
],
1322
"dependencies": {
14-
"bluebird": "^3.5.3",
15-
"moment": "^2.23.0",
16-
"nodemailer": "^5.1.1",
17-
"opn": "^5.4.0",
18-
"pug": "^2.0.3",
23+
"@babel/runtime": "^7.4.5",
24+
"debug": "^4.1.1",
25+
"moment": "^2.24.0",
26+
"nodemailer": "^6.2.1",
27+
"open": "^6.3.0",
28+
"pify": "^4.0.1",
29+
"pug": "^2.0.4",
1930
"uuid": "^3.3.2"
2031
},
21-
"ava": {
22-
"failFast": true,
23-
"verbose": true
24-
},
2532
"devDependencies": {
26-
"auto-bind": "^2.0.0",
27-
"ava": "^1.0.1",
28-
"babel-cli": "^6.26.0",
29-
"babel-preset-env": "^1.7.0",
30-
"codecov": "^3.1.0",
33+
"@babel/cli": "^7.4.4",
34+
"@babel/core": "^7.4.5",
35+
"@babel/plugin-transform-runtime": "^7.4.4",
36+
"@babel/preset-env": "^7.4.5",
37+
"@commitlint/cli": "^8.0.0",
38+
"@commitlint/config-conventional": "^8.0.0",
39+
"auto-bind": "^2.1.0",
40+
"ava": "^2.1.0",
41+
"codecov": "^3.5.0",
3142
"cross-env": "^5.2.0",
32-
"eslint": "^5.12.0",
33-
"eslint-config-prettier": "^3.3.0",
34-
"eslint-plugin-prettier": "^3.0.1",
35-
"husky": "^1.3.1",
36-
"lint-staged": "^8.1.0",
37-
"nyc": "^13.1.0",
38-
"prettier": "^1.15.3",
43+
"eslint": "^6.0.0",
44+
"eslint-config-xo-lass": "^1.0.3",
45+
"eslint-plugin-node": "^9.1.0",
46+
"husky": "^2.4.1",
47+
"lint-staged": "^8.2.1",
48+
"nyc": "^14.1.1",
3949
"remark-cli": "^6.0.1",
40-
"remark-preset-github": "^0.0.13",
41-
"xo": "^0.23.0"
50+
"remark-preset-github": "^0.0.14",
51+
"rimraf": "^2.6.3",
52+
"xo": "^0.24.0"
4253
},
4354
"engines": {
4455
"node": ">=6.4.0"
4556
},
57+
"files": [
58+
"lib",
59+
"template.pug"
60+
],
4661
"homepage": "https://github.com/niftylettuce/preview-email",
62+
"husky": {
63+
"hooks": {
64+
"pre-commit": "npm test",
65+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
66+
}
67+
},
4768
"keywords": [
48-
"litmus",
49-
"demo",
50-
"preview",
51-
"email",
52-
"test",
69+
"auto",
70+
"automatic",
71+
"automatically",
5372
"browser",
54-
"open",
55-
"template",
56-
"render",
57-
"letter",
58-
"opener",
59-
"opn",
6073
"chrome",
74+
"demo",
75+
"email",
6176
"emails",
62-
"templates",
6377
"engine",
64-
"pug",
65-
"show",
66-
"lad",
67-
"koa",
6878
"express",
69-
"nodemailer",
79+
"koa",
80+
"lad",
81+
"lass",
82+
"letter",
83+
"litmus",
7084
"mail",
7185
"mailer",
86+
"nodemailer",
87+
"open",
88+
"open",
89+
"opener",
90+
"opn",
91+
"preview",
92+
"pug",
93+
"render",
94+
"show",
7295
"smtp",
73-
"automatic",
74-
"automatically",
75-
"auto",
76-
"lass"
96+
"template",
97+
"templates",
98+
"test"
7799
],
78100
"license": "MIT",
79101
"lint-staged": {
80-
"*.{js,jsx,mjs,ts,tsx,css,less,scss,json,graphql}": [
81-
"prettier --write --single-quote --trailing-comma none",
82-
"git add"
83-
],
84-
"*.md": [
85-
"remark . -qfo",
86-
"git add"
87-
]
102+
"linters": {
103+
"*.js": [
104+
"xo --fix",
105+
"git add"
106+
],
107+
"*.md": [
108+
"remark . -qfo",
109+
"git add"
110+
],
111+
"package.json": [
112+
"fixpack",
113+
"git add"
114+
]
115+
}
88116
},
89117
"main": "lib/index.js",
90-
"files": [
91-
"lib",
92-
"template.pug"
93-
],
118+
"prettier": {
119+
"singleQuote": true,
120+
"bracketSpacing": true,
121+
"trailingComma": "none"
122+
},
94123
"remarkConfig": {
95124
"plugins": [
96125
"preset-github"
@@ -101,43 +130,21 @@
101130
"url": "https://github.com/niftylettuce/preview-email"
102131
},
103132
"scripts": {
133+
"ava": "cross-env NODE_ENV=test DEBUG=preview-email ava",
134+
"build": "npm run build:clean && npm run build:lib",
135+
"build:clean": "rimraf lib dist",
136+
"build:lib": "babel src --out-dir lib",
104137
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
105-
"lint": "xo && remark . -qfo",
106-
"precommit": "lint-staged && npm test",
107-
"test": "npm run build && npm run lint && npm run test-coverage",
108-
"test-coverage": "cross-env NODE_ENV=test nyc ava",
109-
"build": "node_modules/.bin/babel src --out-dir lib",
110-
"watch": "node_modules/.bin/babel src --watch --out-dir lib"
138+
"lint": "xo && remark . -qfo && eslint lib",
139+
"nyc": "cross-env NODE_ENV=test nyc ava",
140+
"test": "npm run build && npm run lint && npm run ava",
141+
"test-coverage": "npm run build && npm run lint && npm run nyc"
111142
},
112143
"xo": {
113-
"extends": "prettier",
114-
"plugins": [
115-
"prettier"
116-
],
117-
"parserOptions": {
118-
"sourceType": "script"
119-
},
120-
"rules": {
121-
"prettier/prettier": [
122-
"error",
123-
{
124-
"singleQuote": true,
125-
"bracketSpacing": true,
126-
"trailingComma": "none"
127-
}
128-
],
129-
"max-len": [
130-
"error",
131-
{
132-
"code": 80,
133-
"ignoreUrls": true
134-
}
135-
],
136-
"capitalized-comments": "off",
137-
"camelcase": "off",
138-
"no-warning-comments": "off",
139-
"no-use-extend-native/no-use-extend-native": "off"
140-
},
141-
"space": true
144+
"prettier": true,
145+
"space": true,
146+
"extends": [
147+
"xo-lass"
148+
]
142149
}
143150
}

0 commit comments

Comments
 (0)