Skip to content

Commit c8945b4

Browse files
committed
Removed fs-extra dependency, Upgraded dependencies
1 parent 77ec0df commit c8945b4

File tree

3 files changed

+1841
-892
lines changed

3 files changed

+1841
-892
lines changed

package.json

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "preview-email",
3-
"description":
4-
"Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!",
3+
"description": "Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!",
54
"version": "0.0.7",
65
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
76
"bugs": {
@@ -12,34 +11,34 @@
1211
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
1312
],
1413
"dependencies": {
15-
"fs-extra": "^4.0.2",
16-
"moment": "^2.18.1",
17-
"nodemailer": "^4.2.0",
18-
"opn": "^5.1.0",
19-
"pug": "^2.0.0-rc.4",
20-
"uuid": "^3.1.0"
14+
"bluebird": "^3.5.1",
15+
"moment": "^2.22.2",
16+
"nodemailer": "^4.6.8",
17+
"opn": "^5.3.0",
18+
"pug": "^2.0.3",
19+
"uuid": "^3.3.2"
2120
},
2221
"ava": {
2322
"failFast": true,
2423
"verbose": true
2524
},
2625
"devDependencies": {
27-
"auto-bind": "^1.1.0",
28-
"ava": "^0.22.0",
26+
"auto-bind": "^1.2.1",
27+
"ava": "^0.25.0",
2928
"babel-cli": "^6.26.0",
30-
"babel-preset-env": "^1.6.1",
31-
"codecov": "^2.3.0",
32-
"cross-env": "^5.0.5",
33-
"eslint": "^4.5.0",
34-
"eslint-config-prettier": "^2.3.0",
35-
"eslint-plugin-prettier": "^2.2.0",
29+
"babel-preset-env": "^1.7.0",
30+
"codecov": "^3.0.4",
31+
"cross-env": "^5.2.0",
32+
"eslint": "^5.4.0",
33+
"eslint-config-prettier": "^3.0.1",
34+
"eslint-plugin-prettier": "^2.6.2",
3635
"husky": "^0.14.3",
37-
"lint-staged": "^4.0.4",
38-
"nyc": "^11.1.0",
39-
"prettier": "^1.6.1",
40-
"remark-cli": "^4.0.0",
41-
"remark-preset-github": "^0.0.6",
42-
"xo": "^0.19.0"
36+
"lint-staged": "^7.2.2",
37+
"nyc": "^12.0.2",
38+
"prettier": "^1.14.2",
39+
"remark-cli": "^5.0.0",
40+
"remark-preset-github": "^0.0.8",
41+
"xo": "^0.22.0"
4342
},
4443
"engines": {
4544
"node": ">=6.4.0"
@@ -82,12 +81,20 @@
8281
"prettier --write --single-quote --trailing-comma none",
8382
"git add"
8483
],
85-
"*.md": ["remark . -qfo", "git add"]
84+
"*.md": [
85+
"remark . -qfo",
86+
"git add"
87+
]
8688
},
8789
"main": "lib/index.js",
88-
"files": ["lib", "template.pug"],
90+
"files": [
91+
"lib",
92+
"template.pug"
93+
],
8994
"remarkConfig": {
90-
"plugins": ["preset-github"]
95+
"plugins": [
96+
"preset-github"
97+
]
9198
},
9299
"repository": {
93100
"type": "git",
@@ -104,7 +111,9 @@
104111
},
105112
"xo": {
106113
"extends": "prettier",
107-
"plugins": ["prettier"],
114+
"plugins": [
115+
"prettier"
116+
],
108117
"parserOptions": {
109118
"sourceType": "script"
110119
},
@@ -126,7 +135,8 @@
126135
],
127136
"capitalized-comments": "off",
128137
"camelcase": "off",
129-
"no-warning-comments": "off"
138+
"no-warning-comments": "off",
139+
"no-use-extend-native/no-use-extend-native": "off"
130140
},
131141
"space": true
132142
}

src/index.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const path = require('path');
22
const os = require('os');
3-
const fs = require('fs-extra');
3+
const fs = require('fs');
44
const uuid = require('uuid');
55
const opn = require('opn');
66
const nodemailer = require('nodemailer');
77
const moment = require('moment');
88
const pug = require('pug');
9+
const Promise = require('bluebird');
10+
11+
const writeFile = Promise.promisify(fs.writeFile);
912

1013
const transport = nodemailer.createTransport({
1114
jsonTransport: true
@@ -22,37 +25,31 @@ const renderFilePromise = (view, locals) => {
2225
});
2326
};
2427

25-
const previewEmail = (message, id, open = true) => {
26-
return new Promise(async (resolve, reject) => {
27-
try {
28-
if (typeof message !== 'object')
29-
throw new Error('Message argument is required');
28+
const previewEmail = async (message, id, open = true) => {
29+
if (typeof message !== 'object')
30+
throw new Error('Message argument is required');
3031

31-
if (!id) id = uuid.v4();
32+
if (!id) id = uuid.v4();
3233

33-
const res = await transport.sendMail(message);
34+
const res = await transport.sendMail(message);
3435

35-
res.message = JSON.parse(res.message);
36+
res.message = JSON.parse(res.message);
3637

37-
const html = await renderFilePromise(
38-
templateFilePath,
39-
Object.assign(res.message, {
40-
cache: true,
41-
pretty: true,
42-
moment
43-
})
44-
);
38+
const html = await renderFilePromise(
39+
templateFilePath,
40+
Object.assign(res.message, {
41+
cache: true,
42+
pretty: true,
43+
moment
44+
})
45+
);
4546

46-
const filePath = `${os.tmpdir()}/${id}.html`;
47-
await fs.writeFile(filePath, html);
47+
const filePath = `${os.tmpdir()}/${id}.html`;
48+
await writeFile(filePath, html);
4849

49-
if (open) await opn(filePath, { wait: false });
50+
if (open) await opn(filePath, { wait: false });
5051

51-
resolve(`file://${filePath}`);
52-
} catch (err) {
53-
reject(err);
54-
}
55-
});
52+
return `file://${filePath}`;
5653
};
5754

5855
module.exports = previewEmail;

0 commit comments

Comments
 (0)