Skip to content

Commit

Permalink
fix(adapters): Make pug, handlebars and ejs truly optional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
刘佳闻 committed Apr 26, 2020
1 parent efa8b1c commit 981c6cf
Show file tree
Hide file tree
Showing 5 changed files with 2,203 additions and 1,128 deletions.
28 changes: 18 additions & 10 deletions docs/mailer.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Import the MailerModule into the root AppModule.
```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { PugAdapter, MailerModule } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { PugAdapter } from '@nestjs-modules/mailer/dist/adapters/pug.adapter';

@Module({
imports: [
Expand All @@ -73,7 +74,8 @@ export class AppModule {}
```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { HandlebarsAdapter, MailerModule } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';

@Module({
imports: [
Expand All @@ -99,7 +101,8 @@ export class AppModule {}
```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { EjsAdapter, MailerModule } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { EjsAdapter } from '@nestjs-modules/mailer/dist/adapters/ejs.adapter';

@Module({
imports: [
Expand Down Expand Up @@ -133,7 +136,8 @@ Of course, it is possible to use an async configuration:
```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { PugAdapter, MailerModule } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { PugAdapter } from '@nestjs-modules/mailer/dist/adapters/pug.adapter';

@Module({
imports: [
Expand All @@ -160,7 +164,8 @@ export class AppModule {}
```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { HandlebarsAdapter, MailerModule } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';

@Module({
imports: [
Expand All @@ -187,7 +192,8 @@ export class AppModule {}
```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { HandlebarsAdapter, MailerModule } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import * as handlebars from 'handlebars';

const helpers = {
Expand All @@ -201,7 +207,7 @@ const helpers = {
};

// use the formatNumber helper from handlebars-intl
const template = Handlebars.compile('{{formatNumber value}} is the final result!');
const template = handlebars.compile('{{formatNumber value}} is the final result!');

const compiled = template(context, {
data: {intl: intlData}
Expand Down Expand Up @@ -244,7 +250,8 @@ export class AppModule {}
import * as path from 'path';
import { Module } from '@nestjs/common';
import { BullModule } from 'nest-bull';
import { MailerModule, HandlebarsAdapter } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { mailBullConfig } from '../../config/mail';
import { MailService } from './mail.service';
import { MailController } from './mail.controller';
Expand Down Expand Up @@ -392,7 +399,8 @@ Use preview-email to open a preview of the email with the browser. This can be e
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { HandlebarsAdapter, MailerModule } from '@nestjs-modules/mailer';
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';

@Module({
imports: [
Expand Down Expand Up @@ -425,4 +433,4 @@ import { HandlebarsAdapter, MailerModule } from '@nestjs-modules/mailer';
})
export class AppModule {}

```
```
16 changes: 12 additions & 4 deletions lib/adapters/ejs.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ export class EjsAdapter implements TemplateAdapter {

const rendered = this.precompiledTemplates[templateName](mail.data.context);

inlineCss(rendered, { url: ' ' }).then((html) => {
mail.data.html = html;
return callback();
});
const render = (html: string) => {
inlineCss(html, { url: ' ' }).then((html) => {
mail.data.html = html;
return callback();
});
};

if (typeof rendered === 'string') {
render(rendered);
} else {
rendered.then(render);
}
}
}
5 changes: 0 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/** Modules **/
export { MailerModule } from './mailer.module';

/** Adapters **/
export { PugAdapter } from './adapters/pug.adapter';
export { HandlebarsAdapter } from './adapters/handlebars.adapter';
export { EjsAdapter } from './adapters/ejs.adapter';

/** Interfaces **/
export { MailerOptions } from './interfaces/mailer-options.interface';
export { TemplateAdapter } from './interfaces/template-adapter.interface';
Expand Down
93 changes: 49 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,68 @@
{
"name": "@nestjs-modules/mailer",
"version": "1.4.2",
"description": "NestJS - a mailer module (@mailer)",
"author": "Nest Modules TM",
"private": false,
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc -p tsconfig.json",
"format": "prettier **/**/*.ts --ignore-path ./.prettierignore --write",
"test": "jest",
"release": "standard-version",
"patch": "npm run release -- --release-as patch",
"minor": "npm run release -- --release-as minor",
"major": "npm run release -- --release-as major",
"deploy": "sh ./publish.sh"
},
"description": "NestJS - a mailer module (@mailer)",
"keywords": [
"nest",
"nodemailer",
"mailer",
"nodejs"
],
"homepage": "https://github.com/nest-modules/mailer#readme",
"bugs": {
"url": "https://github.com/nest-modules/mailer/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nest-modules/mailer.git"
},
"license": "MIT",
"author": "Nest Modules TM",
"contributors": [
"Cristiam Díaz <[email protected]>",
"Eduardo Leal <[email protected]>",
"Juan Echeverry <[email protected]>",
"Paweł Partyka <[email protected]>",
"Yanarp"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/nest-modules/mailer/issues"
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc -p tsconfig.json",
"deploy": "sh ./publish.sh",
"format": "prettier **/**/*.ts --ignore-path ./.prettierignore --write",
"major": "npm run release -- --release-as major",
"minor": "npm run release -- --release-as minor",
"patch": "npm run release -- --release-as patch",
"release": "standard-version",
"test": "jest"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -c .commitlintrc.json -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.ts": [
"prettier --write"
]
},
"homepage": "https://github.com/nest-modules/mailer#readme",
"dependencies": {
"glob": "7.1.6",
"inline-css": "2.6.3",
"preview-email": "2.0.1"
},
"peerDependencies": {
"@nestjs/common": "^6.7.0 || ^7.0.0",
"@nestjs/core": "^6.7.0 || ^7.0.0",
"nodemailer": "^6.0.0"
},
"optionalDependencies": {
"handlebars": "^4.0.0",
"pug": "^2.0.0",
"ejs": "^3.0.1"
"@types/ejs": "^3.0.2",
"@types/pug": "2.0.4",
"ejs": "^3.1.2",
"handlebars": "^4.7.6",
"pug": "^2.0.4"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-angular": "^8.3.4",
"@nestjs/common": "7.0.9",
"@nestjs/core": "7.0.9",
"@nestjs/testing": "7.0.9",
Expand All @@ -57,37 +71,28 @@
"@types/jest": "25.2.1",
"@types/lodash": "4.14.150",
"@types/nodemailer": "6.4.0",
"@types/pug": "2.0.4",
"@typescript-eslint/eslint-plugin": "2.29.0",
"@typescript-eslint/parser": "2.29.0",
"handlebars": "4.7.6",
"husky": "4.2.5",
"lint-staged": "10.1.7",
"jest": "25.4.0",
"lint-staged": "10.1.7",
"nodemailer": "6.4.6",
"prettier": "2.0.5",
"pug": "2.0.4",
"ejs": "3.1.2",
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"standard-version": "7.1.0",
"ts-jest": "25.4.0",
"ts-node": "8.9.0",
"typescript": "3.8.3"
},
"lint-staged": {
"*.ts": [
"prettier --write"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -c .commitlintrc.json -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/nest-modules/mailer.git"
"peerDependencies": {
"@nestjs/common": "^6.7.0 || ^7.0.0",
"@nestjs/core": "^6.7.0 || ^7.0.0",
"@types/ejs": "^3.0.2",
"@types/pug": "2.0.4",
"ejs": "^3.1.2",
"handlebars": "^4.7.6",
"nodemailer": "^6.0.0",
"pug": "^2.0.4"
}
}
Loading

0 comments on commit 981c6cf

Please sign in to comment.