Skip to content

Commit

Permalink
feat: support for optional types in Hygen script generator (SMS/EMAIL)
Browse files Browse the repository at this point in the history
  • Loading branch information
galezra committed Nov 30, 2021
1 parent dc7d9a7 commit 0ed0b4e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions _templates/provider/new/.eslintrc.json.ejs.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
to: providers/<%= name %>/.eslintrc.json
to: providers/<%= name %>/.eslintrc.js
---

{
"extends": "../../.eslintrc.json"
"extends": "../../.eslintrc.js"
}
5 changes: 3 additions & 2 deletions _templates/provider/new/README.ejs.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
to: providers/<%= name %>/README.md
---

<% LowerType = h.changeCase.lower(type) -%>
<% PascalName = h.changeCase.pascal(name) -%>
# Notifire <%= h.changeCase.pascal(name) %> Provider

A <%= h.changeCase.pascal(name) %> email provider library for [@notifire/core](https://github.com/notifirehq/notifire)
A <%= PascalName %> <%= LowerType %> provider library for [@notifire/core](https://github.com/notifirehq/notifire)

## Usage

Expand Down
18 changes: 12 additions & 6 deletions _templates/provider/new/prompt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module.exports = [
{
type: 'input',
name: 'name',
message: "Write the provider name camelCased:"
}
]
{
type: 'select',
name: 'type',
message: 'What type of provider is this?',
choices: ['EMAIL', 'SMS'],
},
{
type: 'input',
name: 'name',
message: 'Write the provider name camelCased:',
},
];
15 changes: 9 additions & 6 deletions _templates/provider/new/src/lib/provider.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@
to: providers/<%= name %>/src/lib/<%= name %>.provider.ts
---

<% PascalType = h.changeCase.pascal(type) -%>
<% UpperType = h.changeCase.upper(type) -%>
<% PascalName = h.changeCase.pascal(name) -%>
import {
ChannelTypeEnum,
IEmailOptions,
IEmailProvider,
ISendMessageSuccessResponse,
I<%= PascalType %>Options,
I<%= PascalType %>Provider,
} from '@notifire/core';

export class <%= h.changeCase.pascal(name) %>EmailProvider implements IEmailProvider {
channelType = ChannelTypeEnum.EMAIL as ChannelTypeEnum.EMAIL;
export class <%= PascalName %><%= PascalType %>Provider implements I<%= PascalType %>Provider {
channelType = ChannelTypeEnum.<%= UpperType %> as ChannelTypeEnum.<%= UpperType %>;

constructor(
private config: {
apiKey: string;
<%= UpperType === 'EMAIL' ? 'apiKey: string;' : null %>
}
) {
}

async sendMessage(
options: IEmailOptions
options: I<%= PascalType %>Options
): Promise<ISendMessageSuccessResponse> {


Expand Down
4 changes: 3 additions & 1 deletion _templates/provider/new/src/lib/test.provider.spec.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
to: providers/<%= name %>/src/lib/<%= name %>.provider.spec.ts
---

import { <%= h.changeCase.pascal(name) %>EmailProvider } from './<%= name %>.provider';
<% PascalName = h.changeCase.pascal(name) -%>
<% PascalType = h.changeCase.pascal(type) -%>
import { <%= PascalName %><%= PascalType %>Provider } from './<%= name %>.provider';

test('should trigger <%= name %> library correctly', async () => {

Expand Down

0 comments on commit 0ed0b4e

Please sign in to comment.