-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 66c3e1e
Showing
47 changed files
with
6,699 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"semi": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: "npm" | ||
- run: yarn | ||
- run: yarn build | ||
- run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# This gets generated by the CLI when we test locally | ||
src/emails | ||
|
||
# Mac | ||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nodejs 16.14.2 | ||
yarn 1.22.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Peter Sugihara | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
<img src="https://user-images.githubusercontent.com/609038/163605455-478b8883-235c-4803-9b48-fc2d9a912b73.png#gh-dark-mode-only" alt="Mailling logo" width="295" height="128"/> | ||
<img src="https://user-images.githubusercontent.com/609038/163605459-12c1d04b-9891-4c73-9ed0-fbccddfaa476.png#gh-light-mode-only" alt="Mailling logo" width="295" height="128"/> | ||
|
||
<h2>● Send great emails from your react app.</h2> | ||
|
||
- Email templates with React components | ||
- Battle-tested MJML components that work across clients (Outlook!) | ||
- Mail previews for quick development | ||
- Test-mode for ensuring emails send and have the correct content | ||
- Inspired by ActionMailer | ||
- Plays well with js frameworks like redwood.js, remix, next.js | ||
- Written in Typescript | ||
|
||
<br/> | ||
|
||
# TODO: VIDEO HERE | ||
|
||
<br/> | ||
|
||
## ● Why? | ||
|
||
We love good emails. Usage metrics imply that a lot of people do. But every web developer I've ever met hates making them. So, we're trying to make coding them easy. | ||
|
||
<br/> | ||
|
||
## ● Setup | ||
|
||
1. Install mailing in your package.json with yarn or npm. [TODO] | ||
|
||
`npm install mailing mjml mjml-react` or `yarn add mailing mjml mjml-react` | ||
|
||
2. Install the mailing cli tool as a dev dependency [TODO] | ||
|
||
`npm install --save-dev mailing/cli` or `yarn add mailing cli --dev` | ||
|
||
3. Scaffold your `email` directory with `mailing init`. [WORKS] | ||
|
||
This will create the following directory structure: | ||
|
||
``` | ||
emails | ||
├── MyFirstEmail.tsx | ||
├── components | ||
│ ├── Body.tsx | ||
│ └── Header.tsx | ||
├── index.ts | ||
└── previews | ||
└── MyFirstEmail.tsx | ||
``` | ||
|
||
4. Configure your email transport in `email/index.ts`. It defaults to nodemailer's SMTP transport, but you can read about others [here](https://nodemailer.com/transports/). [TODO] | ||
|
||
```tsx | ||
import nodemailer from "nodemailer"; | ||
import { Mailing } from "mailing"; | ||
|
||
const transport = nodemailer.createTransport({ | ||
pool: true, | ||
host: "smtp.example.com", | ||
port: 465, | ||
secure: true, // use TLS | ||
auth: { | ||
user: "username", | ||
pass: "password", | ||
}, | ||
}); | ||
|
||
export default new Mailing({ transport }); | ||
``` | ||
|
||
5. Then send you first email like so: | ||
|
||
```tsx | ||
import { sendMail, MyFirstEmail } from "emails"; | ||
|
||
sendMail(<MyFirstEmail firstName="Bob" />); | ||
``` | ||
|
||
<br/> | ||
|
||
## ● Adding to a next.js app | ||
|
||
TODO | ||
|
||
<br/> | ||
|
||
## Developing with email previews | ||
|
||
Mailing includes a development mode for previewing your emails. Run `mailing preview` to boot the preview app and examine previews for different cases. Previews live reload when files in the emails directory change. [Needs e2e tests] | ||
|
||
[ADD SCREENSHOT OF PREVIEW INDEX] | ||
|
||
<br/> | ||
|
||
## ● Testing emails with jest | ||
|
||
```tsx | ||
import { getTestMessageQueue } from "emails"; | ||
|
||
describe("Example API", () => { | ||
it("sends an email when an issue is ready for review", () => { | ||
// DO SOMETHING THAT SHOULD SEND AN EMAIL | ||
|
||
const emails = await getTestMessageQueue(); | ||
expect(emails.length).toBe(1); | ||
expect(emails[0].subject).toMatch("Re: An issue title"); | ||
expect(emails[0].html).toMatch("READY FOR REVIEW"); | ||
expect(emails[0].html).toMatch("ready for QA"); | ||
}); | ||
}); | ||
``` | ||
|
||
<br/> | ||
|
||
## ● Contributing | ||
|
||
Want to help make this? Cool! | ||
|
||
### Setup | ||
|
||
1. Ensure you have nodejs 12+ setup. | ||
|
||
2. Run these to install the project | ||
|
||
```zsh | ||
git clone [email protected]:psugihara/mailing.git | ||
cd mailing | ||
npm install | ||
npm build # compiles the project to /lib | ||
npm link # symlinks the node module | ||
mailing # this command is defined as bin in package.json | ||
``` | ||
|
||
At this point you should also be able to link import. | ||
|
||
- `src` has the source code | ||
- `lib` is the build directory, no need to manually edit | ||
|
||
### Plan | ||
|
||
show hn requirements | ||
|
||
- [x] setup package with lib and cli | ||
- [x] generate emails directory | ||
- [~] email.ts API | ||
- [ ] basic tests for lib | ||
- [~] basic tests for cli (init test) | ||
- [~] email previews (working on this next) | ||
- [ ] polished README | ||
- [x] logo | ||
- [x] rename (react-mailer, gigaben, mailing, omail, mailbus, must be available on npmjs.com) | ||
- [ ] instructions for next.js integration | ||
- [ ] publish to npm | ||
- [ ] add video to readme | ||
- [ ] split into 2 packages so that preview server is not included | ||
|
||
--- | ||
|
||
just below the line | ||
|
||
- [ ] instructions for redwood.js integration | ||
- [ ] instructions for remix.run integration | ||
- [ ] faktory integration | ||
- [ ] mailing.run website | ||
|
||
#### API | ||
|
||
_`sendMail(mail: ComponentMail)`_ | ||
|
||
Send | ||
|
||
```ts | ||
type Mail | ||
namespace mailing { | ||
export type ComponentMail = { | ||
from: string; | ||
to: string | string[]; | ||
cc?: string | string[]; | ||
bcc?: string | string[]; | ||
subject: string; | ||
component: ReactElement<any, string | JSXElementConstructor<any>>; | ||
text?: string; | ||
headers?: { [key: string]: string }; | ||
}; | ||
export type SendMailOptions = { | ||
transport: Transporter; | ||
defaulFrom?: string; | ||
forceDeliver?: boolean; | ||
forcePreview?: boolean; | ||
}; | ||
} | ||
``` | ||
|
||
The CLI gets installed in `node_modules/.bin` as `mailing` and `mm` for short. | ||
|
||
`mm` alias for `mailing init` | ||
`mailing init` initializes a project then starts the development server | ||
`mailing preview` launches the development server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"@babel/react", | ||
["@babel/preset-typescript", { "isTSX": true, "allExtensions": true }] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require("./cli/dist/mailing-cli.cjs.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
setupFilesAfterEnv: ["<rootDir>/testSetup.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"verbose": true, | ||
"ignore": ["lib/*"] | ||
} |
Oops, something went wrong.